OLD | NEW |
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-2011 D. R. Commander | 6 * Copyright (C) 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 Loading... |
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 /* Include inline routines for colorspace extensions */ |
| 85 |
| 86 #include "jccolext.c" |
| 87 #undef RGB_RED |
| 88 #undef RGB_GREEN |
| 89 #undef RGB_BLUE |
| 90 #undef RGB_PIXELSIZE |
| 91 |
| 92 #define RGB_RED EXT_RGB_RED |
| 93 #define RGB_GREEN EXT_RGB_GREEN |
| 94 #define RGB_BLUE EXT_RGB_BLUE |
| 95 #define RGB_PIXELSIZE EXT_RGB_PIXELSIZE |
| 96 #define rgb_ycc_convert_internal extrgb_ycc_convert_internal |
| 97 #define rgb_gray_convert_internal extrgb_gray_convert_internal |
| 98 #include "jccolext.c" |
| 99 #undef RGB_RED |
| 100 #undef RGB_GREEN |
| 101 #undef RGB_BLUE |
| 102 #undef RGB_PIXELSIZE |
| 103 #undef rgb_ycc_convert_internal |
| 104 #undef rgb_gray_convert_internal |
| 105 |
| 106 #define RGB_RED EXT_RGBX_RED |
| 107 #define RGB_GREEN EXT_RGBX_GREEN |
| 108 #define RGB_BLUE EXT_RGBX_BLUE |
| 109 #define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE |
| 110 #define rgb_ycc_convert_internal extrgbx_ycc_convert_internal |
| 111 #define rgb_gray_convert_internal extrgbx_gray_convert_internal |
| 112 #include "jccolext.c" |
| 113 #undef RGB_RED |
| 114 #undef RGB_GREEN |
| 115 #undef RGB_BLUE |
| 116 #undef RGB_PIXELSIZE |
| 117 #undef rgb_ycc_convert_internal |
| 118 #undef rgb_gray_convert_internal |
| 119 |
| 120 #define RGB_RED EXT_BGR_RED |
| 121 #define RGB_GREEN EXT_BGR_GREEN |
| 122 #define RGB_BLUE EXT_BGR_BLUE |
| 123 #define RGB_PIXELSIZE EXT_BGR_PIXELSIZE |
| 124 #define rgb_ycc_convert_internal extbgr_ycc_convert_internal |
| 125 #define rgb_gray_convert_internal extbgr_gray_convert_internal |
| 126 #include "jccolext.c" |
| 127 #undef RGB_RED |
| 128 #undef RGB_GREEN |
| 129 #undef RGB_BLUE |
| 130 #undef RGB_PIXELSIZE |
| 131 #undef rgb_ycc_convert_internal |
| 132 #undef rgb_gray_convert_internal |
| 133 |
| 134 #define RGB_RED EXT_BGRX_RED |
| 135 #define RGB_GREEN EXT_BGRX_GREEN |
| 136 #define RGB_BLUE EXT_BGRX_BLUE |
| 137 #define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE |
| 138 #define rgb_ycc_convert_internal extbgrx_ycc_convert_internal |
| 139 #define rgb_gray_convert_internal extbgrx_gray_convert_internal |
| 140 #include "jccolext.c" |
| 141 #undef RGB_RED |
| 142 #undef RGB_GREEN |
| 143 #undef RGB_BLUE |
| 144 #undef RGB_PIXELSIZE |
| 145 #undef rgb_ycc_convert_internal |
| 146 #undef rgb_gray_convert_internal |
| 147 |
| 148 #define RGB_RED EXT_XBGR_RED |
| 149 #define RGB_GREEN EXT_XBGR_GREEN |
| 150 #define RGB_BLUE EXT_XBGR_BLUE |
| 151 #define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE |
| 152 #define rgb_ycc_convert_internal extxbgr_ycc_convert_internal |
| 153 #define rgb_gray_convert_internal extxbgr_gray_convert_internal |
| 154 #include "jccolext.c" |
| 155 #undef RGB_RED |
| 156 #undef RGB_GREEN |
| 157 #undef RGB_BLUE |
| 158 #undef RGB_PIXELSIZE |
| 159 #undef rgb_ycc_convert_internal |
| 160 #undef rgb_gray_convert_internal |
| 161 |
| 162 #define RGB_RED EXT_XRGB_RED |
| 163 #define RGB_GREEN EXT_XRGB_GREEN |
| 164 #define RGB_BLUE EXT_XRGB_BLUE |
| 165 #define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE |
| 166 #define rgb_ycc_convert_internal extxrgb_ycc_convert_internal |
| 167 #define rgb_gray_convert_internal extxrgb_gray_convert_internal |
| 168 #include "jccolext.c" |
| 169 #undef RGB_RED |
| 170 #undef RGB_GREEN |
| 171 #undef RGB_BLUE |
| 172 #undef RGB_PIXELSIZE |
| 173 #undef rgb_ycc_convert_internal |
| 174 #undef rgb_gray_convert_internal |
| 175 |
| 176 |
84 /* | 177 /* |
85 * Initialize for RGB->YCC colorspace conversion. | 178 * Initialize for RGB->YCC colorspace conversion. |
86 */ | 179 */ |
87 | 180 |
88 METHODDEF(void) | 181 METHODDEF(void) |
89 rgb_ycc_start (j_compress_ptr cinfo) | 182 rgb_ycc_start (j_compress_ptr cinfo) |
90 { | 183 { |
91 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 184 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
92 INT32 * rgb_ycc_tab; | 185 INT32 * rgb_ycc_tab; |
93 INT32 i; | 186 INT32 i; |
(...skipping 18 matching lines...) Expand all Loading... |
112 rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; | 205 rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; |
113 */ | 206 */ |
114 rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; | 207 rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; |
115 rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; | 208 rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; |
116 } | 209 } |
117 } | 210 } |
118 | 211 |
119 | 212 |
120 /* | 213 /* |
121 * Convert some rows of samples to the JPEG colorspace. | 214 * Convert some rows of samples to the JPEG colorspace. |
122 * | |
123 * Note that we change from the application's interleaved-pixel format | |
124 * to our internal noninterleaved, one-plane-per-component format. | |
125 * The input buffer is therefore three times as wide as the output buffer. | |
126 * | |
127 * A starting row offset is provided only for the output buffer. The caller | |
128 * can easily adjust the passed input_buf value to accommodate any row | |
129 * offset required on that side. | |
130 */ | 215 */ |
131 | 216 |
132 METHODDEF(void) | 217 METHODDEF(void) |
133 rgb_ycc_convert (j_compress_ptr cinfo, | 218 rgb_ycc_convert (j_compress_ptr cinfo, |
134 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 219 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
135 JDIMENSION output_row, int num_rows) | 220 JDIMENSION output_row, int num_rows) |
136 { | 221 { |
137 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 222 switch (cinfo->in_color_space) { |
138 register int r, g, b; | 223 case JCS_EXT_RGB: |
139 register INT32 * ctab = cconvert->rgb_ycc_tab; | 224 extrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
140 register JSAMPROW inptr; | 225 num_rows); |
141 register JSAMPROW outptr0, outptr1, outptr2; | 226 break; |
142 register JDIMENSION col; | 227 case JCS_EXT_RGBX: |
143 JDIMENSION num_cols = cinfo->image_width; | 228 extrgbx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
144 int rindex = rgb_red[cinfo->in_color_space]; | 229 num_rows); |
145 int gindex = rgb_green[cinfo->in_color_space]; | 230 break; |
146 int bindex = rgb_blue[cinfo->in_color_space]; | 231 case JCS_EXT_BGR: |
147 int rgbstride = rgb_pixelsize[cinfo->in_color_space]; | 232 extbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
148 | 233 num_rows); |
149 while (--num_rows >= 0) { | 234 break; |
150 inptr = *input_buf++; | 235 case JCS_EXT_BGRX: |
151 outptr0 = output_buf[0][output_row]; | 236 extbgrx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
152 outptr1 = output_buf[1][output_row]; | 237 num_rows); |
153 outptr2 = output_buf[2][output_row]; | 238 break; |
154 output_row++; | 239 case JCS_EXT_XBGR: |
155 for (col = 0; col < num_cols; col++) { | 240 extxbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
156 r = GETJSAMPLE(inptr[rindex]); | 241 num_rows); |
157 g = GETJSAMPLE(inptr[gindex]); | 242 break; |
158 b = GETJSAMPLE(inptr[bindex]); | 243 case JCS_EXT_XRGB: |
159 inptr += rgbstride; | 244 extxrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
160 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations | 245 num_rows); |
161 * must be too; we do not need an explicit range-limiting operation. | 246 break; |
162 * Hence the value being shifted is never negative, and we don't | 247 default: |
163 * need the general RIGHT_SHIFT macro. | 248 rgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
164 */ | 249 num_rows); |
165 /* Y */ | 250 break; |
166 outptr0[col] = (JSAMPLE) | |
167 » » ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) | |
168 » » >> SCALEBITS); | |
169 /* Cb */ | |
170 outptr1[col] = (JSAMPLE) | |
171 » » ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) | |
172 » » >> SCALEBITS); | |
173 /* Cr */ | |
174 outptr2[col] = (JSAMPLE) | |
175 » » ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) | |
176 » » >> SCALEBITS); | |
177 } | |
178 } | 251 } |
179 } | 252 } |
180 | 253 |
181 | 254 |
182 /**************** Cases other than RGB -> YCbCr **************/ | 255 /**************** Cases other than RGB -> YCbCr **************/ |
183 | 256 |
184 | 257 |
185 /* | 258 /* |
186 * Convert some rows of samples to the JPEG colorspace. | 259 * Convert some rows of samples to the JPEG colorspace. |
187 * This version handles RGB->grayscale conversion, which is the same | |
188 * as the RGB->Y portion of RGB->YCbCr. | |
189 * We assume rgb_ycc_start has been called (we only use the Y tables). | |
190 */ | 260 */ |
191 | 261 |
192 METHODDEF(void) | 262 METHODDEF(void) |
193 rgb_gray_convert (j_compress_ptr cinfo, | 263 rgb_gray_convert (j_compress_ptr cinfo, |
194 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, | 264 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
195 JDIMENSION output_row, int num_rows) | 265 JDIMENSION output_row, int num_rows) |
196 { | 266 { |
197 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; | 267 switch (cinfo->in_color_space) { |
198 register int r, g, b; | 268 case JCS_EXT_RGB: |
199 register INT32 * ctab = cconvert->rgb_ycc_tab; | 269 extrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
200 register JSAMPROW inptr; | 270 num_rows); |
201 register JSAMPROW outptr; | 271 break; |
202 register JDIMENSION col; | 272 case JCS_EXT_RGBX: |
203 JDIMENSION num_cols = cinfo->image_width; | 273 extrgbx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
204 int rindex = rgb_red[cinfo->in_color_space]; | 274 num_rows); |
205 int gindex = rgb_green[cinfo->in_color_space]; | 275 break; |
206 int bindex = rgb_blue[cinfo->in_color_space]; | 276 case JCS_EXT_BGR: |
207 int rgbstride = rgb_pixelsize[cinfo->in_color_space]; | 277 extbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
208 | 278 num_rows); |
209 while (--num_rows >= 0) { | 279 break; |
210 inptr = *input_buf++; | 280 case JCS_EXT_BGRX: |
211 outptr = output_buf[0][output_row]; | 281 extbgrx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
212 output_row++; | 282 num_rows); |
213 for (col = 0; col < num_cols; col++) { | 283 break; |
214 r = GETJSAMPLE(inptr[rindex]); | 284 case JCS_EXT_XBGR: |
215 g = GETJSAMPLE(inptr[gindex]); | 285 extxbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
216 b = GETJSAMPLE(inptr[bindex]); | 286 num_rows); |
217 inptr += rgbstride; | 287 break; |
218 /* Y */ | 288 case JCS_EXT_XRGB: |
219 outptr[col] = (JSAMPLE) | 289 extxrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
220 » » ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) | 290 num_rows); |
221 » » >> SCALEBITS); | 291 break; |
222 } | 292 default: |
| 293 rgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 294 num_rows); |
| 295 break; |
223 } | 296 } |
224 } | 297 } |
225 | 298 |
226 | 299 |
227 /* | 300 /* |
228 * Convert some rows of samples to the JPEG colorspace. | 301 * Convert some rows of samples to the JPEG colorspace. |
229 * This version handles Adobe-style CMYK->YCCK conversion, | 302 * This version handles Adobe-style CMYK->YCCK conversion, |
230 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same | 303 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same |
231 * conversion as above, while passing K (black) unchanged. | 304 * conversion as above, while passing K (black) unchanged. |
232 * We assume rgb_ycc_start has been called. | 305 * We assume rgb_ycc_start has been called. |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 break; | 565 break; |
493 | 566 |
494 default: /* allow null conversion of JCS_UNKNOWN */ | 567 default: /* allow null conversion of JCS_UNKNOWN */ |
495 if (cinfo->jpeg_color_space != cinfo->in_color_space || | 568 if (cinfo->jpeg_color_space != cinfo->in_color_space || |
496 cinfo->num_components != cinfo->input_components) | 569 cinfo->num_components != cinfo->input_components) |
497 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); | 570 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
498 cconvert->pub.color_convert = null_convert; | 571 cconvert->pub.color_convert = null_convert; |
499 break; | 572 break; |
500 } | 573 } |
501 } | 574 } |
OLD | NEW |