OLD | NEW |
---|---|
1 /* | 1 /* |
2 * jdcolor.c | 2 * jdcolor.c |
3 * | 3 * |
4 * Copyright (C) 1991-1997, Thomas G. Lane. | 4 * Copyright (C) 1991-1997, Thomas G. Lane. |
5 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB | 5 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
6 * Copyright (C) 2009, D. R. Commander. | 6 * Copyright (C) 2009, D. R. Commander. |
7 * This file is part of the Independent JPEG Group's software. | 7 * This file is part of the Independent JPEG Group's software. |
8 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README file. |
9 * | 9 * |
10 * This file contains output colorspace conversion routines. | 10 * This file contains output colorspace conversion routines. |
11 */ | 11 */ |
12 | 12 |
13 #define JPEG_INTERNALS | 13 #define JPEG_INTERNALS |
14 #include "jinclude.h" | 14 #include "jinclude.h" |
15 #include "jpeglib.h" | 15 #include "jpeglib.h" |
16 #include "jsimd.h" | 16 #include "jsimd.h" |
17 | 17 |
18 | 18 |
19 /* Private subobject */ | 19 /* Private subobject */ |
20 | 20 |
21 typedef struct { | 21 typedef struct { |
22 struct jpeg_color_deconverter pub; /* public fields */ | 22 struct jpeg_color_deconverter pub; /* public fields */ |
23 | 23 |
24 /* Private state for YCC->RGB conversion */ | 24 /* Private state for YCC->RGB conversion */ |
25 int * Cr_r_tab;» » /* => table for Cr to R conversion */ | 25 int * Cr_r_tab; /* => table for Cr to R conversion */ |
26 int * Cb_b_tab;» » /* => table for Cb to B conversion */ | 26 int * Cb_b_tab; /* => table for Cb to B conversion */ |
27 INT32 * Cr_g_tab;» » /* => table for Cr to G conversion */ | 27 INT32 * Cr_g_tab; /* => table for Cr to G conversion */ |
28 INT32 * Cb_g_tab;» » /* => table for Cb to G conversion */ | 28 INT32 * Cb_g_tab; /* => table for Cb to G conversion */ |
29 } my_color_deconverter; | 29 } my_color_deconverter; |
30 | 30 |
31 typedef my_color_deconverter * my_cconvert_ptr; | 31 typedef my_color_deconverter * my_cconvert_ptr; |
32 | 32 |
33 | 33 |
34 /**************** YCbCr -> RGB conversion: most common case **************/ | 34 /**************** YCbCr -> RGB conversion: most common case **************/ |
35 | 35 |
36 /* | 36 /* |
37 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are | 37 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are |
38 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. | 38 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. |
39 * The conversion equations to be implemented are therefore | 39 * The conversion equations to be implemented are therefore |
40 *» R = Y + 1.40200 * Cr | 40 * R = Y + 1.40200 * Cr |
41 *» G = Y - 0.34414 * Cb - 0.71414 * Cr | 41 * G = Y - 0.34414 * Cb - 0.71414 * Cr |
42 *» B = Y + 1.77200 * Cb | 42 * B = Y + 1.77200 * Cb |
43 * where Cb and Cr represent the incoming values less CENTERJSAMPLE. | 43 * where Cb and Cr represent the incoming values less CENTERJSAMPLE. |
44 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) | 44 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) |
45 * | 45 * |
46 * To avoid floating-point arithmetic, we represent the fractional constants | 46 * To avoid floating-point arithmetic, we represent the fractional constants |
47 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide | 47 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide |
48 * the products by 2^16, with appropriate rounding, to get the correct answer. | 48 * the products by 2^16, with appropriate rounding, to get the correct answer. |
49 * Notice that Y, being an integral input, does not contribute any fraction | 49 * Notice that Y, being an integral input, does not contribute any fraction |
50 * so it need not participate in the rounding. | 50 * so it need not participate in the rounding. |
51 * | 51 * |
52 * For even more speed, we avoid doing any multiplications in the inner loop | 52 * For even more speed, we avoid doing any multiplications in the inner loop |
53 * by precalculating the constants times Cb and Cr for all possible values. | 53 * by precalculating the constants times Cb and Cr for all possible values. |
54 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); | 54 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); |
55 * for 12-bit samples it is still acceptable. It's not very reasonable for | 55 * for 12-bit samples it is still acceptable. It's not very reasonable for |
56 * 16-bit samples, but if you want lossless storage you shouldn't be changing | 56 * 16-bit samples, but if you want lossless storage you shouldn't be changing |
57 * colorspace anyway. | 57 * colorspace anyway. |
58 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the | 58 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the |
59 * values for the G calculation are left scaled up, since we must add them | 59 * values for the G calculation are left scaled up, since we must add them |
60 * together before rounding. | 60 * together before rounding. |
61 */ | 61 */ |
62 | 62 |
63 #define SCALEBITS» 16» /* speediest right-shift on some machines */ | 63 #define SCALEBITS 16 /* speediest right-shift on some machines */ |
64 #define ONE_HALF» ((INT32) 1 << (SCALEBITS-1)) | 64 #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) |
65 #define FIX(x)» » ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) | 65 #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) |
66 | 66 |
67 | 67 |
68 /* | 68 /* |
69 * Initialize tables for YCC->RGB colorspace conversion. | 69 * Initialize tables for YCC->RGB colorspace conversion. |
70 */ | 70 */ |
71 | 71 |
72 LOCAL(void) | 72 LOCAL(void) |
73 build_ycc_rgb_table (j_decompress_ptr cinfo) | 73 build_ycc_rgb_table (j_decompress_ptr cinfo) |
74 { | 74 { |
75 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 75 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
76 int i; | 76 int i; |
77 INT32 x; | 77 INT32 x; |
78 SHIFT_TEMPS | 78 SHIFT_TEMPS |
79 | 79 |
80 cconvert->Cr_r_tab = (int *) | 80 cconvert->Cr_r_tab = (int *) |
81 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 81 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
82 » » » » (MAXJSAMPLE+1) * SIZEOF(int)); | 82 (MAXJSAMPLE+1) * SIZEOF(int)); |
83 cconvert->Cb_b_tab = (int *) | 83 cconvert->Cb_b_tab = (int *) |
84 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 84 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
85 » » » » (MAXJSAMPLE+1) * SIZEOF(int)); | 85 (MAXJSAMPLE+1) * SIZEOF(int)); |
86 cconvert->Cr_g_tab = (INT32 *) | 86 cconvert->Cr_g_tab = (INT32 *) |
87 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 87 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
88 » » » » (MAXJSAMPLE+1) * SIZEOF(INT32)); | 88 (MAXJSAMPLE+1) * SIZEOF(INT32)); |
89 cconvert->Cb_g_tab = (INT32 *) | 89 cconvert->Cb_g_tab = (INT32 *) |
90 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 90 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
91 » » » » (MAXJSAMPLE+1) * SIZEOF(INT32)); | 91 (MAXJSAMPLE+1) * SIZEOF(INT32)); |
92 | 92 |
93 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { | 93 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { |
94 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ | 94 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ |
95 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ | 95 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ |
96 /* Cr=>R value is nearest int to 1.40200 * x */ | 96 /* Cr=>R value is nearest int to 1.40200 * x */ |
97 cconvert->Cr_r_tab[i] = (int) | 97 cconvert->Cr_r_tab[i] = (int) |
98 » » RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); | 98 RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); |
99 /* Cb=>B value is nearest int to 1.77200 * x */ | 99 /* Cb=>B value is nearest int to 1.77200 * x */ |
100 cconvert->Cb_b_tab[i] = (int) | 100 cconvert->Cb_b_tab[i] = (int) |
101 » » RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); | 101 RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); |
102 /* Cr=>G value is scaled-up -0.71414 * x */ | 102 /* Cr=>G value is scaled-up -0.71414 * x */ |
103 cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; | 103 cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; |
104 /* Cb=>G value is scaled-up -0.34414 * x */ | 104 /* Cb=>G value is scaled-up -0.34414 * x */ |
105 /* We also add in ONE_HALF so that need not do it in inner loop */ | 105 /* We also add in ONE_HALF so that need not do it in inner loop */ |
106 cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; | 106 cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 /* | 111 /* |
112 * Convert some rows of samples to the output colorspace. | 112 * Convert some rows of samples to the output colorspace. |
113 * | 113 * |
114 * Note that we change from noninterleaved, one-plane-per-component format | 114 * Note that we change from noninterleaved, one-plane-per-component format |
115 * to interleaved-pixel format. The output buffer is therefore three times | 115 * to interleaved-pixel format. The output buffer is therefore three times |
116 * as wide as the input buffer. | 116 * as wide as the input buffer. |
117 * A starting row offset is provided only for the input buffer. The caller | 117 * A starting row offset is provided only for the input buffer. The caller |
118 * can easily adjust the passed output_buf value to accommodate any row | 118 * can easily adjust the passed output_buf value to accommodate any row |
119 * offset required on that side. | 119 * offset required on that side. |
120 */ | 120 */ |
121 | 121 |
122 METHODDEF(void) | 122 METHODDEF(void) |
123 ycc_rgb_convert (j_decompress_ptr cinfo, | 123 ycc_rgb_convert (j_decompress_ptr cinfo, |
124 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 124 JSAMPIMAGE input_buf, JDIMENSION input_row, |
125 » » JSAMPARRAY output_buf, int num_rows) | 125 JSAMPARRAY output_buf, int num_rows) |
126 { | 126 { |
127 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 127 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
128 register int y, cb, cr; | 128 register int y, cb, cr; |
129 register JSAMPROW outptr; | 129 register JSAMPROW outptr; |
130 register JSAMPROW inptr0, inptr1, inptr2; | 130 register JSAMPROW inptr0, inptr1, inptr2; |
131 register JDIMENSION col; | 131 register JDIMENSION col; |
132 JDIMENSION num_cols = cinfo->output_width; | 132 JDIMENSION num_cols = cinfo->output_width; |
133 /* copy these pointers into registers if possible */ | 133 /* copy these pointers into registers if possible */ |
134 register JSAMPLE * range_limit = cinfo->sample_range_limit; | 134 register JSAMPLE * range_limit = cinfo->sample_range_limit; |
135 register int * Crrtab = cconvert->Cr_r_tab; | 135 register int * Crrtab = cconvert->Cr_r_tab; |
136 register int * Cbbtab = cconvert->Cb_b_tab; | 136 register int * Cbbtab = cconvert->Cb_b_tab; |
137 register INT32 * Crgtab = cconvert->Cr_g_tab; | 137 register INT32 * Crgtab = cconvert->Cr_g_tab; |
138 register INT32 * Cbgtab = cconvert->Cb_g_tab; | 138 register INT32 * Cbgtab = cconvert->Cb_g_tab; |
139 SHIFT_TEMPS | 139 SHIFT_TEMPS |
140 | 140 |
141 while (--num_rows >= 0) { | 141 while (--num_rows >= 0) { |
142 inptr0 = input_buf[0][input_row]; | 142 inptr0 = input_buf[0][input_row]; |
143 inptr1 = input_buf[1][input_row]; | 143 inptr1 = input_buf[1][input_row]; |
144 inptr2 = input_buf[2][input_row]; | 144 inptr2 = input_buf[2][input_row]; |
145 input_row++; | 145 input_row++; |
146 outptr = *output_buf++; | 146 outptr = *output_buf++; |
147 for (col = 0; col < num_cols; col++) { | 147 for (col = 0; col < num_cols; col++) { |
148 y = GETJSAMPLE(inptr0[col]); | 148 y = GETJSAMPLE(inptr0[col]); |
149 cb = GETJSAMPLE(inptr1[col]); | 149 cb = GETJSAMPLE(inptr1[col]); |
150 cr = GETJSAMPLE(inptr2[col]); | 150 cr = GETJSAMPLE(inptr2[col]); |
151 /* Range-limiting is essential due to noise introduced by DCT losses. */ | 151 /* Range-limiting is essential due to noise introduced by DCT losses. */ |
152 outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + Crrtab[cr]]; | 152 outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + Crrtab[cr]]; |
153 outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + | 153 outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + |
154 » » » ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], | 154 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], |
155 » » » » » » SCALEBITS))]; | 155 SCALEBITS))]; |
156 outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + Cbbtab[cb]]; | 156 outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + Cbbtab[cb]]; |
157 outptr += rgb_pixelsize[cinfo->out_color_space]; | 157 outptr += rgb_pixelsize[cinfo->out_color_space]; |
158 } | 158 } |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 /**************** Cases other than YCbCr -> RGB **************/ | 163 /**************** Cases other than YCbCr -> RGB **************/ |
164 | 164 |
165 | 165 |
166 /* | 166 /* |
167 * Color conversion for no colorspace change: just copy the data, | 167 * Color conversion for no colorspace change: just copy the data, |
168 * converting from separate-planes to interleaved representation. | 168 * converting from separate-planes to interleaved representation. |
169 */ | 169 */ |
170 | 170 |
171 METHODDEF(void) | 171 METHODDEF(void) |
172 null_convert (j_decompress_ptr cinfo, | 172 null_convert (j_decompress_ptr cinfo, |
173 » JSAMPIMAGE input_buf, JDIMENSION input_row, | 173 JSAMPIMAGE input_buf, JDIMENSION input_row, |
174 » JSAMPARRAY output_buf, int num_rows) | 174 JSAMPARRAY output_buf, int num_rows) |
175 { | 175 { |
176 register JSAMPROW inptr, outptr; | 176 register JSAMPROW inptr, outptr; |
177 register JDIMENSION count; | 177 register JDIMENSION count; |
178 register int num_components = cinfo->num_components; | 178 register int num_components = cinfo->num_components; |
179 JDIMENSION num_cols = cinfo->output_width; | 179 JDIMENSION num_cols = cinfo->output_width; |
180 int ci; | 180 int ci; |
181 | 181 |
182 while (--num_rows >= 0) { | 182 while (--num_rows >= 0) { |
183 for (ci = 0; ci < num_components; ci++) { | 183 for (ci = 0; ci < num_components; ci++) { |
184 inptr = input_buf[ci][input_row]; | 184 inptr = input_buf[ci][input_row]; |
185 outptr = output_buf[0] + ci; | 185 outptr = output_buf[0] + ci; |
186 for (count = num_cols; count > 0; count--) { | 186 for (count = num_cols; count > 0; count--) { |
187 » *outptr = *inptr++;» /* needn't bother with GETJSAMPLE() here */ | 187 *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ |
188 » outptr += num_components; | 188 outptr += num_components; |
189 } | 189 } |
190 } | 190 } |
191 input_row++; | 191 input_row++; |
192 output_buf++; | 192 output_buf++; |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 | 196 |
197 /* | 197 /* |
198 * Color conversion for grayscale: just copy the data. | 198 * Color conversion for grayscale: just copy the data. |
199 * This also works for YCbCr -> grayscale conversion, in which | 199 * This also works for YCbCr -> grayscale conversion, in which |
200 * we just copy the Y (luminance) component and ignore chrominance. | 200 * we just copy the Y (luminance) component and ignore chrominance. |
201 */ | 201 */ |
202 | 202 |
203 METHODDEF(void) | 203 METHODDEF(void) |
204 grayscale_convert (j_decompress_ptr cinfo, | 204 grayscale_convert (j_decompress_ptr cinfo, |
205 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 205 JSAMPIMAGE input_buf, JDIMENSION input_row, |
206 » » JSAMPARRAY output_buf, int num_rows) | 206 JSAMPARRAY output_buf, int num_rows) |
207 { | 207 { |
208 jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, | 208 jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, |
209 » » num_rows, cinfo->output_width); | 209 num_rows, cinfo->output_width); |
210 } | 210 } |
211 | 211 |
212 | 212 |
213 /* | 213 /* |
214 * Convert grayscale to RGB: just duplicate the graylevel three times. | 214 * Convert grayscale to RGB: just duplicate the graylevel three times. |
215 * This is provided to support applications that don't want to cope | 215 * This is provided to support applications that don't want to cope |
216 * with grayscale as a separate case. | 216 * with grayscale as a separate case. |
217 */ | 217 */ |
218 | 218 |
219 METHODDEF(void) | 219 METHODDEF(void) |
220 gray_rgb_convert (j_decompress_ptr cinfo, | 220 gray_rgb_convert (j_decompress_ptr cinfo, |
221 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 221 JSAMPIMAGE input_buf, JDIMENSION input_row, |
222 » » JSAMPARRAY output_buf, int num_rows) | 222 JSAMPARRAY output_buf, int num_rows) |
223 { | 223 { |
224 register JSAMPROW inptr, outptr; | 224 register JSAMPROW inptr, outptr; |
225 JSAMPLE *maxinptr; | 225 JSAMPLE *maxinptr; |
226 register JDIMENSION col; | |
fbarchard
2011/07/08 08:11:03
This is the real change
| |
227 JDIMENSION num_cols = cinfo->output_width; | 226 JDIMENSION num_cols = cinfo->output_width; |
228 int rindex = rgb_red[cinfo->out_color_space]; | 227 int rindex = rgb_red[cinfo->out_color_space]; |
229 int gindex = rgb_green[cinfo->out_color_space]; | 228 int gindex = rgb_green[cinfo->out_color_space]; |
230 int bindex = rgb_blue[cinfo->out_color_space]; | 229 int bindex = rgb_blue[cinfo->out_color_space]; |
231 int rgbstride = rgb_pixelsize[cinfo->out_color_space]; | 230 int rgbstride = rgb_pixelsize[cinfo->out_color_space]; |
232 | 231 |
233 while (--num_rows >= 0) { | 232 while (--num_rows >= 0) { |
234 inptr = input_buf[0][input_row++]; | 233 inptr = input_buf[0][input_row++]; |
235 maxinptr = &inptr[num_cols]; | 234 maxinptr = &inptr[num_cols]; |
236 outptr = *output_buf++; | 235 outptr = *output_buf++; |
237 for (; inptr < maxinptr; inptr++, outptr += rgbstride) { | 236 for (; inptr < maxinptr; inptr++, outptr += rgbstride) { |
238 /* We can dispense with GETJSAMPLE() here */ | 237 /* We can dispense with GETJSAMPLE() here */ |
239 outptr[rindex] = outptr[gindex] = outptr[bindex] = *inptr; | 238 outptr[rindex] = outptr[gindex] = outptr[bindex] = *inptr; |
240 } | 239 } |
241 } | 240 } |
242 } | 241 } |
243 | 242 |
244 | 243 |
245 /* | 244 /* |
246 * Adobe-style YCCK->CMYK conversion. | 245 * Adobe-style YCCK->CMYK conversion. |
247 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same | 246 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same |
248 * conversion as above, while passing K (black) unchanged. | 247 * conversion as above, while passing K (black) unchanged. |
249 * We assume build_ycc_rgb_table has been called. | 248 * We assume build_ycc_rgb_table has been called. |
250 */ | 249 */ |
251 | 250 |
252 METHODDEF(void) | 251 METHODDEF(void) |
253 ycck_cmyk_convert (j_decompress_ptr cinfo, | 252 ycck_cmyk_convert (j_decompress_ptr cinfo, |
254 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 253 JSAMPIMAGE input_buf, JDIMENSION input_row, |
255 » » JSAMPARRAY output_buf, int num_rows) | 254 JSAMPARRAY output_buf, int num_rows) |
256 { | 255 { |
257 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 256 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
258 register int y, cb, cr; | 257 register int y, cb, cr; |
259 register JSAMPROW outptr; | 258 register JSAMPROW outptr; |
260 register JSAMPROW inptr0, inptr1, inptr2, inptr3; | 259 register JSAMPROW inptr0, inptr1, inptr2, inptr3; |
261 register JDIMENSION col; | 260 register JDIMENSION col; |
262 JDIMENSION num_cols = cinfo->output_width; | 261 JDIMENSION num_cols = cinfo->output_width; |
263 /* copy these pointers into registers if possible */ | 262 /* copy these pointers into registers if possible */ |
264 register JSAMPLE * range_limit = cinfo->sample_range_limit; | 263 register JSAMPLE * range_limit = cinfo->sample_range_limit; |
265 register int * Crrtab = cconvert->Cr_r_tab; | 264 register int * Crrtab = cconvert->Cr_r_tab; |
266 register int * Cbbtab = cconvert->Cb_b_tab; | 265 register int * Cbbtab = cconvert->Cb_b_tab; |
267 register INT32 * Crgtab = cconvert->Cr_g_tab; | 266 register INT32 * Crgtab = cconvert->Cr_g_tab; |
268 register INT32 * Cbgtab = cconvert->Cb_g_tab; | 267 register INT32 * Cbgtab = cconvert->Cb_g_tab; |
269 SHIFT_TEMPS | 268 SHIFT_TEMPS |
270 | 269 |
271 while (--num_rows >= 0) { | 270 while (--num_rows >= 0) { |
272 inptr0 = input_buf[0][input_row]; | 271 inptr0 = input_buf[0][input_row]; |
273 inptr1 = input_buf[1][input_row]; | 272 inptr1 = input_buf[1][input_row]; |
274 inptr2 = input_buf[2][input_row]; | 273 inptr2 = input_buf[2][input_row]; |
275 inptr3 = input_buf[3][input_row]; | 274 inptr3 = input_buf[3][input_row]; |
276 input_row++; | 275 input_row++; |
277 outptr = *output_buf++; | 276 outptr = *output_buf++; |
278 for (col = 0; col < num_cols; col++) { | 277 for (col = 0; col < num_cols; col++) { |
279 y = GETJSAMPLE(inptr0[col]); | 278 y = GETJSAMPLE(inptr0[col]); |
280 cb = GETJSAMPLE(inptr1[col]); | 279 cb = GETJSAMPLE(inptr1[col]); |
281 cr = GETJSAMPLE(inptr2[col]); | 280 cr = GETJSAMPLE(inptr2[col]); |
282 /* Range-limiting is essential due to noise introduced by DCT losses. */ | 281 /* Range-limiting is essential due to noise introduced by DCT losses. */ |
283 outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])];» /* red */ | 282 outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ |
284 outptr[1] = range_limit[MAXJSAMPLE - (y +»» » /* green */ | 283 outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ |
285 » » » ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], | 284 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], |
286 » » » » » » SCALEBITS)))]; | 285 SCALEBITS)))]; |
287 outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])];» /* blue */ | 286 outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ |
288 /* K passes through unchanged */ | 287 /* K passes through unchanged */ |
289 outptr[3] = inptr3[col];» /* don't need GETJSAMPLE here */ | 288 outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ |
290 outptr += 4; | 289 outptr += 4; |
291 } | 290 } |
292 } | 291 } |
293 } | 292 } |
294 | 293 |
295 | 294 |
296 /* | 295 /* |
297 * Empty method for start_pass. | 296 * Empty method for start_pass. |
298 */ | 297 */ |
299 | 298 |
300 METHODDEF(void) | 299 METHODDEF(void) |
301 start_pass_dcolor (j_decompress_ptr cinfo) | 300 start_pass_dcolor (j_decompress_ptr cinfo) |
302 { | 301 { |
303 /* no work needed */ | 302 /* no work needed */ |
304 } | 303 } |
305 | 304 |
306 | 305 |
307 /* | 306 /* |
308 * Module initialization routine for output colorspace conversion. | 307 * Module initialization routine for output colorspace conversion. |
309 */ | 308 */ |
310 | 309 |
311 GLOBAL(void) | 310 GLOBAL(void) |
312 jinit_color_deconverter (j_decompress_ptr cinfo) | 311 jinit_color_deconverter (j_decompress_ptr cinfo) |
313 { | 312 { |
314 my_cconvert_ptr cconvert; | 313 my_cconvert_ptr cconvert; |
315 int ci; | 314 int ci; |
316 | 315 |
317 cconvert = (my_cconvert_ptr) | 316 cconvert = (my_cconvert_ptr) |
318 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 317 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
319 » » » » SIZEOF(my_color_deconverter)); | 318 SIZEOF(my_color_deconverter)); |
320 cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; | 319 cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; |
321 cconvert->pub.start_pass = start_pass_dcolor; | 320 cconvert->pub.start_pass = start_pass_dcolor; |
322 | 321 |
323 /* Make sure num_components agrees with jpeg_color_space */ | 322 /* Make sure num_components agrees with jpeg_color_space */ |
324 switch (cinfo->jpeg_color_space) { | 323 switch (cinfo->jpeg_color_space) { |
325 case JCS_GRAYSCALE: | 324 case JCS_GRAYSCALE: |
326 if (cinfo->num_components != 1) | 325 if (cinfo->num_components != 1) |
327 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 326 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
328 break; | 327 break; |
329 | 328 |
330 case JCS_RGB: | 329 case JCS_RGB: |
331 case JCS_YCbCr: | 330 case JCS_YCbCr: |
332 if (cinfo->num_components != 3) | 331 if (cinfo->num_components != 3) |
333 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 332 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
334 break; | 333 break; |
335 | 334 |
336 case JCS_CMYK: | 335 case JCS_CMYK: |
337 case JCS_YCCK: | 336 case JCS_YCCK: |
338 if (cinfo->num_components != 4) | 337 if (cinfo->num_components != 4) |
339 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 338 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
340 break; | 339 break; |
341 | 340 |
342 default:» » » /* JCS_UNKNOWN can be anything */ | 341 default: /* JCS_UNKNOWN can be anything */ |
343 if (cinfo->num_components < 1) | 342 if (cinfo->num_components < 1) |
344 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 343 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
345 break; | 344 break; |
346 } | 345 } |
347 | 346 |
348 /* Set out_color_components and conversion method based on requested space. | 347 /* Set out_color_components and conversion method based on requested space. |
349 * Also clear the component_needed flags for any unused components, | 348 * Also clear the component_needed flags for any unused components, |
350 * so that earlier pipeline stages can avoid useless computation. | 349 * so that earlier pipeline stages can avoid useless computation. |
351 */ | 350 */ |
352 | 351 |
353 switch (cinfo->out_color_space) { | 352 switch (cinfo->out_color_space) { |
354 case JCS_GRAYSCALE: | 353 case JCS_GRAYSCALE: |
355 cinfo->out_color_components = 1; | 354 cinfo->out_color_components = 1; |
356 if (cinfo->jpeg_color_space == JCS_GRAYSCALE || | 355 if (cinfo->jpeg_color_space == JCS_GRAYSCALE || |
357 » cinfo->jpeg_color_space == JCS_YCbCr) { | 356 cinfo->jpeg_color_space == JCS_YCbCr) { |
358 cconvert->pub.color_convert = grayscale_convert; | 357 cconvert->pub.color_convert = grayscale_convert; |
359 /* For color->grayscale conversion, only the Y (0) component is needed */ | 358 /* For color->grayscale conversion, only the Y (0) component is needed */ |
360 for (ci = 1; ci < cinfo->num_components; ci++) | 359 for (ci = 1; ci < cinfo->num_components; ci++) |
361 » cinfo->comp_info[ci].component_needed = FALSE; | 360 cinfo->comp_info[ci].component_needed = FALSE; |
362 } else | 361 } else |
363 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 362 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
364 break; | 363 break; |
365 | 364 |
366 case JCS_RGB: | 365 case JCS_RGB: |
367 case JCS_EXT_RGB: | 366 case JCS_EXT_RGB: |
368 case JCS_EXT_RGBX: | 367 case JCS_EXT_RGBX: |
369 case JCS_EXT_BGR: | 368 case JCS_EXT_BGR: |
370 case JCS_EXT_BGRX: | 369 case JCS_EXT_BGRX: |
371 case JCS_EXT_XBGR: | 370 case JCS_EXT_XBGR: |
(...skipping 24 matching lines...) Expand all Loading... | |
396 cconvert->pub.color_convert = null_convert; | 395 cconvert->pub.color_convert = null_convert; |
397 } else | 396 } else |
398 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 397 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
399 break; | 398 break; |
400 | 399 |
401 default: | 400 default: |
402 /* Permit null conversion to same output space */ | 401 /* Permit null conversion to same output space */ |
403 if (cinfo->out_color_space == cinfo->jpeg_color_space) { | 402 if (cinfo->out_color_space == cinfo->jpeg_color_space) { |
404 cinfo->out_color_components = cinfo->num_components; | 403 cinfo->out_color_components = cinfo->num_components; |
405 cconvert->pub.color_convert = null_convert; | 404 cconvert->pub.color_convert = null_convert; |
406 } else» » » /* unsupported non-null conversion */ | 405 } else /* unsupported non-null conversion */ |
407 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 406 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
408 break; | 407 break; |
409 } | 408 } |
410 | 409 |
411 if (cinfo->quantize_colors) | 410 if (cinfo->quantize_colors) |
412 cinfo->output_components = 1; /* single colormapped output component */ | 411 cinfo->output_components = 1; /* single colormapped output component */ |
413 else | 412 else |
414 cinfo->output_components = cinfo->out_color_components; | 413 cinfo->output_components = cinfo->out_color_components; |
415 } | 414 } |
OLD | NEW |