OLD | NEW |
1 /* | 1 /* |
2 * jdcolor.c | 2 * jdcolor.c |
3 * | 3 * |
4 * This file was part of the Independent JPEG Group's software: | 4 * This file was part of the Independent JPEG Group's software: |
5 * Copyright (C) 1991-1997, Thomas G. Lane. | 5 * Copyright (C) 1991-1997, Thomas G. Lane. |
6 * Modified 2011 by Guido Vollbeding. | 6 * Modified 2011 by Guido Vollbeding. |
7 * libjpeg-turbo Modifications: | 7 * libjpeg-turbo Modifications: |
8 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB | 8 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
9 * Copyright (C) 2009, 2011-2012, 2014, D. R. Commander. | 9 * Copyright (C) 2009, 2011-2012, 2014-2015, D. R. Commander. |
10 * Copyright (C) 2013, Linaro Limited. | 10 * Copyright (C) 2013, Linaro Limited. |
11 * For conditions of distribution and use, see the accompanying README file. | 11 * For conditions of distribution and use, see the accompanying README.ijg |
| 12 * file. |
12 * | 13 * |
13 * This file contains output colorspace conversion routines. | 14 * This file contains output colorspace conversion routines. |
14 */ | 15 */ |
15 | 16 |
16 #define JPEG_INTERNALS | 17 #define JPEG_INTERNALS |
17 #include "jinclude.h" | 18 #include "jinclude.h" |
18 #include "jpeglib.h" | 19 #include "jpeglib.h" |
19 #include "jsimd.h" | 20 #include "jsimd.h" |
20 #include "config.h" | 21 #include "jconfigint.h" |
21 | 22 |
22 | 23 |
23 /* Private subobject */ | 24 /* Private subobject */ |
24 | 25 |
25 typedef struct { | 26 typedef struct { |
26 struct jpeg_color_deconverter pub; /* public fields */ | 27 struct jpeg_color_deconverter pub; /* public fields */ |
27 | 28 |
28 /* Private state for YCC->RGB conversion */ | 29 /* Private state for YCC->RGB conversion */ |
29 int * Cr_r_tab;» » /* => table for Cr to R conversion */ | 30 int *Cr_r_tab; /* => table for Cr to R conversion */ |
30 int * Cb_b_tab;» » /* => table for Cb to B conversion */ | 31 int *Cb_b_tab; /* => table for Cb to B conversion */ |
31 INT32 * Cr_g_tab;» » /* => table for Cr to G conversion */ | 32 JLONG *Cr_g_tab; /* => table for Cr to G conversion */ |
32 INT32 * Cb_g_tab;» » /* => table for Cb to G conversion */ | 33 JLONG *Cb_g_tab; /* => table for Cb to G conversion */ |
33 | 34 |
34 /* Private state for RGB->Y conversion */ | 35 /* Private state for RGB->Y conversion */ |
35 INT32 * rgb_y_tab;» » /* => table for RGB to Y conversion */ | 36 JLONG *rgb_y_tab; /* => table for RGB to Y conversion */ |
36 } my_color_deconverter; | 37 } my_color_deconverter; |
37 | 38 |
38 typedef my_color_deconverter * my_cconvert_ptr; | 39 typedef my_color_deconverter *my_cconvert_ptr; |
39 | 40 |
40 | 41 |
41 /**************** YCbCr -> RGB conversion: most common case **************/ | 42 /**************** YCbCr -> RGB conversion: most common case **************/ |
42 /**************** RGB -> Y conversion: less common case **************/ | 43 /**************** RGB -> Y conversion: less common case **************/ |
43 | 44 |
44 /* | 45 /* |
45 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are | 46 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are |
46 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. | 47 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. |
47 * The conversion equations to be implemented are therefore | 48 * The conversion equations to be implemented are therefore |
48 * | 49 * |
49 *» R = Y + 1.40200 * Cr | 50 * R = Y + 1.40200 * Cr |
50 *» G = Y - 0.34414 * Cb - 0.71414 * Cr | 51 * G = Y - 0.34414 * Cb - 0.71414 * Cr |
51 *» B = Y + 1.77200 * Cb | 52 * B = Y + 1.77200 * Cb |
52 * | 53 * |
53 *» Y = 0.29900 * R + 0.58700 * G + 0.11400 * B | 54 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B |
54 * | 55 * |
55 * where Cb and Cr represent the incoming values less CENTERJSAMPLE. | 56 * where Cb and Cr represent the incoming values less CENTERJSAMPLE. |
56 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) | 57 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) |
57 * | 58 * |
58 * To avoid floating-point arithmetic, we represent the fractional constants | 59 * To avoid floating-point arithmetic, we represent the fractional constants |
59 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide | 60 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide |
60 * the products by 2^16, with appropriate rounding, to get the correct answer. | 61 * the products by 2^16, with appropriate rounding, to get the correct answer. |
61 * Notice that Y, being an integral input, does not contribute any fraction | 62 * Notice that Y, being an integral input, does not contribute any fraction |
62 * so it need not participate in the rounding. | 63 * so it need not participate in the rounding. |
63 * | 64 * |
64 * For even more speed, we avoid doing any multiplications in the inner loop | 65 * For even more speed, we avoid doing any multiplications in the inner loop |
65 * by precalculating the constants times Cb and Cr for all possible values. | 66 * by precalculating the constants times Cb and Cr for all possible values. |
66 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); | 67 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); |
67 * for 12-bit samples it is still acceptable. It's not very reasonable for | 68 * for 12-bit samples it is still acceptable. It's not very reasonable for |
68 * 16-bit samples, but if you want lossless storage you shouldn't be changing | 69 * 16-bit samples, but if you want lossless storage you shouldn't be changing |
69 * colorspace anyway. | 70 * colorspace anyway. |
70 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the | 71 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the |
71 * values for the G calculation are left scaled up, since we must add them | 72 * values for the G calculation are left scaled up, since we must add them |
72 * together before rounding. | 73 * together before rounding. |
73 */ | 74 */ |
74 | 75 |
75 #define SCALEBITS» 16» /* speediest right-shift on some machines */ | 76 #define SCALEBITS 16 /* speediest right-shift on some machines */ |
76 #define ONE_HALF» ((INT32) 1 << (SCALEBITS-1)) | 77 #define ONE_HALF ((JLONG) 1 << (SCALEBITS-1)) |
77 #define FIX(x)» » ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) | 78 #define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5)) |
78 | 79 |
79 /* We allocate one big table for RGB->Y conversion and divide it up into | 80 /* We allocate one big table for RGB->Y conversion and divide it up into |
80 * three parts, instead of doing three alloc_small requests. This lets us | 81 * three parts, instead of doing three alloc_small requests. This lets us |
81 * use a single table base address, which can be held in a register in the | 82 * use a single table base address, which can be held in a register in the |
82 * inner loops on many machines (more than can hold all three addresses, | 83 * inner loops on many machines (more than can hold all three addresses, |
83 * anyway). | 84 * anyway). |
84 */ | 85 */ |
85 | 86 |
86 #define R_Y_OFF»» 0» » » /* offset to R => Y section */ | 87 #define R_Y_OFF 0 /* offset to R => Y section */ |
87 #define G_Y_OFF»» (1*(MAXJSAMPLE+1))» /* offset to G => Y section */ | 88 #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ |
88 #define B_Y_OFF»» (2*(MAXJSAMPLE+1))» /* etc. */ | 89 #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ |
89 #define TABLE_SIZE» (3*(MAXJSAMPLE+1)) | 90 #define TABLE_SIZE (3*(MAXJSAMPLE+1)) |
90 | 91 |
91 | 92 |
92 /* Include inline routines for colorspace extensions */ | 93 /* Include inline routines for colorspace extensions */ |
93 | 94 |
94 #include "jdcolext.c" | 95 #include "jdcolext.c" |
95 #undef RGB_RED | 96 #undef RGB_RED |
96 #undef RGB_GREEN | 97 #undef RGB_GREEN |
97 #undef RGB_BLUE | 98 #undef RGB_BLUE |
98 #undef RGB_PIXELSIZE | 99 #undef RGB_PIXELSIZE |
99 | 100 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 205 |
205 /* | 206 /* |
206 * Initialize tables for YCC->RGB colorspace conversion. | 207 * Initialize tables for YCC->RGB colorspace conversion. |
207 */ | 208 */ |
208 | 209 |
209 LOCAL(void) | 210 LOCAL(void) |
210 build_ycc_rgb_table (j_decompress_ptr cinfo) | 211 build_ycc_rgb_table (j_decompress_ptr cinfo) |
211 { | 212 { |
212 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 213 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
213 int i; | 214 int i; |
214 INT32 x; | 215 JLONG x; |
215 SHIFT_TEMPS | 216 SHIFT_TEMPS |
216 | 217 |
217 cconvert->Cr_r_tab = (int *) | 218 cconvert->Cr_r_tab = (int *) |
218 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 219 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
219 » » » » (MAXJSAMPLE+1) * SIZEOF(int)); | 220 (MAXJSAMPLE+1) * sizeof(int)); |
220 cconvert->Cb_b_tab = (int *) | 221 cconvert->Cb_b_tab = (int *) |
221 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 222 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
222 » » » » (MAXJSAMPLE+1) * SIZEOF(int)); | 223 (MAXJSAMPLE+1) * sizeof(int)); |
223 cconvert->Cr_g_tab = (INT32 *) | 224 cconvert->Cr_g_tab = (JLONG *) |
224 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 225 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
225 » » » » (MAXJSAMPLE+1) * SIZEOF(INT32)); | 226 (MAXJSAMPLE+1) * sizeof(JLONG)); |
226 cconvert->Cb_g_tab = (INT32 *) | 227 cconvert->Cb_g_tab = (JLONG *) |
227 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 228 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
228 » » » » (MAXJSAMPLE+1) * SIZEOF(INT32)); | 229 (MAXJSAMPLE+1) * sizeof(JLONG)); |
229 | 230 |
230 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { | 231 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { |
231 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ | 232 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ |
232 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ | 233 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ |
233 /* Cr=>R value is nearest int to 1.40200 * x */ | 234 /* Cr=>R value is nearest int to 1.40200 * x */ |
234 cconvert->Cr_r_tab[i] = (int) | 235 cconvert->Cr_r_tab[i] = (int) |
235 » » RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); | 236 RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); |
236 /* Cb=>B value is nearest int to 1.77200 * x */ | 237 /* Cb=>B value is nearest int to 1.77200 * x */ |
237 cconvert->Cb_b_tab[i] = (int) | 238 cconvert->Cb_b_tab[i] = (int) |
238 » » RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); | 239 RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); |
239 /* Cr=>G value is scaled-up -0.71414 * x */ | 240 /* Cr=>G value is scaled-up -0.71414 * x */ |
240 cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; | 241 cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; |
241 /* Cb=>G value is scaled-up -0.34414 * x */ | 242 /* Cb=>G value is scaled-up -0.34414 * x */ |
242 /* We also add in ONE_HALF so that need not do it in inner loop */ | 243 /* We also add in ONE_HALF so that need not do it in inner loop */ |
243 cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; | 244 cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; |
244 } | 245 } |
245 } | 246 } |
246 | 247 |
247 | 248 |
248 /* | 249 /* |
249 * Convert some rows of samples to the output colorspace. | 250 * Convert some rows of samples to the output colorspace. |
250 */ | 251 */ |
251 | 252 |
252 METHODDEF(void) | 253 METHODDEF(void) |
253 ycc_rgb_convert (j_decompress_ptr cinfo, | 254 ycc_rgb_convert (j_decompress_ptr cinfo, |
254 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 255 JSAMPIMAGE input_buf, JDIMENSION input_row, |
255 » » JSAMPARRAY output_buf, int num_rows) | 256 JSAMPARRAY output_buf, int num_rows) |
256 { | 257 { |
257 switch (cinfo->out_color_space) { | 258 switch (cinfo->out_color_space) { |
258 case JCS_EXT_RGB: | 259 case JCS_EXT_RGB: |
259 ycc_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, | 260 ycc_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, |
260 num_rows); | 261 num_rows); |
261 break; | 262 break; |
262 case JCS_EXT_RGBX: | 263 case JCS_EXT_RGBX: |
263 case JCS_EXT_RGBA: | 264 case JCS_EXT_RGBA: |
264 ycc_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, | 265 ycc_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, |
265 num_rows); | 266 num_rows); |
(...skipping 29 matching lines...) Expand all Loading... |
295 | 296 |
296 | 297 |
297 /* | 298 /* |
298 * Initialize for RGB->grayscale colorspace conversion. | 299 * Initialize for RGB->grayscale colorspace conversion. |
299 */ | 300 */ |
300 | 301 |
301 LOCAL(void) | 302 LOCAL(void) |
302 build_rgb_y_table (j_decompress_ptr cinfo) | 303 build_rgb_y_table (j_decompress_ptr cinfo) |
303 { | 304 { |
304 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 305 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
305 INT32 * rgb_y_tab; | 306 JLONG *rgb_y_tab; |
306 INT32 i; | 307 JLONG i; |
307 | 308 |
308 /* Allocate and fill in the conversion tables. */ | 309 /* Allocate and fill in the conversion tables. */ |
309 cconvert->rgb_y_tab = rgb_y_tab = (INT32 *) | 310 cconvert->rgb_y_tab = rgb_y_tab = (JLONG *) |
310 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 311 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
311 » » » » (TABLE_SIZE * SIZEOF(INT32))); | 312 (TABLE_SIZE * sizeof(JLONG))); |
312 | 313 |
313 for (i = 0; i <= MAXJSAMPLE; i++) { | 314 for (i = 0; i <= MAXJSAMPLE; i++) { |
314 rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i; | 315 rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i; |
315 rgb_y_tab[i+G_Y_OFF] = FIX(0.58700) * i; | 316 rgb_y_tab[i+G_Y_OFF] = FIX(0.58700) * i; |
316 rgb_y_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; | 317 rgb_y_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; |
317 } | 318 } |
318 } | 319 } |
319 | 320 |
320 | 321 |
321 /* | 322 /* |
322 * Convert RGB to grayscale. | 323 * Convert RGB to grayscale. |
323 */ | 324 */ |
324 | 325 |
325 METHODDEF(void) | 326 METHODDEF(void) |
326 rgb_gray_convert (j_decompress_ptr cinfo, | 327 rgb_gray_convert (j_decompress_ptr cinfo, |
327 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 328 JSAMPIMAGE input_buf, JDIMENSION input_row, |
328 » » JSAMPARRAY output_buf, int num_rows) | 329 JSAMPARRAY output_buf, int num_rows) |
329 { | 330 { |
330 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 331 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
331 register int r, g, b; | 332 register int r, g, b; |
332 register INT32 * ctab = cconvert->rgb_y_tab; | 333 register JLONG *ctab = cconvert->rgb_y_tab; |
333 register JSAMPROW outptr; | 334 register JSAMPROW outptr; |
334 register JSAMPROW inptr0, inptr1, inptr2; | 335 register JSAMPROW inptr0, inptr1, inptr2; |
335 register JDIMENSION col; | 336 register JDIMENSION col; |
336 JDIMENSION num_cols = cinfo->output_width; | 337 JDIMENSION num_cols = cinfo->output_width; |
337 | 338 |
338 while (--num_rows >= 0) { | 339 while (--num_rows >= 0) { |
339 inptr0 = input_buf[0][input_row]; | 340 inptr0 = input_buf[0][input_row]; |
340 inptr1 = input_buf[1][input_row]; | 341 inptr1 = input_buf[1][input_row]; |
341 inptr2 = input_buf[2][input_row]; | 342 inptr2 = input_buf[2][input_row]; |
342 input_row++; | 343 input_row++; |
343 outptr = *output_buf++; | 344 outptr = *output_buf++; |
344 for (col = 0; col < num_cols; col++) { | 345 for (col = 0; col < num_cols; col++) { |
345 r = GETJSAMPLE(inptr0[col]); | 346 r = GETJSAMPLE(inptr0[col]); |
346 g = GETJSAMPLE(inptr1[col]); | 347 g = GETJSAMPLE(inptr1[col]); |
347 b = GETJSAMPLE(inptr2[col]); | 348 b = GETJSAMPLE(inptr2[col]); |
348 /* Y */ | 349 /* Y */ |
349 outptr[col] = (JSAMPLE) | 350 outptr[col] = (JSAMPLE) |
350 » » ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) | 351 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) |
351 » » >> SCALEBITS); | 352 >> SCALEBITS); |
352 } | 353 } |
353 } | 354 } |
354 } | 355 } |
355 | 356 |
356 | 357 |
357 /* | 358 /* |
358 * Color conversion for no colorspace change: just copy the data, | 359 * Color conversion for no colorspace change: just copy the data, |
359 * converting from separate-planes to interleaved representation. | 360 * converting from separate-planes to interleaved representation. |
360 */ | 361 */ |
361 | 362 |
362 METHODDEF(void) | 363 METHODDEF(void) |
363 null_convert (j_decompress_ptr cinfo, | 364 null_convert (j_decompress_ptr cinfo, |
364 » JSAMPIMAGE input_buf, JDIMENSION input_row, | 365 JSAMPIMAGE input_buf, JDIMENSION input_row, |
365 » JSAMPARRAY output_buf, int num_rows) | 366 JSAMPARRAY output_buf, int num_rows) |
366 { | 367 { |
367 register JSAMPROW inptr, outptr; | 368 register JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr; |
368 register JDIMENSION count; | 369 register JDIMENSION col; |
369 register int num_components = cinfo->num_components; | 370 register int num_components = cinfo->num_components; |
370 JDIMENSION num_cols = cinfo->output_width; | 371 JDIMENSION num_cols = cinfo->output_width; |
371 int ci; | 372 int ci; |
372 | 373 |
373 while (--num_rows >= 0) { | 374 if (num_components == 3) { |
374 for (ci = 0; ci < num_components; ci++) { | 375 while (--num_rows >= 0) { |
375 inptr = input_buf[ci][input_row]; | 376 inptr0 = input_buf[0][input_row]; |
376 outptr = output_buf[0] + ci; | 377 inptr1 = input_buf[1][input_row]; |
377 for (count = num_cols; count > 0; count--) { | 378 inptr2 = input_buf[2][input_row]; |
378 » *outptr = *inptr++;» /* needn't bother with GETJSAMPLE() here */ | 379 input_row++; |
379 » outptr += num_components; | 380 outptr = *output_buf++; |
| 381 for (col = 0; col < num_cols; col++) { |
| 382 *outptr++ = inptr0[col]; |
| 383 *outptr++ = inptr1[col]; |
| 384 *outptr++ = inptr2[col]; |
380 } | 385 } |
381 } | 386 } |
382 input_row++; | 387 } else if (num_components == 4) { |
383 output_buf++; | 388 while (--num_rows >= 0) { |
| 389 inptr0 = input_buf[0][input_row]; |
| 390 inptr1 = input_buf[1][input_row]; |
| 391 inptr2 = input_buf[2][input_row]; |
| 392 inptr3 = input_buf[3][input_row]; |
| 393 input_row++; |
| 394 outptr = *output_buf++; |
| 395 for (col = 0; col < num_cols; col++) { |
| 396 *outptr++ = inptr0[col]; |
| 397 *outptr++ = inptr1[col]; |
| 398 *outptr++ = inptr2[col]; |
| 399 *outptr++ = inptr3[col]; |
| 400 } |
| 401 } |
| 402 } else { |
| 403 while (--num_rows >= 0) { |
| 404 for (ci = 0; ci < num_components; ci++) { |
| 405 inptr = input_buf[ci][input_row]; |
| 406 outptr = *output_buf; |
| 407 for (col = 0; col < num_cols; col++) { |
| 408 outptr[ci] = inptr[col]; |
| 409 outptr += num_components; |
| 410 } |
| 411 } |
| 412 output_buf++; |
| 413 input_row++; |
| 414 } |
384 } | 415 } |
385 } | 416 } |
386 | 417 |
387 | 418 |
388 /* | 419 /* |
389 * Color conversion for grayscale: just copy the data. | 420 * Color conversion for grayscale: just copy the data. |
390 * This also works for YCbCr -> grayscale conversion, in which | 421 * This also works for YCbCr -> grayscale conversion, in which |
391 * we just copy the Y (luminance) component and ignore chrominance. | 422 * we just copy the Y (luminance) component and ignore chrominance. |
392 */ | 423 */ |
393 | 424 |
394 METHODDEF(void) | 425 METHODDEF(void) |
395 grayscale_convert (j_decompress_ptr cinfo, | 426 grayscale_convert (j_decompress_ptr cinfo, |
396 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 427 JSAMPIMAGE input_buf, JDIMENSION input_row, |
397 » » JSAMPARRAY output_buf, int num_rows) | 428 JSAMPARRAY output_buf, int num_rows) |
398 { | 429 { |
399 jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, | 430 jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, |
400 » » num_rows, cinfo->output_width); | 431 num_rows, cinfo->output_width); |
401 } | 432 } |
402 | 433 |
403 | 434 |
404 /* | 435 /* |
405 * Convert grayscale to RGB | 436 * Convert grayscale to RGB |
406 */ | 437 */ |
407 | 438 |
408 METHODDEF(void) | 439 METHODDEF(void) |
409 gray_rgb_convert (j_decompress_ptr cinfo, | 440 gray_rgb_convert (j_decompress_ptr cinfo, |
410 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 441 JSAMPIMAGE input_buf, JDIMENSION input_row, |
411 » » JSAMPARRAY output_buf, int num_rows) | 442 JSAMPARRAY output_buf, int num_rows) |
412 { | 443 { |
413 switch (cinfo->out_color_space) { | 444 switch (cinfo->out_color_space) { |
414 case JCS_EXT_RGB: | 445 case JCS_EXT_RGB: |
415 gray_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, | 446 gray_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, |
416 num_rows); | 447 num_rows); |
417 break; | 448 break; |
418 case JCS_EXT_RGBX: | 449 case JCS_EXT_RGBX: |
419 case JCS_EXT_RGBA: | 450 case JCS_EXT_RGBA: |
420 gray_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, | 451 gray_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, |
421 num_rows); | 452 num_rows); |
(...skipping 24 matching lines...) Expand all Loading... |
446 } | 477 } |
447 } | 478 } |
448 | 479 |
449 | 480 |
450 /* | 481 /* |
451 * Convert plain RGB to extended RGB | 482 * Convert plain RGB to extended RGB |
452 */ | 483 */ |
453 | 484 |
454 METHODDEF(void) | 485 METHODDEF(void) |
455 rgb_rgb_convert (j_decompress_ptr cinfo, | 486 rgb_rgb_convert (j_decompress_ptr cinfo, |
456 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 487 JSAMPIMAGE input_buf, JDIMENSION input_row, |
457 » » JSAMPARRAY output_buf, int num_rows) | 488 JSAMPARRAY output_buf, int num_rows) |
458 { | 489 { |
459 switch (cinfo->out_color_space) { | 490 switch (cinfo->out_color_space) { |
460 case JCS_EXT_RGB: | 491 case JCS_EXT_RGB: |
461 rgb_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, | 492 rgb_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, |
462 num_rows); | 493 num_rows); |
463 break; | 494 break; |
464 case JCS_EXT_RGBX: | 495 case JCS_EXT_RGBX: |
465 case JCS_EXT_RGBA: | 496 case JCS_EXT_RGBA: |
466 rgb_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, | 497 rgb_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, |
467 num_rows); | 498 num_rows); |
(...skipping 27 matching lines...) Expand all Loading... |
495 | 526 |
496 /* | 527 /* |
497 * Adobe-style YCCK->CMYK conversion. | 528 * Adobe-style YCCK->CMYK conversion. |
498 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same | 529 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same |
499 * conversion as above, while passing K (black) unchanged. | 530 * conversion as above, while passing K (black) unchanged. |
500 * We assume build_ycc_rgb_table has been called. | 531 * We assume build_ycc_rgb_table has been called. |
501 */ | 532 */ |
502 | 533 |
503 METHODDEF(void) | 534 METHODDEF(void) |
504 ycck_cmyk_convert (j_decompress_ptr cinfo, | 535 ycck_cmyk_convert (j_decompress_ptr cinfo, |
505 » » JSAMPIMAGE input_buf, JDIMENSION input_row, | 536 JSAMPIMAGE input_buf, JDIMENSION input_row, |
506 » » JSAMPARRAY output_buf, int num_rows) | 537 JSAMPARRAY output_buf, int num_rows) |
507 { | 538 { |
508 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 539 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
509 register int y, cb, cr; | 540 register int y, cb, cr; |
510 register JSAMPROW outptr; | 541 register JSAMPROW outptr; |
511 register JSAMPROW inptr0, inptr1, inptr2, inptr3; | 542 register JSAMPROW inptr0, inptr1, inptr2, inptr3; |
512 register JDIMENSION col; | 543 register JDIMENSION col; |
513 JDIMENSION num_cols = cinfo->output_width; | 544 JDIMENSION num_cols = cinfo->output_width; |
514 /* copy these pointers into registers if possible */ | 545 /* copy these pointers into registers if possible */ |
515 register JSAMPLE * range_limit = cinfo->sample_range_limit; | 546 register JSAMPLE *range_limit = cinfo->sample_range_limit; |
516 register int * Crrtab = cconvert->Cr_r_tab; | 547 register int *Crrtab = cconvert->Cr_r_tab; |
517 register int * Cbbtab = cconvert->Cb_b_tab; | 548 register int *Cbbtab = cconvert->Cb_b_tab; |
518 register INT32 * Crgtab = cconvert->Cr_g_tab; | 549 register JLONG *Crgtab = cconvert->Cr_g_tab; |
519 register INT32 * Cbgtab = cconvert->Cb_g_tab; | 550 register JLONG *Cbgtab = cconvert->Cb_g_tab; |
520 SHIFT_TEMPS | 551 SHIFT_TEMPS |
521 | 552 |
522 while (--num_rows >= 0) { | 553 while (--num_rows >= 0) { |
523 inptr0 = input_buf[0][input_row]; | 554 inptr0 = input_buf[0][input_row]; |
524 inptr1 = input_buf[1][input_row]; | 555 inptr1 = input_buf[1][input_row]; |
525 inptr2 = input_buf[2][input_row]; | 556 inptr2 = input_buf[2][input_row]; |
526 inptr3 = input_buf[3][input_row]; | 557 inptr3 = input_buf[3][input_row]; |
527 input_row++; | 558 input_row++; |
528 outptr = *output_buf++; | 559 outptr = *output_buf++; |
529 for (col = 0; col < num_cols; col++) { | 560 for (col = 0; col < num_cols; col++) { |
530 y = GETJSAMPLE(inptr0[col]); | 561 y = GETJSAMPLE(inptr0[col]); |
531 cb = GETJSAMPLE(inptr1[col]); | 562 cb = GETJSAMPLE(inptr1[col]); |
532 cr = GETJSAMPLE(inptr2[col]); | 563 cr = GETJSAMPLE(inptr2[col]); |
533 /* Range-limiting is essential due to noise introduced by DCT losses. */ | 564 /* Range-limiting is essential due to noise introduced by DCT losses. */ |
534 outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])];» /* red */ | 565 outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ |
535 outptr[1] = range_limit[MAXJSAMPLE - (y +»» » /* green */ | 566 outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ |
536 » » » ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], | 567 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], |
537 » » » » » » SCALEBITS)))]; | 568 SCALEBITS)))]; |
538 outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])];» /* blue */ | 569 outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ |
539 /* K passes through unchanged */ | 570 /* K passes through unchanged */ |
540 outptr[3] = inptr3[col];» /* don't need GETJSAMPLE here */ | 571 outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ |
541 outptr += 4; | 572 outptr += 4; |
542 } | 573 } |
543 } | 574 } |
544 } | 575 } |
545 | 576 |
546 | 577 |
547 /* | 578 /* |
548 * RGB565 conversion | 579 * RGB565 conversion |
549 */ | 580 */ |
550 | 581 |
(...skipping 15 matching lines...) Expand all Loading... |
566 #define DITHER_565_B(b, dither) ((b) + ((dither) & 0xFF)) | 597 #define DITHER_565_B(b, dither) ((b) + ((dither) & 0xFF)) |
567 | 598 |
568 | 599 |
569 /* Declarations for ordered dithering | 600 /* Declarations for ordered dithering |
570 * | 601 * |
571 * We use a 4x4 ordered dither array packed into 32 bits. This array is | 602 * We use a 4x4 ordered dither array packed into 32 bits. This array is |
572 * sufficent for dithering RGB888 to RGB565. | 603 * sufficent for dithering RGB888 to RGB565. |
573 */ | 604 */ |
574 | 605 |
575 #define DITHER_MASK 0x3 | 606 #define DITHER_MASK 0x3 |
576 #define DITHER_ROTATE(x) (((x) << 24) | (((x) >> 8) & 0x00FFFFFF)) | 607 #define DITHER_ROTATE(x) ((((x) & 0xFF) << 24) | (((x) >> 8) & 0x00FFFFFF)) |
577 static const INT32 dither_matrix[4] = { | 608 static const JLONG dither_matrix[4] = { |
578 0x0008020A, | 609 0x0008020A, |
579 0x0C040E06, | 610 0x0C040E06, |
580 0x030B0109, | 611 0x030B0109, |
581 0x0F070D05 | 612 0x0F070D05 |
582 }; | 613 }; |
583 | 614 |
584 | 615 |
585 static INLINE boolean is_big_endian(void) | 616 static INLINE boolean is_big_endian(void) |
586 { | 617 { |
587 int test_value = 1; | 618 int test_value = 1; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 */ | 749 */ |
719 | 750 |
720 GLOBAL(void) | 751 GLOBAL(void) |
721 jinit_color_deconverter (j_decompress_ptr cinfo) | 752 jinit_color_deconverter (j_decompress_ptr cinfo) |
722 { | 753 { |
723 my_cconvert_ptr cconvert; | 754 my_cconvert_ptr cconvert; |
724 int ci; | 755 int ci; |
725 | 756 |
726 cconvert = (my_cconvert_ptr) | 757 cconvert = (my_cconvert_ptr) |
727 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 758 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
728 » » » » SIZEOF(my_color_deconverter)); | 759 sizeof(my_color_deconverter)); |
729 cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; | 760 cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; |
730 cconvert->pub.start_pass = start_pass_dcolor; | 761 cconvert->pub.start_pass = start_pass_dcolor; |
731 | 762 |
732 /* Make sure num_components agrees with jpeg_color_space */ | 763 /* Make sure num_components agrees with jpeg_color_space */ |
733 switch (cinfo->jpeg_color_space) { | 764 switch (cinfo->jpeg_color_space) { |
734 case JCS_GRAYSCALE: | 765 case JCS_GRAYSCALE: |
735 if (cinfo->num_components != 1) | 766 if (cinfo->num_components != 1) |
736 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 767 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
737 break; | 768 break; |
738 | 769 |
739 case JCS_RGB: | 770 case JCS_RGB: |
740 case JCS_YCbCr: | 771 case JCS_YCbCr: |
741 if (cinfo->num_components != 3) | 772 if (cinfo->num_components != 3) |
742 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 773 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
743 break; | 774 break; |
744 | 775 |
745 case JCS_CMYK: | 776 case JCS_CMYK: |
746 case JCS_YCCK: | 777 case JCS_YCCK: |
747 if (cinfo->num_components != 4) | 778 if (cinfo->num_components != 4) |
748 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 779 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
749 break; | 780 break; |
750 | 781 |
751 default:» » » /* JCS_UNKNOWN can be anything */ | 782 default: /* JCS_UNKNOWN can be anything */ |
752 if (cinfo->num_components < 1) | 783 if (cinfo->num_components < 1) |
753 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 784 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
754 break; | 785 break; |
755 } | 786 } |
756 | 787 |
757 /* Set out_color_components and conversion method based on requested space. | 788 /* Set out_color_components and conversion method based on requested space. |
758 * Also clear the component_needed flags for any unused components, | 789 * Also clear the component_needed flags for any unused components, |
759 * so that earlier pipeline stages can avoid useless computation. | 790 * so that earlier pipeline stages can avoid useless computation. |
760 */ | 791 */ |
761 | 792 |
762 switch (cinfo->out_color_space) { | 793 switch (cinfo->out_color_space) { |
763 case JCS_GRAYSCALE: | 794 case JCS_GRAYSCALE: |
764 cinfo->out_color_components = 1; | 795 cinfo->out_color_components = 1; |
765 if (cinfo->jpeg_color_space == JCS_GRAYSCALE || | 796 if (cinfo->jpeg_color_space == JCS_GRAYSCALE || |
766 » cinfo->jpeg_color_space == JCS_YCbCr) { | 797 cinfo->jpeg_color_space == JCS_YCbCr) { |
767 cconvert->pub.color_convert = grayscale_convert; | 798 cconvert->pub.color_convert = grayscale_convert; |
768 /* For color->grayscale conversion, only the Y (0) component is needed */ | 799 /* For color->grayscale conversion, only the Y (0) component is needed */ |
769 for (ci = 1; ci < cinfo->num_components; ci++) | 800 for (ci = 1; ci < cinfo->num_components; ci++) |
770 » cinfo->comp_info[ci].component_needed = FALSE; | 801 cinfo->comp_info[ci].component_needed = FALSE; |
771 } else if (cinfo->jpeg_color_space == JCS_RGB) { | 802 } else if (cinfo->jpeg_color_space == JCS_RGB) { |
772 cconvert->pub.color_convert = rgb_gray_convert; | 803 cconvert->pub.color_convert = rgb_gray_convert; |
773 build_rgb_y_table(cinfo); | 804 build_rgb_y_table(cinfo); |
774 } else | 805 } else |
775 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 806 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
776 break; | 807 break; |
777 | 808 |
778 case JCS_RGB: | 809 case JCS_RGB: |
779 case JCS_EXT_RGB: | 810 case JCS_EXT_RGB: |
780 case JCS_EXT_RGBX: | 811 case JCS_EXT_RGBX: |
(...skipping 24 matching lines...) Expand all Loading... |
805 else | 836 else |
806 cconvert->pub.color_convert = rgb_rgb_convert; | 837 cconvert->pub.color_convert = rgb_rgb_convert; |
807 } else | 838 } else |
808 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 839 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
809 break; | 840 break; |
810 | 841 |
811 case JCS_RGB565: | 842 case JCS_RGB565: |
812 cinfo->out_color_components = 3; | 843 cinfo->out_color_components = 3; |
813 if (cinfo->dither_mode == JDITHER_NONE) { | 844 if (cinfo->dither_mode == JDITHER_NONE) { |
814 if (cinfo->jpeg_color_space == JCS_YCbCr) { | 845 if (cinfo->jpeg_color_space == JCS_YCbCr) { |
815 if (jsimd_can_ycc_rgb565()) | 846 if (jsimd_can_ycc_rgb565()) |
816 cconvert->pub.color_convert = jsimd_ycc_rgb565_convert; | 847 cconvert->pub.color_convert = jsimd_ycc_rgb565_convert; |
817 else { | 848 else { |
818 cconvert->pub.color_convert = ycc_rgb565_convert; | 849 cconvert->pub.color_convert = ycc_rgb565_convert; |
819 build_ycc_rgb_table(cinfo); | 850 build_ycc_rgb_table(cinfo); |
820 } | 851 } |
821 } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { | 852 } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { |
822 cconvert->pub.color_convert = gray_rgb565_convert; | 853 cconvert->pub.color_convert = gray_rgb565_convert; |
823 } else if (cinfo->jpeg_color_space == JCS_RGB) { | 854 } else if (cinfo->jpeg_color_space == JCS_RGB) { |
824 cconvert->pub.color_convert = rgb_rgb565_convert; | 855 cconvert->pub.color_convert = rgb_rgb565_convert; |
825 } else | 856 } else |
826 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 857 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
827 } else { | 858 } else { |
828 /* only ordered dithering is supported */ | 859 /* only ordered dithering is supported */ |
829 if (cinfo->jpeg_color_space == JCS_YCbCr) { | 860 if (cinfo->jpeg_color_space == JCS_YCbCr) { |
830 cconvert->pub.color_convert = ycc_rgb565D_convert; | 861 cconvert->pub.color_convert = ycc_rgb565D_convert; |
831 build_ycc_rgb_table(cinfo); | 862 build_ycc_rgb_table(cinfo); |
832 } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { | 863 } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { |
833 cconvert->pub.color_convert = gray_rgb565D_convert; | 864 cconvert->pub.color_convert = gray_rgb565D_convert; |
834 } else if (cinfo->jpeg_color_space == JCS_RGB) { | 865 } else if (cinfo->jpeg_color_space == JCS_RGB) { |
835 cconvert->pub.color_convert = rgb_rgb565D_convert; | 866 cconvert->pub.color_convert = rgb_rgb565D_convert; |
836 } else | 867 } else |
837 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 868 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
838 } | 869 } |
839 break; | 870 break; |
840 | 871 |
841 case JCS_CMYK: | 872 case JCS_CMYK: |
842 cinfo->out_color_components = 4; | 873 cinfo->out_color_components = 4; |
843 if (cinfo->jpeg_color_space == JCS_YCCK) { | 874 if (cinfo->jpeg_color_space == JCS_YCCK) { |
844 cconvert->pub.color_convert = ycck_cmyk_convert; | 875 cconvert->pub.color_convert = ycck_cmyk_convert; |
845 build_ycc_rgb_table(cinfo); | 876 build_ycc_rgb_table(cinfo); |
846 } else if (cinfo->jpeg_color_space == JCS_CMYK) { | 877 } else if (cinfo->jpeg_color_space == JCS_CMYK) { |
847 cconvert->pub.color_convert = null_convert; | 878 cconvert->pub.color_convert = null_convert; |
848 } else | 879 } else |
849 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 880 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
850 break; | 881 break; |
851 | 882 |
852 default: | 883 default: |
853 /* Permit null conversion to same output space */ | 884 /* Permit null conversion to same output space */ |
854 if (cinfo->out_color_space == cinfo->jpeg_color_space) { | 885 if (cinfo->out_color_space == cinfo->jpeg_color_space) { |
855 cinfo->out_color_components = cinfo->num_components; | 886 cinfo->out_color_components = cinfo->num_components; |
856 cconvert->pub.color_convert = null_convert; | 887 cconvert->pub.color_convert = null_convert; |
857 } else» » » /* unsupported non-null conversion */ | 888 } else /* unsupported non-null conversion */ |
858 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 889 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
859 break; | 890 break; |
860 } | 891 } |
861 | 892 |
862 if (cinfo->quantize_colors) | 893 if (cinfo->quantize_colors) |
863 cinfo->output_components = 1; /* single colormapped output component */ | 894 cinfo->output_components = 1; /* single colormapped output component */ |
864 else | 895 else |
865 cinfo->output_components = cinfo->out_color_components; | 896 cinfo->output_components = cinfo->out_color_components; |
866 } | 897 } |
OLD | NEW |