shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * jdcol565.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
 * Modifications:
shun-iwasawa 82a8f5
 * Copyright (C) 2013, Linaro Limited.
shun-iwasawa 82a8f5
 * Copyright (C) 2014-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
/* This file is included by jdcolor.c */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
ycc_rgb565_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
    JLONG rgb;
shun-iwasawa 82a8f5
    unsigned int r, g, b;
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
shun-iwasawa 82a8f5
    if (PACK_NEED_ALIGNMENT(outptr)) {
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      r = range_limit[y + Crrtab[cr]];
shun-iwasawa 82a8f5
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                            SCALEBITS))];
shun-iwasawa 82a8f5
      b = range_limit[y + Cbbtab[cb]];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
      outptr += 2;
shun-iwasawa 82a8f5
      num_cols--;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    for (col = 0; col < (num_cols >> 1); col++) {
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      r = range_limit[y + Crrtab[cr]];
shun-iwasawa 82a8f5
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                            SCALEBITS))];
shun-iwasawa 82a8f5
      b = range_limit[y + Cbbtab[cb]];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      r = range_limit[y + Crrtab[cr]];
shun-iwasawa 82a8f5
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                            SCALEBITS))];
shun-iwasawa 82a8f5
      b = range_limit[y + Cbbtab[cb]];
shun-iwasawa 82a8f5
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
shun-iwasawa 82a8f5
      outptr += 4;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    if (num_cols & 1) {
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2);
shun-iwasawa 82a8f5
      r = range_limit[y + Crrtab[cr]];
shun-iwasawa 82a8f5
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                            SCALEBITS))];
shun-iwasawa 82a8f5
      b = range_limit[y + Cbbtab[cb]];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
ycc_rgb565D_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
  JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
shun-iwasawa 82a8f5
  SHIFT_TEMPS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    JLONG rgb;
shun-iwasawa 82a8f5
    unsigned int r, g, b;
shun-iwasawa 82a8f5
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
    if (PACK_NEED_ALIGNMENT(outptr)) {
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(y +
shun-iwasawa 82a8f5
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                                     SCALEBITS)), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
      outptr += 2;
shun-iwasawa 82a8f5
      num_cols--;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    for (col = 0; col < (num_cols >> 1); col++) {
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(y +
shun-iwasawa 82a8f5
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                                     SCALEBITS)), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
shun-iwasawa 82a8f5
      d0 = DITHER_ROTATE(d0);
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(y +
shun-iwasawa 82a8f5
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                                     SCALEBITS)), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
shun-iwasawa 82a8f5
      d0 = DITHER_ROTATE(d0);
shun-iwasawa 82a8f5
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
shun-iwasawa 82a8f5
      outptr += 4;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    if (num_cols & 1) {
shun-iwasawa 82a8f5
      y  = GETJSAMPLE(*inptr0);
shun-iwasawa 82a8f5
      cb = GETJSAMPLE(*inptr1);
shun-iwasawa 82a8f5
      cr = GETJSAMPLE(*inptr2);
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(y +
shun-iwasawa 82a8f5
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
shun-iwasawa 82a8f5
                                                     SCALEBITS)), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
rgb_rgb565_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 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
  SHIFT_TEMPS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    JLONG rgb;
shun-iwasawa 82a8f5
    unsigned int r, g, b;
shun-iwasawa 82a8f5
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
    if (PACK_NEED_ALIGNMENT(outptr)) {
shun-iwasawa 82a8f5
      r = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      g = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      b = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
      outptr += 2;
shun-iwasawa 82a8f5
      num_cols--;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    for (col = 0; col < (num_cols >> 1); col++) {
shun-iwasawa 82a8f5
      r = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      g = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      b = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      r = GETJSAMPLE(*inptr0++);
shun-iwasawa 82a8f5
      g = GETJSAMPLE(*inptr1++);
shun-iwasawa 82a8f5
      b = GETJSAMPLE(*inptr2++);
shun-iwasawa 82a8f5
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
shun-iwasawa 82a8f5
      outptr += 4;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    if (num_cols & 1) {
shun-iwasawa 82a8f5
      r = GETJSAMPLE(*inptr0);
shun-iwasawa 82a8f5
      g = GETJSAMPLE(*inptr1);
shun-iwasawa 82a8f5
      b = GETJSAMPLE(*inptr2);
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
rgb_rgb565D_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 outptr;
shun-iwasawa 82a8f5
  register JSAMPROW inptr0, inptr1, inptr2;
shun-iwasawa 82a8f5
  register JDIMENSION col;
shun-iwasawa 82a8f5
  register JSAMPLE *range_limit = cinfo->sample_range_limit;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->output_width;
shun-iwasawa 82a8f5
  JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
shun-iwasawa 82a8f5
  SHIFT_TEMPS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    JLONG rgb;
shun-iwasawa 82a8f5
    unsigned int r, g, b;
shun-iwasawa 82a8f5
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
    if (PACK_NEED_ALIGNMENT(outptr)) {
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
      outptr += 2;
shun-iwasawa 82a8f5
      num_cols--;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    for (col = 0; col < (num_cols >> 1); col++) {
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
shun-iwasawa 82a8f5
      d0 = DITHER_ROTATE(d0);
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
shun-iwasawa 82a8f5
      d0 = DITHER_ROTATE(d0);
shun-iwasawa 82a8f5
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
shun-iwasawa 82a8f5
      outptr += 4;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    if (num_cols & 1) {
shun-iwasawa 82a8f5
      r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0), d0)];
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1), d0)];
shun-iwasawa 82a8f5
      b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2), d0)];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(r, g, b);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
gray_rgb565_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
    JLONG rgb;
shun-iwasawa 82a8f5
    unsigned int g;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    inptr = input_buf[0][input_row++];
shun-iwasawa 82a8f5
    outptr = *output_buf++;
shun-iwasawa 82a8f5
    if (PACK_NEED_ALIGNMENT(outptr)) {
shun-iwasawa 82a8f5
      g = *inptr++;
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(g, g, g);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
      outptr += 2;
shun-iwasawa 82a8f5
      num_cols--;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    for (col = 0; col < (num_cols >> 1); col++) {
shun-iwasawa 82a8f5
      g = *inptr++;
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(g, g, g);
shun-iwasawa 82a8f5
      g = *inptr++;
shun-iwasawa 82a8f5
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
shun-iwasawa 82a8f5
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
shun-iwasawa 82a8f5
      outptr += 4;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    if (num_cols & 1) {
shun-iwasawa 82a8f5
      g = *inptr;
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(g, g, g);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
INLINE
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
gray_rgb565D_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
  register JSAMPLE *range_limit = cinfo->sample_range_limit;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->output_width;
shun-iwasawa 82a8f5
  JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    JLONG rgb;
shun-iwasawa 82a8f5
    unsigned int g;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    inptr = input_buf[0][input_row++];
shun-iwasawa 82a8f5
    outptr = *output_buf++;
shun-iwasawa 82a8f5
    if (PACK_NEED_ALIGNMENT(outptr)) {
shun-iwasawa 82a8f5
      g = *inptr++;
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_R(g, d0)];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(g, g, g);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
      outptr += 2;
shun-iwasawa 82a8f5
      num_cols--;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    for (col = 0; col < (num_cols >> 1); col++) {
shun-iwasawa 82a8f5
      g = *inptr++;
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_R(g, d0)];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(g, g, g);
shun-iwasawa 82a8f5
      d0 = DITHER_ROTATE(d0);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      g = *inptr++;
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_R(g, d0)];
shun-iwasawa 82a8f5
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
shun-iwasawa 82a8f5
      d0 = DITHER_ROTATE(d0);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
shun-iwasawa 82a8f5
      outptr += 4;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
    if (num_cols & 1) {
shun-iwasawa 82a8f5
      g = *inptr;
shun-iwasawa 82a8f5
      g = range_limit[DITHER_565_R(g, d0)];
shun-iwasawa 82a8f5
      rgb = PACK_SHORT_565(g, g, g);
shun-iwasawa 82a8f5
      *(INT16 *)outptr = (INT16)rgb;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}