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

Side by Side Diff: jdmerge.c

Issue 1953443002: Update to libjpeg_turbo 1.4.90 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « jdmaster.c ('k') | jdmrg565.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 * jdmerge.c 2 * jdmerge.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) 1994-1996, Thomas G. Lane. 5 * Copyright (C) 1994-1996, Thomas G. Lane.
6 * libjpeg-turbo Modifications:
6 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB 7 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
7 * libjpeg-turbo Modifications: 8 * Copyright (C) 2009, 2011, 2014-2015, D. R. Commander.
8 * Copyright (C) 2009, 2011, 2014 D. R. Commander.
9 * Copyright (C) 2013, Linaro Limited. 9 * Copyright (C) 2013, Linaro Limited.
10 * For conditions of distribution and use, see the accompanying README file. 10 * For conditions of distribution and use, see the accompanying README.ijg
11 * file.
11 * 12 *
12 * This file contains code for merged upsampling/color conversion. 13 * This file contains code for merged upsampling/color conversion.
13 * 14 *
14 * This file combines functions from jdsample.c and jdcolor.c; 15 * This file combines functions from jdsample.c and jdcolor.c;
15 * read those files first to understand what's going on. 16 * read those files first to understand what's going on.
16 * 17 *
17 * When the chroma components are to be upsampled by simple replication 18 * When the chroma components are to be upsampled by simple replication
18 * (ie, box filtering), we can save some work in color conversion by 19 * (ie, box filtering), we can save some work in color conversion by
19 * calculating all the output pixels corresponding to a pair of chroma 20 * calculating all the output pixels corresponding to a pair of chroma
20 * samples at one time. In the conversion equations 21 * samples at one time. In the conversion equations
21 *» R = Y + K1 * Cr 22 * R = Y + K1 * Cr
22 *» G = Y + K2 * Cb + K3 * Cr 23 * G = Y + K2 * Cb + K3 * Cr
23 *» B = Y + K4 * Cb 24 * B = Y + K4 * Cb
24 * only the Y term varies among the group of pixels corresponding to a pair 25 * only the Y term varies among the group of pixels corresponding to a pair
25 * of chroma samples, so the rest of the terms can be calculated just once. 26 * of chroma samples, so the rest of the terms can be calculated just once.
26 * At typical sampling ratios, this eliminates half or three-quarters of the 27 * At typical sampling ratios, this eliminates half or three-quarters of the
27 * multiplications needed for color conversion. 28 * multiplications needed for color conversion.
28 * 29 *
29 * This file currently provides implementations for the following cases: 30 * This file currently provides implementations for the following cases:
30 *» YCbCr => RGB color conversion only. 31 * YCbCr => RGB color conversion only.
31 *» Sampling ratios of 2h1v or 2h2v. 32 * Sampling ratios of 2h1v or 2h2v.
32 *» No scaling needed at upsample time. 33 * No scaling needed at upsample time.
33 *» Corner-aligned (non-CCIR601) sampling alignment. 34 * Corner-aligned (non-CCIR601) sampling alignment.
34 * Other special cases could be added, but in most applications these are 35 * Other special cases could be added, but in most applications these are
35 * the only common cases. (For uncommon cases we fall back on the more 36 * the only common cases. (For uncommon cases we fall back on the more
36 * general code in jdsample.c and jdcolor.c.) 37 * general code in jdsample.c and jdcolor.c.)
37 */ 38 */
38 39
39 #define JPEG_INTERNALS 40 #define JPEG_INTERNALS
40 #include "jinclude.h" 41 #include "jinclude.h"
41 #include "jpeglib.h" 42 #include "jpeglib.h"
42 #include "jsimd.h" 43 #include "jsimd.h"
43 #include "config.h" 44 #include "jconfigint.h"
44 45
45 #ifdef UPSAMPLE_MERGING_SUPPORTED 46 #ifdef UPSAMPLE_MERGING_SUPPORTED
46 47
47 48
48 /* Private subobject */ 49 /* Private subobject */
49 50
50 typedef struct { 51 typedef struct {
51 struct jpeg_upsampler pub;» /* public fields */ 52 struct jpeg_upsampler pub; /* public fields */
52 53
53 /* Pointer to routine to do actual upsampling/conversion of one row group */ 54 /* Pointer to routine to do actual upsampling/conversion of one row group */
54 JMETHOD(void, upmethod, (j_decompress_ptr cinfo, 55 void (*upmethod) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
55 » » » JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, 56 JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf);
56 » » » JSAMPARRAY output_buf));
57 57
58 /* Private state for YCC->RGB conversion */ 58 /* Private state for YCC->RGB conversion */
59 int * Cr_r_tab;» » /* => table for Cr to R conversion */ 59 int *Cr_r_tab; /* => table for Cr to R conversion */
60 int * Cb_b_tab;» » /* => table for Cb to B conversion */ 60 int *Cb_b_tab; /* => table for Cb to B conversion */
61 INT32 * Cr_g_tab;» » /* => table for Cr to G conversion */ 61 JLONG *Cr_g_tab; /* => table for Cr to G conversion */
62 INT32 * Cb_g_tab;» » /* => table for Cb to G conversion */ 62 JLONG *Cb_g_tab; /* => table for Cb to G conversion */
63 63
64 /* For 2:1 vertical sampling, we produce two output rows at a time. 64 /* For 2:1 vertical sampling, we produce two output rows at a time.
65 * We need a "spare" row buffer to hold the second output row if the 65 * We need a "spare" row buffer to hold the second output row if the
66 * application provides just a one-row buffer; we also use the spare 66 * application provides just a one-row buffer; we also use the spare
67 * to discard the dummy last row if the image height is odd. 67 * to discard the dummy last row if the image height is odd.
68 */ 68 */
69 JSAMPROW spare_row; 69 JSAMPROW spare_row;
70 boolean spare_full;» » /* T if spare buffer is occupied */ 70 boolean spare_full; /* T if spare buffer is occupied */
71 71
72 JDIMENSION out_row_width;» /* samples per output row */ 72 JDIMENSION out_row_width; /* samples per output row */
73 JDIMENSION rows_to_go;» /* counts rows remaining in image */ 73 JDIMENSION rows_to_go; /* counts rows remaining in image */
74 } my_upsampler; 74 } my_upsampler;
75 75
76 typedef my_upsampler * my_upsample_ptr; 76 typedef my_upsampler *my_upsample_ptr;
77 77
78 #define SCALEBITS» 16» /* speediest right-shift on some machines */ 78 #define SCALEBITS 16 /* speediest right-shift on some machines */
79 #define ONE_HALF» ((INT32) 1 << (SCALEBITS-1)) 79 #define ONE_HALF ((JLONG) 1 << (SCALEBITS-1))
80 #define FIX(x)» » ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) 80 #define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5))
81 81
82 82
83 /* Include inline routines for colorspace extensions */ 83 /* Include inline routines for colorspace extensions */
84 84
85 #include "jdmrgext.c" 85 #include "jdmrgext.c"
86 #undef RGB_RED 86 #undef RGB_RED
87 #undef RGB_GREEN 87 #undef RGB_GREEN
88 #undef RGB_BLUE 88 #undef RGB_BLUE
89 #undef RGB_PIXELSIZE 89 #undef RGB_PIXELSIZE
90 90
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 /* 184 /*
185 * Initialize tables for YCC->RGB colorspace conversion. 185 * Initialize tables for YCC->RGB colorspace conversion.
186 * This is taken directly from jdcolor.c; see that file for more info. 186 * This is taken directly from jdcolor.c; see that file for more info.
187 */ 187 */
188 188
189 LOCAL(void) 189 LOCAL(void)
190 build_ycc_rgb_table (j_decompress_ptr cinfo) 190 build_ycc_rgb_table (j_decompress_ptr cinfo)
191 { 191 {
192 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; 192 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
193 int i; 193 int i;
194 INT32 x; 194 JLONG x;
195 SHIFT_TEMPS 195 SHIFT_TEMPS
196 196
197 upsample->Cr_r_tab = (int *) 197 upsample->Cr_r_tab = (int *)
198 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 198 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
199 » » » » (MAXJSAMPLE+1) * SIZEOF(int)); 199 (MAXJSAMPLE+1) * sizeof(int));
200 upsample->Cb_b_tab = (int *) 200 upsample->Cb_b_tab = (int *)
201 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 201 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
202 » » » » (MAXJSAMPLE+1) * SIZEOF(int)); 202 (MAXJSAMPLE+1) * sizeof(int));
203 upsample->Cr_g_tab = (INT32 *) 203 upsample->Cr_g_tab = (JLONG *)
204 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 204 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
205 » » » » (MAXJSAMPLE+1) * SIZEOF(INT32)); 205 (MAXJSAMPLE+1) * sizeof(JLONG));
206 upsample->Cb_g_tab = (INT32 *) 206 upsample->Cb_g_tab = (JLONG *)
207 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 207 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
208 » » » » (MAXJSAMPLE+1) * SIZEOF(INT32)); 208 (MAXJSAMPLE+1) * sizeof(JLONG));
209 209
210 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { 210 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
211 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ 211 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
212 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ 212 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
213 /* Cr=>R value is nearest int to 1.40200 * x */ 213 /* Cr=>R value is nearest int to 1.40200 * x */
214 upsample->Cr_r_tab[i] = (int) 214 upsample->Cr_r_tab[i] = (int)
215 » » RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); 215 RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
216 /* Cb=>B value is nearest int to 1.77200 * x */ 216 /* Cb=>B value is nearest int to 1.77200 * x */
217 upsample->Cb_b_tab[i] = (int) 217 upsample->Cb_b_tab[i] = (int)
218 » » RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); 218 RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
219 /* Cr=>G value is scaled-up -0.71414 * x */ 219 /* Cr=>G value is scaled-up -0.71414 * x */
220 upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x; 220 upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
221 /* Cb=>G value is scaled-up -0.34414 * x */ 221 /* Cb=>G value is scaled-up -0.34414 * x */
222 /* We also add in ONE_HALF so that need not do it in inner loop */ 222 /* We also add in ONE_HALF so that need not do it in inner loop */
223 upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; 223 upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
224 } 224 }
225 } 225 }
226 226
227 227
228 /* 228 /*
(...skipping 13 matching lines...) Expand all
242 242
243 243
244 /* 244 /*
245 * Control routine to do upsampling (and color conversion). 245 * Control routine to do upsampling (and color conversion).
246 * 246 *
247 * The control routine just handles the row buffering considerations. 247 * The control routine just handles the row buffering considerations.
248 */ 248 */
249 249
250 METHODDEF(void) 250 METHODDEF(void)
251 merged_2v_upsample (j_decompress_ptr cinfo, 251 merged_2v_upsample (j_decompress_ptr cinfo,
252 » » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 252 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
253 » » JDIMENSION in_row_groups_avail, 253 JDIMENSION in_row_groups_avail,
254 » » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 254 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
255 » » JDIMENSION out_rows_avail) 255 JDIMENSION out_rows_avail)
256 /* 2:1 vertical sampling case: may need a spare row. */ 256 /* 2:1 vertical sampling case: may need a spare row. */
257 { 257 {
258 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; 258 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
259 JSAMPROW work_ptrs[2]; 259 JSAMPROW work_ptrs[2];
260 JDIMENSION num_rows;» » /* number of rows returned to caller */ 260 JDIMENSION num_rows; /* number of rows returned to caller */
261 261
262 if (upsample->spare_full) { 262 if (upsample->spare_full) {
263 /* If we have a spare row saved from a previous cycle, just return it. */ 263 /* If we have a spare row saved from a previous cycle, just return it. */
264 JDIMENSION size = upsample->out_row_width; 264 JDIMENSION size = upsample->out_row_width;
265 if (cinfo->out_color_space == JCS_RGB565) 265 if (cinfo->out_color_space == JCS_RGB565)
266 size = cinfo->output_width * 2; 266 size = cinfo->output_width * 2;
267 jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0, 267 jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
268 » » 1, size); 268 1, size);
269 num_rows = 1; 269 num_rows = 1;
270 upsample->spare_full = FALSE; 270 upsample->spare_full = FALSE;
271 } else { 271 } else {
272 /* Figure number of rows to return to caller. */ 272 /* Figure number of rows to return to caller. */
273 num_rows = 2; 273 num_rows = 2;
274 /* Not more than the distance to the end of the image. */ 274 /* Not more than the distance to the end of the image. */
275 if (num_rows > upsample->rows_to_go) 275 if (num_rows > upsample->rows_to_go)
276 num_rows = upsample->rows_to_go; 276 num_rows = upsample->rows_to_go;
277 /* And not more than what the client can accept: */ 277 /* And not more than what the client can accept: */
278 out_rows_avail -= *out_row_ctr; 278 out_rows_avail -= *out_row_ctr;
(...skipping 15 matching lines...) Expand all
294 *out_row_ctr += num_rows; 294 *out_row_ctr += num_rows;
295 upsample->rows_to_go -= num_rows; 295 upsample->rows_to_go -= num_rows;
296 /* When the buffer is emptied, declare this input row group consumed */ 296 /* When the buffer is emptied, declare this input row group consumed */
297 if (! upsample->spare_full) 297 if (! upsample->spare_full)
298 (*in_row_group_ctr)++; 298 (*in_row_group_ctr)++;
299 } 299 }
300 300
301 301
302 METHODDEF(void) 302 METHODDEF(void)
303 merged_1v_upsample (j_decompress_ptr cinfo, 303 merged_1v_upsample (j_decompress_ptr cinfo,
304 » » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 304 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
305 » » JDIMENSION in_row_groups_avail, 305 JDIMENSION in_row_groups_avail,
306 » » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 306 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
307 » » JDIMENSION out_rows_avail) 307 JDIMENSION out_rows_avail)
308 /* 1:1 vertical sampling case: much easier, never need a spare row. */ 308 /* 1:1 vertical sampling case: much easier, never need a spare row. */
309 { 309 {
310 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; 310 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
311 311
312 /* Just do the upsampling. */ 312 /* Just do the upsampling. */
313 (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, 313 (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
314 » » » output_buf + *out_row_ctr); 314 output_buf + *out_row_ctr);
315 /* Adjust counts */ 315 /* Adjust counts */
316 (*out_row_ctr)++; 316 (*out_row_ctr)++;
317 (*in_row_group_ctr)++; 317 (*in_row_group_ctr)++;
318 } 318 }
319 319
320 320
321 /* 321 /*
322 * These are the routines invoked by the control routines to do 322 * These are the routines invoked by the control routines to do
323 * the actual upsampling/conversion. One row group is processed per call. 323 * the actual upsampling/conversion. One row group is processed per call.
324 * 324 *
325 * Note: since we may be writing directly into application-supplied buffers, 325 * Note: since we may be writing directly into application-supplied buffers,
326 * we have to be honest about the output width; we can't assume the buffer 326 * we have to be honest about the output width; we can't assume the buffer
327 * has been rounded up to an even width. 327 * has been rounded up to an even width.
328 */ 328 */
329 329
330 330
331 /* 331 /*
332 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. 332 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
333 */ 333 */
334 334
335 METHODDEF(void) 335 METHODDEF(void)
336 h2v1_merged_upsample (j_decompress_ptr cinfo, 336 h2v1_merged_upsample (j_decompress_ptr cinfo,
337 » » JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, 337 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
338 » » JSAMPARRAY output_buf) 338 JSAMPARRAY output_buf)
339 { 339 {
340 switch (cinfo->out_color_space) { 340 switch (cinfo->out_color_space) {
341 case JCS_EXT_RGB: 341 case JCS_EXT_RGB:
342 extrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, 342 extrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
343 output_buf); 343 output_buf);
344 break; 344 break;
345 case JCS_EXT_RGBX: 345 case JCS_EXT_RGBX:
346 case JCS_EXT_RGBA: 346 case JCS_EXT_RGBA:
347 extrgbx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, 347 extrgbx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
348 output_buf); 348 output_buf);
(...skipping 24 matching lines...) Expand all
373 } 373 }
374 } 374 }
375 375
376 376
377 /* 377 /*
378 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. 378 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
379 */ 379 */
380 380
381 METHODDEF(void) 381 METHODDEF(void)
382 h2v2_merged_upsample (j_decompress_ptr cinfo, 382 h2v2_merged_upsample (j_decompress_ptr cinfo,
383 » » JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, 383 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
384 » » JSAMPARRAY output_buf) 384 JSAMPARRAY output_buf)
385 { 385 {
386 switch (cinfo->out_color_space) { 386 switch (cinfo->out_color_space) {
387 case JCS_EXT_RGB: 387 case JCS_EXT_RGB:
388 extrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, 388 extrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
389 output_buf); 389 output_buf);
390 break; 390 break;
391 case JCS_EXT_RGBX: 391 case JCS_EXT_RGBX:
392 case JCS_EXT_RGBA: 392 case JCS_EXT_RGBA:
393 extrgbx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, 393 extrgbx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
394 output_buf); 394 output_buf);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 #define PACK_SHORT_565_BE(r, g, b) (((r) & 0xF8) | ((g) >> 5) | \ 429 #define PACK_SHORT_565_BE(r, g, b) (((r) & 0xF8) | ((g) >> 5) | \
430 (((g) << 11) & 0xE000) | \ 430 (((g) << 11) & 0xE000) | \
431 (((b) << 5) & 0x1F00)) 431 (((b) << 5) & 0x1F00))
432 432
433 #define PACK_TWO_PIXELS_LE(l, r) ((r << 16) | l) 433 #define PACK_TWO_PIXELS_LE(l, r) ((r << 16) | l)
434 #define PACK_TWO_PIXELS_BE(l, r) ((l << 16) | r) 434 #define PACK_TWO_PIXELS_BE(l, r) ((l << 16) | r)
435 435
436 #define PACK_NEED_ALIGNMENT(ptr) (((size_t)(ptr)) & 3) 436 #define PACK_NEED_ALIGNMENT(ptr) (((size_t)(ptr)) & 3)
437 437
438 #define WRITE_TWO_PIXELS_LE(addr, pixels) { \ 438 #define WRITE_TWO_PIXELS_LE(addr, pixels) { \
439 ((INT16*)(addr))[0] = (pixels); \ 439 ((INT16*)(addr))[0] = (INT16)(pixels); \
440 ((INT16*)(addr))[1] = (pixels) >> 16; \ 440 ((INT16*)(addr))[1] = (INT16)((pixels) >> 16); \
441 } 441 }
442 #define WRITE_TWO_PIXELS_BE(addr, pixels) { \ 442 #define WRITE_TWO_PIXELS_BE(addr, pixels) { \
443 ((INT16*)(addr))[1] = (pixels); \ 443 ((INT16*)(addr))[1] = (INT16)(pixels); \
444 ((INT16*)(addr))[0] = (pixels) >> 16; \ 444 ((INT16*)(addr))[0] = (INT16)((pixels) >> 16); \
445 } 445 }
446 446
447 #define DITHER_565_R(r, dither) ((r) + ((dither) & 0xFF)) 447 #define DITHER_565_R(r, dither) ((r) + ((dither) & 0xFF))
448 #define DITHER_565_G(g, dither) ((g) + (((dither) & 0xFF) >> 1)) 448 #define DITHER_565_G(g, dither) ((g) + (((dither) & 0xFF) >> 1))
449 #define DITHER_565_B(b, dither) ((b) + ((dither) & 0xFF)) 449 #define DITHER_565_B(b, dither) ((b) + ((dither) & 0xFF))
450 450
451 451
452 /* Declarations for ordered dithering 452 /* Declarations for ordered dithering
453 * 453 *
454 * We use a 4x4 ordered dither array packed into 32 bits. This array is 454 * We use a 4x4 ordered dither array packed into 32 bits. This array is
455 * sufficent for dithering RGB888 to RGB565. 455 * sufficent for dithering RGB888 to RGB565.
456 */ 456 */
457 457
458 #define DITHER_MASK 0x3 458 #define DITHER_MASK 0x3
459 #define DITHER_ROTATE(x) (((x) << 24) | (((x) >> 8) & 0x00FFFFFF)) 459 #define DITHER_ROTATE(x) ((((x) & 0xFF) << 24) | (((x) >> 8) & 0x00FFFFFF))
460 static const INT32 dither_matrix[4] = { 460 static const JLONG dither_matrix[4] = {
461 0x0008020A, 461 0x0008020A,
462 0x0C040E06, 462 0x0C040E06,
463 0x030B0109, 463 0x030B0109,
464 0x0F070D05 464 0x0F070D05
465 }; 465 };
466 466
467 467
468 /* Include inline routines for RGB565 conversion */ 468 /* Include inline routines for RGB565 conversion */
469 469
470 #define PACK_SHORT_565 PACK_SHORT_565_LE 470 #define PACK_SHORT_565 PACK_SHORT_565_LE
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 h2v1_merged_upsample_565 (j_decompress_ptr cinfo, 513 h2v1_merged_upsample_565 (j_decompress_ptr cinfo,
514 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, 514 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
515 JSAMPARRAY output_buf) 515 JSAMPARRAY output_buf)
516 { 516 {
517 if (is_big_endian()) 517 if (is_big_endian())
518 h2v1_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr, 518 h2v1_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
519 output_buf); 519 output_buf);
520 else 520 else
521 h2v1_merged_upsample_565_le(cinfo, input_buf, in_row_group_ctr, 521 h2v1_merged_upsample_565_le(cinfo, input_buf, in_row_group_ctr,
522 output_buf); 522 output_buf);
523 } 523 }
524 524
525 525
526 METHODDEF(void) 526 METHODDEF(void)
527 h2v1_merged_upsample_565D (j_decompress_ptr cinfo, 527 h2v1_merged_upsample_565D (j_decompress_ptr cinfo,
528 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, 528 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
529 JSAMPARRAY output_buf) 529 JSAMPARRAY output_buf)
530 { 530 {
531 if (is_big_endian()) 531 if (is_big_endian())
532 h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr, 532 h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
533 output_buf); 533 output_buf);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 * of this module; no safety checks are made here. 573 * of this module; no safety checks are made here.
574 */ 574 */
575 575
576 GLOBAL(void) 576 GLOBAL(void)
577 jinit_merged_upsampler (j_decompress_ptr cinfo) 577 jinit_merged_upsampler (j_decompress_ptr cinfo)
578 { 578 {
579 my_upsample_ptr upsample; 579 my_upsample_ptr upsample;
580 580
581 upsample = (my_upsample_ptr) 581 upsample = (my_upsample_ptr)
582 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 582 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
583 » » » » SIZEOF(my_upsampler)); 583 sizeof(my_upsampler));
584 cinfo->upsample = (struct jpeg_upsampler *) upsample; 584 cinfo->upsample = (struct jpeg_upsampler *) upsample;
585 upsample->pub.start_pass = start_pass_merged_upsample; 585 upsample->pub.start_pass = start_pass_merged_upsample;
586 upsample->pub.need_context_rows = FALSE; 586 upsample->pub.need_context_rows = FALSE;
587 587
588 upsample->out_row_width = cinfo->output_width * cinfo->out_color_components; 588 upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
589 589
590 if (cinfo->max_v_samp_factor == 2) { 590 if (cinfo->max_v_samp_factor == 2) {
591 upsample->pub.upsample = merged_2v_upsample; 591 upsample->pub.upsample = merged_2v_upsample;
592 if (jsimd_can_h2v2_merged_upsample()) 592 if (jsimd_can_h2v2_merged_upsample())
593 upsample->upmethod = jsimd_h2v2_merged_upsample; 593 upsample->upmethod = jsimd_h2v2_merged_upsample;
594 else 594 else
595 upsample->upmethod = h2v2_merged_upsample; 595 upsample->upmethod = h2v2_merged_upsample;
596 if (cinfo->out_color_space == JCS_RGB565) { 596 if (cinfo->out_color_space == JCS_RGB565) {
597 if (cinfo->dither_mode != JDITHER_NONE) { 597 if (cinfo->dither_mode != JDITHER_NONE) {
598 upsample->upmethod = h2v2_merged_upsample_565D; 598 upsample->upmethod = h2v2_merged_upsample_565D;
599 } else { 599 } else {
600 upsample->upmethod = h2v2_merged_upsample_565; 600 upsample->upmethod = h2v2_merged_upsample_565;
601 } 601 }
602 } 602 }
603 /* Allocate a spare row buffer */ 603 /* Allocate a spare row buffer */
604 upsample->spare_row = (JSAMPROW) 604 upsample->spare_row = (JSAMPROW)
605 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, 605 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
606 » » (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE))); 606 (size_t) (upsample->out_row_width * sizeof(JSAMPLE)));
607 } else { 607 } else {
608 upsample->pub.upsample = merged_1v_upsample; 608 upsample->pub.upsample = merged_1v_upsample;
609 if (jsimd_can_h2v1_merged_upsample()) 609 if (jsimd_can_h2v1_merged_upsample())
610 upsample->upmethod = jsimd_h2v1_merged_upsample; 610 upsample->upmethod = jsimd_h2v1_merged_upsample;
611 else 611 else
612 upsample->upmethod = h2v1_merged_upsample; 612 upsample->upmethod = h2v1_merged_upsample;
613 if (cinfo->out_color_space == JCS_RGB565) { 613 if (cinfo->out_color_space == JCS_RGB565) {
614 if (cinfo->dither_mode != JDITHER_NONE) { 614 if (cinfo->dither_mode != JDITHER_NONE) {
615 upsample->upmethod = h2v1_merged_upsample_565D; 615 upsample->upmethod = h2v1_merged_upsample_565D;
616 } else { 616 } else {
617 upsample->upmethod = h2v1_merged_upsample_565; 617 upsample->upmethod = h2v1_merged_upsample_565;
618 } 618 }
619 } 619 }
620 /* No spare row needed */ 620 /* No spare row needed */
621 upsample->spare_row = NULL; 621 upsample->spare_row = NULL;
622 } 622 }
623 623
624 build_ycc_rgb_table(cinfo); 624 build_ycc_rgb_table(cinfo);
625 } 625 }
626 626
627 #endif /* UPSAMPLE_MERGING_SUPPORTED */ 627 #endif /* UPSAMPLE_MERGING_SUPPORTED */
OLDNEW
« no previous file with comments | « jdmaster.c ('k') | jdmrg565.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698