media/libjpeg/jccolext.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * jccolext.c
michael@0 3 *
michael@0 4 * This file was part of the Independent JPEG Group's software:
michael@0 5 * Copyright (C) 1991-1996, Thomas G. Lane.
michael@0 6 * libjpeg-turbo Modifications:
michael@0 7 * Copyright (C) 2009-2012, 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 input colorspace conversion routines.
michael@0 11 */
michael@0 12
michael@0 13
michael@0 14 /* This file is included by jccolor.c */
michael@0 15
michael@0 16
michael@0 17 /*
michael@0 18 * Convert some rows of samples to the JPEG colorspace.
michael@0 19 *
michael@0 20 * Note that we change from the application's interleaved-pixel format
michael@0 21 * to our internal noninterleaved, one-plane-per-component format.
michael@0 22 * The input buffer is therefore three times as wide as the output buffer.
michael@0 23 *
michael@0 24 * A starting row offset is provided only for the output buffer. The caller
michael@0 25 * can easily adjust the passed input_buf value to accommodate any row
michael@0 26 * offset required on that side.
michael@0 27 */
michael@0 28
michael@0 29 INLINE
michael@0 30 LOCAL(void)
michael@0 31 rgb_ycc_convert_internal (j_compress_ptr cinfo,
michael@0 32 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
michael@0 33 JDIMENSION output_row, int num_rows)
michael@0 34 {
michael@0 35 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
michael@0 36 register int r, g, b;
michael@0 37 register INT32 * ctab = cconvert->rgb_ycc_tab;
michael@0 38 register JSAMPROW inptr;
michael@0 39 register JSAMPROW outptr0, outptr1, outptr2;
michael@0 40 register JDIMENSION col;
michael@0 41 JDIMENSION num_cols = cinfo->image_width;
michael@0 42
michael@0 43 while (--num_rows >= 0) {
michael@0 44 inptr = *input_buf++;
michael@0 45 outptr0 = output_buf[0][output_row];
michael@0 46 outptr1 = output_buf[1][output_row];
michael@0 47 outptr2 = output_buf[2][output_row];
michael@0 48 output_row++;
michael@0 49 for (col = 0; col < num_cols; col++) {
michael@0 50 r = GETJSAMPLE(inptr[RGB_RED]);
michael@0 51 g = GETJSAMPLE(inptr[RGB_GREEN]);
michael@0 52 b = GETJSAMPLE(inptr[RGB_BLUE]);
michael@0 53 inptr += RGB_PIXELSIZE;
michael@0 54 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
michael@0 55 * must be too; we do not need an explicit range-limiting operation.
michael@0 56 * Hence the value being shifted is never negative, and we don't
michael@0 57 * need the general RIGHT_SHIFT macro.
michael@0 58 */
michael@0 59 /* Y */
michael@0 60 outptr0[col] = (JSAMPLE)
michael@0 61 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
michael@0 62 >> SCALEBITS);
michael@0 63 /* Cb */
michael@0 64 outptr1[col] = (JSAMPLE)
michael@0 65 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
michael@0 66 >> SCALEBITS);
michael@0 67 /* Cr */
michael@0 68 outptr2[col] = (JSAMPLE)
michael@0 69 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
michael@0 70 >> SCALEBITS);
michael@0 71 }
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75
michael@0 76 /**************** Cases other than RGB -> YCbCr **************/
michael@0 77
michael@0 78
michael@0 79 /*
michael@0 80 * Convert some rows of samples to the JPEG colorspace.
michael@0 81 * This version handles RGB->grayscale conversion, which is the same
michael@0 82 * as the RGB->Y portion of RGB->YCbCr.
michael@0 83 * We assume rgb_ycc_start has been called (we only use the Y tables).
michael@0 84 */
michael@0 85
michael@0 86 INLINE
michael@0 87 LOCAL(void)
michael@0 88 rgb_gray_convert_internal (j_compress_ptr cinfo,
michael@0 89 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
michael@0 90 JDIMENSION output_row, int num_rows)
michael@0 91 {
michael@0 92 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
michael@0 93 register int r, g, b;
michael@0 94 register INT32 * ctab = cconvert->rgb_ycc_tab;
michael@0 95 register JSAMPROW inptr;
michael@0 96 register JSAMPROW outptr;
michael@0 97 register JDIMENSION col;
michael@0 98 JDIMENSION num_cols = cinfo->image_width;
michael@0 99
michael@0 100 while (--num_rows >= 0) {
michael@0 101 inptr = *input_buf++;
michael@0 102 outptr = output_buf[0][output_row];
michael@0 103 output_row++;
michael@0 104 for (col = 0; col < num_cols; col++) {
michael@0 105 r = GETJSAMPLE(inptr[RGB_RED]);
michael@0 106 g = GETJSAMPLE(inptr[RGB_GREEN]);
michael@0 107 b = GETJSAMPLE(inptr[RGB_BLUE]);
michael@0 108 inptr += RGB_PIXELSIZE;
michael@0 109 /* Y */
michael@0 110 outptr[col] = (JSAMPLE)
michael@0 111 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
michael@0 112 >> SCALEBITS);
michael@0 113 }
michael@0 114 }
michael@0 115 }
michael@0 116
michael@0 117
michael@0 118 /*
michael@0 119 * Convert some rows of samples to the JPEG colorspace.
michael@0 120 * This version handles extended RGB->plain RGB conversion
michael@0 121 */
michael@0 122
michael@0 123 INLINE
michael@0 124 LOCAL(void)
michael@0 125 rgb_rgb_convert_internal (j_compress_ptr cinfo,
michael@0 126 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
michael@0 127 JDIMENSION output_row, int num_rows)
michael@0 128 {
michael@0 129 register JSAMPROW inptr;
michael@0 130 register JSAMPROW outptr0, outptr1, outptr2;
michael@0 131 register JDIMENSION col;
michael@0 132 JDIMENSION num_cols = cinfo->image_width;
michael@0 133
michael@0 134 while (--num_rows >= 0) {
michael@0 135 inptr = *input_buf++;
michael@0 136 outptr0 = output_buf[0][output_row];
michael@0 137 outptr1 = output_buf[1][output_row];
michael@0 138 outptr2 = output_buf[2][output_row];
michael@0 139 output_row++;
michael@0 140 for (col = 0; col < num_cols; col++) {
michael@0 141 outptr0[col] = GETJSAMPLE(inptr[RGB_RED]);
michael@0 142 outptr1[col] = GETJSAMPLE(inptr[RGB_GREEN]);
michael@0 143 outptr2[col] = GETJSAMPLE(inptr[RGB_BLUE]);
michael@0 144 inptr += RGB_PIXELSIZE;
michael@0 145 }
michael@0 146 }
michael@0 147 }

mercurial