media/libjpeg/jdcolext.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * jdcolext.c
michael@0 3 *
michael@0 4 * This file was part of the Independent JPEG Group's software:
michael@0 5 * Copyright (C) 1991-1997, Thomas G. Lane.
michael@0 6 * libjpeg-turbo Modifications:
michael@0 7 * Copyright (C) 2009, 2011, D. R. Commander.
michael@0 8 * For conditions of distribution and use, see the accompanying README file.
michael@0 9 *
michael@0 10 * This file contains output colorspace conversion routines.
michael@0 11 */
michael@0 12
michael@0 13
michael@0 14 /* This file is included by jdcolor.c */
michael@0 15
michael@0 16
michael@0 17 /*
michael@0 18 * Convert some rows of samples to the output colorspace.
michael@0 19 *
michael@0 20 * Note that we change from noninterleaved, one-plane-per-component format
michael@0 21 * to interleaved-pixel format. The output buffer is therefore three times
michael@0 22 * as wide as the input buffer.
michael@0 23 * A starting row offset is provided only for the input buffer. The caller
michael@0 24 * can easily adjust the passed output_buf value to accommodate any row
michael@0 25 * offset required on that side.
michael@0 26 */
michael@0 27
michael@0 28 INLINE
michael@0 29 LOCAL(void)
michael@0 30 ycc_rgb_convert_internal (j_decompress_ptr cinfo,
michael@0 31 JSAMPIMAGE input_buf, JDIMENSION input_row,
michael@0 32 JSAMPARRAY output_buf, int num_rows)
michael@0 33 {
michael@0 34 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
michael@0 35 register int y, cb, cr;
michael@0 36 register JSAMPROW outptr;
michael@0 37 register JSAMPROW inptr0, inptr1, inptr2;
michael@0 38 register JDIMENSION col;
michael@0 39 JDIMENSION num_cols = cinfo->output_width;
michael@0 40 /* copy these pointers into registers if possible */
michael@0 41 register JSAMPLE * range_limit = cinfo->sample_range_limit;
michael@0 42 register int * Crrtab = cconvert->Cr_r_tab;
michael@0 43 register int * Cbbtab = cconvert->Cb_b_tab;
michael@0 44 register INT32 * Crgtab = cconvert->Cr_g_tab;
michael@0 45 register INT32 * Cbgtab = cconvert->Cb_g_tab;
michael@0 46 SHIFT_TEMPS
michael@0 47
michael@0 48 while (--num_rows >= 0) {
michael@0 49 inptr0 = input_buf[0][input_row];
michael@0 50 inptr1 = input_buf[1][input_row];
michael@0 51 inptr2 = input_buf[2][input_row];
michael@0 52 input_row++;
michael@0 53 outptr = *output_buf++;
michael@0 54 for (col = 0; col < num_cols; col++) {
michael@0 55 y = GETJSAMPLE(inptr0[col]);
michael@0 56 cb = GETJSAMPLE(inptr1[col]);
michael@0 57 cr = GETJSAMPLE(inptr2[col]);
michael@0 58 /* Range-limiting is essential due to noise introduced by DCT losses. */
michael@0 59 outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
michael@0 60 outptr[RGB_GREEN] = range_limit[y +
michael@0 61 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
michael@0 62 SCALEBITS))];
michael@0 63 outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
michael@0 64 /* Set unused byte to 0xFF so it can be interpreted as an opaque */
michael@0 65 /* alpha channel value */
michael@0 66 #ifdef RGB_ALPHA
michael@0 67 outptr[RGB_ALPHA] = 0xFF;
michael@0 68 #endif
michael@0 69 outptr += RGB_PIXELSIZE;
michael@0 70 }
michael@0 71 }
michael@0 72 }
michael@0 73
michael@0 74
michael@0 75 /*
michael@0 76 * Convert grayscale to RGB: just duplicate the graylevel three times.
michael@0 77 * This is provided to support applications that don't want to cope
michael@0 78 * with grayscale as a separate case.
michael@0 79 */
michael@0 80
michael@0 81 INLINE
michael@0 82 LOCAL(void)
michael@0 83 gray_rgb_convert_internal (j_decompress_ptr cinfo,
michael@0 84 JSAMPIMAGE input_buf, JDIMENSION input_row,
michael@0 85 JSAMPARRAY output_buf, int num_rows)
michael@0 86 {
michael@0 87 register JSAMPROW inptr, outptr;
michael@0 88 register JDIMENSION col;
michael@0 89 JDIMENSION num_cols = cinfo->output_width;
michael@0 90
michael@0 91 while (--num_rows >= 0) {
michael@0 92 inptr = input_buf[0][input_row++];
michael@0 93 outptr = *output_buf++;
michael@0 94 for (col = 0; col < num_cols; col++) {
michael@0 95 /* We can dispense with GETJSAMPLE() here */
michael@0 96 outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
michael@0 97 /* Set unused byte to 0xFF so it can be interpreted as an opaque */
michael@0 98 /* alpha channel value */
michael@0 99 #ifdef RGB_ALPHA
michael@0 100 outptr[RGB_ALPHA] = 0xFF;
michael@0 101 #endif
michael@0 102 outptr += RGB_PIXELSIZE;
michael@0 103 }
michael@0 104 }
michael@0 105 }
michael@0 106
michael@0 107
michael@0 108 /*
michael@0 109 * Convert RGB to extended RGB: just swap the order of source pixels
michael@0 110 */
michael@0 111
michael@0 112 INLINE
michael@0 113 LOCAL(void)
michael@0 114 rgb_rgb_convert_internal (j_decompress_ptr cinfo,
michael@0 115 JSAMPIMAGE input_buf, JDIMENSION input_row,
michael@0 116 JSAMPARRAY output_buf, int num_rows)
michael@0 117 {
michael@0 118 register JSAMPROW inptr0, inptr1, inptr2;
michael@0 119 register JSAMPROW outptr;
michael@0 120 register JDIMENSION col;
michael@0 121 JDIMENSION num_cols = cinfo->output_width;
michael@0 122
michael@0 123 while (--num_rows >= 0) {
michael@0 124 inptr0 = input_buf[0][input_row];
michael@0 125 inptr1 = input_buf[1][input_row];
michael@0 126 inptr2 = input_buf[2][input_row];
michael@0 127 input_row++;
michael@0 128 outptr = *output_buf++;
michael@0 129 for (col = 0; col < num_cols; col++) {
michael@0 130 /* We can dispense with GETJSAMPLE() here */
michael@0 131 outptr[RGB_RED] = inptr0[col];
michael@0 132 outptr[RGB_GREEN] = inptr1[col];
michael@0 133 outptr[RGB_BLUE] = inptr2[col];
michael@0 134 /* Set unused byte to 0xFF so it can be interpreted as an opaque */
michael@0 135 /* alpha channel value */
michael@0 136 #ifdef RGB_ALPHA
michael@0 137 outptr[RGB_ALPHA] = 0xFF;
michael@0 138 #endif
michael@0 139 outptr += RGB_PIXELSIZE;
michael@0 140 }
michael@0 141 }
michael@0 142 }

mercurial