OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * jdmrgext.c |
| 3 * |
| 4 * Copyright (C) 1994-1996, Thomas G. Lane. |
| 5 * This file is part of the Independent JPEG Group's software. |
| 6 * For conditions of distribution and use, see the accompanying README file. |
| 7 * |
| 8 * This file contains code for merged upsampling/color conversion. |
| 9 */ |
| 10 |
| 11 |
| 12 /* This file is included by jdmerge.c */ |
| 13 |
| 14 |
| 15 /* |
| 16 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. |
| 17 */ |
| 18 |
| 19 INLINE |
| 20 LOCAL(void) |
| 21 h2v1_merged_upsample_internal (j_decompress_ptr cinfo, |
| 22 JSAMPIMAGE input_buf, |
| 23 JDIMENSION in_row_group_ctr, |
| 24 JSAMPARRAY output_buf) |
| 25 { |
| 26 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
| 27 register int y, cred, cgreen, cblue; |
| 28 int cb, cr; |
| 29 register JSAMPROW outptr; |
| 30 JSAMPROW inptr0, inptr1, inptr2; |
| 31 JDIMENSION col; |
| 32 /* copy these pointers into registers if possible */ |
| 33 register JSAMPLE * range_limit = cinfo->sample_range_limit; |
| 34 int * Crrtab = upsample->Cr_r_tab; |
| 35 int * Cbbtab = upsample->Cb_b_tab; |
| 36 INT32 * Crgtab = upsample->Cr_g_tab; |
| 37 INT32 * Cbgtab = upsample->Cb_g_tab; |
| 38 SHIFT_TEMPS |
| 39 |
| 40 inptr0 = input_buf[0][in_row_group_ctr]; |
| 41 inptr1 = input_buf[1][in_row_group_ctr]; |
| 42 inptr2 = input_buf[2][in_row_group_ctr]; |
| 43 outptr = output_buf[0]; |
| 44 /* Loop for each pair of output pixels */ |
| 45 for (col = cinfo->output_width >> 1; col > 0; col--) { |
| 46 /* Do the chroma part of the calculation */ |
| 47 cb = GETJSAMPLE(*inptr1++); |
| 48 cr = GETJSAMPLE(*inptr2++); |
| 49 cred = Crrtab[cr]; |
| 50 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
| 51 cblue = Cbbtab[cb]; |
| 52 /* Fetch 2 Y values and emit 2 pixels */ |
| 53 y = GETJSAMPLE(*inptr0++); |
| 54 outptr[RGB_RED] = range_limit[y + cred]; |
| 55 outptr[RGB_GREEN] = range_limit[y + cgreen]; |
| 56 outptr[RGB_BLUE] = range_limit[y + cblue]; |
| 57 outptr += RGB_PIXELSIZE; |
| 58 y = GETJSAMPLE(*inptr0++); |
| 59 outptr[RGB_RED] = range_limit[y + cred]; |
| 60 outptr[RGB_GREEN] = range_limit[y + cgreen]; |
| 61 outptr[RGB_BLUE] = range_limit[y + cblue]; |
| 62 outptr += RGB_PIXELSIZE; |
| 63 } |
| 64 /* If image width is odd, do the last output column separately */ |
| 65 if (cinfo->output_width & 1) { |
| 66 cb = GETJSAMPLE(*inptr1); |
| 67 cr = GETJSAMPLE(*inptr2); |
| 68 cred = Crrtab[cr]; |
| 69 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
| 70 cblue = Cbbtab[cb]; |
| 71 y = GETJSAMPLE(*inptr0); |
| 72 outptr[RGB_RED] = range_limit[y + cred]; |
| 73 outptr[RGB_GREEN] = range_limit[y + cgreen]; |
| 74 outptr[RGB_BLUE] = range_limit[y + cblue]; |
| 75 } |
| 76 } |
| 77 |
| 78 |
| 79 /* |
| 80 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. |
| 81 */ |
| 82 |
| 83 INLINE |
| 84 LOCAL(void) |
| 85 h2v2_merged_upsample_internal (j_decompress_ptr cinfo, |
| 86 JSAMPIMAGE input_buf, |
| 87 JDIMENSION in_row_group_ctr, |
| 88 JSAMPARRAY output_buf) |
| 89 { |
| 90 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
| 91 register int y, cred, cgreen, cblue; |
| 92 int cb, cr; |
| 93 register JSAMPROW outptr0, outptr1; |
| 94 JSAMPROW inptr00, inptr01, inptr1, inptr2; |
| 95 JDIMENSION col; |
| 96 /* copy these pointers into registers if possible */ |
| 97 register JSAMPLE * range_limit = cinfo->sample_range_limit; |
| 98 int * Crrtab = upsample->Cr_r_tab; |
| 99 int * Cbbtab = upsample->Cb_b_tab; |
| 100 INT32 * Crgtab = upsample->Cr_g_tab; |
| 101 INT32 * Cbgtab = upsample->Cb_g_tab; |
| 102 SHIFT_TEMPS |
| 103 |
| 104 inptr00 = input_buf[0][in_row_group_ctr*2]; |
| 105 inptr01 = input_buf[0][in_row_group_ctr*2 + 1]; |
| 106 inptr1 = input_buf[1][in_row_group_ctr]; |
| 107 inptr2 = input_buf[2][in_row_group_ctr]; |
| 108 outptr0 = output_buf[0]; |
| 109 outptr1 = output_buf[1]; |
| 110 /* Loop for each group of output pixels */ |
| 111 for (col = cinfo->output_width >> 1; col > 0; col--) { |
| 112 /* Do the chroma part of the calculation */ |
| 113 cb = GETJSAMPLE(*inptr1++); |
| 114 cr = GETJSAMPLE(*inptr2++); |
| 115 cred = Crrtab[cr]; |
| 116 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
| 117 cblue = Cbbtab[cb]; |
| 118 /* Fetch 4 Y values and emit 4 pixels */ |
| 119 y = GETJSAMPLE(*inptr00++); |
| 120 outptr0[RGB_RED] = range_limit[y + cred]; |
| 121 outptr0[RGB_GREEN] = range_limit[y + cgreen]; |
| 122 outptr0[RGB_BLUE] = range_limit[y + cblue]; |
| 123 outptr0 += RGB_PIXELSIZE; |
| 124 y = GETJSAMPLE(*inptr00++); |
| 125 outptr0[RGB_RED] = range_limit[y + cred]; |
| 126 outptr0[RGB_GREEN] = range_limit[y + cgreen]; |
| 127 outptr0[RGB_BLUE] = range_limit[y + cblue]; |
| 128 outptr0 += RGB_PIXELSIZE; |
| 129 y = GETJSAMPLE(*inptr01++); |
| 130 outptr1[RGB_RED] = range_limit[y + cred]; |
| 131 outptr1[RGB_GREEN] = range_limit[y + cgreen]; |
| 132 outptr1[RGB_BLUE] = range_limit[y + cblue]; |
| 133 outptr1 += RGB_PIXELSIZE; |
| 134 y = GETJSAMPLE(*inptr01++); |
| 135 outptr1[RGB_RED] = range_limit[y + cred]; |
| 136 outptr1[RGB_GREEN] = range_limit[y + cgreen]; |
| 137 outptr1[RGB_BLUE] = range_limit[y + cblue]; |
| 138 outptr1 += RGB_PIXELSIZE; |
| 139 } |
| 140 /* If image width is odd, do the last output column separately */ |
| 141 if (cinfo->output_width & 1) { |
| 142 cb = GETJSAMPLE(*inptr1); |
| 143 cr = GETJSAMPLE(*inptr2); |
| 144 cred = Crrtab[cr]; |
| 145 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
| 146 cblue = Cbbtab[cb]; |
| 147 y = GETJSAMPLE(*inptr00); |
| 148 outptr0[RGB_RED] = range_limit[y + cred]; |
| 149 outptr0[RGB_GREEN] = range_limit[y + cgreen]; |
| 150 outptr0[RGB_BLUE] = range_limit[y + cblue]; |
| 151 y = GETJSAMPLE(*inptr01); |
| 152 outptr1[RGB_RED] = range_limit[y + cred]; |
| 153 outptr1[RGB_GREEN] = range_limit[y + cgreen]; |
| 154 outptr1[RGB_BLUE] = range_limit[y + cblue]; |
| 155 } |
| 156 } |
OLD | NEW |