shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * jdcolext.c
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file was part of the Independent JPEG Group's software:
shun-iwasawa 82a8f5
 * Copyright (C) 1991-1997, Thomas G. Lane.
shun-iwasawa 82a8f5
 * libjpeg-turbo Modifications:
shun-iwasawa 82a8f5
 * Copyright (C) 2009, 2011, 2015, D. R. Commander.
shun-iwasawa 82a8f5
 * For conditions of distribution and use, see the accompanying README.ijg
shun-iwasawa 82a8f5
 * file.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file contains output colorspace conversion routines.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* This file is included by jdcolor.c */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert some rows of samples to the output colorspace.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * Note that we change from noninterleaved, one-plane-per-component format
shun-iwasawa 82a8f5
 * to interleaved-pixel format.  The output buffer is therefore three times
shun-iwasawa 82a8f5
 * as wide as the input buffer.
shun-iwasawa 82a8f5
 * A starting row offset is provided only for the input buffer.  The caller
shun-iwasawa 82a8f5
 * can easily adjust the passed output_buf value to accommodate any row
shun-iwasawa 82a8f5
 * offset required on that side.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
shun-iwasawa 82a8f5
                         JDIMENSION input_row, JSAMPARRAY output_buf,
shun-iwasawa 82a8f5
                         int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
shun-iwasawa 82a8f5
  register int y, cb, cr;
shun-iwasawa 82a8f5
  register JSAMPROW outptr;
shun-iwasawa 82a8f5
  register JSAMPROW inptr0, inptr1, inptr2;
shun-iwasawa 82a8f5
  register JDIMENSION col;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->output_width;
shun-iwasawa 82a8f5
  /* copy these pointers into registers if possible */
shun-iwasawa 82a8f5
  register JSAMPLE *range_limit = cinfo->sample_range_limit;
shun-iwasawa 82a8f5
  register int *Crrtab = cconvert->Cr_r_tab;
shun-iwasawa 82a8f5
  register int *Cbbtab = cconvert->Cb_b_tab;
shun-iwasawa 82a8f5
  register JLONG *Crgtab = cconvert->Cr_g_tab;
shun-iwasawa 82a8f5
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
shun-iwasawa 82a8f5
  SHIFT_TEMPS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    inptr0 = input_buf[0][input_row];
shun-iwasawa 82a8f5
    inptr1 = input_buf[1][input_row];
shun-iwasawa 82a8f5
    inptr2 = input_buf[2][input_row];
shun-iwasawa 82a8f5
    input_row++;
shun-iwasawa 82a8f5
    outptr = *output_buf++;
shun-iwasawa 82a8f5
    for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(inptr0[col]);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(inptr1[col]);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(inptr2[col]);
shun-iwasawa 82a8f5
      /* Range-limiting is essential due to noise introduced by DCT losses. */
shun-iwasawa 82a8f5
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
shun-iwasawa 82a8f5
      outptr[RGB_GREEN] = range_limit[y +
shun-iwasawa 82a8f5
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                                SCALEBITS))];
shun-iwasawa 82a8f5
      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
shun-iwasawa 82a8f5
      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
shun-iwasawa 82a8f5
      /* alpha channel value */
shun-iwasawa 82a8f5
#ifdef RGB_ALPHA
shun-iwasawa 82a8f5
      outptr[RGB_ALPHA] = 0xFF;
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
      outptr += RGB_PIXELSIZE;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert grayscale to RGB: just duplicate the graylevel three times.
shun-iwasawa 82a8f5
 * This is provided to support applications that don't want to cope
shun-iwasawa 82a8f5
 * with grayscale as a separate case.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
shun-iwasawa 82a8f5
                          JDIMENSION input_row, JSAMPARRAY output_buf,
shun-iwasawa 82a8f5
                          int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  register JSAMPROW inptr, outptr;
shun-iwasawa 82a8f5
  register JDIMENSION col;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->output_width;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    inptr = input_buf[0][input_row++];
shun-iwasawa 82a8f5
    outptr = *output_buf++;
shun-iwasawa 82a8f5
    for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
      /* We can dispense with GETJSAMPLE() here */
shun-iwasawa 82a8f5
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
shun-iwasawa 82a8f5
      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
shun-iwasawa 82a8f5
      /* alpha channel value */
shun-iwasawa 82a8f5
#ifdef RGB_ALPHA
shun-iwasawa 82a8f5
      outptr[RGB_ALPHA] = 0xFF;
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
      outptr += RGB_PIXELSIZE;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert RGB to extended RGB: just swap the order of source pixels
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
shun-iwasawa 82a8f5
                         JDIMENSION input_row, JSAMPARRAY output_buf,
shun-iwasawa 82a8f5
                         int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  register JSAMPROW inptr0, inptr1, inptr2;
shun-iwasawa 82a8f5
  register JSAMPROW outptr;
shun-iwasawa 82a8f5
  register JDIMENSION col;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->output_width;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    inptr0 = input_buf[0][input_row];
shun-iwasawa 82a8f5
    inptr1 = input_buf[1][input_row];
shun-iwasawa 82a8f5
    inptr2 = input_buf[2][input_row];
shun-iwasawa 82a8f5
    input_row++;
shun-iwasawa 82a8f5
    outptr = *output_buf++;
shun-iwasawa 82a8f5
    for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
      /* We can dispense with GETJSAMPLE() here */
shun-iwasawa 82a8f5
      outptr[RGB_RED] = inptr0[col];
shun-iwasawa 82a8f5
      outptr[RGB_GREEN] = inptr1[col];
shun-iwasawa 82a8f5
      outptr[RGB_BLUE] = inptr2[col];
shun-iwasawa 82a8f5
      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
shun-iwasawa 82a8f5
      /* alpha channel value */
shun-iwasawa 82a8f5
#ifdef RGB_ALPHA
shun-iwasawa 82a8f5
      outptr[RGB_ALPHA] = 0xFF;
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
      outptr += RGB_PIXELSIZE;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}