dbf-halloween2015

annotate libs/libjpeg/jccolor.c @ 1:c3f5c32cb210

barfed all the libraries in the source tree to make porting easier
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 00:36:56 +0200
parents
children
rev   line source
nuclear@1 1 /*
nuclear@1 2 * jccolor.c
nuclear@1 3 *
nuclear@1 4 * Copyright (C) 1991-1996, Thomas G. Lane.
nuclear@1 5 * This file is part of the Independent JPEG Group's software.
nuclear@1 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@1 7 *
nuclear@1 8 * This file contains input colorspace conversion routines.
nuclear@1 9 */
nuclear@1 10
nuclear@1 11 #define JPEG_INTERNALS
nuclear@1 12 #include "jinclude.h"
nuclear@1 13 #include "jpeglib.h"
nuclear@1 14
nuclear@1 15
nuclear@1 16 /* Private subobject */
nuclear@1 17
nuclear@1 18 typedef struct {
nuclear@1 19 struct jpeg_color_converter pub; /* public fields */
nuclear@1 20
nuclear@1 21 /* Private state for RGB->YCC conversion */
nuclear@1 22 INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
nuclear@1 23 } my_color_converter;
nuclear@1 24
nuclear@1 25 typedef my_color_converter * my_cconvert_ptr;
nuclear@1 26
nuclear@1 27
nuclear@1 28 /**************** RGB -> YCbCr conversion: most common case **************/
nuclear@1 29
nuclear@1 30 /*
nuclear@1 31 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
nuclear@1 32 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
nuclear@1 33 * The conversion equations to be implemented are therefore
nuclear@1 34 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
nuclear@1 35 * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
nuclear@1 36 * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
nuclear@1 37 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
nuclear@1 38 * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
nuclear@1 39 * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
nuclear@1 40 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
nuclear@1 41 * were not represented exactly. Now we sacrifice exact representation of
nuclear@1 42 * maximum red and maximum blue in order to get exact grayscales.
nuclear@1 43 *
nuclear@1 44 * To avoid floating-point arithmetic, we represent the fractional constants
nuclear@1 45 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
nuclear@1 46 * the products by 2^16, with appropriate rounding, to get the correct answer.
nuclear@1 47 *
nuclear@1 48 * For even more speed, we avoid doing any multiplications in the inner loop
nuclear@1 49 * by precalculating the constants times R,G,B for all possible values.
nuclear@1 50 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
nuclear@1 51 * for 12-bit samples it is still acceptable. It's not very reasonable for
nuclear@1 52 * 16-bit samples, but if you want lossless storage you shouldn't be changing
nuclear@1 53 * colorspace anyway.
nuclear@1 54 * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
nuclear@1 55 * in the tables to save adding them separately in the inner loop.
nuclear@1 56 */
nuclear@1 57
nuclear@1 58 #define SCALEBITS 16 /* speediest right-shift on some machines */
nuclear@1 59 #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
nuclear@1 60 #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
nuclear@1 61 #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
nuclear@1 62
nuclear@1 63 /* We allocate one big table and divide it up into eight parts, instead of
nuclear@1 64 * doing eight alloc_small requests. This lets us use a single table base
nuclear@1 65 * address, which can be held in a register in the inner loops on many
nuclear@1 66 * machines (more than can hold all eight addresses, anyway).
nuclear@1 67 */
nuclear@1 68
nuclear@1 69 #define R_Y_OFF 0 /* offset to R => Y section */
nuclear@1 70 #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
nuclear@1 71 #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
nuclear@1 72 #define R_CB_OFF (3*(MAXJSAMPLE+1))
nuclear@1 73 #define G_CB_OFF (4*(MAXJSAMPLE+1))
nuclear@1 74 #define B_CB_OFF (5*(MAXJSAMPLE+1))
nuclear@1 75 #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
nuclear@1 76 #define G_CR_OFF (6*(MAXJSAMPLE+1))
nuclear@1 77 #define B_CR_OFF (7*(MAXJSAMPLE+1))
nuclear@1 78 #define TABLE_SIZE (8*(MAXJSAMPLE+1))
nuclear@1 79
nuclear@1 80
nuclear@1 81 /*
nuclear@1 82 * Initialize for RGB->YCC colorspace conversion.
nuclear@1 83 */
nuclear@1 84
nuclear@1 85 METHODDEF(void)
nuclear@1 86 rgb_ycc_start (j_compress_ptr cinfo)
nuclear@1 87 {
nuclear@1 88 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
nuclear@1 89 INT32 * rgb_ycc_tab;
nuclear@1 90 INT32 i;
nuclear@1 91
nuclear@1 92 /* Allocate and fill in the conversion tables. */
nuclear@1 93 cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
nuclear@1 94 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
nuclear@1 95 (TABLE_SIZE * SIZEOF(INT32)));
nuclear@1 96
nuclear@1 97 for (i = 0; i <= MAXJSAMPLE; i++) {
nuclear@1 98 rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
nuclear@1 99 rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
nuclear@1 100 rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
nuclear@1 101 rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
nuclear@1 102 rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
nuclear@1 103 /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
nuclear@1 104 * This ensures that the maximum output will round to MAXJSAMPLE
nuclear@1 105 * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
nuclear@1 106 */
nuclear@1 107 rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
nuclear@1 108 /* B=>Cb and R=>Cr tables are the same
nuclear@1 109 rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
nuclear@1 110 */
nuclear@1 111 rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
nuclear@1 112 rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
nuclear@1 113 }
nuclear@1 114 }
nuclear@1 115
nuclear@1 116
nuclear@1 117 /*
nuclear@1 118 * Convert some rows of samples to the JPEG colorspace.
nuclear@1 119 *
nuclear@1 120 * Note that we change from the application's interleaved-pixel format
nuclear@1 121 * to our internal noninterleaved, one-plane-per-component format.
nuclear@1 122 * The input buffer is therefore three times as wide as the output buffer.
nuclear@1 123 *
nuclear@1 124 * A starting row offset is provided only for the output buffer. The caller
nuclear@1 125 * can easily adjust the passed input_buf value to accommodate any row
nuclear@1 126 * offset required on that side.
nuclear@1 127 */
nuclear@1 128
nuclear@1 129 METHODDEF(void)
nuclear@1 130 rgb_ycc_convert (j_compress_ptr cinfo,
nuclear@1 131 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
nuclear@1 132 JDIMENSION output_row, int num_rows)
nuclear@1 133 {
nuclear@1 134 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
nuclear@1 135 register int r, g, b;
nuclear@1 136 register INT32 * ctab = cconvert->rgb_ycc_tab;
nuclear@1 137 register JSAMPROW inptr;
nuclear@1 138 register JSAMPROW outptr0, outptr1, outptr2;
nuclear@1 139 register JDIMENSION col;
nuclear@1 140 JDIMENSION num_cols = cinfo->image_width;
nuclear@1 141
nuclear@1 142 while (--num_rows >= 0) {
nuclear@1 143 inptr = *input_buf++;
nuclear@1 144 outptr0 = output_buf[0][output_row];
nuclear@1 145 outptr1 = output_buf[1][output_row];
nuclear@1 146 outptr2 = output_buf[2][output_row];
nuclear@1 147 output_row++;
nuclear@1 148 for (col = 0; col < num_cols; col++) {
nuclear@1 149 r = GETJSAMPLE(inptr[RGB_RED]);
nuclear@1 150 g = GETJSAMPLE(inptr[RGB_GREEN]);
nuclear@1 151 b = GETJSAMPLE(inptr[RGB_BLUE]);
nuclear@1 152 inptr += RGB_PIXELSIZE;
nuclear@1 153 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
nuclear@1 154 * must be too; we do not need an explicit range-limiting operation.
nuclear@1 155 * Hence the value being shifted is never negative, and we don't
nuclear@1 156 * need the general RIGHT_SHIFT macro.
nuclear@1 157 */
nuclear@1 158 /* Y */
nuclear@1 159 outptr0[col] = (JSAMPLE)
nuclear@1 160 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
nuclear@1 161 >> SCALEBITS);
nuclear@1 162 /* Cb */
nuclear@1 163 outptr1[col] = (JSAMPLE)
nuclear@1 164 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
nuclear@1 165 >> SCALEBITS);
nuclear@1 166 /* Cr */
nuclear@1 167 outptr2[col] = (JSAMPLE)
nuclear@1 168 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
nuclear@1 169 >> SCALEBITS);
nuclear@1 170 }
nuclear@1 171 }
nuclear@1 172 }
nuclear@1 173
nuclear@1 174
nuclear@1 175 /**************** Cases other than RGB -> YCbCr **************/
nuclear@1 176
nuclear@1 177
nuclear@1 178 /*
nuclear@1 179 * Convert some rows of samples to the JPEG colorspace.
nuclear@1 180 * This version handles RGB->grayscale conversion, which is the same
nuclear@1 181 * as the RGB->Y portion of RGB->YCbCr.
nuclear@1 182 * We assume rgb_ycc_start has been called (we only use the Y tables).
nuclear@1 183 */
nuclear@1 184
nuclear@1 185 METHODDEF(void)
nuclear@1 186 rgb_gray_convert (j_compress_ptr cinfo,
nuclear@1 187 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
nuclear@1 188 JDIMENSION output_row, int num_rows)
nuclear@1 189 {
nuclear@1 190 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
nuclear@1 191 register int r, g, b;
nuclear@1 192 register INT32 * ctab = cconvert->rgb_ycc_tab;
nuclear@1 193 register JSAMPROW inptr;
nuclear@1 194 register JSAMPROW outptr;
nuclear@1 195 register JDIMENSION col;
nuclear@1 196 JDIMENSION num_cols = cinfo->image_width;
nuclear@1 197
nuclear@1 198 while (--num_rows >= 0) {
nuclear@1 199 inptr = *input_buf++;
nuclear@1 200 outptr = output_buf[0][output_row];
nuclear@1 201 output_row++;
nuclear@1 202 for (col = 0; col < num_cols; col++) {
nuclear@1 203 r = GETJSAMPLE(inptr[RGB_RED]);
nuclear@1 204 g = GETJSAMPLE(inptr[RGB_GREEN]);
nuclear@1 205 b = GETJSAMPLE(inptr[RGB_BLUE]);
nuclear@1 206 inptr += RGB_PIXELSIZE;
nuclear@1 207 /* Y */
nuclear@1 208 outptr[col] = (JSAMPLE)
nuclear@1 209 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
nuclear@1 210 >> SCALEBITS);
nuclear@1 211 }
nuclear@1 212 }
nuclear@1 213 }
nuclear@1 214
nuclear@1 215
nuclear@1 216 /*
nuclear@1 217 * Convert some rows of samples to the JPEG colorspace.
nuclear@1 218 * This version handles Adobe-style CMYK->YCCK conversion,
nuclear@1 219 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
nuclear@1 220 * conversion as above, while passing K (black) unchanged.
nuclear@1 221 * We assume rgb_ycc_start has been called.
nuclear@1 222 */
nuclear@1 223
nuclear@1 224 METHODDEF(void)
nuclear@1 225 cmyk_ycck_convert (j_compress_ptr cinfo,
nuclear@1 226 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
nuclear@1 227 JDIMENSION output_row, int num_rows)
nuclear@1 228 {
nuclear@1 229 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
nuclear@1 230 register int r, g, b;
nuclear@1 231 register INT32 * ctab = cconvert->rgb_ycc_tab;
nuclear@1 232 register JSAMPROW inptr;
nuclear@1 233 register JSAMPROW outptr0, outptr1, outptr2, outptr3;
nuclear@1 234 register JDIMENSION col;
nuclear@1 235 JDIMENSION num_cols = cinfo->image_width;
nuclear@1 236
nuclear@1 237 while (--num_rows >= 0) {
nuclear@1 238 inptr = *input_buf++;
nuclear@1 239 outptr0 = output_buf[0][output_row];
nuclear@1 240 outptr1 = output_buf[1][output_row];
nuclear@1 241 outptr2 = output_buf[2][output_row];
nuclear@1 242 outptr3 = output_buf[3][output_row];
nuclear@1 243 output_row++;
nuclear@1 244 for (col = 0; col < num_cols; col++) {
nuclear@1 245 r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
nuclear@1 246 g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
nuclear@1 247 b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
nuclear@1 248 /* K passes through as-is */
nuclear@1 249 outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
nuclear@1 250 inptr += 4;
nuclear@1 251 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
nuclear@1 252 * must be too; we do not need an explicit range-limiting operation.
nuclear@1 253 * Hence the value being shifted is never negative, and we don't
nuclear@1 254 * need the general RIGHT_SHIFT macro.
nuclear@1 255 */
nuclear@1 256 /* Y */
nuclear@1 257 outptr0[col] = (JSAMPLE)
nuclear@1 258 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
nuclear@1 259 >> SCALEBITS);
nuclear@1 260 /* Cb */
nuclear@1 261 outptr1[col] = (JSAMPLE)
nuclear@1 262 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
nuclear@1 263 >> SCALEBITS);
nuclear@1 264 /* Cr */
nuclear@1 265 outptr2[col] = (JSAMPLE)
nuclear@1 266 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
nuclear@1 267 >> SCALEBITS);
nuclear@1 268 }
nuclear@1 269 }
nuclear@1 270 }
nuclear@1 271
nuclear@1 272
nuclear@1 273 /*
nuclear@1 274 * Convert some rows of samples to the JPEG colorspace.
nuclear@1 275 * This version handles grayscale output with no conversion.
nuclear@1 276 * The source can be either plain grayscale or YCbCr (since Y == gray).
nuclear@1 277 */
nuclear@1 278
nuclear@1 279 METHODDEF(void)
nuclear@1 280 grayscale_convert (j_compress_ptr cinfo,
nuclear@1 281 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
nuclear@1 282 JDIMENSION output_row, int num_rows)
nuclear@1 283 {
nuclear@1 284 register JSAMPROW inptr;
nuclear@1 285 register JSAMPROW outptr;
nuclear@1 286 register JDIMENSION col;
nuclear@1 287 JDIMENSION num_cols = cinfo->image_width;
nuclear@1 288 int instride = cinfo->input_components;
nuclear@1 289
nuclear@1 290 while (--num_rows >= 0) {
nuclear@1 291 inptr = *input_buf++;
nuclear@1 292 outptr = output_buf[0][output_row];
nuclear@1 293 output_row++;
nuclear@1 294 for (col = 0; col < num_cols; col++) {
nuclear@1 295 outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
nuclear@1 296 inptr += instride;
nuclear@1 297 }
nuclear@1 298 }
nuclear@1 299 }
nuclear@1 300
nuclear@1 301
nuclear@1 302 /*
nuclear@1 303 * Convert some rows of samples to the JPEG colorspace.
nuclear@1 304 * This version handles multi-component colorspaces without conversion.
nuclear@1 305 * We assume input_components == num_components.
nuclear@1 306 */
nuclear@1 307
nuclear@1 308 METHODDEF(void)
nuclear@1 309 null_convert (j_compress_ptr cinfo,
nuclear@1 310 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
nuclear@1 311 JDIMENSION output_row, int num_rows)
nuclear@1 312 {
nuclear@1 313 register JSAMPROW inptr;
nuclear@1 314 register JSAMPROW outptr;
nuclear@1 315 register JDIMENSION col;
nuclear@1 316 register int ci;
nuclear@1 317 int nc = cinfo->num_components;
nuclear@1 318 JDIMENSION num_cols = cinfo->image_width;
nuclear@1 319
nuclear@1 320 while (--num_rows >= 0) {
nuclear@1 321 /* It seems fastest to make a separate pass for each component. */
nuclear@1 322 for (ci = 0; ci < nc; ci++) {
nuclear@1 323 inptr = *input_buf;
nuclear@1 324 outptr = output_buf[ci][output_row];
nuclear@1 325 for (col = 0; col < num_cols; col++) {
nuclear@1 326 outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
nuclear@1 327 inptr += nc;
nuclear@1 328 }
nuclear@1 329 }
nuclear@1 330 input_buf++;
nuclear@1 331 output_row++;
nuclear@1 332 }
nuclear@1 333 }
nuclear@1 334
nuclear@1 335
nuclear@1 336 /*
nuclear@1 337 * Empty method for start_pass.
nuclear@1 338 */
nuclear@1 339
nuclear@1 340 METHODDEF(void)
nuclear@1 341 null_method (j_compress_ptr cinfo)
nuclear@1 342 {
nuclear@1 343 /* no work needed */
nuclear@1 344 }
nuclear@1 345
nuclear@1 346
nuclear@1 347 /*
nuclear@1 348 * Module initialization routine for input colorspace conversion.
nuclear@1 349 */
nuclear@1 350
nuclear@1 351 GLOBAL(void)
nuclear@1 352 jinit_color_converter (j_compress_ptr cinfo)
nuclear@1 353 {
nuclear@1 354 my_cconvert_ptr cconvert;
nuclear@1 355
nuclear@1 356 cconvert = (my_cconvert_ptr)
nuclear@1 357 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
nuclear@1 358 SIZEOF(my_color_converter));
nuclear@1 359 cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
nuclear@1 360 /* set start_pass to null method until we find out differently */
nuclear@1 361 cconvert->pub.start_pass = null_method;
nuclear@1 362
nuclear@1 363 /* Make sure input_components agrees with in_color_space */
nuclear@1 364 switch (cinfo->in_color_space) {
nuclear@1 365 case JCS_GRAYSCALE:
nuclear@1 366 if (cinfo->input_components != 1)
nuclear@1 367 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
nuclear@1 368 break;
nuclear@1 369
nuclear@1 370 case JCS_RGB:
nuclear@1 371 #if RGB_PIXELSIZE != 3
nuclear@1 372 if (cinfo->input_components != RGB_PIXELSIZE)
nuclear@1 373 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
nuclear@1 374 break;
nuclear@1 375 #endif /* else share code with YCbCr */
nuclear@1 376
nuclear@1 377 case JCS_YCbCr:
nuclear@1 378 if (cinfo->input_components != 3)
nuclear@1 379 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
nuclear@1 380 break;
nuclear@1 381
nuclear@1 382 case JCS_CMYK:
nuclear@1 383 case JCS_YCCK:
nuclear@1 384 if (cinfo->input_components != 4)
nuclear@1 385 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
nuclear@1 386 break;
nuclear@1 387
nuclear@1 388 default: /* JCS_UNKNOWN can be anything */
nuclear@1 389 if (cinfo->input_components < 1)
nuclear@1 390 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
nuclear@1 391 break;
nuclear@1 392 }
nuclear@1 393
nuclear@1 394 /* Check num_components, set conversion method based on requested space */
nuclear@1 395 switch (cinfo->jpeg_color_space) {
nuclear@1 396 case JCS_GRAYSCALE:
nuclear@1 397 if (cinfo->num_components != 1)
nuclear@1 398 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
nuclear@1 399 if (cinfo->in_color_space == JCS_GRAYSCALE)
nuclear@1 400 cconvert->pub.color_convert = grayscale_convert;
nuclear@1 401 else if (cinfo->in_color_space == JCS_RGB) {
nuclear@1 402 cconvert->pub.start_pass = rgb_ycc_start;
nuclear@1 403 cconvert->pub.color_convert = rgb_gray_convert;
nuclear@1 404 } else if (cinfo->in_color_space == JCS_YCbCr)
nuclear@1 405 cconvert->pub.color_convert = grayscale_convert;
nuclear@1 406 else
nuclear@1 407 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
nuclear@1 408 break;
nuclear@1 409
nuclear@1 410 case JCS_RGB:
nuclear@1 411 if (cinfo->num_components != 3)
nuclear@1 412 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
nuclear@1 413 if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
nuclear@1 414 cconvert->pub.color_convert = null_convert;
nuclear@1 415 else
nuclear@1 416 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
nuclear@1 417 break;
nuclear@1 418
nuclear@1 419 case JCS_YCbCr:
nuclear@1 420 if (cinfo->num_components != 3)
nuclear@1 421 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
nuclear@1 422 if (cinfo->in_color_space == JCS_RGB) {
nuclear@1 423 cconvert->pub.start_pass = rgb_ycc_start;
nuclear@1 424 cconvert->pub.color_convert = rgb_ycc_convert;
nuclear@1 425 } else if (cinfo->in_color_space == JCS_YCbCr)
nuclear@1 426 cconvert->pub.color_convert = null_convert;
nuclear@1 427 else
nuclear@1 428 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
nuclear@1 429 break;
nuclear@1 430
nuclear@1 431 case JCS_CMYK:
nuclear@1 432 if (cinfo->num_components != 4)
nuclear@1 433 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
nuclear@1 434 if (cinfo->in_color_space == JCS_CMYK)
nuclear@1 435 cconvert->pub.color_convert = null_convert;
nuclear@1 436 else
nuclear@1 437 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
nuclear@1 438 break;
nuclear@1 439
nuclear@1 440 case JCS_YCCK:
nuclear@1 441 if (cinfo->num_components != 4)
nuclear@1 442 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
nuclear@1 443 if (cinfo->in_color_space == JCS_CMYK) {
nuclear@1 444 cconvert->pub.start_pass = rgb_ycc_start;
nuclear@1 445 cconvert->pub.color_convert = cmyk_ycck_convert;
nuclear@1 446 } else if (cinfo->in_color_space == JCS_YCCK)
nuclear@1 447 cconvert->pub.color_convert = null_convert;
nuclear@1 448 else
nuclear@1 449 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
nuclear@1 450 break;
nuclear@1 451
nuclear@1 452 default: /* allow null conversion of JCS_UNKNOWN */
nuclear@1 453 if (cinfo->jpeg_color_space != cinfo->in_color_space ||
nuclear@1 454 cinfo->num_components != cinfo->input_components)
nuclear@1 455 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
nuclear@1 456 cconvert->pub.color_convert = null_convert;
nuclear@1 457 break;
nuclear@1 458 }
nuclear@1 459 }