media/libjpeg/jccolext.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libjpeg/jccolext.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +/*
     1.5 + * jccolext.c
     1.6 + *
     1.7 + * This file was part of the Independent JPEG Group's software:
     1.8 + * Copyright (C) 1991-1996, Thomas G. Lane.
     1.9 + * libjpeg-turbo Modifications:
    1.10 + * Copyright (C) 2009-2012, D. R. Commander.
    1.11 + * For conditions of distribution and use, see the accompanying README file.
    1.12 + *
    1.13 + * This file contains input colorspace conversion routines.
    1.14 + */
    1.15 +
    1.16 +
    1.17 +/* This file is included by jccolor.c */
    1.18 +
    1.19 +
    1.20 +/*
    1.21 + * Convert some rows of samples to the JPEG colorspace.
    1.22 + *
    1.23 + * Note that we change from the application's interleaved-pixel format
    1.24 + * to our internal noninterleaved, one-plane-per-component format.
    1.25 + * The input buffer is therefore three times as wide as the output buffer.
    1.26 + *
    1.27 + * A starting row offset is provided only for the output buffer.  The caller
    1.28 + * can easily adjust the passed input_buf value to accommodate any row
    1.29 + * offset required on that side.
    1.30 + */
    1.31 +
    1.32 +INLINE
    1.33 +LOCAL(void)
    1.34 +rgb_ycc_convert_internal (j_compress_ptr cinfo,
    1.35 +                          JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
    1.36 +                          JDIMENSION output_row, int num_rows)
    1.37 +{
    1.38 +  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
    1.39 +  register int r, g, b;
    1.40 +  register INT32 * ctab = cconvert->rgb_ycc_tab;
    1.41 +  register JSAMPROW inptr;
    1.42 +  register JSAMPROW outptr0, outptr1, outptr2;
    1.43 +  register JDIMENSION col;
    1.44 +  JDIMENSION num_cols = cinfo->image_width;
    1.45 +
    1.46 +  while (--num_rows >= 0) {
    1.47 +    inptr = *input_buf++;
    1.48 +    outptr0 = output_buf[0][output_row];
    1.49 +    outptr1 = output_buf[1][output_row];
    1.50 +    outptr2 = output_buf[2][output_row];
    1.51 +    output_row++;
    1.52 +    for (col = 0; col < num_cols; col++) {
    1.53 +      r = GETJSAMPLE(inptr[RGB_RED]);
    1.54 +      g = GETJSAMPLE(inptr[RGB_GREEN]);
    1.55 +      b = GETJSAMPLE(inptr[RGB_BLUE]);
    1.56 +      inptr += RGB_PIXELSIZE;
    1.57 +      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
    1.58 +       * must be too; we do not need an explicit range-limiting operation.
    1.59 +       * Hence the value being shifted is never negative, and we don't
    1.60 +       * need the general RIGHT_SHIFT macro.
    1.61 +       */
    1.62 +      /* Y */
    1.63 +      outptr0[col] = (JSAMPLE)
    1.64 +		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
    1.65 +		 >> SCALEBITS);
    1.66 +      /* Cb */
    1.67 +      outptr1[col] = (JSAMPLE)
    1.68 +		((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
    1.69 +		 >> SCALEBITS);
    1.70 +      /* Cr */
    1.71 +      outptr2[col] = (JSAMPLE)
    1.72 +		((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
    1.73 +		 >> SCALEBITS);
    1.74 +    }
    1.75 +  }
    1.76 +}
    1.77 +
    1.78 +
    1.79 +/**************** Cases other than RGB -> YCbCr **************/
    1.80 +
    1.81 +
    1.82 +/*
    1.83 + * Convert some rows of samples to the JPEG colorspace.
    1.84 + * This version handles RGB->grayscale conversion, which is the same
    1.85 + * as the RGB->Y portion of RGB->YCbCr.
    1.86 + * We assume rgb_ycc_start has been called (we only use the Y tables).
    1.87 + */
    1.88 +
    1.89 +INLINE
    1.90 +LOCAL(void)
    1.91 +rgb_gray_convert_internal (j_compress_ptr cinfo,
    1.92 +                           JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
    1.93 +                           JDIMENSION output_row, int num_rows)
    1.94 +{
    1.95 +  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
    1.96 +  register int r, g, b;
    1.97 +  register INT32 * ctab = cconvert->rgb_ycc_tab;
    1.98 +  register JSAMPROW inptr;
    1.99 +  register JSAMPROW outptr;
   1.100 +  register JDIMENSION col;
   1.101 +  JDIMENSION num_cols = cinfo->image_width;
   1.102 +
   1.103 +  while (--num_rows >= 0) {
   1.104 +    inptr = *input_buf++;
   1.105 +    outptr = output_buf[0][output_row];
   1.106 +    output_row++;
   1.107 +    for (col = 0; col < num_cols; col++) {
   1.108 +      r = GETJSAMPLE(inptr[RGB_RED]);
   1.109 +      g = GETJSAMPLE(inptr[RGB_GREEN]);
   1.110 +      b = GETJSAMPLE(inptr[RGB_BLUE]);
   1.111 +      inptr += RGB_PIXELSIZE;
   1.112 +      /* Y */
   1.113 +      outptr[col] = (JSAMPLE)
   1.114 +		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
   1.115 +		 >> SCALEBITS);
   1.116 +    }
   1.117 +  }
   1.118 +}
   1.119 +
   1.120 +
   1.121 +/*
   1.122 + * Convert some rows of samples to the JPEG colorspace.
   1.123 + * This version handles extended RGB->plain RGB conversion
   1.124 + */
   1.125 +
   1.126 +INLINE
   1.127 +LOCAL(void)
   1.128 +rgb_rgb_convert_internal (j_compress_ptr cinfo,
   1.129 +                          JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
   1.130 +                          JDIMENSION output_row, int num_rows)
   1.131 +{
   1.132 +  register JSAMPROW inptr;
   1.133 +  register JSAMPROW outptr0, outptr1, outptr2;
   1.134 +  register JDIMENSION col;
   1.135 +  JDIMENSION num_cols = cinfo->image_width;
   1.136 +
   1.137 +  while (--num_rows >= 0) {
   1.138 +    inptr = *input_buf++;
   1.139 +    outptr0 = output_buf[0][output_row];
   1.140 +    outptr1 = output_buf[1][output_row];
   1.141 +    outptr2 = output_buf[2][output_row];
   1.142 +    output_row++;
   1.143 +    for (col = 0; col < num_cols; col++) {
   1.144 +      outptr0[col] = GETJSAMPLE(inptr[RGB_RED]);
   1.145 +      outptr1[col] = GETJSAMPLE(inptr[RGB_GREEN]);
   1.146 +      outptr2[col] = GETJSAMPLE(inptr[RGB_BLUE]);
   1.147 +      inptr += RGB_PIXELSIZE;
   1.148 +    }
   1.149 +  }
   1.150 +}

mercurial