4 * This file was part of the Independent JPEG Group's software:
5 * Copyright (C) 1991-1996, Thomas G. Lane.
6 * libjpeg-turbo Modifications:
7 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8 * Copyright (C) 2009-2012, 2015, 2022, D. R. Commander.
9 * Copyright (C) 2014, MIPS Technologies, Inc., California.
10 * For conditions of distribution and use, see the accompanying README.ijg
13 * This file contains input colorspace conversion routines.
16 #define JPEG_INTERNALS
20 #include "jsamplecomp.h"
23 #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
25 /* Private subobject */
28 struct jpeg_color_converter pub
; /* public fields */
30 #if BITS_IN_JSAMPLE != 16
31 /* Private state for RGB->YCC conversion */
32 JLONG
*rgb_ycc_tab
; /* => table for RGB to YCbCr conversion */
36 typedef my_color_converter
*my_cconvert_ptr
;
39 /**************** RGB -> YCbCr conversion: most common case **************/
42 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
43 * normalized to the range 0.._MAXJSAMPLE rather than -0.5 .. 0.5.
44 * The conversion equations to be implemented are therefore
45 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
46 * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + _CENTERJSAMPLE
47 * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + _CENTERJSAMPLE
48 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
49 * Note: older versions of the IJG code used a zero offset of _MAXJSAMPLE/2,
50 * rather than _CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
51 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
52 * were not represented exactly. Now we sacrifice exact representation of
53 * maximum red and maximum blue in order to get exact grayscales.
55 * To avoid floating-point arithmetic, we represent the fractional constants
56 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
57 * the products by 2^16, with appropriate rounding, to get the correct answer.
59 * For even more speed, we avoid doing any multiplications in the inner loop
60 * by precalculating the constants times R,G,B for all possible values.
61 * For 8-bit samples this is very reasonable (only 256 entries per table);
62 * for 12-bit samples it is still acceptable. It's not very reasonable for
63 * 16-bit samples, but if you want lossless storage you shouldn't be changing
65 * The _CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
66 * in the tables to save adding them separately in the inner loop.
69 #define SCALEBITS 16 /* speediest right-shift on some machines */
70 #define CBCR_OFFSET ((JLONG)_CENTERJSAMPLE << SCALEBITS)
71 #define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
72 #define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
74 /* We allocate one big table and divide it up into eight parts, instead of
75 * doing eight alloc_small requests. This lets us use a single table base
76 * address, which can be held in a register in the inner loops on many
77 * machines (more than can hold all eight addresses, anyway).
80 #define R_Y_OFF 0 /* offset to R => Y section */
81 #define G_Y_OFF (1 * (_MAXJSAMPLE + 1)) /* offset to G => Y section */
82 #define B_Y_OFF (2 * (_MAXJSAMPLE + 1)) /* etc. */
83 #define R_CB_OFF (3 * (_MAXJSAMPLE + 1))
84 #define G_CB_OFF (4 * (_MAXJSAMPLE + 1))
85 #define B_CB_OFF (5 * (_MAXJSAMPLE + 1))
86 #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
87 #define G_CR_OFF (6 * (_MAXJSAMPLE + 1))
88 #define B_CR_OFF (7 * (_MAXJSAMPLE + 1))
89 #define TABLE_SIZE (8 * (_MAXJSAMPLE + 1))
91 /* 12-bit samples use a 16-bit data type, so it is possible to pass
92 * out-of-range sample values (< 0 or > 4095) to jpeg_write_scanlines().
93 * Thus, we mask the incoming 12-bit samples to guard against overrunning
94 * or underrunning the conversion tables.
97 #if BITS_IN_JSAMPLE == 12
98 #define RANGE_LIMIT(value) ((value) & 0xFFF)
100 #define RANGE_LIMIT(value) (value)
104 /* Include inline routines for colorspace extensions */
106 #include "jccolext.c"
112 #define RGB_RED EXT_RGB_RED
113 #define RGB_GREEN EXT_RGB_GREEN
114 #define RGB_BLUE EXT_RGB_BLUE
115 #define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
116 #define rgb_ycc_convert_internal extrgb_ycc_convert_internal
117 #define rgb_gray_convert_internal extrgb_gray_convert_internal
118 #define rgb_rgb_convert_internal extrgb_rgb_convert_internal
119 #include "jccolext.c"
124 #undef rgb_ycc_convert_internal
125 #undef rgb_gray_convert_internal
126 #undef rgb_rgb_convert_internal
128 #define RGB_RED EXT_RGBX_RED
129 #define RGB_GREEN EXT_RGBX_GREEN
130 #define RGB_BLUE EXT_RGBX_BLUE
131 #define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
132 #define rgb_ycc_convert_internal extrgbx_ycc_convert_internal
133 #define rgb_gray_convert_internal extrgbx_gray_convert_internal
134 #define rgb_rgb_convert_internal extrgbx_rgb_convert_internal
135 #include "jccolext.c"
140 #undef rgb_ycc_convert_internal
141 #undef rgb_gray_convert_internal
142 #undef rgb_rgb_convert_internal
144 #define RGB_RED EXT_BGR_RED
145 #define RGB_GREEN EXT_BGR_GREEN
146 #define RGB_BLUE EXT_BGR_BLUE
147 #define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
148 #define rgb_ycc_convert_internal extbgr_ycc_convert_internal
149 #define rgb_gray_convert_internal extbgr_gray_convert_internal
150 #define rgb_rgb_convert_internal extbgr_rgb_convert_internal
151 #include "jccolext.c"
156 #undef rgb_ycc_convert_internal
157 #undef rgb_gray_convert_internal
158 #undef rgb_rgb_convert_internal
160 #define RGB_RED EXT_BGRX_RED
161 #define RGB_GREEN EXT_BGRX_GREEN
162 #define RGB_BLUE EXT_BGRX_BLUE
163 #define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
164 #define rgb_ycc_convert_internal extbgrx_ycc_convert_internal
165 #define rgb_gray_convert_internal extbgrx_gray_convert_internal
166 #define rgb_rgb_convert_internal extbgrx_rgb_convert_internal
167 #include "jccolext.c"
172 #undef rgb_ycc_convert_internal
173 #undef rgb_gray_convert_internal
174 #undef rgb_rgb_convert_internal
176 #define RGB_RED EXT_XBGR_RED
177 #define RGB_GREEN EXT_XBGR_GREEN
178 #define RGB_BLUE EXT_XBGR_BLUE
179 #define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
180 #define rgb_ycc_convert_internal extxbgr_ycc_convert_internal
181 #define rgb_gray_convert_internal extxbgr_gray_convert_internal
182 #define rgb_rgb_convert_internal extxbgr_rgb_convert_internal
183 #include "jccolext.c"
188 #undef rgb_ycc_convert_internal
189 #undef rgb_gray_convert_internal
190 #undef rgb_rgb_convert_internal
192 #define RGB_RED EXT_XRGB_RED
193 #define RGB_GREEN EXT_XRGB_GREEN
194 #define RGB_BLUE EXT_XRGB_BLUE
195 #define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
196 #define rgb_ycc_convert_internal extxrgb_ycc_convert_internal
197 #define rgb_gray_convert_internal extxrgb_gray_convert_internal
198 #define rgb_rgb_convert_internal extxrgb_rgb_convert_internal
199 #include "jccolext.c"
204 #undef rgb_ycc_convert_internal
205 #undef rgb_gray_convert_internal
206 #undef rgb_rgb_convert_internal
210 * Initialize for RGB->YCC colorspace conversion.
214 rgb_ycc_start(j_compress_ptr cinfo
)
216 #if BITS_IN_JSAMPLE != 16
217 my_cconvert_ptr cconvert
= (my_cconvert_ptr
)cinfo
->cconvert
;
221 /* Allocate and fill in the conversion tables. */
222 cconvert
->rgb_ycc_tab
= rgb_ycc_tab
= (JLONG
*)
223 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
)cinfo
, JPOOL_IMAGE
,
224 (TABLE_SIZE
* sizeof(JLONG
)));
226 for (i
= 0; i
<= _MAXJSAMPLE
; i
++) {
227 rgb_ycc_tab
[i
+ R_Y_OFF
] = FIX(0.29900) * i
;
228 rgb_ycc_tab
[i
+ G_Y_OFF
] = FIX(0.58700) * i
;
229 rgb_ycc_tab
[i
+ B_Y_OFF
] = FIX(0.11400) * i
+ ONE_HALF
;
230 rgb_ycc_tab
[i
+ R_CB_OFF
] = (-FIX(0.16874)) * i
;
231 rgb_ycc_tab
[i
+ G_CB_OFF
] = (-FIX(0.33126)) * i
;
232 /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
233 * This ensures that the maximum output will round to _MAXJSAMPLE
234 * not _MAXJSAMPLE+1, and thus that we don't have to range-limit.
236 rgb_ycc_tab
[i
+ B_CB_OFF
] = FIX(0.50000) * i
+ CBCR_OFFSET
+ ONE_HALF
- 1;
237 /* B=>Cb and R=>Cr tables are the same
238 rgb_ycc_tab[i + R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF - 1;
240 rgb_ycc_tab
[i
+ G_CR_OFF
] = (-FIX(0.41869)) * i
;
241 rgb_ycc_tab
[i
+ B_CR_OFF
] = (-FIX(0.08131)) * i
;
244 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
250 * Convert some rows of samples to the JPEG colorspace.
254 rgb_ycc_convert(j_compress_ptr cinfo
, _JSAMPARRAY input_buf
,
255 _JSAMPIMAGE output_buf
, JDIMENSION output_row
, int num_rows
)
257 switch (cinfo
->in_color_space
) {
259 extrgb_ycc_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
264 extrgbx_ycc_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
268 extbgr_ycc_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
273 extbgrx_ycc_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
278 extxbgr_ycc_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
283 extxrgb_ycc_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
287 rgb_ycc_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
294 /**************** Cases other than RGB -> YCbCr **************/
298 * Convert some rows of samples to the JPEG colorspace.
302 rgb_gray_convert(j_compress_ptr cinfo
, _JSAMPARRAY input_buf
,
303 _JSAMPIMAGE output_buf
, JDIMENSION output_row
, int num_rows
)
305 switch (cinfo
->in_color_space
) {
307 extrgb_gray_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
312 extrgbx_gray_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
316 extbgr_gray_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
321 extbgrx_gray_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
326 extxbgr_gray_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
331 extxrgb_gray_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
335 rgb_gray_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
343 * Extended RGB to plain RGB conversion
347 rgb_rgb_convert(j_compress_ptr cinfo
, _JSAMPARRAY input_buf
,
348 _JSAMPIMAGE output_buf
, JDIMENSION output_row
, int num_rows
)
350 switch (cinfo
->in_color_space
) {
352 extrgb_rgb_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
357 extrgbx_rgb_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
361 extbgr_rgb_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
366 extbgrx_rgb_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
371 extxbgr_rgb_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
376 extxrgb_rgb_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
380 rgb_rgb_convert_internal(cinfo
, input_buf
, output_buf
, output_row
,
388 * Convert some rows of samples to the JPEG colorspace.
389 * This version handles Adobe-style CMYK->YCCK conversion,
390 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
391 * conversion as above, while passing K (black) unchanged.
392 * We assume rgb_ycc_start has been called.
396 cmyk_ycck_convert(j_compress_ptr cinfo
, _JSAMPARRAY input_buf
,
397 _JSAMPIMAGE output_buf
, JDIMENSION output_row
, int num_rows
)
399 #if BITS_IN_JSAMPLE != 16
400 my_cconvert_ptr cconvert
= (my_cconvert_ptr
)cinfo
->cconvert
;
401 register int r
, g
, b
;
402 register JLONG
*ctab
= cconvert
->rgb_ycc_tab
;
403 register _JSAMPROW inptr
;
404 register _JSAMPROW outptr0
, outptr1
, outptr2
, outptr3
;
405 register JDIMENSION col
;
406 JDIMENSION num_cols
= cinfo
->image_width
;
408 while (--num_rows
>= 0) {
409 inptr
= *input_buf
++;
410 outptr0
= output_buf
[0][output_row
];
411 outptr1
= output_buf
[1][output_row
];
412 outptr2
= output_buf
[2][output_row
];
413 outptr3
= output_buf
[3][output_row
];
415 for (col
= 0; col
< num_cols
; col
++) {
416 r
= _MAXJSAMPLE
- RANGE_LIMIT(inptr
[0]);
417 g
= _MAXJSAMPLE
- RANGE_LIMIT(inptr
[1]);
418 b
= _MAXJSAMPLE
- RANGE_LIMIT(inptr
[2]);
419 /* K passes through as-is */
420 outptr3
[col
] = inptr
[3];
422 /* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
423 * must be too; we do not need an explicit range-limiting operation.
424 * Hence the value being shifted is never negative, and we don't
425 * need the general RIGHT_SHIFT macro.
428 outptr0
[col
] = (_JSAMPLE
)((ctab
[r
+ R_Y_OFF
] + ctab
[g
+ G_Y_OFF
] +
429 ctab
[b
+ B_Y_OFF
]) >> SCALEBITS
);
431 outptr1
[col
] = (_JSAMPLE
)((ctab
[r
+ R_CB_OFF
] + ctab
[g
+ G_CB_OFF
] +
432 ctab
[b
+ B_CB_OFF
]) >> SCALEBITS
);
434 outptr2
[col
] = (_JSAMPLE
)((ctab
[r
+ R_CR_OFF
] + ctab
[g
+ G_CR_OFF
] +
435 ctab
[b
+ B_CR_OFF
]) >> SCALEBITS
);
439 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
445 * Convert some rows of samples to the JPEG colorspace.
446 * This version handles grayscale output with no conversion.
447 * The source can be either plain grayscale or YCbCr (since Y == gray).
451 grayscale_convert(j_compress_ptr cinfo
, _JSAMPARRAY input_buf
,
452 _JSAMPIMAGE output_buf
, JDIMENSION output_row
, int num_rows
)
454 register _JSAMPROW inptr
;
455 register _JSAMPROW outptr
;
456 register JDIMENSION col
;
457 JDIMENSION num_cols
= cinfo
->image_width
;
458 int instride
= cinfo
->input_components
;
460 while (--num_rows
>= 0) {
461 inptr
= *input_buf
++;
462 outptr
= output_buf
[0][output_row
];
464 for (col
= 0; col
< num_cols
; col
++) {
465 outptr
[col
] = inptr
[0];
473 * Convert some rows of samples to the JPEG colorspace.
474 * This version handles multi-component colorspaces without conversion.
475 * We assume input_components == num_components.
479 null_convert(j_compress_ptr cinfo
, _JSAMPARRAY input_buf
,
480 _JSAMPIMAGE output_buf
, JDIMENSION output_row
, int num_rows
)
482 register _JSAMPROW inptr
;
483 register _JSAMPROW outptr
, outptr0
, outptr1
, outptr2
, outptr3
;
484 register JDIMENSION col
;
486 int nc
= cinfo
->num_components
;
487 JDIMENSION num_cols
= cinfo
->image_width
;
490 while (--num_rows
>= 0) {
491 inptr
= *input_buf
++;
492 outptr0
= output_buf
[0][output_row
];
493 outptr1
= output_buf
[1][output_row
];
494 outptr2
= output_buf
[2][output_row
];
496 for (col
= 0; col
< num_cols
; col
++) {
497 outptr0
[col
] = *inptr
++;
498 outptr1
[col
] = *inptr
++;
499 outptr2
[col
] = *inptr
++;
502 } else if (nc
== 4) {
503 while (--num_rows
>= 0) {
504 inptr
= *input_buf
++;
505 outptr0
= output_buf
[0][output_row
];
506 outptr1
= output_buf
[1][output_row
];
507 outptr2
= output_buf
[2][output_row
];
508 outptr3
= output_buf
[3][output_row
];
510 for (col
= 0; col
< num_cols
; col
++) {
511 outptr0
[col
] = *inptr
++;
512 outptr1
[col
] = *inptr
++;
513 outptr2
[col
] = *inptr
++;
514 outptr3
[col
] = *inptr
++;
518 while (--num_rows
>= 0) {
519 /* It seems fastest to make a separate pass for each component. */
520 for (ci
= 0; ci
< nc
; ci
++) {
522 outptr
= output_buf
[ci
][output_row
];
523 for (col
= 0; col
< num_cols
; col
++) {
524 outptr
[col
] = inptr
[ci
];
536 * Empty method for start_pass.
540 null_method(j_compress_ptr cinfo
)
547 * Module initialization routine for input colorspace conversion.
551 _jinit_color_converter(j_compress_ptr cinfo
)
553 my_cconvert_ptr cconvert
;
555 if (cinfo
->data_precision
!= BITS_IN_JSAMPLE
)
556 ERREXIT1(cinfo
, JERR_BAD_PRECISION
, cinfo
->data_precision
);
558 cconvert
= (my_cconvert_ptr
)
559 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
)cinfo
, JPOOL_IMAGE
,
560 sizeof(my_color_converter
));
561 cinfo
->cconvert
= (struct jpeg_color_converter
*)cconvert
;
562 /* set start_pass to null method until we find out differently */
563 cconvert
->pub
.start_pass
= null_method
;
565 /* Make sure input_components agrees with in_color_space */
566 switch (cinfo
->in_color_space
) {
568 if (cinfo
->input_components
!= 1)
569 ERREXIT(cinfo
, JERR_BAD_IN_COLORSPACE
);
583 if (cinfo
->input_components
!= rgb_pixelsize
[cinfo
->in_color_space
])
584 ERREXIT(cinfo
, JERR_BAD_IN_COLORSPACE
);
588 if (cinfo
->input_components
!= 3)
589 ERREXIT(cinfo
, JERR_BAD_IN_COLORSPACE
);
594 if (cinfo
->input_components
!= 4)
595 ERREXIT(cinfo
, JERR_BAD_IN_COLORSPACE
);
598 default: /* JCS_UNKNOWN can be anything */
599 if (cinfo
->input_components
< 1)
600 ERREXIT(cinfo
, JERR_BAD_IN_COLORSPACE
);
604 /* Check num_components, set conversion method based on requested space.
605 * NOTE: We do not allow any lossy color conversion algorithms in lossless
608 switch (cinfo
->jpeg_color_space
) {
610 if (cinfo
->master
->lossless
&&
611 cinfo
->in_color_space
!= cinfo
->jpeg_color_space
)
612 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
613 if (cinfo
->num_components
!= 1)
614 ERREXIT(cinfo
, JERR_BAD_J_COLORSPACE
);
615 if (cinfo
->in_color_space
== JCS_GRAYSCALE
)
616 cconvert
->pub
._color_convert
= grayscale_convert
;
617 else if (IsExtRGB(cinfo
->in_color_space
)) {
619 if (jsimd_can_rgb_gray())
620 cconvert
->pub
._color_convert
= jsimd_rgb_gray_convert
;
624 cconvert
->pub
.start_pass
= rgb_ycc_start
;
625 cconvert
->pub
._color_convert
= rgb_gray_convert
;
627 } else if (cinfo
->in_color_space
== JCS_YCbCr
)
628 cconvert
->pub
._color_convert
= grayscale_convert
;
630 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
634 if (cinfo
->master
->lossless
&& !IsExtRGB(cinfo
->in_color_space
))
635 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
636 if (cinfo
->num_components
!= 3)
637 ERREXIT(cinfo
, JERR_BAD_J_COLORSPACE
);
638 if (rgb_red
[cinfo
->in_color_space
] == 0 &&
639 rgb_green
[cinfo
->in_color_space
] == 1 &&
640 rgb_blue
[cinfo
->in_color_space
] == 2 &&
641 rgb_pixelsize
[cinfo
->in_color_space
] == 3) {
642 #if defined(WITH_SIMD) && defined(__mips__)
643 if (jsimd_c_can_null_convert())
644 cconvert
->pub
._color_convert
= jsimd_c_null_convert
;
647 cconvert
->pub
._color_convert
= null_convert
;
648 } else if (IsExtRGB(cinfo
->in_color_space
))
649 cconvert
->pub
._color_convert
= rgb_rgb_convert
;
651 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
655 if (cinfo
->master
->lossless
&&
656 cinfo
->in_color_space
!= cinfo
->jpeg_color_space
)
657 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
658 if (cinfo
->num_components
!= 3)
659 ERREXIT(cinfo
, JERR_BAD_J_COLORSPACE
);
660 if (IsExtRGB(cinfo
->in_color_space
)) {
662 if (jsimd_can_rgb_ycc())
663 cconvert
->pub
._color_convert
= jsimd_rgb_ycc_convert
;
667 cconvert
->pub
.start_pass
= rgb_ycc_start
;
668 cconvert
->pub
._color_convert
= rgb_ycc_convert
;
670 } else if (cinfo
->in_color_space
== JCS_YCbCr
) {
671 #if defined(WITH_SIMD) && defined(__mips__)
672 if (jsimd_c_can_null_convert())
673 cconvert
->pub
._color_convert
= jsimd_c_null_convert
;
676 cconvert
->pub
._color_convert
= null_convert
;
678 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
682 if (cinfo
->master
->lossless
&&
683 cinfo
->in_color_space
!= cinfo
->jpeg_color_space
)
684 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
685 if (cinfo
->num_components
!= 4)
686 ERREXIT(cinfo
, JERR_BAD_J_COLORSPACE
);
687 if (cinfo
->in_color_space
== JCS_CMYK
) {
688 #if defined(WITH_SIMD) && defined(__mips__)
689 if (jsimd_c_can_null_convert())
690 cconvert
->pub
._color_convert
= jsimd_c_null_convert
;
693 cconvert
->pub
._color_convert
= null_convert
;
695 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
699 if (cinfo
->master
->lossless
&&
700 cinfo
->in_color_space
!= cinfo
->jpeg_color_space
)
701 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
702 if (cinfo
->num_components
!= 4)
703 ERREXIT(cinfo
, JERR_BAD_J_COLORSPACE
);
704 if (cinfo
->in_color_space
== JCS_CMYK
) {
705 cconvert
->pub
.start_pass
= rgb_ycc_start
;
706 cconvert
->pub
._color_convert
= cmyk_ycck_convert
;
707 } else if (cinfo
->in_color_space
== JCS_YCCK
) {
708 #if defined(WITH_SIMD) && defined(__mips__)
709 if (jsimd_c_can_null_convert())
710 cconvert
->pub
._color_convert
= jsimd_c_null_convert
;
713 cconvert
->pub
._color_convert
= null_convert
;
715 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
718 default: /* allow null conversion of JCS_UNKNOWN */
719 if (cinfo
->jpeg_color_space
!= cinfo
->in_color_space
||
720 cinfo
->num_components
!= cinfo
->input_components
)
721 ERREXIT(cinfo
, JERR_CONVERSION_NOTIMPL
);
722 #if defined(WITH_SIMD) && defined(__mips__)
723 if (jsimd_c_can_null_convert())
724 cconvert
->pub
._color_convert
= jsimd_c_null_convert
;
727 cconvert
->pub
._color_convert
= null_convert
;
732 #endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */