vrshoot

annotate libs/libjpeg/jccolor.c @ 0:b2f14e535253

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