istereo2

annotate libs/libjpeg/jccolor.c @ 2:81d35769f546

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