media/libjpeg/jdcolext.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libjpeg/jdcolext.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,142 @@
     1.4 +/*
     1.5 + * jdcolext.c
     1.6 + *
     1.7 + * This file was part of the Independent JPEG Group's software:
     1.8 + * Copyright (C) 1991-1997, Thomas G. Lane.
     1.9 + * libjpeg-turbo Modifications:
    1.10 + * Copyright (C) 2009, 2011, D. R. Commander.
    1.11 + * For conditions of distribution and use, see the accompanying README file.
    1.12 + *
    1.13 + * This file contains output colorspace conversion routines.
    1.14 + */
    1.15 +
    1.16 +
    1.17 +/* This file is included by jdcolor.c */
    1.18 +
    1.19 +
    1.20 +/*
    1.21 + * Convert some rows of samples to the output colorspace.
    1.22 + *
    1.23 + * Note that we change from noninterleaved, one-plane-per-component format
    1.24 + * to interleaved-pixel format.  The output buffer is therefore three times
    1.25 + * as wide as the input buffer.
    1.26 + * A starting row offset is provided only for the input buffer.  The caller
    1.27 + * can easily adjust the passed output_buf value to accommodate any row
    1.28 + * offset required on that side.
    1.29 + */
    1.30 +
    1.31 +INLINE
    1.32 +LOCAL(void)
    1.33 +ycc_rgb_convert_internal (j_decompress_ptr cinfo,
    1.34 +                          JSAMPIMAGE input_buf, JDIMENSION input_row,
    1.35 +                          JSAMPARRAY output_buf, int num_rows)
    1.36 +{
    1.37 +  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
    1.38 +  register int y, cb, cr;
    1.39 +  register JSAMPROW outptr;
    1.40 +  register JSAMPROW inptr0, inptr1, inptr2;
    1.41 +  register JDIMENSION col;
    1.42 +  JDIMENSION num_cols = cinfo->output_width;
    1.43 +  /* copy these pointers into registers if possible */
    1.44 +  register JSAMPLE * range_limit = cinfo->sample_range_limit;
    1.45 +  register int * Crrtab = cconvert->Cr_r_tab;
    1.46 +  register int * Cbbtab = cconvert->Cb_b_tab;
    1.47 +  register INT32 * Crgtab = cconvert->Cr_g_tab;
    1.48 +  register INT32 * Cbgtab = cconvert->Cb_g_tab;
    1.49 +  SHIFT_TEMPS
    1.50 +
    1.51 +  while (--num_rows >= 0) {
    1.52 +    inptr0 = input_buf[0][input_row];
    1.53 +    inptr1 = input_buf[1][input_row];
    1.54 +    inptr2 = input_buf[2][input_row];
    1.55 +    input_row++;
    1.56 +    outptr = *output_buf++;
    1.57 +    for (col = 0; col < num_cols; col++) {
    1.58 +      y  = GETJSAMPLE(inptr0[col]);
    1.59 +      cb = GETJSAMPLE(inptr1[col]);
    1.60 +      cr = GETJSAMPLE(inptr2[col]);
    1.61 +      /* Range-limiting is essential due to noise introduced by DCT losses. */
    1.62 +      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
    1.63 +      outptr[RGB_GREEN] = range_limit[y +
    1.64 +			      ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
    1.65 +						 SCALEBITS))];
    1.66 +      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
    1.67 +      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
    1.68 +      /* alpha channel value */
    1.69 +#ifdef RGB_ALPHA
    1.70 +      outptr[RGB_ALPHA] = 0xFF;
    1.71 +#endif
    1.72 +      outptr += RGB_PIXELSIZE;
    1.73 +    }
    1.74 +  }
    1.75 +}
    1.76 +
    1.77 +
    1.78 +/*
    1.79 + * Convert grayscale to RGB: just duplicate the graylevel three times.
    1.80 + * This is provided to support applications that don't want to cope
    1.81 + * with grayscale as a separate case.
    1.82 + */
    1.83 +
    1.84 +INLINE
    1.85 +LOCAL(void)
    1.86 +gray_rgb_convert_internal (j_decompress_ptr cinfo,
    1.87 +                           JSAMPIMAGE input_buf, JDIMENSION input_row,
    1.88 +                           JSAMPARRAY output_buf, int num_rows)
    1.89 +{
    1.90 +  register JSAMPROW inptr, outptr;
    1.91 +  register JDIMENSION col;
    1.92 +  JDIMENSION num_cols = cinfo->output_width;
    1.93 +
    1.94 +  while (--num_rows >= 0) {
    1.95 +    inptr = input_buf[0][input_row++];
    1.96 +    outptr = *output_buf++;
    1.97 +    for (col = 0; col < num_cols; col++) {
    1.98 +      /* We can dispense with GETJSAMPLE() here */
    1.99 +      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
   1.100 +      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
   1.101 +      /* alpha channel value */
   1.102 +#ifdef RGB_ALPHA
   1.103 +      outptr[RGB_ALPHA] = 0xFF;
   1.104 +#endif
   1.105 +      outptr += RGB_PIXELSIZE;
   1.106 +    }
   1.107 +  }
   1.108 +}
   1.109 +
   1.110 +
   1.111 +/*
   1.112 + * Convert RGB to extended RGB: just swap the order of source pixels
   1.113 + */
   1.114 +
   1.115 +INLINE
   1.116 +LOCAL(void)
   1.117 +rgb_rgb_convert_internal (j_decompress_ptr cinfo,
   1.118 +                          JSAMPIMAGE input_buf, JDIMENSION input_row,
   1.119 +                          JSAMPARRAY output_buf, int num_rows)
   1.120 +{
   1.121 +  register JSAMPROW inptr0, inptr1, inptr2;
   1.122 +  register JSAMPROW outptr;
   1.123 +  register JDIMENSION col;
   1.124 +  JDIMENSION num_cols = cinfo->output_width;
   1.125 +
   1.126 +  while (--num_rows >= 0) {
   1.127 +    inptr0 = input_buf[0][input_row];
   1.128 +    inptr1 = input_buf[1][input_row];
   1.129 +    inptr2 = input_buf[2][input_row];
   1.130 +    input_row++;
   1.131 +    outptr = *output_buf++;
   1.132 +    for (col = 0; col < num_cols; col++) {
   1.133 +      /* We can dispense with GETJSAMPLE() here */
   1.134 +      outptr[RGB_RED] = inptr0[col];
   1.135 +      outptr[RGB_GREEN] = inptr1[col];
   1.136 +      outptr[RGB_BLUE] = inptr2[col];
   1.137 +      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
   1.138 +      /* alpha channel value */
   1.139 +#ifdef RGB_ALPHA
   1.140 +      outptr[RGB_ALPHA] = 0xFF;
   1.141 +#endif
   1.142 +      outptr += RGB_PIXELSIZE;
   1.143 +    }
   1.144 +  }
   1.145 +}

mercurial