OLD | NEW |
1 /* | 1 /* |
2 * jdmerge.c | 2 * jdmerge.c |
3 * | 3 * |
4 * Copyright (C) 1994-1996, Thomas G. Lane. | 4 * Copyright (C) 1994-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 (C) 2009, 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 code for merged upsampling/color conversion. | 10 * This file contains code for merged upsampling/color conversion. |
11 * | 11 * |
12 * This file combines functions from jdsample.c and jdcolor.c; | 12 * This file combines functions from jdsample.c and jdcolor.c; |
13 * read those files first to understand what's going on. | 13 * read those files first to understand what's going on. |
14 * | 14 * |
15 * When the chroma components are to be upsampled by simple replication | 15 * When the chroma components are to be upsampled by simple replication |
16 * (ie, box filtering), we can save some work in color conversion by | 16 * (ie, box filtering), we can save some work in color conversion by |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 JDIMENSION rows_to_go; /* counts rows remaining in image */ | 70 JDIMENSION rows_to_go; /* counts rows remaining in image */ |
71 } my_upsampler; | 71 } my_upsampler; |
72 | 72 |
73 typedef my_upsampler * my_upsample_ptr; | 73 typedef my_upsampler * my_upsample_ptr; |
74 | 74 |
75 #define SCALEBITS 16 /* speediest right-shift on some machines */ | 75 #define SCALEBITS 16 /* speediest right-shift on some machines */ |
76 #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) | 76 #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) |
77 #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) | 77 #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) |
78 | 78 |
79 | 79 |
| 80 /* Include inline routines for colorspace extensions */ |
| 81 |
| 82 #include "jdmrgext.c" |
| 83 #undef RGB_RED |
| 84 #undef RGB_GREEN |
| 85 #undef RGB_BLUE |
| 86 #undef RGB_PIXELSIZE |
| 87 |
| 88 #define RGB_RED EXT_RGB_RED |
| 89 #define RGB_GREEN EXT_RGB_GREEN |
| 90 #define RGB_BLUE EXT_RGB_BLUE |
| 91 #define RGB_PIXELSIZE EXT_RGB_PIXELSIZE |
| 92 #define h2v1_merged_upsample_internal extrgb_h2v1_merged_upsample_internal |
| 93 #define h2v2_merged_upsample_internal extrgb_h2v2_merged_upsample_internal |
| 94 #include "jdmrgext.c" |
| 95 #undef RGB_RED |
| 96 #undef RGB_GREEN |
| 97 #undef RGB_BLUE |
| 98 #undef RGB_PIXELSIZE |
| 99 #undef h2v1_merged_upsample_internal |
| 100 #undef h2v2_merged_upsample_internal |
| 101 |
| 102 #define RGB_RED EXT_RGBX_RED |
| 103 #define RGB_GREEN EXT_RGBX_GREEN |
| 104 #define RGB_BLUE EXT_RGBX_BLUE |
| 105 #define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE |
| 106 #define h2v1_merged_upsample_internal extrgbx_h2v1_merged_upsample_internal |
| 107 #define h2v2_merged_upsample_internal extrgbx_h2v2_merged_upsample_internal |
| 108 #include "jdmrgext.c" |
| 109 #undef RGB_RED |
| 110 #undef RGB_GREEN |
| 111 #undef RGB_BLUE |
| 112 #undef RGB_PIXELSIZE |
| 113 #undef h2v1_merged_upsample_internal |
| 114 #undef h2v2_merged_upsample_internal |
| 115 |
| 116 #define RGB_RED EXT_BGR_RED |
| 117 #define RGB_GREEN EXT_BGR_GREEN |
| 118 #define RGB_BLUE EXT_BGR_BLUE |
| 119 #define RGB_PIXELSIZE EXT_BGR_PIXELSIZE |
| 120 #define h2v1_merged_upsample_internal extbgr_h2v1_merged_upsample_internal |
| 121 #define h2v2_merged_upsample_internal extbgr_h2v2_merged_upsample_internal |
| 122 #include "jdmrgext.c" |
| 123 #undef RGB_RED |
| 124 #undef RGB_GREEN |
| 125 #undef RGB_BLUE |
| 126 #undef RGB_PIXELSIZE |
| 127 #undef h2v1_merged_upsample_internal |
| 128 #undef h2v2_merged_upsample_internal |
| 129 |
| 130 #define RGB_RED EXT_BGRX_RED |
| 131 #define RGB_GREEN EXT_BGRX_GREEN |
| 132 #define RGB_BLUE EXT_BGRX_BLUE |
| 133 #define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE |
| 134 #define h2v1_merged_upsample_internal extbgrx_h2v1_merged_upsample_internal |
| 135 #define h2v2_merged_upsample_internal extbgrx_h2v2_merged_upsample_internal |
| 136 #include "jdmrgext.c" |
| 137 #undef RGB_RED |
| 138 #undef RGB_GREEN |
| 139 #undef RGB_BLUE |
| 140 #undef RGB_PIXELSIZE |
| 141 #undef h2v1_merged_upsample_internal |
| 142 #undef h2v2_merged_upsample_internal |
| 143 |
| 144 #define RGB_RED EXT_XBGR_RED |
| 145 #define RGB_GREEN EXT_XBGR_GREEN |
| 146 #define RGB_BLUE EXT_XBGR_BLUE |
| 147 #define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE |
| 148 #define h2v1_merged_upsample_internal extxbgr_h2v1_merged_upsample_internal |
| 149 #define h2v2_merged_upsample_internal extxbgr_h2v2_merged_upsample_internal |
| 150 #include "jdmrgext.c" |
| 151 #undef RGB_RED |
| 152 #undef RGB_GREEN |
| 153 #undef RGB_BLUE |
| 154 #undef RGB_PIXELSIZE |
| 155 #undef h2v1_merged_upsample_internal |
| 156 #undef h2v2_merged_upsample_internal |
| 157 |
| 158 #define RGB_RED EXT_XRGB_RED |
| 159 #define RGB_GREEN EXT_XRGB_GREEN |
| 160 #define RGB_BLUE EXT_XRGB_BLUE |
| 161 #define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE |
| 162 #define h2v1_merged_upsample_internal extxrgb_h2v1_merged_upsample_internal |
| 163 #define h2v2_merged_upsample_internal extxrgb_h2v2_merged_upsample_internal |
| 164 #include "jdmrgext.c" |
| 165 #undef RGB_RED |
| 166 #undef RGB_GREEN |
| 167 #undef RGB_BLUE |
| 168 #undef RGB_PIXELSIZE |
| 169 #undef h2v1_merged_upsample_internal |
| 170 #undef h2v2_merged_upsample_internal |
| 171 |
| 172 |
80 /* | 173 /* |
81 * Initialize tables for YCC->RGB colorspace conversion. | 174 * Initialize tables for YCC->RGB colorspace conversion. |
82 * This is taken directly from jdcolor.c; see that file for more info. | 175 * This is taken directly from jdcolor.c; see that file for more info. |
83 */ | 176 */ |
84 | 177 |
85 LOCAL(void) | 178 LOCAL(void) |
86 build_ycc_rgb_table (j_decompress_ptr cinfo) | 179 build_ycc_rgb_table (j_decompress_ptr cinfo) |
87 { | 180 { |
88 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; | 181 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
89 int i; | 182 int i; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 316 |
224 /* | 317 /* |
225 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. | 318 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. |
226 */ | 319 */ |
227 | 320 |
228 METHODDEF(void) | 321 METHODDEF(void) |
229 h2v1_merged_upsample (j_decompress_ptr cinfo, | 322 h2v1_merged_upsample (j_decompress_ptr cinfo, |
230 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, | 323 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, |
231 JSAMPARRAY output_buf) | 324 JSAMPARRAY output_buf) |
232 { | 325 { |
233 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; | 326 switch (cinfo->out_color_space) { |
234 register int y, cred, cgreen, cblue; | 327 case JCS_EXT_RGB: |
235 int cb, cr; | 328 extrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
236 register JSAMPROW outptr; | 329 output_buf); |
237 JSAMPROW inptr0, inptr1, inptr2; | 330 break; |
238 JDIMENSION col; | 331 case JCS_EXT_RGBX: |
239 /* copy these pointers into registers if possible */ | 332 extrgbx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
240 register JSAMPLE * range_limit = cinfo->sample_range_limit; | 333 output_buf); |
241 int * Crrtab = upsample->Cr_r_tab; | 334 break; |
242 int * Cbbtab = upsample->Cb_b_tab; | 335 case JCS_EXT_BGR: |
243 INT32 * Crgtab = upsample->Cr_g_tab; | 336 extbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
244 INT32 * Cbgtab = upsample->Cb_g_tab; | 337 output_buf); |
245 SHIFT_TEMPS | 338 break; |
246 | 339 case JCS_EXT_BGRX: |
247 inptr0 = input_buf[0][in_row_group_ctr]; | 340 extbgrx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
248 inptr1 = input_buf[1][in_row_group_ctr]; | 341 output_buf); |
249 inptr2 = input_buf[2][in_row_group_ctr]; | 342 break; |
250 outptr = output_buf[0]; | 343 case JCS_EXT_XBGR: |
251 /* Loop for each pair of output pixels */ | 344 extxbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
252 for (col = cinfo->output_width >> 1; col > 0; col--) { | 345 output_buf); |
253 /* Do the chroma part of the calculation */ | 346 break; |
254 cb = GETJSAMPLE(*inptr1++); | 347 case JCS_EXT_XRGB: |
255 cr = GETJSAMPLE(*inptr2++); | 348 extxrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
256 cred = Crrtab[cr]; | 349 output_buf); |
257 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); | 350 break; |
258 cblue = Cbbtab[cb]; | 351 default: |
259 /* Fetch 2 Y values and emit 2 pixels */ | 352 h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
260 y = GETJSAMPLE(*inptr0++); | 353 output_buf); |
261 outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | 354 break; |
262 outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
263 outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
264 outptr += rgb_pixelsize[cinfo->out_color_space]; | |
265 y = GETJSAMPLE(*inptr0++); | |
266 outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
267 outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
268 outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
269 outptr += rgb_pixelsize[cinfo->out_color_space]; | |
270 } | |
271 /* If image width is odd, do the last output column separately */ | |
272 if (cinfo->output_width & 1) { | |
273 cb = GETJSAMPLE(*inptr1); | |
274 cr = GETJSAMPLE(*inptr2); | |
275 cred = Crrtab[cr]; | |
276 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); | |
277 cblue = Cbbtab[cb]; | |
278 y = GETJSAMPLE(*inptr0); | |
279 outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
280 outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
281 outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
282 } | 355 } |
283 } | 356 } |
284 | 357 |
285 | 358 |
286 /* | 359 /* |
287 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. | 360 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. |
288 */ | 361 */ |
289 | 362 |
290 METHODDEF(void) | 363 METHODDEF(void) |
291 h2v2_merged_upsample (j_decompress_ptr cinfo, | 364 h2v2_merged_upsample (j_decompress_ptr cinfo, |
292 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, | 365 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, |
293 JSAMPARRAY output_buf) | 366 JSAMPARRAY output_buf) |
294 { | 367 { |
295 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; | 368 switch (cinfo->out_color_space) { |
296 register int y, cred, cgreen, cblue; | 369 case JCS_EXT_RGB: |
297 int cb, cr; | 370 extrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
298 register JSAMPROW outptr0, outptr1; | 371 output_buf); |
299 JSAMPROW inptr00, inptr01, inptr1, inptr2; | 372 break; |
300 JDIMENSION col; | 373 case JCS_EXT_RGBX: |
301 /* copy these pointers into registers if possible */ | 374 extrgbx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
302 register JSAMPLE * range_limit = cinfo->sample_range_limit; | 375 output_buf); |
303 int * Crrtab = upsample->Cr_r_tab; | 376 break; |
304 int * Cbbtab = upsample->Cb_b_tab; | 377 case JCS_EXT_BGR: |
305 INT32 * Crgtab = upsample->Cr_g_tab; | 378 extbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
306 INT32 * Cbgtab = upsample->Cb_g_tab; | 379 output_buf); |
307 SHIFT_TEMPS | 380 break; |
308 | 381 case JCS_EXT_BGRX: |
309 inptr00 = input_buf[0][in_row_group_ctr*2]; | 382 extbgrx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
310 inptr01 = input_buf[0][in_row_group_ctr*2 + 1]; | 383 output_buf); |
311 inptr1 = input_buf[1][in_row_group_ctr]; | 384 break; |
312 inptr2 = input_buf[2][in_row_group_ctr]; | 385 case JCS_EXT_XBGR: |
313 outptr0 = output_buf[0]; | 386 extxbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
314 outptr1 = output_buf[1]; | 387 output_buf); |
315 /* Loop for each group of output pixels */ | 388 break; |
316 for (col = cinfo->output_width >> 1; col > 0; col--) { | 389 case JCS_EXT_XRGB: |
317 /* Do the chroma part of the calculation */ | 390 extxrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
318 cb = GETJSAMPLE(*inptr1++); | 391 output_buf); |
319 cr = GETJSAMPLE(*inptr2++); | 392 break; |
320 cred = Crrtab[cr]; | 393 default: |
321 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); | 394 h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
322 cblue = Cbbtab[cb]; | 395 output_buf); |
323 /* Fetch 4 Y values and emit 4 pixels */ | 396 break; |
324 y = GETJSAMPLE(*inptr00++); | |
325 outptr0[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
326 outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
327 outptr0[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
328 outptr0 += RGB_PIXELSIZE; | |
329 y = GETJSAMPLE(*inptr00++); | |
330 outptr0[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
331 outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
332 outptr0[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
333 outptr0 += RGB_PIXELSIZE; | |
334 y = GETJSAMPLE(*inptr01++); | |
335 outptr1[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
336 outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
337 outptr1[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
338 outptr1 += RGB_PIXELSIZE; | |
339 y = GETJSAMPLE(*inptr01++); | |
340 outptr1[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
341 outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
342 outptr1[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
343 outptr1 += RGB_PIXELSIZE; | |
344 } | |
345 /* If image width is odd, do the last output column separately */ | |
346 if (cinfo->output_width & 1) { | |
347 cb = GETJSAMPLE(*inptr1); | |
348 cr = GETJSAMPLE(*inptr2); | |
349 cred = Crrtab[cr]; | |
350 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); | |
351 cblue = Cbbtab[cb]; | |
352 y = GETJSAMPLE(*inptr00); | |
353 outptr0[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
354 outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
355 outptr0[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
356 y = GETJSAMPLE(*inptr01); | |
357 outptr1[rgb_red[cinfo->out_color_space]] = range_limit[y + cred]; | |
358 outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen]; | |
359 outptr1[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue]; | |
360 } | 397 } |
361 } | 398 } |
362 | 399 |
363 | 400 |
364 /* | 401 /* |
365 * Module initialization routine for merged upsampling/color conversion. | 402 * Module initialization routine for merged upsampling/color conversion. |
366 * | 403 * |
367 * NB: this is called under the conditions determined by use_merged_upsample() | 404 * NB: this is called under the conditions determined by use_merged_upsample() |
368 * in jdmaster.c. That routine MUST correspond to the actual capabilities | 405 * in jdmaster.c. That routine MUST correspond to the actual capabilities |
369 * of this module; no safety checks are made here. | 406 * of this module; no safety checks are made here. |
(...skipping 30 matching lines...) Expand all Loading... |
400 else | 437 else |
401 upsample->upmethod = h2v1_merged_upsample; | 438 upsample->upmethod = h2v1_merged_upsample; |
402 /* No spare row needed */ | 439 /* No spare row needed */ |
403 upsample->spare_row = NULL; | 440 upsample->spare_row = NULL; |
404 } | 441 } |
405 | 442 |
406 build_ycc_rgb_table(cinfo); | 443 build_ycc_rgb_table(cinfo); |
407 } | 444 } |
408 | 445 |
409 #endif /* UPSAMPLE_MERGING_SUPPORTED */ | 446 #endif /* UPSAMPLE_MERGING_SUPPORTED */ |
OLD | NEW |