shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * jccolor.c
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file was part of the Independent JPEG Group's software:
shun-iwasawa 82a8f5
 * Copyright (C) 1991-1996, Thomas G. Lane.
shun-iwasawa 82a8f5
 * libjpeg-turbo Modifications:
shun-iwasawa 82a8f5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB</ossman@cendio.se>
shun-iwasawa 82a8f5
 * Copyright (C) 2009-2012, 2015, D. R. Commander.
shun-iwasawa 82a8f5
 * Copyright (C) 2014, MIPS Technologies, Inc., California.
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 input colorspace conversion routines.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define JPEG_INTERNALS
shun-iwasawa 82a8f5
#include "jinclude.h"
shun-iwasawa 82a8f5
#include "jpeglib.h"
shun-iwasawa 82a8f5
#include "jsimd.h"
shun-iwasawa 82a8f5
#include "jconfigint.h"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Private subobject */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
typedef struct {
shun-iwasawa 82a8f5
  struct jpeg_color_converter pub; /* public fields */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Private state for RGB->YCC conversion */
shun-iwasawa 82a8f5
  JLONG *rgb_ycc_tab;           /* => table for RGB to YCbCr conversion */
shun-iwasawa 82a8f5
} my_color_converter;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
typedef my_color_converter *my_cconvert_ptr;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**************** RGB -> YCbCr conversion: most common case **************/
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
shun-iwasawa 82a8f5
 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
shun-iwasawa 82a8f5
 * The conversion equations to be implemented are therefore
shun-iwasawa 82a8f5
 *      Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
shun-iwasawa 82a8f5
 *      Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B  + CENTERJSAMPLE
shun-iwasawa 82a8f5
 *      Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B  + CENTERJSAMPLE
shun-iwasawa 82a8f5
 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
shun-iwasawa 82a8f5
 * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
shun-iwasawa 82a8f5
 * rather than CENTERJSAMPLE, for Cb and Cr.  This gave equal positive and
shun-iwasawa 82a8f5
 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
shun-iwasawa 82a8f5
 * were not represented exactly.  Now we sacrifice exact representation of
shun-iwasawa 82a8f5
 * maximum red and maximum blue in order to get exact grayscales.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * To avoid floating-point arithmetic, we represent the fractional constants
shun-iwasawa 82a8f5
 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
shun-iwasawa 82a8f5
 * the products by 2^16, with appropriate rounding, to get the correct answer.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * For even more speed, we avoid doing any multiplications in the inner loop
shun-iwasawa 82a8f5
 * by precalculating the constants times R,G,B for all possible values.
shun-iwasawa 82a8f5
 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
shun-iwasawa 82a8f5
 * for 12-bit samples it is still acceptable.  It's not very reasonable for
shun-iwasawa 82a8f5
 * 16-bit samples, but if you want lossless storage you shouldn't be changing
shun-iwasawa 82a8f5
 * colorspace anyway.
shun-iwasawa 82a8f5
 * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
shun-iwasawa 82a8f5
 * in the tables to save adding them separately in the inner loop.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define SCALEBITS       16      /* speediest right-shift on some machines */
shun-iwasawa 82a8f5
#define CBCR_OFFSET     ((JLONG)CENTERJSAMPLE << SCALEBITS)
shun-iwasawa 82a8f5
#define ONE_HALF        ((JLONG)1 << (SCALEBITS - 1))
shun-iwasawa 82a8f5
#define FIX(x)          ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* We allocate one big table and divide it up into eight parts, instead of
shun-iwasawa 82a8f5
 * doing eight alloc_small requests.  This lets us use a single table base
shun-iwasawa 82a8f5
 * address, which can be held in a register in the inner loops on many
shun-iwasawa 82a8f5
 * machines (more than can hold all eight addresses, anyway).
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define R_Y_OFF         0                       /* offset to R => Y section */
shun-iwasawa 82a8f5
#define G_Y_OFF         (1 * (MAXJSAMPLE + 1))  /* offset to G => Y section */
shun-iwasawa 82a8f5
#define B_Y_OFF         (2 * (MAXJSAMPLE + 1))  /* etc. */
shun-iwasawa 82a8f5
#define R_CB_OFF        (3 * (MAXJSAMPLE + 1))
shun-iwasawa 82a8f5
#define G_CB_OFF        (4 * (MAXJSAMPLE + 1))
shun-iwasawa 82a8f5
#define B_CB_OFF        (5 * (MAXJSAMPLE + 1))
shun-iwasawa 82a8f5
#define R_CR_OFF        B_CB_OFF                /* B=>Cb, R=>Cr are the same */
shun-iwasawa 82a8f5
#define G_CR_OFF        (6 * (MAXJSAMPLE + 1))
shun-iwasawa 82a8f5
#define B_CR_OFF        (7 * (MAXJSAMPLE + 1))
shun-iwasawa 82a8f5
#define TABLE_SIZE      (8 * (MAXJSAMPLE + 1))
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Include inline routines for colorspace extensions */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#include "jccolext.c"
shun-iwasawa 82a8f5
#undef RGB_RED
shun-iwasawa 82a8f5
#undef RGB_GREEN
shun-iwasawa 82a8f5
#undef RGB_BLUE
shun-iwasawa 82a8f5
#undef RGB_PIXELSIZE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define RGB_RED  EXT_RGB_RED
shun-iwasawa 82a8f5
#define RGB_GREEN  EXT_RGB_GREEN
shun-iwasawa 82a8f5
#define RGB_BLUE  EXT_RGB_BLUE
shun-iwasawa 82a8f5
#define RGB_PIXELSIZE  EXT_RGB_PIXELSIZE
shun-iwasawa 82a8f5
#define rgb_ycc_convert_internal  extrgb_ycc_convert_internal
shun-iwasawa 82a8f5
#define rgb_gray_convert_internal  extrgb_gray_convert_internal
shun-iwasawa 82a8f5
#define rgb_rgb_convert_internal  extrgb_rgb_convert_internal
shun-iwasawa 82a8f5
#include "jccolext.c"
shun-iwasawa 82a8f5
#undef RGB_RED
shun-iwasawa 82a8f5
#undef RGB_GREEN
shun-iwasawa 82a8f5
#undef RGB_BLUE
shun-iwasawa 82a8f5
#undef RGB_PIXELSIZE
shun-iwasawa 82a8f5
#undef rgb_ycc_convert_internal
shun-iwasawa 82a8f5
#undef rgb_gray_convert_internal
shun-iwasawa 82a8f5
#undef rgb_rgb_convert_internal
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define RGB_RED  EXT_RGBX_RED
shun-iwasawa 82a8f5
#define RGB_GREEN  EXT_RGBX_GREEN
shun-iwasawa 82a8f5
#define RGB_BLUE  EXT_RGBX_BLUE
shun-iwasawa 82a8f5
#define RGB_PIXELSIZE  EXT_RGBX_PIXELSIZE
shun-iwasawa 82a8f5
#define rgb_ycc_convert_internal  extrgbx_ycc_convert_internal
shun-iwasawa 82a8f5
#define rgb_gray_convert_internal  extrgbx_gray_convert_internal
shun-iwasawa 82a8f5
#define rgb_rgb_convert_internal  extrgbx_rgb_convert_internal
shun-iwasawa 82a8f5
#include "jccolext.c"
shun-iwasawa 82a8f5
#undef RGB_RED
shun-iwasawa 82a8f5
#undef RGB_GREEN
shun-iwasawa 82a8f5
#undef RGB_BLUE
shun-iwasawa 82a8f5
#undef RGB_PIXELSIZE
shun-iwasawa 82a8f5
#undef rgb_ycc_convert_internal
shun-iwasawa 82a8f5
#undef rgb_gray_convert_internal
shun-iwasawa 82a8f5
#undef rgb_rgb_convert_internal
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define RGB_RED  EXT_BGR_RED
shun-iwasawa 82a8f5
#define RGB_GREEN  EXT_BGR_GREEN
shun-iwasawa 82a8f5
#define RGB_BLUE  EXT_BGR_BLUE
shun-iwasawa 82a8f5
#define RGB_PIXELSIZE  EXT_BGR_PIXELSIZE
shun-iwasawa 82a8f5
#define rgb_ycc_convert_internal  extbgr_ycc_convert_internal
shun-iwasawa 82a8f5
#define rgb_gray_convert_internal  extbgr_gray_convert_internal
shun-iwasawa 82a8f5
#define rgb_rgb_convert_internal  extbgr_rgb_convert_internal
shun-iwasawa 82a8f5
#include "jccolext.c"
shun-iwasawa 82a8f5
#undef RGB_RED
shun-iwasawa 82a8f5
#undef RGB_GREEN
shun-iwasawa 82a8f5
#undef RGB_BLUE
shun-iwasawa 82a8f5
#undef RGB_PIXELSIZE
shun-iwasawa 82a8f5
#undef rgb_ycc_convert_internal
shun-iwasawa 82a8f5
#undef rgb_gray_convert_internal
shun-iwasawa 82a8f5
#undef rgb_rgb_convert_internal
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define RGB_RED  EXT_BGRX_RED
shun-iwasawa 82a8f5
#define RGB_GREEN  EXT_BGRX_GREEN
shun-iwasawa 82a8f5
#define RGB_BLUE  EXT_BGRX_BLUE
shun-iwasawa 82a8f5
#define RGB_PIXELSIZE  EXT_BGRX_PIXELSIZE
shun-iwasawa 82a8f5
#define rgb_ycc_convert_internal  extbgrx_ycc_convert_internal
shun-iwasawa 82a8f5
#define rgb_gray_convert_internal  extbgrx_gray_convert_internal
shun-iwasawa 82a8f5
#define rgb_rgb_convert_internal  extbgrx_rgb_convert_internal
shun-iwasawa 82a8f5
#include "jccolext.c"
shun-iwasawa 82a8f5
#undef RGB_RED
shun-iwasawa 82a8f5
#undef RGB_GREEN
shun-iwasawa 82a8f5
#undef RGB_BLUE
shun-iwasawa 82a8f5
#undef RGB_PIXELSIZE
shun-iwasawa 82a8f5
#undef rgb_ycc_convert_internal
shun-iwasawa 82a8f5
#undef rgb_gray_convert_internal
shun-iwasawa 82a8f5
#undef rgb_rgb_convert_internal
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define RGB_RED  EXT_XBGR_RED
shun-iwasawa 82a8f5
#define RGB_GREEN  EXT_XBGR_GREEN
shun-iwasawa 82a8f5
#define RGB_BLUE  EXT_XBGR_BLUE
shun-iwasawa 82a8f5
#define RGB_PIXELSIZE  EXT_XBGR_PIXELSIZE
shun-iwasawa 82a8f5
#define rgb_ycc_convert_internal  extxbgr_ycc_convert_internal
shun-iwasawa 82a8f5
#define rgb_gray_convert_internal  extxbgr_gray_convert_internal
shun-iwasawa 82a8f5
#define rgb_rgb_convert_internal  extxbgr_rgb_convert_internal
shun-iwasawa 82a8f5
#include "jccolext.c"
shun-iwasawa 82a8f5
#undef RGB_RED
shun-iwasawa 82a8f5
#undef RGB_GREEN
shun-iwasawa 82a8f5
#undef RGB_BLUE
shun-iwasawa 82a8f5
#undef RGB_PIXELSIZE
shun-iwasawa 82a8f5
#undef rgb_ycc_convert_internal
shun-iwasawa 82a8f5
#undef rgb_gray_convert_internal
shun-iwasawa 82a8f5
#undef rgb_rgb_convert_internal
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define RGB_RED  EXT_XRGB_RED
shun-iwasawa 82a8f5
#define RGB_GREEN  EXT_XRGB_GREEN
shun-iwasawa 82a8f5
#define RGB_BLUE  EXT_XRGB_BLUE
shun-iwasawa 82a8f5
#define RGB_PIXELSIZE  EXT_XRGB_PIXELSIZE
shun-iwasawa 82a8f5
#define rgb_ycc_convert_internal  extxrgb_ycc_convert_internal
shun-iwasawa 82a8f5
#define rgb_gray_convert_internal  extxrgb_gray_convert_internal
shun-iwasawa 82a8f5
#define rgb_rgb_convert_internal  extxrgb_rgb_convert_internal
shun-iwasawa 82a8f5
#include "jccolext.c"
shun-iwasawa 82a8f5
#undef RGB_RED
shun-iwasawa 82a8f5
#undef RGB_GREEN
shun-iwasawa 82a8f5
#undef RGB_BLUE
shun-iwasawa 82a8f5
#undef RGB_PIXELSIZE
shun-iwasawa 82a8f5
#undef rgb_ycc_convert_internal
shun-iwasawa 82a8f5
#undef rgb_gray_convert_internal
shun-iwasawa 82a8f5
#undef rgb_rgb_convert_internal
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Initialize for RGB->YCC colorspace conversion.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
rgb_ycc_start(j_compress_ptr cinfo)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
shun-iwasawa 82a8f5
  JLONG *rgb_ycc_tab;
shun-iwasawa 82a8f5
  JLONG i;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Allocate and fill in the conversion tables. */
shun-iwasawa 82a8f5
  cconvert->rgb_ycc_tab = rgb_ycc_tab = (JLONG *)
shun-iwasawa 82a8f5
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
shun-iwasawa 82a8f5
                                (TABLE_SIZE * sizeof(JLONG)));
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  for (i = 0; i <= MAXJSAMPLE; i++) {
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + R_Y_OFF] = FIX(0.29900) * i;
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + G_Y_OFF] = FIX(0.58700) * i;
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + B_Y_OFF] = FIX(0.11400) * i   + ONE_HALF;
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + R_CB_OFF] = (-FIX(0.16874)) * i;
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + G_CB_OFF] = (-FIX(0.33126)) * i;
shun-iwasawa 82a8f5
    /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
shun-iwasawa 82a8f5
     * This ensures that the maximum output will round to MAXJSAMPLE
shun-iwasawa 82a8f5
     * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
shun-iwasawa 82a8f5
     */
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + B_CB_OFF] = FIX(0.50000) * i  + CBCR_OFFSET + ONE_HALF - 1;
shun-iwasawa 82a8f5
/*  B=>Cb and R=>Cr tables are the same
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + R_CR_OFF] = FIX(0.50000) * i  + CBCR_OFFSET + ONE_HALF - 1;
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + G_CR_OFF] = (-FIX(0.41869)) * i;
shun-iwasawa 82a8f5
    rgb_ycc_tab[i + B_CR_OFF] = (-FIX(0.08131)) * i;
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert some rows of samples to the JPEG colorspace.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
shun-iwasawa 82a8f5
                JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  switch (cinfo->in_color_space) {
shun-iwasawa 82a8f5
  case JCS_EXT_RGB:
shun-iwasawa 82a8f5
    extrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_RGBX:
shun-iwasawa 82a8f5
  case JCS_EXT_RGBA:
shun-iwasawa 82a8f5
    extrgbx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_BGR:
shun-iwasawa 82a8f5
    extbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_BGRX:
shun-iwasawa 82a8f5
  case JCS_EXT_BGRA:
shun-iwasawa 82a8f5
    extbgrx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_XBGR:
shun-iwasawa 82a8f5
  case JCS_EXT_ABGR:
shun-iwasawa 82a8f5
    extxbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_XRGB:
shun-iwasawa 82a8f5
  case JCS_EXT_ARGB:
shun-iwasawa 82a8f5
    extxrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  default:
shun-iwasawa 82a8f5
    rgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                             num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**************** Cases other than RGB -> YCbCr **************/
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert some rows of samples to the JPEG colorspace.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
shun-iwasawa 82a8f5
                 JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  switch (cinfo->in_color_space) {
shun-iwasawa 82a8f5
  case JCS_EXT_RGB:
shun-iwasawa 82a8f5
    extrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_RGBX:
shun-iwasawa 82a8f5
  case JCS_EXT_RGBA:
shun-iwasawa 82a8f5
    extrgbx_gray_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                  num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_BGR:
shun-iwasawa 82a8f5
    extbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_BGRX:
shun-iwasawa 82a8f5
  case JCS_EXT_BGRA:
shun-iwasawa 82a8f5
    extbgrx_gray_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                  num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_XBGR:
shun-iwasawa 82a8f5
  case JCS_EXT_ABGR:
shun-iwasawa 82a8f5
    extxbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                  num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_XRGB:
shun-iwasawa 82a8f5
  case JCS_EXT_ARGB:
shun-iwasawa 82a8f5
    extxrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                  num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  default:
shun-iwasawa 82a8f5
    rgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                              num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Extended RGB to plain RGB conversion
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
rgb_rgb_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
shun-iwasawa 82a8f5
                JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  switch (cinfo->in_color_space) {
shun-iwasawa 82a8f5
  case JCS_EXT_RGB:
shun-iwasawa 82a8f5
    extrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_RGBX:
shun-iwasawa 82a8f5
  case JCS_EXT_RGBA:
shun-iwasawa 82a8f5
    extrgbx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_BGR:
shun-iwasawa 82a8f5
    extbgr_rgb_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_BGRX:
shun-iwasawa 82a8f5
  case JCS_EXT_BGRA:
shun-iwasawa 82a8f5
    extbgrx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_XBGR:
shun-iwasawa 82a8f5
  case JCS_EXT_ABGR:
shun-iwasawa 82a8f5
    extxbgr_rgb_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  case JCS_EXT_XRGB:
shun-iwasawa 82a8f5
  case JCS_EXT_ARGB:
shun-iwasawa 82a8f5
    extxrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                                 num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  default:
shun-iwasawa 82a8f5
    rgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row,
shun-iwasawa 82a8f5
                             num_rows);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert some rows of samples to the JPEG colorspace.
shun-iwasawa 82a8f5
 * This version handles Adobe-style CMYK->YCCK conversion,
shun-iwasawa 82a8f5
 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
shun-iwasawa 82a8f5
 * conversion as above, while passing K (black) unchanged.
shun-iwasawa 82a8f5
 * We assume rgb_ycc_start has been called.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
shun-iwasawa 82a8f5
                  JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
shun-iwasawa 82a8f5
  register int r, g, b;
shun-iwasawa 82a8f5
  register JLONG *ctab = cconvert->rgb_ycc_tab;
shun-iwasawa 82a8f5
  register JSAMPROW inptr;
shun-iwasawa 82a8f5
  register JSAMPROW outptr0, outptr1, outptr2, outptr3;
shun-iwasawa 82a8f5
  register JDIMENSION col;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->image_width;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    inptr = *input_buf++;
shun-iwasawa 82a8f5
    outptr0 = output_buf[0][output_row];
shun-iwasawa 82a8f5
    outptr1 = output_buf[1][output_row];
shun-iwasawa 82a8f5
    outptr2 = output_buf[2][output_row];
shun-iwasawa 82a8f5
    outptr3 = output_buf[3][output_row];
shun-iwasawa 82a8f5
    output_row++;
shun-iwasawa 82a8f5
    for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
      r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
shun-iwasawa 82a8f5
      g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
shun-iwasawa 82a8f5
      b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
shun-iwasawa 82a8f5
      /* K passes through as-is */
shun-iwasawa 82a8f5
      outptr3[col] = inptr[3];  /* don't need GETJSAMPLE here */
shun-iwasawa 82a8f5
      inptr += 4;
shun-iwasawa 82a8f5
      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
shun-iwasawa 82a8f5
       * must be too; we do not need an explicit range-limiting operation.
shun-iwasawa 82a8f5
       * Hence the value being shifted is never negative, and we don't
shun-iwasawa 82a8f5
       * need the general RIGHT_SHIFT macro.
shun-iwasawa 82a8f5
       */
shun-iwasawa 82a8f5
      /* Y */
shun-iwasawa 82a8f5
      outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
shun-iwasawa 82a8f5
                                ctab[b + B_Y_OFF]) >> SCALEBITS);
shun-iwasawa 82a8f5
      /* Cb */
shun-iwasawa 82a8f5
      outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
shun-iwasawa 82a8f5
                                ctab[b + B_CB_OFF]) >> SCALEBITS);
shun-iwasawa 82a8f5
      /* Cr */
shun-iwasawa 82a8f5
      outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
shun-iwasawa 82a8f5
                                ctab[b + B_CR_OFF]) >> SCALEBITS);
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert some rows of samples to the JPEG colorspace.
shun-iwasawa 82a8f5
 * This version handles grayscale output with no conversion.
shun-iwasawa 82a8f5
 * The source can be either plain grayscale or YCbCr (since Y == gray).
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
shun-iwasawa 82a8f5
                  JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  register JSAMPROW inptr;
shun-iwasawa 82a8f5
  register JSAMPROW outptr;
shun-iwasawa 82a8f5
  register JDIMENSION col;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->image_width;
shun-iwasawa 82a8f5
  int instride = cinfo->input_components;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    inptr = *input_buf++;
shun-iwasawa 82a8f5
    outptr = output_buf[0][output_row];
shun-iwasawa 82a8f5
    output_row++;
shun-iwasawa 82a8f5
    for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
      outptr[col] = inptr[0];   /* don't need GETJSAMPLE() here */
shun-iwasawa 82a8f5
      inptr += instride;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Convert some rows of samples to the JPEG colorspace.
shun-iwasawa 82a8f5
 * This version handles multi-component colorspaces without conversion.
shun-iwasawa 82a8f5
 * We assume input_components == num_components.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
shun-iwasawa 82a8f5
             JDIMENSION output_row, int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  register JSAMPROW inptr;
shun-iwasawa 82a8f5
  register JSAMPROW outptr, outptr0, outptr1, outptr2, outptr3;
shun-iwasawa 82a8f5
  register JDIMENSION col;
shun-iwasawa 82a8f5
  register int ci;
shun-iwasawa 82a8f5
  int nc = cinfo->num_components;
shun-iwasawa 82a8f5
  JDIMENSION num_cols = cinfo->image_width;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  if (nc == 3) {
shun-iwasawa 82a8f5
    while (--num_rows >= 0) {
shun-iwasawa 82a8f5
      inptr = *input_buf++;
shun-iwasawa 82a8f5
      outptr0 = output_buf[0][output_row];
shun-iwasawa 82a8f5
      outptr1 = output_buf[1][output_row];
shun-iwasawa 82a8f5
      outptr2 = output_buf[2][output_row];
shun-iwasawa 82a8f5
      output_row++;
shun-iwasawa 82a8f5
      for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
        outptr0[col] = *inptr++;
shun-iwasawa 82a8f5
        outptr1[col] = *inptr++;
shun-iwasawa 82a8f5
        outptr2[col] = *inptr++;
shun-iwasawa 82a8f5
      }
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  } else if (nc == 4) {
shun-iwasawa 82a8f5
    while (--num_rows >= 0) {
shun-iwasawa 82a8f5
      inptr = *input_buf++;
shun-iwasawa 82a8f5
      outptr0 = output_buf[0][output_row];
shun-iwasawa 82a8f5
      outptr1 = output_buf[1][output_row];
shun-iwasawa 82a8f5
      outptr2 = output_buf[2][output_row];
shun-iwasawa 82a8f5
      outptr3 = output_buf[3][output_row];
shun-iwasawa 82a8f5
      output_row++;
shun-iwasawa 82a8f5
      for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
        outptr0[col] = *inptr++;
shun-iwasawa 82a8f5
        outptr1[col] = *inptr++;
shun-iwasawa 82a8f5
        outptr2[col] = *inptr++;
shun-iwasawa 82a8f5
        outptr3[col] = *inptr++;
shun-iwasawa 82a8f5
      }
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  } else {
shun-iwasawa 82a8f5
    while (--num_rows >= 0) {
shun-iwasawa 82a8f5
      /* It seems fastest to make a separate pass for each component. */
shun-iwasawa 82a8f5
      for (ci = 0; ci < nc; ci++) {
shun-iwasawa 82a8f5
        inptr = *input_buf;
shun-iwasawa 82a8f5
        outptr = output_buf[ci][output_row];
shun-iwasawa 82a8f5
        for (col = 0; col < num_cols; col++) {
shun-iwasawa 82a8f5
          outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
shun-iwasawa 82a8f5
          inptr += nc;
shun-iwasawa 82a8f5
        }
shun-iwasawa 82a8f5
      }
shun-iwasawa 82a8f5
      input_buf++;
shun-iwasawa 82a8f5
      output_row++;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Empty method for start_pass.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
METHODDEF(void)
shun-iwasawa 82a8f5
null_method(j_compress_ptr cinfo)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  /* no work needed */
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Module initialization routine for input colorspace conversion.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
GLOBAL(void)
shun-iwasawa 82a8f5
jinit_color_converter(j_compress_ptr cinfo)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  my_cconvert_ptr cconvert;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  cconvert = (my_cconvert_ptr)
shun-iwasawa 82a8f5
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
shun-iwasawa 82a8f5
                                sizeof(my_color_converter));
shun-iwasawa 82a8f5
  cinfo->cconvert = (struct jpeg_color_converter *)cconvert;
shun-iwasawa 82a8f5
  /* set start_pass to null method until we find out differently */
shun-iwasawa 82a8f5
  cconvert->pub.start_pass = null_method;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Make sure input_components agrees with in_color_space */
shun-iwasawa 82a8f5
  switch (cinfo->in_color_space) {
shun-iwasawa 82a8f5
  case JCS_GRAYSCALE:
shun-iwasawa 82a8f5
    if (cinfo->input_components != 1)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  case JCS_RGB:
shun-iwasawa 82a8f5
  case JCS_EXT_RGB:
shun-iwasawa 82a8f5
  case JCS_EXT_RGBX:
shun-iwasawa 82a8f5
  case JCS_EXT_BGR:
shun-iwasawa 82a8f5
  case JCS_EXT_BGRX:
shun-iwasawa 82a8f5
  case JCS_EXT_XBGR:
shun-iwasawa 82a8f5
  case JCS_EXT_XRGB:
shun-iwasawa 82a8f5
  case JCS_EXT_RGBA:
shun-iwasawa 82a8f5
  case JCS_EXT_BGRA:
shun-iwasawa 82a8f5
  case JCS_EXT_ABGR:
shun-iwasawa 82a8f5
  case JCS_EXT_ARGB:
shun-iwasawa 82a8f5
    if (cinfo->input_components != rgb_pixelsize[cinfo->in_color_space])
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  case JCS_YCbCr:
shun-iwasawa 82a8f5
    if (cinfo->input_components != 3)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  case JCS_CMYK:
shun-iwasawa 82a8f5
  case JCS_YCCK:
shun-iwasawa 82a8f5
    if (cinfo->input_components != 4)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  default:                      /* JCS_UNKNOWN can be anything */
shun-iwasawa 82a8f5
    if (cinfo->input_components < 1)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Check num_components, set conversion method based on requested space */
shun-iwasawa 82a8f5
  switch (cinfo->jpeg_color_space) {
shun-iwasawa 82a8f5
  case JCS_GRAYSCALE:
shun-iwasawa 82a8f5
    if (cinfo->num_components != 1)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
shun-iwasawa 82a8f5
    if (cinfo->in_color_space == JCS_GRAYSCALE)
shun-iwasawa 82a8f5
      cconvert->pub.color_convert = grayscale_convert;
shun-iwasawa 82a8f5
    else if (cinfo->in_color_space == JCS_RGB ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_RGB ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_RGBX ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_BGR ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_BGRX ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_XBGR ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_XRGB ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_RGBA ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_BGRA ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_ABGR ||
shun-iwasawa 82a8f5
             cinfo->in_color_space == JCS_EXT_ARGB) {
shun-iwasawa 82a8f5
      if (jsimd_can_rgb_gray())
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = jsimd_rgb_gray_convert;
shun-iwasawa 82a8f5
      else {
shun-iwasawa 82a8f5
        cconvert->pub.start_pass = rgb_ycc_start;
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = rgb_gray_convert;
shun-iwasawa 82a8f5
      }
shun-iwasawa 82a8f5
    } else if (cinfo->in_color_space == JCS_YCbCr)
shun-iwasawa 82a8f5
      cconvert->pub.color_convert = grayscale_convert;
shun-iwasawa 82a8f5
    else
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  case JCS_RGB:
shun-iwasawa 82a8f5
    if (cinfo->num_components != 3)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
shun-iwasawa 82a8f5
    if (rgb_red[cinfo->in_color_space] == 0 &&
shun-iwasawa 82a8f5
        rgb_green[cinfo->in_color_space] == 1 &&
shun-iwasawa 82a8f5
        rgb_blue[cinfo->in_color_space] == 2 &&
shun-iwasawa 82a8f5
        rgb_pixelsize[cinfo->in_color_space] == 3) {
shun-iwasawa 82a8f5
#if defined(__mips__)
shun-iwasawa 82a8f5
      if (jsimd_c_can_null_convert())
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = jsimd_c_null_convert;
shun-iwasawa 82a8f5
      else
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = null_convert;
shun-iwasawa 82a8f5
    } else if (cinfo->in_color_space == JCS_RGB ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_RGB ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_RGBX ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_BGR ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_BGRX ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_XBGR ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_XRGB ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_RGBA ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_BGRA ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_ABGR ||
shun-iwasawa 82a8f5
               cinfo->in_color_space == JCS_EXT_ARGB)
shun-iwasawa 82a8f5
      cconvert->pub.color_convert = rgb_rgb_convert;
shun-iwasawa 82a8f5
    else
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  case JCS_YCbCr:
shun-iwasawa 82a8f5
    if (cinfo->num_components != 3)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
shun-iwasawa 82a8f5
    if (cinfo->in_color_space == JCS_RGB ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_RGB ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_RGBX ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_BGR ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_BGRX ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_XBGR ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_XRGB ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_RGBA ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_BGRA ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_ABGR ||
shun-iwasawa 82a8f5
        cinfo->in_color_space == JCS_EXT_ARGB) {
shun-iwasawa 82a8f5
      if (jsimd_can_rgb_ycc())
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = jsimd_rgb_ycc_convert;
shun-iwasawa 82a8f5
      else {
shun-iwasawa 82a8f5
        cconvert->pub.start_pass = rgb_ycc_start;
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = rgb_ycc_convert;
shun-iwasawa 82a8f5
      }
shun-iwasawa 82a8f5
    } else if (cinfo->in_color_space == JCS_YCbCr) {
shun-iwasawa 82a8f5
#if defined(__mips__)
shun-iwasawa 82a8f5
      if (jsimd_c_can_null_convert())
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = jsimd_c_null_convert;
shun-iwasawa 82a8f5
      else
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = null_convert;
shun-iwasawa 82a8f5
    } else
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  case JCS_CMYK:
shun-iwasawa 82a8f5
    if (cinfo->num_components != 4)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
shun-iwasawa 82a8f5
    if (cinfo->in_color_space == JCS_CMYK) {
shun-iwasawa 82a8f5
#if defined(__mips__)
shun-iwasawa 82a8f5
      if (jsimd_c_can_null_convert())
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = jsimd_c_null_convert;
shun-iwasawa 82a8f5
      else
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = null_convert;
shun-iwasawa 82a8f5
    } else
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  case JCS_YCCK:
shun-iwasawa 82a8f5
    if (cinfo->num_components != 4)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
shun-iwasawa 82a8f5
    if (cinfo->in_color_space == JCS_CMYK) {
shun-iwasawa 82a8f5
      cconvert->pub.start_pass = rgb_ycc_start;
shun-iwasawa 82a8f5
      cconvert->pub.color_convert = cmyk_ycck_convert;
shun-iwasawa 82a8f5
    } else if (cinfo->in_color_space == JCS_YCCK) {
shun-iwasawa 82a8f5
#if defined(__mips__)
shun-iwasawa 82a8f5
      if (jsimd_c_can_null_convert())
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = jsimd_c_null_convert;
shun-iwasawa 82a8f5
      else
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
        cconvert->pub.color_convert = null_convert;
shun-iwasawa 82a8f5
    } else
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  default:                      /* allow null conversion of JCS_UNKNOWN */
shun-iwasawa 82a8f5
    if (cinfo->jpeg_color_space != cinfo->in_color_space ||
shun-iwasawa 82a8f5
        cinfo->num_components != cinfo->input_components)
shun-iwasawa 82a8f5
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
shun-iwasawa 82a8f5
#if defined(__mips__)
shun-iwasawa 82a8f5
    if (jsimd_c_can_null_convert())
shun-iwasawa 82a8f5
      cconvert->pub.color_convert = jsimd_c_null_convert;
shun-iwasawa 82a8f5
    else
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
      cconvert->pub.color_convert = null_convert;
shun-iwasawa 82a8f5
    break;
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}