OLD | NEW |
1 /* | 1 /* |
2 * jccolor.c | 2 * jccolor.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-1996, Thomas G. Lane. | 5 * Copyright (C) 1991-1996, Thomas G. Lane. |
6 * libjpeg-turbo Modifications: | 6 * libjpeg-turbo Modifications: |
7 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB | 7 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
8 * Copyright (C) 2009-2012, D. R. Commander. | 8 * Copyright (C) 2009-2012, 2015 D. R. Commander. |
9 * For conditions of distribution and use, see the accompanying README file. | 9 * Copyright (C) 2014, MIPS Technologies, Inc., California |
| 10 * For conditions of distribution and use, see the accompanying README.ijg |
| 11 * file. |
10 * | 12 * |
11 * This file contains input colorspace conversion routines. | 13 * This file contains input colorspace conversion routines. |
12 */ | 14 */ |
13 | 15 |
14 #define JPEG_INTERNALS | 16 #define JPEG_INTERNALS |
15 #include "jinclude.h" | 17 #include "jinclude.h" |
16 #include "jpeglib.h" | 18 #include "jpeglib.h" |
17 #include "jsimd.h" | 19 #include "jsimd.h" |
18 #include "config.h" | 20 #include "jconfigint.h" |
19 | 21 |
20 | 22 |
21 /* Private subobject */ | 23 /* Private subobject */ |
22 | 24 |
23 typedef struct { | 25 typedef struct { |
24 struct jpeg_color_converter pub; /* public fields */ | 26 struct jpeg_color_converter pub; /* public fields */ |
25 | 27 |
26 /* Private state for RGB->YCC conversion */ | 28 /* Private state for RGB->YCC conversion */ |
27 INT32 * rgb_ycc_tab;» » /* => table for RGB to YCbCr conversion */ | 29 JLONG *rgb_ycc_tab; /* => table for RGB to YCbCr conversion */ |
28 } my_color_converter; | 30 } my_color_converter; |
29 | 31 |
30 typedef my_color_converter * my_cconvert_ptr; | 32 typedef my_color_converter *my_cconvert_ptr; |
31 | 33 |
32 | 34 |
33 /**************** RGB -> YCbCr conversion: most common case **************/ | 35 /**************** RGB -> YCbCr conversion: most common case **************/ |
34 | 36 |
35 /* | 37 /* |
36 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are | 38 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are |
37 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. | 39 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. |
38 * The conversion equations to be implemented are therefore | 40 * The conversion equations to be implemented are therefore |
39 *» Y = 0.29900 * R + 0.58700 * G + 0.11400 * B | 41 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B |
40 *» Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE | 42 * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE |
41 *» Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE | 43 * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE |
42 * (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.) |
43 * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, | 45 * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, |
44 * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and | 46 * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and |
45 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0) | 47 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0) |
46 * were not represented exactly. Now we sacrifice exact representation of | 48 * were not represented exactly. Now we sacrifice exact representation of |
47 * maximum red and maximum blue in order to get exact grayscales. | 49 * maximum red and maximum blue in order to get exact grayscales. |
48 * | 50 * |
49 * To avoid floating-point arithmetic, we represent the fractional constants | 51 * To avoid floating-point arithmetic, we represent the fractional constants |
50 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide | 52 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide |
51 * the products by 2^16, with appropriate rounding, to get the correct answer. | 53 * the products by 2^16, with appropriate rounding, to get the correct answer. |
52 * | 54 * |
53 * For even more speed, we avoid doing any multiplications in the inner loop | 55 * For even more speed, we avoid doing any multiplications in the inner loop |
54 * by precalculating the constants times R,G,B for all possible values. | 56 * by precalculating the constants times R,G,B for all possible values. |
55 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); | 57 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); |
56 * for 12-bit samples it is still acceptable. It's not very reasonable for | 58 * for 12-bit samples it is still acceptable. It's not very reasonable for |
57 * 16-bit samples, but if you want lossless storage you shouldn't be changing | 59 * 16-bit samples, but if you want lossless storage you shouldn't be changing |
58 * colorspace anyway. | 60 * colorspace anyway. |
59 * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included | 61 * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included |
60 * in the tables to save adding them separately in the inner loop. | 62 * in the tables to save adding them separately in the inner loop. |
61 */ | 63 */ |
62 | 64 |
63 #define SCALEBITS» 16» /* speediest right-shift on some machines */ | 65 #define SCALEBITS 16 /* speediest right-shift on some machines */ |
64 #define CBCR_OFFSET» ((INT32) CENTERJSAMPLE << SCALEBITS) | 66 #define CBCR_OFFSET ((JLONG) CENTERJSAMPLE << SCALEBITS) |
65 #define ONE_HALF» ((INT32) 1 << (SCALEBITS-1)) | 67 #define ONE_HALF ((JLONG) 1 << (SCALEBITS-1)) |
66 #define FIX(x)» » ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) | 68 #define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5)) |
67 | 69 |
68 /* We allocate one big table and divide it up into eight parts, instead of | 70 /* We allocate one big table and divide it up into eight parts, instead of |
69 * doing eight alloc_small requests. This lets us use a single table base | 71 * doing eight alloc_small requests. This lets us use a single table base |
70 * address, which can be held in a register in the inner loops on many | 72 * address, which can be held in a register in the inner loops on many |
71 * machines (more than can hold all eight addresses, anyway). | 73 * machines (more than can hold all eight addresses, anyway). |
72 */ | 74 */ |
73 | 75 |
74 #define R_Y_OFF»» 0» » » /* offset to R => Y section */ | 76 #define R_Y_OFF 0 /* offset to R => Y section */ |
75 #define G_Y_OFF»» (1*(MAXJSAMPLE+1))» /* offset to G => Y section */ | 77 #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ |
76 #define B_Y_OFF»» (2*(MAXJSAMPLE+1))» /* etc. */ | 78 #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ |
77 #define R_CB_OFF» (3*(MAXJSAMPLE+1)) | 79 #define R_CB_OFF (3*(MAXJSAMPLE+1)) |
78 #define G_CB_OFF» (4*(MAXJSAMPLE+1)) | 80 #define G_CB_OFF (4*(MAXJSAMPLE+1)) |
79 #define B_CB_OFF» (5*(MAXJSAMPLE+1)) | 81 #define B_CB_OFF (5*(MAXJSAMPLE+1)) |
80 #define R_CR_OFF» B_CB_OFF» » /* B=>Cb, R=>Cr are the same */ | 82 #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ |
81 #define G_CR_OFF» (6*(MAXJSAMPLE+1)) | 83 #define G_CR_OFF (6*(MAXJSAMPLE+1)) |
82 #define B_CR_OFF» (7*(MAXJSAMPLE+1)) | 84 #define B_CR_OFF (7*(MAXJSAMPLE+1)) |
83 #define TABLE_SIZE» (8*(MAXJSAMPLE+1)) | 85 #define TABLE_SIZE (8*(MAXJSAMPLE+1)) |
84 | 86 |
85 | 87 |
86 /* Include inline routines for colorspace extensions */ | 88 /* Include inline routines for colorspace extensions */ |
87 | 89 |
88 #include "jccolext.c" | 90 #include "jccolext.c" |
89 #undef RGB_RED | 91 #undef RGB_RED |
90 #undef RGB_GREEN | 92 #undef RGB_GREEN |
91 #undef RGB_BLUE | 93 #undef RGB_BLUE |
92 #undef RGB_PIXELSIZE | 94 #undef RGB_PIXELSIZE |
93 | 95 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 191 |
190 | 192 |
191 /* | 193 /* |
192 * Initialize for RGB->YCC colorspace conversion. | 194 * Initialize for RGB->YCC colorspace conversion. |
193 */ | 195 */ |
194 | 196 |
195 METHODDEF(void) | 197 METHODDEF(void) |
196 rgb_ycc_start (j_compress_ptr cinfo) | 198 rgb_ycc_start (j_compress_ptr cinfo) |
197 { | 199 { |
198 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 200 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
199 INT32 * rgb_ycc_tab; | 201 JLONG *rgb_ycc_tab; |
200 INT32 i; | 202 JLONG i; |
201 | 203 |
202 /* Allocate and fill in the conversion tables. */ | 204 /* Allocate and fill in the conversion tables. */ |
203 cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) | 205 cconvert->rgb_ycc_tab = rgb_ycc_tab = (JLONG *) |
204 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 206 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
205 » » » » (TABLE_SIZE * SIZEOF(INT32))); | 207 (TABLE_SIZE * sizeof(JLONG))); |
206 | 208 |
207 for (i = 0; i <= MAXJSAMPLE; i++) { | 209 for (i = 0; i <= MAXJSAMPLE; i++) { |
208 rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; | 210 rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; |
209 rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; | 211 rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; |
210 rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; | 212 rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; |
211 rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; | 213 rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; |
212 rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; | 214 rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; |
213 /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. | 215 /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. |
214 * This ensures that the maximum output will round to MAXJSAMPLE | 216 * This ensures that the maximum output will round to MAXJSAMPLE |
215 * not MAXJSAMPLE+1, and thus that we don't have to range-limit. | 217 * not MAXJSAMPLE+1, and thus that we don't have to range-limit. |
216 */ | 218 */ |
217 rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; | 219 rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; |
218 /* B=>Cb and R=>Cr tables are the same | 220 /* B=>Cb and R=>Cr tables are the same |
219 rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; | 221 rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; |
220 */ | 222 */ |
221 rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; | 223 rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; |
222 rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; | 224 rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; |
223 } | 225 } |
224 } | 226 } |
225 | 227 |
226 | 228 |
227 /* | 229 /* |
228 * Convert some rows of samples to the JPEG colorspace. | 230 * Convert some rows of samples to the JPEG colorspace. |
229 */ | 231 */ |
230 | 232 |
231 METHODDEF(void) | 233 METHODDEF(void) |
232 rgb_ycc_convert (j_compress_ptr cinfo, | 234 rgb_ycc_convert (j_compress_ptr cinfo, |
233 » » JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 235 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
234 » » JDIMENSION output_row, int num_rows) | 236 JDIMENSION output_row, int num_rows) |
235 { | 237 { |
236 switch (cinfo->in_color_space) { | 238 switch (cinfo->in_color_space) { |
237 case JCS_EXT_RGB: | 239 case JCS_EXT_RGB: |
238 extrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, | 240 extrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
239 num_rows); | 241 num_rows); |
240 break; | 242 break; |
241 case JCS_EXT_RGBX: | 243 case JCS_EXT_RGBX: |
242 case JCS_EXT_RGBA: | 244 case JCS_EXT_RGBA: |
243 extrgbx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, | 245 extrgbx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
244 num_rows); | 246 num_rows); |
(...skipping 27 matching lines...) Expand all Loading... |
272 | 274 |
273 /**************** Cases other than RGB -> YCbCr **************/ | 275 /**************** Cases other than RGB -> YCbCr **************/ |
274 | 276 |
275 | 277 |
276 /* | 278 /* |
277 * Convert some rows of samples to the JPEG colorspace. | 279 * Convert some rows of samples to the JPEG colorspace. |
278 */ | 280 */ |
279 | 281 |
280 METHODDEF(void) | 282 METHODDEF(void) |
281 rgb_gray_convert (j_compress_ptr cinfo, | 283 rgb_gray_convert (j_compress_ptr cinfo, |
282 » » JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 284 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
283 » » JDIMENSION output_row, int num_rows) | 285 JDIMENSION output_row, int num_rows) |
284 { | 286 { |
285 switch (cinfo->in_color_space) { | 287 switch (cinfo->in_color_space) { |
286 case JCS_EXT_RGB: | 288 case JCS_EXT_RGB: |
287 extrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, | 289 extrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
288 num_rows); | 290 num_rows); |
289 break; | 291 break; |
290 case JCS_EXT_RGBX: | 292 case JCS_EXT_RGBX: |
291 case JCS_EXT_RGBA: | 293 case JCS_EXT_RGBA: |
292 extrgbx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, | 294 extrgbx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
293 num_rows); | 295 num_rows); |
(...skipping 24 matching lines...) Expand all Loading... |
318 } | 320 } |
319 } | 321 } |
320 | 322 |
321 | 323 |
322 /* | 324 /* |
323 * Extended RGB to plain RGB conversion | 325 * Extended RGB to plain RGB conversion |
324 */ | 326 */ |
325 | 327 |
326 METHODDEF(void) | 328 METHODDEF(void) |
327 rgb_rgb_convert (j_compress_ptr cinfo, | 329 rgb_rgb_convert (j_compress_ptr cinfo, |
328 » » JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 330 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
329 » » JDIMENSION output_row, int num_rows) | 331 JDIMENSION output_row, int num_rows) |
330 { | 332 { |
331 switch (cinfo->in_color_space) { | 333 switch (cinfo->in_color_space) { |
332 case JCS_EXT_RGB: | 334 case JCS_EXT_RGB: |
333 extrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, | 335 extrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
334 num_rows); | 336 num_rows); |
335 break; | 337 break; |
336 case JCS_EXT_RGBX: | 338 case JCS_EXT_RGBX: |
337 case JCS_EXT_RGBA: | 339 case JCS_EXT_RGBA: |
338 extrgbx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, | 340 extrgbx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
339 num_rows); | 341 num_rows); |
(...skipping 28 matching lines...) Expand all Loading... |
368 /* | 370 /* |
369 * Convert some rows of samples to the JPEG colorspace. | 371 * Convert some rows of samples to the JPEG colorspace. |
370 * This version handles Adobe-style CMYK->YCCK conversion, | 372 * This version handles Adobe-style CMYK->YCCK conversion, |
371 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same | 373 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same |
372 * conversion as above, while passing K (black) unchanged. | 374 * conversion as above, while passing K (black) unchanged. |
373 * We assume rgb_ycc_start has been called. | 375 * We assume rgb_ycc_start has been called. |
374 */ | 376 */ |
375 | 377 |
376 METHODDEF(void) | 378 METHODDEF(void) |
377 cmyk_ycck_convert (j_compress_ptr cinfo, | 379 cmyk_ycck_convert (j_compress_ptr cinfo, |
378 » » JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 380 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
379 » » JDIMENSION output_row, int num_rows) | 381 JDIMENSION output_row, int num_rows) |
380 { | 382 { |
381 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 383 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
382 register int r, g, b; | 384 register int r, g, b; |
383 register INT32 * ctab = cconvert->rgb_ycc_tab; | 385 register JLONG *ctab = cconvert->rgb_ycc_tab; |
384 register JSAMPROW inptr; | 386 register JSAMPROW inptr; |
385 register JSAMPROW outptr0, outptr1, outptr2, outptr3; | 387 register JSAMPROW outptr0, outptr1, outptr2, outptr3; |
386 register JDIMENSION col; | 388 register JDIMENSION col; |
387 JDIMENSION num_cols = cinfo->image_width; | 389 JDIMENSION num_cols = cinfo->image_width; |
388 | 390 |
389 while (--num_rows >= 0) { | 391 while (--num_rows >= 0) { |
390 inptr = *input_buf++; | 392 inptr = *input_buf++; |
391 outptr0 = output_buf[0][output_row]; | 393 outptr0 = output_buf[0][output_row]; |
392 outptr1 = output_buf[1][output_row]; | 394 outptr1 = output_buf[1][output_row]; |
393 outptr2 = output_buf[2][output_row]; | 395 outptr2 = output_buf[2][output_row]; |
394 outptr3 = output_buf[3][output_row]; | 396 outptr3 = output_buf[3][output_row]; |
395 output_row++; | 397 output_row++; |
396 for (col = 0; col < num_cols; col++) { | 398 for (col = 0; col < num_cols; col++) { |
397 r = MAXJSAMPLE - GETJSAMPLE(inptr[0]); | 399 r = MAXJSAMPLE - GETJSAMPLE(inptr[0]); |
398 g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); | 400 g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); |
399 b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); | 401 b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); |
400 /* K passes through as-is */ | 402 /* K passes through as-is */ |
401 outptr3[col] = inptr[3];» /* don't need GETJSAMPLE here */ | 403 outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ |
402 inptr += 4; | 404 inptr += 4; |
403 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations | 405 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations |
404 * must be too; we do not need an explicit range-limiting operation. | 406 * must be too; we do not need an explicit range-limiting operation. |
405 * Hence the value being shifted is never negative, and we don't | 407 * Hence the value being shifted is never negative, and we don't |
406 * need the general RIGHT_SHIFT macro. | 408 * need the general RIGHT_SHIFT macro. |
407 */ | 409 */ |
408 /* Y */ | 410 /* Y */ |
409 outptr0[col] = (JSAMPLE) | 411 outptr0[col] = (JSAMPLE) |
410 » » ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) | 412 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) |
411 » » >> SCALEBITS); | 413 >> SCALEBITS); |
412 /* Cb */ | 414 /* Cb */ |
413 outptr1[col] = (JSAMPLE) | 415 outptr1[col] = (JSAMPLE) |
414 » » ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) | 416 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) |
415 » » >> SCALEBITS); | 417 >> SCALEBITS); |
416 /* Cr */ | 418 /* Cr */ |
417 outptr2[col] = (JSAMPLE) | 419 outptr2[col] = (JSAMPLE) |
418 » » ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) | 420 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) |
419 » » >> SCALEBITS); | 421 >> SCALEBITS); |
420 } | 422 } |
421 } | 423 } |
422 } | 424 } |
423 | 425 |
424 | 426 |
425 /* | 427 /* |
426 * Convert some rows of samples to the JPEG colorspace. | 428 * Convert some rows of samples to the JPEG colorspace. |
427 * This version handles grayscale output with no conversion. | 429 * This version handles grayscale output with no conversion. |
428 * The source can be either plain grayscale or YCbCr (since Y == gray). | 430 * The source can be either plain grayscale or YCbCr (since Y == gray). |
429 */ | 431 */ |
430 | 432 |
431 METHODDEF(void) | 433 METHODDEF(void) |
432 grayscale_convert (j_compress_ptr cinfo, | 434 grayscale_convert (j_compress_ptr cinfo, |
433 » » JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 435 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
434 » » JDIMENSION output_row, int num_rows) | 436 JDIMENSION output_row, int num_rows) |
435 { | 437 { |
436 register JSAMPROW inptr; | 438 register JSAMPROW inptr; |
437 register JSAMPROW outptr; | 439 register JSAMPROW outptr; |
438 register JDIMENSION col; | 440 register JDIMENSION col; |
439 JDIMENSION num_cols = cinfo->image_width; | 441 JDIMENSION num_cols = cinfo->image_width; |
440 int instride = cinfo->input_components; | 442 int instride = cinfo->input_components; |
441 | 443 |
442 while (--num_rows >= 0) { | 444 while (--num_rows >= 0) { |
443 inptr = *input_buf++; | 445 inptr = *input_buf++; |
444 outptr = output_buf[0][output_row]; | 446 outptr = output_buf[0][output_row]; |
445 output_row++; | 447 output_row++; |
446 for (col = 0; col < num_cols; col++) { | 448 for (col = 0; col < num_cols; col++) { |
447 outptr[col] = inptr[0];» /* don't need GETJSAMPLE() here */ | 449 outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ |
448 inptr += instride; | 450 inptr += instride; |
449 } | 451 } |
450 } | 452 } |
451 } | 453 } |
452 | 454 |
453 | 455 |
454 /* | 456 /* |
455 * Convert some rows of samples to the JPEG colorspace. | 457 * Convert some rows of samples to the JPEG colorspace. |
456 * This version handles multi-component colorspaces without conversion. | 458 * This version handles multi-component colorspaces without conversion. |
457 * We assume input_components == num_components. | 459 * We assume input_components == num_components. |
458 */ | 460 */ |
459 | 461 |
460 METHODDEF(void) | 462 METHODDEF(void) |
461 null_convert (j_compress_ptr cinfo, | 463 null_convert (j_compress_ptr cinfo, |
462 » JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 464 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
463 » JDIMENSION output_row, int num_rows) | 465 JDIMENSION output_row, int num_rows) |
464 { | 466 { |
465 register JSAMPROW inptr; | 467 register JSAMPROW inptr; |
466 register JSAMPROW outptr; | 468 register JSAMPROW outptr, outptr0, outptr1, outptr2, outptr3; |
467 register JDIMENSION col; | 469 register JDIMENSION col; |
468 register int ci; | 470 register int ci; |
469 int nc = cinfo->num_components; | 471 int nc = cinfo->num_components; |
470 JDIMENSION num_cols = cinfo->image_width; | 472 JDIMENSION num_cols = cinfo->image_width; |
471 | 473 |
472 while (--num_rows >= 0) { | 474 if (nc == 3) { |
473 /* It seems fastest to make a separate pass for each component. */ | 475 while (--num_rows >= 0) { |
474 for (ci = 0; ci < nc; ci++) { | 476 inptr = *input_buf++; |
475 inptr = *input_buf; | 477 outptr0 = output_buf[0][output_row]; |
476 outptr = output_buf[ci][output_row]; | 478 outptr1 = output_buf[1][output_row]; |
| 479 outptr2 = output_buf[2][output_row]; |
| 480 output_row++; |
477 for (col = 0; col < num_cols; col++) { | 481 for (col = 0; col < num_cols; col++) { |
478 » outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ | 482 outptr0[col] = *inptr++; |
479 » inptr += nc; | 483 outptr1[col] = *inptr++; |
| 484 outptr2[col] = *inptr++; |
480 } | 485 } |
481 } | 486 } |
482 input_buf++; | 487 } else if (nc == 4) { |
483 output_row++; | 488 while (--num_rows >= 0) { |
| 489 inptr = *input_buf++; |
| 490 outptr0 = output_buf[0][output_row]; |
| 491 outptr1 = output_buf[1][output_row]; |
| 492 outptr2 = output_buf[2][output_row]; |
| 493 outptr3 = output_buf[3][output_row]; |
| 494 output_row++; |
| 495 for (col = 0; col < num_cols; col++) { |
| 496 outptr0[col] = *inptr++; |
| 497 outptr1[col] = *inptr++; |
| 498 outptr2[col] = *inptr++; |
| 499 outptr3[col] = *inptr++; |
| 500 } |
| 501 } |
| 502 } else { |
| 503 while (--num_rows >= 0) { |
| 504 /* It seems fastest to make a separate pass for each component. */ |
| 505 for (ci = 0; ci < nc; ci++) { |
| 506 inptr = *input_buf; |
| 507 outptr = output_buf[ci][output_row]; |
| 508 for (col = 0; col < num_cols; col++) { |
| 509 outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ |
| 510 inptr += nc; |
| 511 } |
| 512 } |
| 513 input_buf++; |
| 514 output_row++; |
| 515 } |
484 } | 516 } |
485 } | 517 } |
486 | 518 |
487 | 519 |
488 /* | 520 /* |
489 * Empty method for start_pass. | 521 * Empty method for start_pass. |
490 */ | 522 */ |
491 | 523 |
492 METHODDEF(void) | 524 METHODDEF(void) |
493 null_method (j_compress_ptr cinfo) | 525 null_method (j_compress_ptr cinfo) |
494 { | 526 { |
495 /* no work needed */ | 527 /* no work needed */ |
496 } | 528 } |
497 | 529 |
498 | 530 |
499 /* | 531 /* |
500 * Module initialization routine for input colorspace conversion. | 532 * Module initialization routine for input colorspace conversion. |
501 */ | 533 */ |
502 | 534 |
503 GLOBAL(void) | 535 GLOBAL(void) |
504 jinit_color_converter (j_compress_ptr cinfo) | 536 jinit_color_converter (j_compress_ptr cinfo) |
505 { | 537 { |
506 my_cconvert_ptr cconvert; | 538 my_cconvert_ptr cconvert; |
507 | 539 |
508 cconvert = (my_cconvert_ptr) | 540 cconvert = (my_cconvert_ptr) |
509 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 541 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
510 » » » » SIZEOF(my_color_converter)); | 542 sizeof(my_color_converter)); |
511 cinfo->cconvert = (struct jpeg_color_converter *) cconvert; | 543 cinfo->cconvert = (struct jpeg_color_converter *) cconvert; |
512 /* set start_pass to null method until we find out differently */ | 544 /* set start_pass to null method until we find out differently */ |
513 cconvert->pub.start_pass = null_method; | 545 cconvert->pub.start_pass = null_method; |
514 | 546 |
515 /* Make sure input_components agrees with in_color_space */ | 547 /* Make sure input_components agrees with in_color_space */ |
516 switch (cinfo->in_color_space) { | 548 switch (cinfo->in_color_space) { |
517 case JCS_GRAYSCALE: | 549 case JCS_GRAYSCALE: |
518 if (cinfo->input_components != 1) | 550 if (cinfo->input_components != 1) |
519 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 551 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
520 break; | 552 break; |
(...skipping 17 matching lines...) Expand all Loading... |
538 if (cinfo->input_components != 3) | 570 if (cinfo->input_components != 3) |
539 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 571 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
540 break; | 572 break; |
541 | 573 |
542 case JCS_CMYK: | 574 case JCS_CMYK: |
543 case JCS_YCCK: | 575 case JCS_YCCK: |
544 if (cinfo->input_components != 4) | 576 if (cinfo->input_components != 4) |
545 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 577 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
546 break; | 578 break; |
547 | 579 |
548 default:» » » /* JCS_UNKNOWN can be anything */ | 580 default: /* JCS_UNKNOWN can be anything */ |
549 if (cinfo->input_components < 1) | 581 if (cinfo->input_components < 1) |
550 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 582 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
551 break; | 583 break; |
552 } | 584 } |
553 | 585 |
554 /* Check num_components, set conversion method based on requested space */ | 586 /* Check num_components, set conversion method based on requested space */ |
555 switch (cinfo->jpeg_color_space) { | 587 switch (cinfo->jpeg_color_space) { |
556 case JCS_GRAYSCALE: | 588 case JCS_GRAYSCALE: |
557 if (cinfo->num_components != 1) | 589 if (cinfo->num_components != 1) |
558 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 590 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
(...skipping 21 matching lines...) Expand all Loading... |
580 else | 612 else |
581 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 613 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
582 break; | 614 break; |
583 | 615 |
584 case JCS_RGB: | 616 case JCS_RGB: |
585 if (cinfo->num_components != 3) | 617 if (cinfo->num_components != 3) |
586 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 618 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
587 if (rgb_red[cinfo->in_color_space] == 0 && | 619 if (rgb_red[cinfo->in_color_space] == 0 && |
588 rgb_green[cinfo->in_color_space] == 1 && | 620 rgb_green[cinfo->in_color_space] == 1 && |
589 rgb_blue[cinfo->in_color_space] == 2 && | 621 rgb_blue[cinfo->in_color_space] == 2 && |
590 rgb_pixelsize[cinfo->in_color_space] == 3) | 622 rgb_pixelsize[cinfo->in_color_space] == 3) { |
591 cconvert->pub.color_convert = null_convert; | 623 #if defined(__mips__) |
592 else if (cinfo->in_color_space == JCS_RGB || | 624 if (jsimd_c_can_null_convert()) |
593 cinfo->in_color_space == JCS_EXT_RGB || | 625 cconvert->pub.color_convert = jsimd_c_null_convert; |
594 cinfo->in_color_space == JCS_EXT_RGBX || | 626 else |
595 cinfo->in_color_space == JCS_EXT_BGR || | 627 #endif |
596 cinfo->in_color_space == JCS_EXT_BGRX || | 628 cconvert->pub.color_convert = null_convert; |
597 cinfo->in_color_space == JCS_EXT_XBGR || | 629 } else if (cinfo->in_color_space == JCS_RGB || |
598 cinfo->in_color_space == JCS_EXT_XRGB || | 630 cinfo->in_color_space == JCS_EXT_RGB || |
599 cinfo->in_color_space == JCS_EXT_RGBA || | 631 cinfo->in_color_space == JCS_EXT_RGBX || |
600 cinfo->in_color_space == JCS_EXT_BGRA || | 632 cinfo->in_color_space == JCS_EXT_BGR || |
601 cinfo->in_color_space == JCS_EXT_ABGR || | 633 cinfo->in_color_space == JCS_EXT_BGRX || |
602 cinfo->in_color_space == JCS_EXT_ARGB) | 634 cinfo->in_color_space == JCS_EXT_XBGR || |
| 635 cinfo->in_color_space == JCS_EXT_XRGB || |
| 636 cinfo->in_color_space == JCS_EXT_RGBA || |
| 637 cinfo->in_color_space == JCS_EXT_BGRA || |
| 638 cinfo->in_color_space == JCS_EXT_ABGR || |
| 639 cinfo->in_color_space == JCS_EXT_ARGB) |
603 cconvert->pub.color_convert = rgb_rgb_convert; | 640 cconvert->pub.color_convert = rgb_rgb_convert; |
604 else | 641 else |
605 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 642 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
606 break; | 643 break; |
607 | 644 |
608 case JCS_YCbCr: | 645 case JCS_YCbCr: |
609 if (cinfo->num_components != 3) | 646 if (cinfo->num_components != 3) |
610 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 647 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
611 if (cinfo->in_color_space == JCS_RGB || | 648 if (cinfo->in_color_space == JCS_RGB || |
612 cinfo->in_color_space == JCS_EXT_RGB || | 649 cinfo->in_color_space == JCS_EXT_RGB || |
613 cinfo->in_color_space == JCS_EXT_RGBX || | 650 cinfo->in_color_space == JCS_EXT_RGBX || |
614 cinfo->in_color_space == JCS_EXT_BGR || | 651 cinfo->in_color_space == JCS_EXT_BGR || |
615 cinfo->in_color_space == JCS_EXT_BGRX || | 652 cinfo->in_color_space == JCS_EXT_BGRX || |
616 cinfo->in_color_space == JCS_EXT_XBGR || | 653 cinfo->in_color_space == JCS_EXT_XBGR || |
617 cinfo->in_color_space == JCS_EXT_XRGB || | 654 cinfo->in_color_space == JCS_EXT_XRGB || |
618 cinfo->in_color_space == JCS_EXT_RGBA || | 655 cinfo->in_color_space == JCS_EXT_RGBA || |
619 cinfo->in_color_space == JCS_EXT_BGRA || | 656 cinfo->in_color_space == JCS_EXT_BGRA || |
620 cinfo->in_color_space == JCS_EXT_ABGR || | 657 cinfo->in_color_space == JCS_EXT_ABGR || |
621 cinfo->in_color_space == JCS_EXT_ARGB) { | 658 cinfo->in_color_space == JCS_EXT_ARGB) { |
622 if (jsimd_can_rgb_ycc()) | 659 if (jsimd_can_rgb_ycc()) |
623 cconvert->pub.color_convert = jsimd_rgb_ycc_convert; | 660 cconvert->pub.color_convert = jsimd_rgb_ycc_convert; |
624 else { | 661 else { |
625 cconvert->pub.start_pass = rgb_ycc_start; | 662 cconvert->pub.start_pass = rgb_ycc_start; |
626 cconvert->pub.color_convert = rgb_ycc_convert; | 663 cconvert->pub.color_convert = rgb_ycc_convert; |
627 } | 664 } |
628 } else if (cinfo->in_color_space == JCS_YCbCr) | 665 } else if (cinfo->in_color_space == JCS_YCbCr) { |
629 cconvert->pub.color_convert = null_convert; | 666 #if defined(__mips__) |
630 else | 667 if (jsimd_c_can_null_convert()) |
| 668 cconvert->pub.color_convert = jsimd_c_null_convert; |
| 669 else |
| 670 #endif |
| 671 cconvert->pub.color_convert = null_convert; |
| 672 } else |
631 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 673 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
632 break; | 674 break; |
633 | 675 |
634 case JCS_CMYK: | 676 case JCS_CMYK: |
635 if (cinfo->num_components != 4) | 677 if (cinfo->num_components != 4) |
636 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 678 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
637 if (cinfo->in_color_space == JCS_CMYK) | 679 if (cinfo->in_color_space == JCS_CMYK) { |
638 cconvert->pub.color_convert = null_convert; | 680 #if defined(__mips__) |
639 else | 681 if (jsimd_c_can_null_convert()) |
| 682 cconvert->pub.color_convert = jsimd_c_null_convert; |
| 683 else |
| 684 #endif |
| 685 cconvert->pub.color_convert = null_convert; |
| 686 } else |
640 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 687 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
641 break; | 688 break; |
642 | 689 |
643 case JCS_YCCK: | 690 case JCS_YCCK: |
644 if (cinfo->num_components != 4) | 691 if (cinfo->num_components != 4) |
645 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); | 692 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
646 if (cinfo->in_color_space == JCS_CMYK) { | 693 if (cinfo->in_color_space == JCS_CMYK) { |
647 cconvert->pub.start_pass = rgb_ycc_start; | 694 cconvert->pub.start_pass = rgb_ycc_start; |
648 cconvert->pub.color_convert = cmyk_ycck_convert; | 695 cconvert->pub.color_convert = cmyk_ycck_convert; |
649 } else if (cinfo->in_color_space == JCS_YCCK) | 696 } else if (cinfo->in_color_space == JCS_YCCK) { |
650 cconvert->pub.color_convert = null_convert; | 697 #if defined(__mips__) |
651 else | 698 if (jsimd_c_can_null_convert()) |
| 699 cconvert->pub.color_convert = jsimd_c_null_convert; |
| 700 else |
| 701 #endif |
| 702 cconvert->pub.color_convert = null_convert; |
| 703 } else |
652 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 704 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
653 break; | 705 break; |
654 | 706 |
655 default:» » » /* allow null conversion of JCS_UNKNOWN */ | 707 default: /* allow null conversion of JCS_UNKNOWN */ |
656 if (cinfo->jpeg_color_space != cinfo->in_color_space || | 708 if (cinfo->jpeg_color_space != cinfo->in_color_space || |
657 » cinfo->num_components != cinfo->input_components) | 709 cinfo->num_components != cinfo->input_components) |
658 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 710 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
659 cconvert->pub.color_convert = null_convert; | 711 #if defined(__mips__) |
| 712 if (jsimd_c_can_null_convert()) |
| 713 cconvert->pub.color_convert = jsimd_c_null_convert; |
| 714 else |
| 715 #endif |
| 716 cconvert->pub.color_convert = null_convert; |
660 break; | 717 break; |
661 } | 718 } |
662 } | 719 } |
OLD | NEW |