Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Side by Side Diff: third_party/libjpeg_turbo/jccolor.c

Issue 7554002: Updates libjpeg-turbo to 1.1.90 (r677) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libjpeg_turbo/jcarith.c ('k') | third_party/libjpeg_turbo/jcdctmgr.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * jccolor.c 2 * jccolor.c
3 * 3 *
4 * Copyright (C) 1991-1996, Thomas G. Lane. 4 * Copyright (C) 1991-1996, 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 2009 D. R. Commander 6 * Copyright 2009-2011 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 input colorspace conversion routines. 10 * This file contains input 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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ 74 #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
75 #define R_CB_OFF (3*(MAXJSAMPLE+1)) 75 #define R_CB_OFF (3*(MAXJSAMPLE+1))
76 #define G_CB_OFF (4*(MAXJSAMPLE+1)) 76 #define G_CB_OFF (4*(MAXJSAMPLE+1))
77 #define B_CB_OFF (5*(MAXJSAMPLE+1)) 77 #define B_CB_OFF (5*(MAXJSAMPLE+1))
78 #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ 78 #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
79 #define G_CR_OFF (6*(MAXJSAMPLE+1)) 79 #define G_CR_OFF (6*(MAXJSAMPLE+1))
80 #define B_CR_OFF (7*(MAXJSAMPLE+1)) 80 #define B_CR_OFF (7*(MAXJSAMPLE+1))
81 #define TABLE_SIZE (8*(MAXJSAMPLE+1)) 81 #define TABLE_SIZE (8*(MAXJSAMPLE+1))
82 82
83 83
84 #if BITS_IN_JSAMPLE == 8
85
86 const unsigned char red_lut[256] = {
87 0 , 0 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 4 , 4 ,
88 5 , 5 , 5 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 8 , 8 , 8 , 9 , 9 , 9 ,
89 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14,
90 14, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19,
91 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 24,
92 24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 28,
93 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33,
94 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 36, 37, 37, 37, 38, 38,
95 38, 39, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, 42, 43,
96 43, 43, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 47, 47, 47, 48,
97 48, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52,
98 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57,
99 57, 58, 58, 58, 59, 59, 59, 60, 60, 60, 60, 61, 61, 61, 62, 62,
100 62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67,
101 67, 67, 68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71,
102 72, 72, 72, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76
103 };
104
105 const unsigned char green_lut[256] = {
106 0 , 1 , 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 6 , 6 ,
107 7 , 8 , 8 , 9 , 9 , 10 , 11 , 11 , 12 , 12 , 13 , 14 ,
108 14 , 15 , 15 , 16 , 16 , 17 , 18 , 18 , 19 , 19 , 20 , 21 ,
109 21 , 22 , 22 , 23 , 23 , 24 , 25 , 25 , 26 , 26 , 27 , 28 ,
110 28 , 29 , 29 , 30 , 31 , 31 , 32 , 32 , 33 , 33 , 34 , 35 ,
111 35 , 36 , 36 , 37 , 38 , 38 , 39 , 39 , 40 , 41 , 41 , 42 ,
112 42 , 43 , 43 , 44 , 45 , 45 , 46 , 46 , 47 , 48 , 48 , 49 ,
113 49 , 50 , 50 , 51 , 52 , 52 , 53 , 53 , 54 , 55 , 55 , 56 ,
114 56 , 57 , 58 , 58 , 59 , 59 , 60 , 60 , 61 , 62 , 62 , 63 ,
115 63 , 64 , 65 , 65 , 66 , 66 , 67 , 68 , 68 , 69 , 69 , 70 ,
116 70 , 71 , 72 , 72 , 73 , 73 , 74 , 75 , 75 , 76 , 76 , 77 ,
117 77 , 78 , 79 , 79 , 80 , 80 , 81 , 82 , 82 , 83 , 83 , 84 ,
118 85 , 85 , 86 , 86 , 87 , 87 , 88 , 89 , 89 , 90 , 90 , 91 ,
119 92 , 92 , 93 , 93 , 94 , 95 , 95 , 96 , 96 , 97 , 97 , 98 ,
120 99 , 99 , 100, 100, 101, 102, 102, 103, 103, 104, 104, 105,
121 106, 106, 107, 107, 108, 109, 109, 110, 110, 111, 112, 112,
122 113, 113, 114, 114, 115, 116, 116, 117, 117, 118, 119, 119,
123 120, 120, 121, 122, 122, 123, 123, 124, 124, 125, 126, 126,
124 127, 127, 128, 129, 129, 130, 130, 131, 131, 132, 133, 133,
125 34, 134, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140,
126 141, 141, 142, 143, 143, 144, 144, 145, 146, 146, 147, 147,
127 148, 149, 149, 150
128 };
129
130 const unsigned char blue_lut[256] = {
131 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 ,
132 2 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 4 ,
133 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ,
134 5 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 7 , 7 ,
135 7 , 7 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 9 , 9 , 9 , 9 , 9 ,
136 9 , 9 , 9 , 9 , 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11,
137 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13,
138 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14,
139 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
140 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18,
141 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20,
142 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22,
143 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24,
144 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25,
145 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27,
146 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29
147 };
148
149 #endif
150
151
152 /* 84 /*
153 * Initialize for RGB->YCC colorspace conversion. 85 * Initialize for RGB->YCC colorspace conversion.
154 */ 86 */
155 87
156 METHODDEF(void) 88 METHODDEF(void)
157 rgb_ycc_start (j_compress_ptr cinfo) 89 rgb_ycc_start (j_compress_ptr cinfo)
158 { 90 {
159 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 91 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
160 INT32 * rgb_ycc_tab; 92 INT32 * rgb_ycc_tab;
161 INT32 i; 93 INT32 i;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 134 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
203 JDIMENSION output_row, int num_rows) 135 JDIMENSION output_row, int num_rows)
204 { 136 {
205 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 137 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
206 register int r, g, b; 138 register int r, g, b;
207 register INT32 * ctab = cconvert->rgb_ycc_tab; 139 register INT32 * ctab = cconvert->rgb_ycc_tab;
208 register JSAMPROW inptr; 140 register JSAMPROW inptr;
209 register JSAMPROW outptr0, outptr1, outptr2; 141 register JSAMPROW outptr0, outptr1, outptr2;
210 register JDIMENSION col; 142 register JDIMENSION col;
211 JDIMENSION num_cols = cinfo->image_width; 143 JDIMENSION num_cols = cinfo->image_width;
144 int rindex = rgb_red[cinfo->in_color_space];
145 int gindex = rgb_green[cinfo->in_color_space];
146 int bindex = rgb_blue[cinfo->in_color_space];
147 int rgbstride = rgb_pixelsize[cinfo->in_color_space];
212 148
213 while (--num_rows >= 0) { 149 while (--num_rows >= 0) {
214 inptr = *input_buf++; 150 inptr = *input_buf++;
215 outptr0 = output_buf[0][output_row]; 151 outptr0 = output_buf[0][output_row];
216 outptr1 = output_buf[1][output_row]; 152 outptr1 = output_buf[1][output_row];
217 outptr2 = output_buf[2][output_row]; 153 outptr2 = output_buf[2][output_row];
218 output_row++; 154 output_row++;
219 for (col = 0; col < num_cols; col++) { 155 for (col = 0; col < num_cols; col++) {
220 r = GETJSAMPLE(inptr[rgb_red[cinfo->in_color_space]]); 156 r = GETJSAMPLE(inptr[rindex]);
221 g = GETJSAMPLE(inptr[rgb_green[cinfo->in_color_space]]); 157 g = GETJSAMPLE(inptr[gindex]);
222 b = GETJSAMPLE(inptr[rgb_blue[cinfo->in_color_space]]); 158 b = GETJSAMPLE(inptr[bindex]);
223 inptr += rgb_pixelsize[cinfo->in_color_space]; 159 inptr += rgbstride;
224 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations 160 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
225 * must be too; we do not need an explicit range-limiting operation. 161 * must be too; we do not need an explicit range-limiting operation.
226 * Hence the value being shifted is never negative, and we don't 162 * Hence the value being shifted is never negative, and we don't
227 * need the general RIGHT_SHIFT macro. 163 * need the general RIGHT_SHIFT macro.
228 */ 164 */
229 /* Y */ 165 /* Y */
230 outptr0[col] = (JSAMPLE) 166 outptr0[col] = (JSAMPLE)
231 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) 167 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
232 >> SCALEBITS); 168 >> SCALEBITS);
233 /* Cb */ 169 /* Cb */
(...skipping 18 matching lines...) Expand all
252 * as the RGB->Y portion of RGB->YCbCr. 188 * as the RGB->Y portion of RGB->YCbCr.
253 * We assume rgb_ycc_start has been called (we only use the Y tables). 189 * We assume rgb_ycc_start has been called (we only use the Y tables).
254 */ 190 */
255 191
256 METHODDEF(void) 192 METHODDEF(void)
257 rgb_gray_convert (j_compress_ptr cinfo, 193 rgb_gray_convert (j_compress_ptr cinfo,
258 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 194 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
259 JDIMENSION output_row, int num_rows) 195 JDIMENSION output_row, int num_rows)
260 { 196 {
261 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 197 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
262 #if BITS_IN_JSAMPLE != 8 198 register int r, g, b;
263 register INT32 * ctab = cconvert->rgb_ycc_tab; 199 register INT32 * ctab = cconvert->rgb_ycc_tab;
264 #endif
265 register JSAMPROW inptr; 200 register JSAMPROW inptr;
266 register JSAMPROW outptr; 201 register JSAMPROW outptr;
267 JSAMPLE *maxoutptr;
268 register JDIMENSION col; 202 register JDIMENSION col;
269 JDIMENSION num_cols = cinfo->image_width; 203 JDIMENSION num_cols = cinfo->image_width;
270 int rindex = rgb_red[cinfo->in_color_space]; 204 int rindex = rgb_red[cinfo->in_color_space];
271 int gindex = rgb_green[cinfo->in_color_space]; 205 int gindex = rgb_green[cinfo->in_color_space];
272 int bindex = rgb_blue[cinfo->in_color_space]; 206 int bindex = rgb_blue[cinfo->in_color_space];
273 int rgbstride = rgb_pixelsize[cinfo->in_color_space]; 207 int rgbstride = rgb_pixelsize[cinfo->in_color_space];
274 208
275 while (--num_rows >= 0) { 209 while (--num_rows >= 0) {
276 inptr = *input_buf++; 210 inptr = *input_buf++;
277 outptr = output_buf[0][output_row]; 211 outptr = output_buf[0][output_row];
278 maxoutptr = &outptr[num_cols];
279 output_row++; 212 output_row++;
280 for (; outptr < maxoutptr; outptr++, inptr += rgbstride) { 213 for (col = 0; col < num_cols; col++) {
214 r = GETJSAMPLE(inptr[rindex]);
215 g = GETJSAMPLE(inptr[gindex]);
216 b = GETJSAMPLE(inptr[bindex]);
217 inptr += rgbstride;
281 /* Y */ 218 /* Y */
282 #if BITS_IN_JSAMPLE == 8 219 outptr[col] = (JSAMPLE)
283 *outptr = red_lut[inptr[rindex]] + green_lut[inptr[gindex]] 220 » » ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
284 » + blue_lut[inptr[bindex]]; 221 » » >> SCALEBITS);
285 #else
286 *outptr = (JSAMPLE)
287 » ((ctab[GETJSAMPLE(inptr[rindex])+R_Y_OFF]
288 » + ctab[GETJSAMPLE(inptr[gindex])+G_Y_OFF]
289 » + ctab[GETJSAMPLE(inptr[bindex])+B_Y_OFF])
290 » >> SCALEBITS);
291 #endif
292 } 222 }
293 } 223 }
294 } 224 }
295 225
296 226
297 /* 227 /*
298 * Convert some rows of samples to the JPEG colorspace. 228 * Convert some rows of samples to the JPEG colorspace.
299 * This version handles Adobe-style CMYK->YCCK conversion, 229 * This version handles Adobe-style CMYK->YCCK conversion,
300 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same 230 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
301 * conversion as above, while passing K (black) unchanged. 231 * conversion as above, while passing K (black) unchanged.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 413 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
484 if (cinfo->in_color_space == JCS_GRAYSCALE) 414 if (cinfo->in_color_space == JCS_GRAYSCALE)
485 cconvert->pub.color_convert = grayscale_convert; 415 cconvert->pub.color_convert = grayscale_convert;
486 else if (cinfo->in_color_space == JCS_RGB || 416 else if (cinfo->in_color_space == JCS_RGB ||
487 cinfo->in_color_space == JCS_EXT_RGB || 417 cinfo->in_color_space == JCS_EXT_RGB ||
488 cinfo->in_color_space == JCS_EXT_RGBX || 418 cinfo->in_color_space == JCS_EXT_RGBX ||
489 cinfo->in_color_space == JCS_EXT_BGR || 419 cinfo->in_color_space == JCS_EXT_BGR ||
490 cinfo->in_color_space == JCS_EXT_BGRX || 420 cinfo->in_color_space == JCS_EXT_BGRX ||
491 cinfo->in_color_space == JCS_EXT_XBGR || 421 cinfo->in_color_space == JCS_EXT_XBGR ||
492 cinfo->in_color_space == JCS_EXT_XRGB) { 422 cinfo->in_color_space == JCS_EXT_XRGB) {
493 cconvert->pub.start_pass = rgb_ycc_start; 423 if (jsimd_can_rgb_gray())
494 cconvert->pub.color_convert = rgb_gray_convert; 424 cconvert->pub.color_convert = jsimd_rgb_gray_convert;
425 else {
426 cconvert->pub.start_pass = rgb_ycc_start;
427 cconvert->pub.color_convert = rgb_gray_convert;
428 }
495 } else if (cinfo->in_color_space == JCS_YCbCr) 429 } else if (cinfo->in_color_space == JCS_YCbCr)
496 cconvert->pub.color_convert = grayscale_convert; 430 cconvert->pub.color_convert = grayscale_convert;
497 else 431 else
498 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 432 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
499 break; 433 break;
500 434
501 case JCS_RGB: 435 case JCS_RGB:
502 case JCS_EXT_RGB: 436 case JCS_EXT_RGB:
503 case JCS_EXT_RGBX: 437 case JCS_EXT_RGBX:
504 case JCS_EXT_BGR: 438 case JCS_EXT_BGR:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 break; 492 break;
559 493
560 default: /* allow null conversion of JCS_UNKNOWN */ 494 default: /* allow null conversion of JCS_UNKNOWN */
561 if (cinfo->jpeg_color_space != cinfo->in_color_space || 495 if (cinfo->jpeg_color_space != cinfo->in_color_space ||
562 cinfo->num_components != cinfo->input_components) 496 cinfo->num_components != cinfo->input_components)
563 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 497 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
564 cconvert->pub.color_convert = null_convert; 498 cconvert->pub.color_convert = null_convert;
565 break; 499 break;
566 } 500 }
567 } 501 }
OLDNEW
« no previous file with comments | « third_party/libjpeg_turbo/jcarith.c ('k') | third_party/libjpeg_turbo/jcdctmgr.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698