Blame gtkmm-osx/jpeg-6b/jccolor.c

darco 56a656
/*
darco 56a656
 * jccolor.c
darco 56a656
 *
darco 56a656
 * Copyright (C) 1991-1996, Thomas G. Lane.
darco 56a656
 * This file is part of the Independent JPEG Group's software.
darco 56a656
 * For conditions of distribution and use, see the accompanying README file.
darco 56a656
 *
darco 56a656
 * This file contains input colorspace conversion routines.
darco 56a656
 */
darco 56a656
darco 56a656
#define JPEG_INTERNALS
darco 56a656
#include "jinclude.h"
darco 56a656
#include "jpeglib.h"
darco 56a656
darco 56a656
darco 56a656
/* Private subobject */
darco 56a656
darco 56a656
typedef struct {
darco 56a656
  struct jpeg_color_converter pub; /* public fields */
darco 56a656
darco 56a656
  /* Private state for RGB->YCC conversion */
darco 56a656
  INT32 * rgb_ycc_tab;		/* => table for RGB to YCbCr conversion */
darco 56a656
} my_color_converter;
darco 56a656
darco 56a656
typedef my_color_converter * my_cconvert_ptr;
darco 56a656
darco 56a656
darco 56a656
/**************** RGB -> YCbCr conversion: most common case **************/
darco 56a656
darco 56a656
/*
darco 56a656
 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
darco 56a656
 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
darco 56a656
 * The conversion equations to be implemented are therefore
darco 56a656
 *	Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
darco 56a656
 *	Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B  + CENTERJSAMPLE
darco 56a656
 *	Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B  + CENTERJSAMPLE
darco 56a656
 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
darco 56a656
 * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
darco 56a656
 * rather than CENTERJSAMPLE, for Cb and Cr.  This gave equal positive and
darco 56a656
 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
darco 56a656
 * were not represented exactly.  Now we sacrifice exact representation of
darco 56a656
 * maximum red and maximum blue in order to get exact grayscales.
darco 56a656
 *
darco 56a656
 * To avoid floating-point arithmetic, we represent the fractional constants
darco 56a656
 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
darco 56a656
 * the products by 2^16, with appropriate rounding, to get the correct answer.
darco 56a656
 *
darco 56a656
 * For even more speed, we avoid doing any multiplications in the inner loop
darco 56a656
 * by precalculating the constants times R,G,B for all possible values.
darco 56a656
 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
darco 56a656
 * for 12-bit samples it is still acceptable.  It's not very reasonable for
darco 56a656
 * 16-bit samples, but if you want lossless storage you shouldn't be changing
darco 56a656
 * colorspace anyway.
darco 56a656
 * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
darco 56a656
 * in the tables to save adding them separately in the inner loop.
darco 56a656
 */
darco 56a656
darco 56a656
#define SCALEBITS	16	/* speediest right-shift on some machines */
darco 56a656
#define CBCR_OFFSET	((INT32) CENTERJSAMPLE << SCALEBITS)
darco 56a656
#define ONE_HALF	((INT32) 1 << (SCALEBITS-1))
darco 56a656
#define FIX(x)		((INT32) ((x) * (1L<
darco 56a656
darco 56a656
/* We allocate one big table and divide it up into eight parts, instead of
darco 56a656
 * doing eight alloc_small requests.  This lets us use a single table base
darco 56a656
 * address, which can be held in a register in the inner loops on many
darco 56a656
 * machines (more than can hold all eight addresses, anyway).
darco 56a656
 */
darco 56a656
darco 56a656
#define R_Y_OFF		0			/* offset to R => Y section */
darco 56a656
#define G_Y_OFF		(1*(MAXJSAMPLE+1))	/* offset to G => Y section */
darco 56a656
#define B_Y_OFF		(2*(MAXJSAMPLE+1))	/* etc. */
darco 56a656
#define R_CB_OFF	(3*(MAXJSAMPLE+1))
darco 56a656
#define G_CB_OFF	(4*(MAXJSAMPLE+1))
darco 56a656
#define B_CB_OFF	(5*(MAXJSAMPLE+1))
darco 56a656
#define R_CR_OFF	B_CB_OFF		/* B=>Cb, R=>Cr are the same */
darco 56a656
#define G_CR_OFF	(6*(MAXJSAMPLE+1))
darco 56a656
#define B_CR_OFF	(7*(MAXJSAMPLE+1))
darco 56a656
#define TABLE_SIZE	(8*(MAXJSAMPLE+1))
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Initialize for RGB->YCC colorspace conversion.
darco 56a656
 */
darco 56a656
darco 56a656
METHODDEF(void)
darco 56a656
rgb_ycc_start (j_compress_ptr cinfo)
darco 56a656
{
darco 56a656
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
darco 56a656
  INT32 * rgb_ycc_tab;
darco 56a656
  INT32 i;
darco 56a656
darco 56a656
  /* Allocate and fill in the conversion tables. */
darco 56a656
  cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
darco 56a656
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
darco 56a656
				(TABLE_SIZE * SIZEOF(INT32)));
darco 56a656
darco 56a656
  for (i = 0; i <= MAXJSAMPLE; i++) {
darco 56a656
    rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
darco 56a656
    rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
darco 56a656
    rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i     + ONE_HALF;
darco 56a656
    rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
darco 56a656
    rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
darco 56a656
    /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
darco 56a656
     * This ensures that the maximum output will round to MAXJSAMPLE
darco 56a656
     * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
darco 56a656
     */
darco 56a656
    rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
darco 56a656
/*  B=>Cb and R=>Cr tables are the same
darco 56a656
    rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
darco 56a656
*/
darco 56a656
    rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
darco 56a656
    rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
darco 56a656
  }
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Convert some rows of samples to the JPEG colorspace.
darco 56a656
 *
darco 56a656
 * Note that we change from the application's interleaved-pixel format
darco 56a656
 * to our internal noninterleaved, one-plane-per-component format.
darco 56a656
 * The input buffer is therefore three times as wide as the output buffer.
darco 56a656
 *
darco 56a656
 * A starting row offset is provided only for the output buffer.  The caller
darco 56a656
 * can easily adjust the passed input_buf value to accommodate any row
darco 56a656
 * offset required on that side.
darco 56a656
 */
darco 56a656
darco 56a656
METHODDEF(void)
darco 56a656
rgb_ycc_convert (j_compress_ptr cinfo,
darco 56a656
		 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
darco 56a656
		 JDIMENSION output_row, int num_rows)
darco 56a656
{
darco 56a656
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
darco 56a656
  register int r, g, b;
darco 56a656
  register INT32 * ctab = cconvert->rgb_ycc_tab;
darco 56a656
  register JSAMPROW inptr;
darco 56a656
  register JSAMPROW outptr0, outptr1, outptr2;
darco 56a656
  register JDIMENSION col;
darco 56a656
  JDIMENSION num_cols = cinfo->image_width;
darco 56a656
darco 56a656
  while (--num_rows >= 0) {
darco 56a656
    inptr = *input_buf++;
darco 56a656
    outptr0 = output_buf[0][output_row];
darco 56a656
    outptr1 = output_buf[1][output_row];
darco 56a656
    outptr2 = output_buf[2][output_row];
darco 56a656
    output_row++;
darco 56a656
    for (col = 0; col < num_cols; col++) {
darco 56a656
      r = GETJSAMPLE(inptr[RGB_RED]);
darco 56a656
      g = GETJSAMPLE(inptr[RGB_GREEN]);
darco 56a656
      b = GETJSAMPLE(inptr[RGB_BLUE]);
darco 56a656
      inptr += RGB_PIXELSIZE;
darco 56a656
      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
darco 56a656
       * must be too; we do not need an explicit range-limiting operation.
darco 56a656
       * Hence the value being shifted is never negative, and we don't
darco 56a656
       * need the general RIGHT_SHIFT macro.
darco 56a656
       */
darco 56a656
      /* Y */
darco 56a656
      outptr0[col] = (JSAMPLE)
darco 56a656
		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
darco 56a656
		 >> SCALEBITS);
darco 56a656
      /* Cb */
darco 56a656
      outptr1[col] = (JSAMPLE)
darco 56a656
		((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
darco 56a656
		 >> SCALEBITS);
darco 56a656
      /* Cr */
darco 56a656
      outptr2[col] = (JSAMPLE)
darco 56a656
		((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
darco 56a656
		 >> SCALEBITS);
darco 56a656
    }
darco 56a656
  }
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/**************** Cases other than RGB -> YCbCr **************/
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Convert some rows of samples to the JPEG colorspace.
darco 56a656
 * This version handles RGB->grayscale conversion, which is the same
darco 56a656
 * as the RGB->Y portion of RGB->YCbCr.
darco 56a656
 * We assume rgb_ycc_start has been called (we only use the Y tables).
darco 56a656
 */
darco 56a656
darco 56a656
METHODDEF(void)
darco 56a656
rgb_gray_convert (j_compress_ptr cinfo,
darco 56a656
		  JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
darco 56a656
		  JDIMENSION output_row, int num_rows)
darco 56a656
{
darco 56a656
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
darco 56a656
  register int r, g, b;
darco 56a656
  register INT32 * ctab = cconvert->rgb_ycc_tab;
darco 56a656
  register JSAMPROW inptr;
darco 56a656
  register JSAMPROW outptr;
darco 56a656
  register JDIMENSION col;
darco 56a656
  JDIMENSION num_cols = cinfo->image_width;
darco 56a656
darco 56a656
  while (--num_rows >= 0) {
darco 56a656
    inptr = *input_buf++;
darco 56a656
    outptr = output_buf[0][output_row];
darco 56a656
    output_row++;
darco 56a656
    for (col = 0; col < num_cols; col++) {
darco 56a656
      r = GETJSAMPLE(inptr[RGB_RED]);
darco 56a656
      g = GETJSAMPLE(inptr[RGB_GREEN]);
darco 56a656
      b = GETJSAMPLE(inptr[RGB_BLUE]);
darco 56a656
      inptr += RGB_PIXELSIZE;
darco 56a656
      /* Y */
darco 56a656
      outptr[col] = (JSAMPLE)
darco 56a656
		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
darco 56a656
		 >> SCALEBITS);
darco 56a656
    }
darco 56a656
  }
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Convert some rows of samples to the JPEG colorspace.
darco 56a656
 * This version handles Adobe-style CMYK->YCCK conversion,
darco 56a656
 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
darco 56a656
 * conversion as above, while passing K (black) unchanged.
darco 56a656
 * We assume rgb_ycc_start has been called.
darco 56a656
 */
darco 56a656
darco 56a656
METHODDEF(void)
darco 56a656
cmyk_ycck_convert (j_compress_ptr cinfo,
darco 56a656
		   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
darco 56a656
		   JDIMENSION output_row, int num_rows)
darco 56a656
{
darco 56a656
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
darco 56a656
  register int r, g, b;
darco 56a656
  register INT32 * ctab = cconvert->rgb_ycc_tab;
darco 56a656
  register JSAMPROW inptr;
darco 56a656
  register JSAMPROW outptr0, outptr1, outptr2, outptr3;
darco 56a656
  register JDIMENSION col;
darco 56a656
  JDIMENSION num_cols = cinfo->image_width;
darco 56a656
darco 56a656
  while (--num_rows >= 0) {
darco 56a656
    inptr = *input_buf++;
darco 56a656
    outptr0 = output_buf[0][output_row];
darco 56a656
    outptr1 = output_buf[1][output_row];
darco 56a656
    outptr2 = output_buf[2][output_row];
darco 56a656
    outptr3 = output_buf[3][output_row];
darco 56a656
    output_row++;
darco 56a656
    for (col = 0; col < num_cols; col++) {
darco 56a656
      r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
darco 56a656
      g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
darco 56a656
      b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
darco 56a656
      /* K passes through as-is */
darco 56a656
      outptr3[col] = inptr[3];	/* don't need GETJSAMPLE here */
darco 56a656
      inptr += 4;
darco 56a656
      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
darco 56a656
       * must be too; we do not need an explicit range-limiting operation.
darco 56a656
       * Hence the value being shifted is never negative, and we don't
darco 56a656
       * need the general RIGHT_SHIFT macro.
darco 56a656
       */
darco 56a656
      /* Y */
darco 56a656
      outptr0[col] = (JSAMPLE)
darco 56a656
		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
darco 56a656
		 >> SCALEBITS);
darco 56a656
      /* Cb */
darco 56a656
      outptr1[col] = (JSAMPLE)
darco 56a656
		((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
darco 56a656
		 >> SCALEBITS);
darco 56a656
      /* Cr */
darco 56a656
      outptr2[col] = (JSAMPLE)
darco 56a656
		((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
darco 56a656
		 >> SCALEBITS);
darco 56a656
    }
darco 56a656
  }
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Convert some rows of samples to the JPEG colorspace.
darco 56a656
 * This version handles grayscale output with no conversion.
darco 56a656
 * The source can be either plain grayscale or YCbCr (since Y == gray).
darco 56a656
 */
darco 56a656
darco 56a656
METHODDEF(void)
darco 56a656
grayscale_convert (j_compress_ptr cinfo,
darco 56a656
		   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
darco 56a656
		   JDIMENSION output_row, int num_rows)
darco 56a656
{
darco 56a656
  register JSAMPROW inptr;
darco 56a656
  register JSAMPROW outptr;
darco 56a656
  register JDIMENSION col;
darco 56a656
  JDIMENSION num_cols = cinfo->image_width;
darco 56a656
  int instride = cinfo->input_components;
darco 56a656
darco 56a656
  while (--num_rows >= 0) {
darco 56a656
    inptr = *input_buf++;
darco 56a656
    outptr = output_buf[0][output_row];
darco 56a656
    output_row++;
darco 56a656
    for (col = 0; col < num_cols; col++) {
darco 56a656
      outptr[col] = inptr[0];	/* don't need GETJSAMPLE() here */
darco 56a656
      inptr += instride;
darco 56a656
    }
darco 56a656
  }
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Convert some rows of samples to the JPEG colorspace.
darco 56a656
 * This version handles multi-component colorspaces without conversion.
darco 56a656
 * We assume input_components == num_components.
darco 56a656
 */
darco 56a656
darco 56a656
METHODDEF(void)
darco 56a656
null_convert (j_compress_ptr cinfo,
darco 56a656
	      JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
darco 56a656
	      JDIMENSION output_row, int num_rows)
darco 56a656
{
darco 56a656
  register JSAMPROW inptr;
darco 56a656
  register JSAMPROW outptr;
darco 56a656
  register JDIMENSION col;
darco 56a656
  register int ci;
darco 56a656
  int nc = cinfo->num_components;
darco 56a656
  JDIMENSION num_cols = cinfo->image_width;
darco 56a656
darco 56a656
  while (--num_rows >= 0) {
darco 56a656
    /* It seems fastest to make a separate pass for each component. */
darco 56a656
    for (ci = 0; ci < nc; ci++) {
darco 56a656
      inptr = *input_buf;
darco 56a656
      outptr = output_buf[ci][output_row];
darco 56a656
      for (col = 0; col < num_cols; col++) {
darco 56a656
	outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
darco 56a656
	inptr += nc;
darco 56a656
      }
darco 56a656
    }
darco 56a656
    input_buf++;
darco 56a656
    output_row++;
darco 56a656
  }
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Empty method for start_pass.
darco 56a656
 */
darco 56a656
darco 56a656
METHODDEF(void)
darco 56a656
null_method (j_compress_ptr cinfo)
darco 56a656
{
darco 56a656
  /* no work needed */
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Module initialization routine for input colorspace conversion.
darco 56a656
 */
darco 56a656
darco 56a656
GLOBAL(void)
darco 56a656
jinit_color_converter (j_compress_ptr cinfo)
darco 56a656
{
darco 56a656
  my_cconvert_ptr cconvert;
darco 56a656
darco 56a656
  cconvert = (my_cconvert_ptr)
darco 56a656
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
darco 56a656
				SIZEOF(my_color_converter));
darco 56a656
  cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
darco 56a656
  /* set start_pass to null method until we find out differently */
darco 56a656
  cconvert->pub.start_pass = null_method;
darco 56a656
darco 56a656
  /* Make sure input_components agrees with in_color_space */
darco 56a656
  switch (cinfo->in_color_space) {
darco 56a656
  case JCS_GRAYSCALE:
darco 56a656
    if (cinfo->input_components != 1)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
darco 56a656
    break;
darco 56a656
darco 56a656
  case JCS_RGB:
darco 56a656
#if RGB_PIXELSIZE != 3
darco 56a656
    if (cinfo->input_components != RGB_PIXELSIZE)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
darco 56a656
    break;
darco 56a656
#endif /* else share code with YCbCr */
darco 56a656
darco 56a656
  case JCS_YCbCr:
darco 56a656
    if (cinfo->input_components != 3)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
darco 56a656
    break;
darco 56a656
darco 56a656
  case JCS_CMYK:
darco 56a656
  case JCS_YCCK:
darco 56a656
    if (cinfo->input_components != 4)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
darco 56a656
    break;
darco 56a656
darco 56a656
  default:			/* JCS_UNKNOWN can be anything */
darco 56a656
    if (cinfo->input_components < 1)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
darco 56a656
    break;
darco 56a656
  }
darco 56a656
darco 56a656
  /* Check num_components, set conversion method based on requested space */
darco 56a656
  switch (cinfo->jpeg_color_space) {
darco 56a656
  case JCS_GRAYSCALE:
darco 56a656
    if (cinfo->num_components != 1)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
darco 56a656
    if (cinfo->in_color_space == JCS_GRAYSCALE)
darco 56a656
      cconvert->pub.color_convert = grayscale_convert;
darco 56a656
    else if (cinfo->in_color_space == JCS_RGB) {
darco 56a656
      cconvert->pub.start_pass = rgb_ycc_start;
darco 56a656
      cconvert->pub.color_convert = rgb_gray_convert;
darco 56a656
    } else if (cinfo->in_color_space == JCS_YCbCr)
darco 56a656
      cconvert->pub.color_convert = grayscale_convert;
darco 56a656
    else
darco 56a656
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
darco 56a656
    break;
darco 56a656
darco 56a656
  case JCS_RGB:
darco 56a656
    if (cinfo->num_components != 3)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
darco 56a656
    if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
darco 56a656
      cconvert->pub.color_convert = null_convert;
darco 56a656
    else
darco 56a656
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
darco 56a656
    break;
darco 56a656
darco 56a656
  case JCS_YCbCr:
darco 56a656
    if (cinfo->num_components != 3)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
darco 56a656
    if (cinfo->in_color_space == JCS_RGB) {
darco 56a656
      cconvert->pub.start_pass = rgb_ycc_start;
darco 56a656
      cconvert->pub.color_convert = rgb_ycc_convert;
darco 56a656
    } else if (cinfo->in_color_space == JCS_YCbCr)
darco 56a656
      cconvert->pub.color_convert = null_convert;
darco 56a656
    else
darco 56a656
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
darco 56a656
    break;
darco 56a656
darco 56a656
  case JCS_CMYK:
darco 56a656
    if (cinfo->num_components != 4)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
darco 56a656
    if (cinfo->in_color_space == JCS_CMYK)
darco 56a656
      cconvert->pub.color_convert = null_convert;
darco 56a656
    else
darco 56a656
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
darco 56a656
    break;
darco 56a656
darco 56a656
  case JCS_YCCK:
darco 56a656
    if (cinfo->num_components != 4)
darco 56a656
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
darco 56a656
    if (cinfo->in_color_space == JCS_CMYK) {
darco 56a656
      cconvert->pub.start_pass = rgb_ycc_start;
darco 56a656
      cconvert->pub.color_convert = cmyk_ycck_convert;
darco 56a656
    } else if (cinfo->in_color_space == JCS_YCCK)
darco 56a656
      cconvert->pub.color_convert = null_convert;
darco 56a656
    else
darco 56a656
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
darco 56a656
    break;
darco 56a656
darco 56a656
  default:			/* allow null conversion of JCS_UNKNOWN */
darco 56a656
    if (cinfo->jpeg_color_space != cinfo->in_color_space ||
darco 56a656
	cinfo->num_components != cinfo->input_components)
darco 56a656
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
darco 56a656
    cconvert->pub.color_convert = null_convert;
darco 56a656
    break;
darco 56a656
  }
darco 56a656
}