Coverage Report

Created: 2026-04-12 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.0.x/jdcolor.c
Line
Count
Source
1
/*
2
 * jdcolor.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
6
 * Modified 2011 by Guido Vollbeding.
7
 * libjpeg-turbo Modifications:
8
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
 * Copyright (C) 2009, 2011-2012, 2014-2015, 2022, D. R. Commander.
10
 * Copyright (C) 2013, Linaro Limited.
11
 * For conditions of distribution and use, see the accompanying README.ijg
12
 * file.
13
 *
14
 * This file contains output colorspace conversion routines.
15
 */
16
17
#define JPEG_INTERNALS
18
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jsimd.h"
21
#include "jsamplecomp.h"
22
23
24
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
25
26
/* Private subobject */
27
28
typedef struct {
29
  struct jpeg_color_deconverter pub; /* public fields */
30
31
#if BITS_IN_JSAMPLE != 16
32
  /* Private state for YCC->RGB conversion */
33
  int *Cr_r_tab;                /* => table for Cr to R conversion */
34
  int *Cb_b_tab;                /* => table for Cb to B conversion */
35
  JLONG *Cr_g_tab;              /* => table for Cr to G conversion */
36
  JLONG *Cb_g_tab;              /* => table for Cb to G conversion */
37
38
  /* Private state for RGB->Y conversion */
39
  JLONG *rgb_y_tab;             /* => table for RGB to Y conversion */
40
#endif
41
} my_color_deconverter;
42
43
typedef my_color_deconverter *my_cconvert_ptr;
44
45
46
/**************** YCbCr -> RGB conversion: most common case **************/
47
/****************   RGB -> Y   conversion: less common case **************/
48
49
/*
50
 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
51
 * normalized to the range 0.._MAXJSAMPLE rather than -0.5 .. 0.5.
52
 * The conversion equations to be implemented are therefore
53
 *
54
 *      R = Y                + 1.40200 * Cr
55
 *      G = Y - 0.34414 * Cb - 0.71414 * Cr
56
 *      B = Y + 1.77200 * Cb
57
 *
58
 *      Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
59
 *
60
 * where Cb and Cr represent the incoming values less _CENTERJSAMPLE.
61
 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
62
 *
63
 * To avoid floating-point arithmetic, we represent the fractional constants
64
 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
65
 * the products by 2^16, with appropriate rounding, to get the correct answer.
66
 * Notice that Y, being an integral input, does not contribute any fraction
67
 * so it need not participate in the rounding.
68
 *
69
 * For even more speed, we avoid doing any multiplications in the inner loop
70
 * by precalculating the constants times Cb and Cr for all possible values.
71
 * For 8-bit samples this is very reasonable (only 256 entries per table);
72
 * for 12-bit samples it is still acceptable.  It's not very reasonable for
73
 * 16-bit samples, but if you want lossless storage you shouldn't be changing
74
 * colorspace anyway.
75
 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the
76
 * values for the G calculation are left scaled up, since we must add them
77
 * together before rounding.
78
 */
79
80
33.4M
#define SCALEBITS       16      /* speediest right-shift on some machines */
81
3.65M
#define ONE_HALF        ((JLONG)1 << (SCALEBITS - 1))
82
7.50M
#define FIX(x)          ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
83
84
/* We allocate one big table for RGB->Y conversion and divide it up into
85
 * three parts, instead of doing three alloc_small requests.  This lets us
86
 * use a single table base address, which can be held in a register in the
87
 * inner loops on many machines (more than can hold all three addresses,
88
 * anyway).
89
 */
90
91
22.5M
#define R_Y_OFF         0                       /* offset to R => Y section */
92
22.5M
#define G_Y_OFF         (1 * (_MAXJSAMPLE + 1)) /* offset to G => Y section */
93
22.5M
#define B_Y_OFF         (2 * (_MAXJSAMPLE + 1)) /* etc. */
94
97
#define TABLE_SIZE      (3 * (_MAXJSAMPLE + 1))
95
96
97
/* Include inline routines for colorspace extensions */
98
99
#include "jdcolext.c"
100
#undef RGB_RED
101
#undef RGB_GREEN
102
#undef RGB_BLUE
103
#undef RGB_PIXELSIZE
104
105
746M
#define RGB_RED  EXT_RGB_RED
106
746M
#define RGB_GREEN  EXT_RGB_GREEN
107
746M
#define RGB_BLUE  EXT_RGB_BLUE
108
746M
#define RGB_PIXELSIZE  EXT_RGB_PIXELSIZE
109
#define ycc_rgb_convert_internal  ycc_extrgb_convert_internal
110
#define gray_rgb_convert_internal  gray_extrgb_convert_internal
111
#define rgb_rgb_convert_internal  rgb_extrgb_convert_internal
112
#include "jdcolext.c"
113
#undef RGB_RED
114
#undef RGB_GREEN
115
#undef RGB_BLUE
116
#undef RGB_PIXELSIZE
117
#undef ycc_rgb_convert_internal
118
#undef gray_rgb_convert_internal
119
#undef rgb_rgb_convert_internal
120
121
0
#define RGB_RED  EXT_RGBX_RED
122
0
#define RGB_GREEN  EXT_RGBX_GREEN
123
0
#define RGB_BLUE  EXT_RGBX_BLUE
124
0
#define RGB_ALPHA  3
125
0
#define RGB_PIXELSIZE  EXT_RGBX_PIXELSIZE
126
#define ycc_rgb_convert_internal  ycc_extrgbx_convert_internal
127
#define gray_rgb_convert_internal  gray_extrgbx_convert_internal
128
#define rgb_rgb_convert_internal  rgb_extrgbx_convert_internal
129
#include "jdcolext.c"
130
#undef RGB_RED
131
#undef RGB_GREEN
132
#undef RGB_BLUE
133
#undef RGB_ALPHA
134
#undef RGB_PIXELSIZE
135
#undef ycc_rgb_convert_internal
136
#undef gray_rgb_convert_internal
137
#undef rgb_rgb_convert_internal
138
139
30.0M
#define RGB_RED  EXT_BGR_RED
140
30.0M
#define RGB_GREEN  EXT_BGR_GREEN
141
30.0M
#define RGB_BLUE  EXT_BGR_BLUE
142
30.0M
#define RGB_PIXELSIZE  EXT_BGR_PIXELSIZE
143
#define ycc_rgb_convert_internal  ycc_extbgr_convert_internal
144
#define gray_rgb_convert_internal  gray_extbgr_convert_internal
145
#define rgb_rgb_convert_internal  rgb_extbgr_convert_internal
146
#include "jdcolext.c"
147
#undef RGB_RED
148
#undef RGB_GREEN
149
#undef RGB_BLUE
150
#undef RGB_PIXELSIZE
151
#undef ycc_rgb_convert_internal
152
#undef gray_rgb_convert_internal
153
#undef rgb_rgb_convert_internal
154
155
224M
#define RGB_RED  EXT_BGRX_RED
156
224M
#define RGB_GREEN  EXT_BGRX_GREEN
157
224M
#define RGB_BLUE  EXT_BGRX_BLUE
158
224M
#define RGB_ALPHA  3
159
224M
#define RGB_PIXELSIZE  EXT_BGRX_PIXELSIZE
160
#define ycc_rgb_convert_internal  ycc_extbgrx_convert_internal
161
#define gray_rgb_convert_internal  gray_extbgrx_convert_internal
162
#define rgb_rgb_convert_internal  rgb_extbgrx_convert_internal
163
#include "jdcolext.c"
164
#undef RGB_RED
165
#undef RGB_GREEN
166
#undef RGB_BLUE
167
#undef RGB_ALPHA
168
#undef RGB_PIXELSIZE
169
#undef ycc_rgb_convert_internal
170
#undef gray_rgb_convert_internal
171
#undef rgb_rgb_convert_internal
172
173
0
#define RGB_RED  EXT_XBGR_RED
174
0
#define RGB_GREEN  EXT_XBGR_GREEN
175
0
#define RGB_BLUE  EXT_XBGR_BLUE
176
0
#define RGB_ALPHA  0
177
0
#define RGB_PIXELSIZE  EXT_XBGR_PIXELSIZE
178
#define ycc_rgb_convert_internal  ycc_extxbgr_convert_internal
179
#define gray_rgb_convert_internal  gray_extxbgr_convert_internal
180
#define rgb_rgb_convert_internal  rgb_extxbgr_convert_internal
181
#include "jdcolext.c"
182
#undef RGB_RED
183
#undef RGB_GREEN
184
#undef RGB_BLUE
185
#undef RGB_ALPHA
186
#undef RGB_PIXELSIZE
187
#undef ycc_rgb_convert_internal
188
#undef gray_rgb_convert_internal
189
#undef rgb_rgb_convert_internal
190
191
17.7M
#define RGB_RED  EXT_XRGB_RED
192
17.7M
#define RGB_GREEN  EXT_XRGB_GREEN
193
17.7M
#define RGB_BLUE  EXT_XRGB_BLUE
194
17.7M
#define RGB_ALPHA  0
195
17.7M
#define RGB_PIXELSIZE  EXT_XRGB_PIXELSIZE
196
#define ycc_rgb_convert_internal  ycc_extxrgb_convert_internal
197
#define gray_rgb_convert_internal  gray_extxrgb_convert_internal
198
#define rgb_rgb_convert_internal  rgb_extxrgb_convert_internal
199
#include "jdcolext.c"
200
#undef RGB_RED
201
#undef RGB_GREEN
202
#undef RGB_BLUE
203
#undef RGB_ALPHA
204
#undef RGB_PIXELSIZE
205
#undef ycc_rgb_convert_internal
206
#undef gray_rgb_convert_internal
207
#undef rgb_rgb_convert_internal
208
209
210
/*
211
 * Initialize tables for YCC->RGB colorspace conversion.
212
 */
213
214
LOCAL(void)
215
build_ycc_rgb_table(j_decompress_ptr cinfo)
216
868
{
217
868
#if BITS_IN_JSAMPLE != 16
218
868
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
219
868
  int i;
220
868
  JLONG x;
221
868
  SHIFT_TEMPS
222
223
868
  cconvert->Cr_r_tab = (int *)
224
868
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
225
868
                                (_MAXJSAMPLE + 1) * sizeof(int));
226
868
  cconvert->Cb_b_tab = (int *)
227
868
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
228
868
                                (_MAXJSAMPLE + 1) * sizeof(int));
229
868
  cconvert->Cr_g_tab = (JLONG *)
230
868
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
231
868
                                (_MAXJSAMPLE + 1) * sizeof(JLONG));
232
868
  cconvert->Cb_g_tab = (JLONG *)
233
868
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
234
868
                                (_MAXJSAMPLE + 1) * sizeof(JLONG));
235
236
3.47M
  for (i = 0, x = -_CENTERJSAMPLE; i <= _MAXJSAMPLE; i++, x++) {
237
    /* i is the actual input pixel value, in the range 0.._MAXJSAMPLE */
238
    /* The Cb or Cr value we are thinking of is x = i - _CENTERJSAMPLE */
239
    /* Cr=>R value is nearest int to 1.40200 * x */
240
3.47M
    cconvert->Cr_r_tab[i] = (int)
241
3.47M
                    RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
242
    /* Cb=>B value is nearest int to 1.77200 * x */
243
3.47M
    cconvert->Cb_b_tab[i] = (int)
244
3.47M
                    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
245
    /* Cr=>G value is scaled-up -0.71414 * x */
246
3.47M
    cconvert->Cr_g_tab[i] = (-FIX(0.71414)) * x;
247
    /* Cb=>G value is scaled-up -0.34414 * x */
248
    /* We also add in ONE_HALF so that need not do it in inner loop */
249
3.47M
    cconvert->Cb_g_tab[i] = (-FIX(0.34414)) * x + ONE_HALF;
250
3.47M
  }
251
#else
252
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
253
#endif
254
868
}
255
256
257
/*
258
 * Convert some rows of samples to the output colorspace.
259
 */
260
261
METHODDEF(void)
262
ycc_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
263
                JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
264
999k
{
265
999k
  switch (cinfo->out_color_space) {
266
601k
  case JCS_EXT_RGB:
267
601k
    ycc_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf,
268
601k
                                num_rows);
269
601k
    break;
270
0
  case JCS_EXT_RGBX:
271
0
  case JCS_EXT_RGBA:
272
0
    ycc_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf,
273
0
                                 num_rows);
274
0
    break;
275
0
  case JCS_EXT_BGR:
276
0
    ycc_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf,
277
0
                                num_rows);
278
0
    break;
279
398k
  case JCS_EXT_BGRX:
280
398k
  case JCS_EXT_BGRA:
281
398k
    ycc_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf,
282
398k
                                 num_rows);
283
398k
    break;
284
0
  case JCS_EXT_XBGR:
285
0
  case JCS_EXT_ABGR:
286
0
    ycc_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf,
287
0
                                 num_rows);
288
0
    break;
289
0
  case JCS_EXT_XRGB:
290
0
  case JCS_EXT_ARGB:
291
0
    ycc_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf,
292
0
                                 num_rows);
293
0
    break;
294
0
  default:
295
0
    ycc_rgb_convert_internal(cinfo, input_buf, input_row, output_buf,
296
0
                             num_rows);
297
0
    break;
298
999k
  }
299
999k
}
300
301
302
/**************** Cases other than YCbCr -> RGB **************/
303
304
305
/*
306
 * Initialize for RGB->grayscale colorspace conversion.
307
 */
308
309
LOCAL(void)
310
build_rgb_y_table(j_decompress_ptr cinfo)
311
97
{
312
97
#if BITS_IN_JSAMPLE != 16
313
97
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
314
97
  JLONG *rgb_y_tab;
315
97
  JLONG i;
316
317
  /* Allocate and fill in the conversion tables. */
318
97
  cconvert->rgb_y_tab = rgb_y_tab = (JLONG *)
319
97
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
320
97
                                (TABLE_SIZE * sizeof(JLONG)));
321
322
186k
  for (i = 0; i <= _MAXJSAMPLE; i++) {
323
186k
    rgb_y_tab[i + R_Y_OFF] = FIX(0.29900) * i;
324
186k
    rgb_y_tab[i + G_Y_OFF] = FIX(0.58700) * i;
325
186k
    rgb_y_tab[i + B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
326
186k
  }
327
#else
328
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
329
#endif
330
97
}
331
332
333
/*
334
 * Convert RGB to grayscale.
335
 */
336
337
METHODDEF(void)
338
rgb_gray_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
339
                 JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
340
216k
{
341
216k
#if BITS_IN_JSAMPLE != 16
342
216k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
343
216k
  register int r, g, b;
344
216k
  register JLONG *ctab = cconvert->rgb_y_tab;
345
216k
  register _JSAMPROW outptr;
346
216k
  register _JSAMPROW inptr0, inptr1, inptr2;
347
216k
  register JDIMENSION col;
348
216k
  JDIMENSION num_cols = cinfo->output_width;
349
350
608k
  while (--num_rows >= 0) {
351
392k
    inptr0 = input_buf[0][input_row];
352
392k
    inptr1 = input_buf[1][input_row];
353
392k
    inptr2 = input_buf[2][input_row];
354
392k
    input_row++;
355
392k
    outptr = *output_buf++;
356
22.7M
    for (col = 0; col < num_cols; col++) {
357
22.3M
      r = inptr0[col];
358
22.3M
      g = inptr1[col];
359
22.3M
      b = inptr2[col];
360
      /* Y */
361
22.3M
      outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
362
22.3M
                                ctab[b + B_Y_OFF]) >> SCALEBITS);
363
22.3M
    }
364
392k
  }
365
#else
366
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
367
#endif
368
216k
}
369
370
371
/*
372
 * Color conversion for no colorspace change: just copy the data,
373
 * converting from separate-planes to interleaved representation.
374
 */
375
376
METHODDEF(void)
377
null_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
378
             JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
379
887k
{
380
887k
  register _JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr;
381
887k
  register JDIMENSION col;
382
887k
  register int num_components = cinfo->num_components;
383
887k
  JDIMENSION num_cols = cinfo->output_width;
384
887k
  int ci;
385
386
887k
  if (num_components == 3) {
387
2.46M
    while (--num_rows >= 0) {
388
1.61M
      inptr0 = input_buf[0][input_row];
389
1.61M
      inptr1 = input_buf[1][input_row];
390
1.61M
      inptr2 = input_buf[2][input_row];
391
1.61M
      input_row++;
392
1.61M
      outptr = *output_buf++;
393
45.8M
      for (col = 0; col < num_cols; col++) {
394
44.2M
        *outptr++ = inptr0[col];
395
44.2M
        *outptr++ = inptr1[col];
396
44.2M
        *outptr++ = inptr2[col];
397
44.2M
      }
398
1.61M
    }
399
848k
  } else if (num_components == 4) {
400
135k
    while (--num_rows >= 0) {
401
96.8k
      inptr0 = input_buf[0][input_row];
402
96.8k
      inptr1 = input_buf[1][input_row];
403
96.8k
      inptr2 = input_buf[2][input_row];
404
96.8k
      inptr3 = input_buf[3][input_row];
405
96.8k
      input_row++;
406
96.8k
      outptr = *output_buf++;
407
10.7M
      for (col = 0; col < num_cols; col++) {
408
10.6M
        *outptr++ = inptr0[col];
409
10.6M
        *outptr++ = inptr1[col];
410
10.6M
        *outptr++ = inptr2[col];
411
10.6M
        *outptr++ = inptr3[col];
412
10.6M
      }
413
96.8k
    }
414
38.1k
  } else {
415
0
    while (--num_rows >= 0) {
416
0
      for (ci = 0; ci < num_components; ci++) {
417
0
        inptr = input_buf[ci][input_row];
418
0
        outptr = *output_buf;
419
0
        for (col = 0; col < num_cols; col++) {
420
0
          outptr[ci] = inptr[col];
421
0
          outptr += num_components;
422
0
        }
423
0
      }
424
0
      output_buf++;
425
0
      input_row++;
426
0
    }
427
0
  }
428
887k
}
429
430
431
/*
432
 * Color conversion for grayscale: just copy the data.
433
 * This also works for YCbCr -> grayscale conversion, in which
434
 * we just copy the Y (luminance) component and ignore chrominance.
435
 */
436
437
METHODDEF(void)
438
grayscale_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
439
                  JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
440
10.4M
{
441
10.4M
  _jcopy_sample_rows(input_buf[0], (int)input_row, output_buf, 0, num_rows,
442
10.4M
                     cinfo->output_width);
443
10.4M
}
444
445
446
/*
447
 * Convert grayscale to RGB
448
 */
449
450
METHODDEF(void)
451
gray_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
452
                 JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
453
10.3M
{
454
10.3M
  switch (cinfo->out_color_space) {
455
5.30M
  case JCS_EXT_RGB:
456
5.30M
    gray_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf,
457
5.30M
                                 num_rows);
458
5.30M
    break;
459
0
  case JCS_EXT_RGBX:
460
0
  case JCS_EXT_RGBA:
461
0
    gray_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf,
462
0
                                  num_rows);
463
0
    break;
464
1.36M
  case JCS_EXT_BGR:
465
1.36M
    gray_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf,
466
1.36M
                                 num_rows);
467
1.36M
    break;
468
2.62M
  case JCS_EXT_BGRX:
469
2.62M
  case JCS_EXT_BGRA:
470
2.62M
    gray_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf,
471
2.62M
                                  num_rows);
472
2.62M
    break;
473
0
  case JCS_EXT_XBGR:
474
0
  case JCS_EXT_ABGR:
475
0
    gray_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf,
476
0
                                  num_rows);
477
0
    break;
478
1.02M
  case JCS_EXT_XRGB:
479
1.02M
  case JCS_EXT_ARGB:
480
1.02M
    gray_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf,
481
1.02M
                                  num_rows);
482
1.02M
    break;
483
0
  default:
484
0
    gray_rgb_convert_internal(cinfo, input_buf, input_row, output_buf,
485
0
                              num_rows);
486
0
    break;
487
10.3M
  }
488
10.3M
}
489
490
491
/*
492
 * Convert plain RGB to extended RGB
493
 */
494
495
METHODDEF(void)
496
rgb_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
497
                JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
498
894k
{
499
894k
  switch (cinfo->out_color_space) {
500
0
  case JCS_EXT_RGB:
501
0
    rgb_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf,
502
0
                                num_rows);
503
0
    break;
504
0
  case JCS_EXT_RGBX:
505
0
  case JCS_EXT_RGBA:
506
0
    rgb_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf,
507
0
                                 num_rows);
508
0
    break;
509
68.3k
  case JCS_EXT_BGR:
510
68.3k
    rgb_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf,
511
68.3k
                                num_rows);
512
68.3k
    break;
513
774k
  case JCS_EXT_BGRX:
514
774k
  case JCS_EXT_BGRA:
515
774k
    rgb_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf,
516
774k
                                 num_rows);
517
774k
    break;
518
0
  case JCS_EXT_XBGR:
519
0
  case JCS_EXT_ABGR:
520
0
    rgb_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf,
521
0
                                 num_rows);
522
0
    break;
523
51.2k
  case JCS_EXT_XRGB:
524
51.2k
  case JCS_EXT_ARGB:
525
51.2k
    rgb_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf,
526
51.2k
                                 num_rows);
527
51.2k
    break;
528
0
  default:
529
0
    rgb_rgb_convert_internal(cinfo, input_buf, input_row, output_buf,
530
0
                             num_rows);
531
0
    break;
532
894k
  }
533
894k
}
534
535
536
/*
537
 * Adobe-style YCCK->CMYK conversion.
538
 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
539
 * conversion as above, while passing K (black) unchanged.
540
 * We assume build_ycc_rgb_table has been called.
541
 */
542
543
METHODDEF(void)
544
ycck_cmyk_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
545
                  JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
546
16.0k
{
547
16.0k
#if BITS_IN_JSAMPLE != 16
548
16.0k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
549
16.0k
  register int y, cb, cr;
550
16.0k
  register _JSAMPROW outptr;
551
16.0k
  register _JSAMPROW inptr0, inptr1, inptr2, inptr3;
552
16.0k
  register JDIMENSION col;
553
16.0k
  JDIMENSION num_cols = cinfo->output_width;
554
  /* copy these pointers into registers if possible */
555
16.0k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
556
16.0k
  register int *Crrtab = cconvert->Cr_r_tab;
557
16.0k
  register int *Cbbtab = cconvert->Cb_b_tab;
558
16.0k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
559
16.0k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
560
16.0k
  SHIFT_TEMPS
561
562
71.4k
  while (--num_rows >= 0) {
563
55.4k
    inptr0 = input_buf[0][input_row];
564
55.4k
    inptr1 = input_buf[1][input_row];
565
55.4k
    inptr2 = input_buf[2][input_row];
566
55.4k
    inptr3 = input_buf[3][input_row];
567
55.4k
    input_row++;
568
55.4k
    outptr = *output_buf++;
569
4.25M
    for (col = 0; col < num_cols; col++) {
570
4.19M
      y  = inptr0[col];
571
4.19M
      cb = inptr1[col];
572
4.19M
      cr = inptr2[col];
573
      /* Range-limiting is essential due to noise introduced by DCT losses. */
574
4.19M
      outptr[0] = range_limit[_MAXJSAMPLE - (y + Crrtab[cr])];  /* red */
575
4.19M
      outptr[1] = range_limit[_MAXJSAMPLE - (y +                /* green */
576
4.19M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
577
4.19M
                                                 SCALEBITS)))];
578
4.19M
      outptr[2] = range_limit[_MAXJSAMPLE - (y + Cbbtab[cb])];  /* blue */
579
      /* K passes through unchanged */
580
4.19M
      outptr[3] = inptr3[col];
581
4.19M
      outptr += 4;
582
4.19M
    }
583
55.4k
  }
584
#else
585
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
586
#endif
587
16.0k
}
588
589
590
/*
591
 * RGB565 conversion
592
 */
593
594
#define PACK_SHORT_565_LE(r, g, b) \
595
0
  ((((r) << 8) & 0xF800) | (((g) << 3) & 0x7E0) | ((b) >> 3))
596
#define PACK_SHORT_565_BE(r, g, b) \
597
0
  (((r) & 0xF8) | ((g) >> 5) | (((g) << 11) & 0xE000) | (((b) << 5) & 0x1F00))
598
599
0
#define PACK_TWO_PIXELS_LE(l, r)    ((r << 16) | l)
600
0
#define PACK_TWO_PIXELS_BE(l, r)    ((l << 16) | r)
601
602
0
#define PACK_NEED_ALIGNMENT(ptr)    (((size_t)(ptr)) & 3)
603
604
0
#define WRITE_TWO_ALIGNED_PIXELS(addr, pixels)  ((*(int *)(addr)) = pixels)
605
606
0
#define DITHER_565_R(r, dither)  ((r) + ((dither) & 0xFF))
607
0
#define DITHER_565_G(g, dither)  ((g) + (((dither) & 0xFF) >> 1))
608
0
#define DITHER_565_B(b, dither)  ((b) + ((dither) & 0xFF))
609
610
611
/* Declarations for ordered dithering
612
 *
613
 * We use a 4x4 ordered dither array packed into 32 bits.  This array is
614
 * sufficient for dithering RGB888 to RGB565.
615
 */
616
617
0
#define DITHER_MASK       0x3
618
0
#define DITHER_ROTATE(x)  ((((x) & 0xFF) << 24) | (((x) >> 8) & 0x00FFFFFF))
619
static const JLONG dither_matrix[4] = {
620
  0x0008020A,
621
  0x0C040E06,
622
  0x030B0109,
623
  0x0F070D05
624
};
625
626
627
static INLINE boolean is_big_endian(void)
628
0
{
629
0
  int test_value = 1;
630
0
  if (*(char *)&test_value != 1)
631
0
    return TRUE;
632
0
  return FALSE;
633
0
}
634
635
636
/* Include inline routines for RGB565 conversion */
637
638
0
#define PACK_SHORT_565  PACK_SHORT_565_LE
639
0
#define PACK_TWO_PIXELS  PACK_TWO_PIXELS_LE
640
#define ycc_rgb565_convert_internal  ycc_rgb565_convert_le
641
#define ycc_rgb565D_convert_internal  ycc_rgb565D_convert_le
642
#define rgb_rgb565_convert_internal  rgb_rgb565_convert_le
643
#define rgb_rgb565D_convert_internal  rgb_rgb565D_convert_le
644
#define gray_rgb565_convert_internal  gray_rgb565_convert_le
645
#define gray_rgb565D_convert_internal  gray_rgb565D_convert_le
646
#include "jdcol565.c"
647
#undef PACK_SHORT_565
648
#undef PACK_TWO_PIXELS
649
#undef ycc_rgb565_convert_internal
650
#undef ycc_rgb565D_convert_internal
651
#undef rgb_rgb565_convert_internal
652
#undef rgb_rgb565D_convert_internal
653
#undef gray_rgb565_convert_internal
654
#undef gray_rgb565D_convert_internal
655
656
0
#define PACK_SHORT_565  PACK_SHORT_565_BE
657
0
#define PACK_TWO_PIXELS  PACK_TWO_PIXELS_BE
658
#define ycc_rgb565_convert_internal  ycc_rgb565_convert_be
659
#define ycc_rgb565D_convert_internal  ycc_rgb565D_convert_be
660
#define rgb_rgb565_convert_internal  rgb_rgb565_convert_be
661
#define rgb_rgb565D_convert_internal  rgb_rgb565D_convert_be
662
#define gray_rgb565_convert_internal  gray_rgb565_convert_be
663
#define gray_rgb565D_convert_internal  gray_rgb565D_convert_be
664
#include "jdcol565.c"
665
#undef PACK_SHORT_565
666
#undef PACK_TWO_PIXELS
667
#undef ycc_rgb565_convert_internal
668
#undef ycc_rgb565D_convert_internal
669
#undef rgb_rgb565_convert_internal
670
#undef rgb_rgb565D_convert_internal
671
#undef gray_rgb565_convert_internal
672
#undef gray_rgb565D_convert_internal
673
674
675
METHODDEF(void)
676
ycc_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
677
                   JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
678
0
{
679
0
  if (is_big_endian())
680
0
    ycc_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
681
0
  else
682
0
    ycc_rgb565_convert_le(cinfo, input_buf, input_row, output_buf, num_rows);
683
0
}
684
685
686
METHODDEF(void)
687
ycc_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
688
                    JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
689
0
{
690
0
  if (is_big_endian())
691
0
    ycc_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
692
0
  else
693
0
    ycc_rgb565D_convert_le(cinfo, input_buf, input_row, output_buf, num_rows);
694
0
}
695
696
697
METHODDEF(void)
698
rgb_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
699
                   JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
700
0
{
701
0
  if (is_big_endian())
702
0
    rgb_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
703
0
  else
704
0
    rgb_rgb565_convert_le(cinfo, input_buf, input_row, output_buf, num_rows);
705
0
}
706
707
708
METHODDEF(void)
709
rgb_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
710
                    JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
711
0
{
712
0
  if (is_big_endian())
713
0
    rgb_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
714
0
  else
715
0
    rgb_rgb565D_convert_le(cinfo, input_buf, input_row, output_buf, num_rows);
716
0
}
717
718
719
METHODDEF(void)
720
gray_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
721
                    JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
722
0
{
723
0
  if (is_big_endian())
724
0
    gray_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
725
0
  else
726
0
    gray_rgb565_convert_le(cinfo, input_buf, input_row, output_buf, num_rows);
727
0
}
728
729
730
METHODDEF(void)
731
gray_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
732
                     JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
733
0
{
734
0
  if (is_big_endian())
735
0
    gray_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
736
0
  else
737
0
    gray_rgb565D_convert_le(cinfo, input_buf, input_row, output_buf, num_rows);
738
0
}
739
740
741
/*
742
 * Empty method for start_pass.
743
 */
744
745
METHODDEF(void)
746
start_pass_dcolor(j_decompress_ptr cinfo)
747
12.7k
{
748
  /* no work needed */
749
12.7k
}
750
751
752
/*
753
 * Module initialization routine for output colorspace conversion.
754
 */
755
756
GLOBAL(void)
757
_jinit_color_deconverter(j_decompress_ptr cinfo)
758
26.8k
{
759
26.8k
  my_cconvert_ptr cconvert;
760
26.8k
  int ci;
761
762
26.8k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
763
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
764
765
26.8k
  cconvert = (my_cconvert_ptr)
766
26.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
767
26.8k
                                sizeof(my_color_deconverter));
768
26.8k
  cinfo->cconvert = (struct jpeg_color_deconverter *)cconvert;
769
26.8k
  cconvert->pub.start_pass = start_pass_dcolor;
770
771
  /* Make sure num_components agrees with jpeg_color_space */
772
26.8k
  switch (cinfo->jpeg_color_space) {
773
10.6k
  case JCS_GRAYSCALE:
774
10.6k
    if (cinfo->num_components != 1)
775
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
776
10.6k
    break;
777
778
9.03k
  case JCS_RGB:
779
15.1k
  case JCS_YCbCr:
780
15.1k
    if (cinfo->num_components != 3)
781
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
782
15.1k
    break;
783
784
736
  case JCS_CMYK:
785
924
  case JCS_YCCK:
786
924
    if (cinfo->num_components != 4)
787
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
788
924
    break;
789
790
64
  default:                      /* JCS_UNKNOWN can be anything */
791
64
    if (cinfo->num_components < 1)
792
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
793
64
    break;
794
26.8k
  }
795
796
  /* Set out_color_components and conversion method based on requested space.
797
   * Also clear the component_needed flags for any unused components,
798
   * so that earlier pipeline stages can avoid useless computation.
799
   * NOTE: We do not allow any lossy color conversion algorithms in lossless
800
   * mode.
801
   */
802
803
26.8k
  switch (cinfo->out_color_space) {
804
6.00k
  case JCS_GRAYSCALE:
805
6.00k
#ifdef D_LOSSLESS_SUPPORTED
806
6.00k
    if (cinfo->master->lossless &&
807
1.69k
        cinfo->jpeg_color_space != cinfo->out_color_space)
808
1.24k
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
809
6.00k
#endif
810
6.00k
    cinfo->out_color_components = 1;
811
6.00k
    if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
812
4.49k
        cinfo->jpeg_color_space == JCS_YCbCr) {
813
4.49k
      cconvert->pub._color_convert = grayscale_convert;
814
      /* For color->grayscale conversion, only the Y (0) component is needed */
815
7.83k
      for (ci = 1; ci < cinfo->num_components; ci++)
816
3.34k
        cinfo->comp_info[ci].component_needed = FALSE;
817
4.49k
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
818
101
      cconvert->pub._color_convert = rgb_gray_convert;
819
101
      build_rgb_y_table(cinfo);
820
101
    } else
821
1.41k
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
822
6.00k
    break;
823
824
4.05k
  case JCS_RGB:
825
9.31k
  case JCS_EXT_RGB:
826
9.31k
  case JCS_EXT_RGBX:
827
9.48k
  case JCS_EXT_BGR:
828
15.0k
  case JCS_EXT_BGRX:
829
15.0k
  case JCS_EXT_XBGR:
830
15.2k
  case JCS_EXT_XRGB:
831
15.2k
  case JCS_EXT_RGBA:
832
15.2k
  case JCS_EXT_BGRA:
833
15.2k
  case JCS_EXT_ABGR:
834
15.2k
  case JCS_EXT_ARGB:
835
15.2k
#ifdef D_LOSSLESS_SUPPORTED
836
15.2k
    if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB)
837
759
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
838
15.2k
#endif
839
15.2k
    cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
840
15.2k
    if (cinfo->jpeg_color_space == JCS_YCbCr) {
841
#ifdef WITH_SIMD
842
2.01k
      if (jsimd_can_ycc_rgb())
843
2.01k
        cconvert->pub._color_convert = jsimd_ycc_rgb_convert;
844
0
      else
845
0
#endif
846
0
      {
847
847
        cconvert->pub._color_convert = ycc_rgb_convert;
848
0
        build_ycc_rgb_table(cinfo);
849
0
      }
850
12.3k
    } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
851
4.75k
      cconvert->pub._color_convert = gray_rgb_convert;
852
7.63k
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
853
6.53k
      if (rgb_red[cinfo->out_color_space] == 0 &&
854
5.24k
          rgb_green[cinfo->out_color_space] == 1 &&
855
5.24k
          rgb_blue[cinfo->out_color_space] == 2 &&
856
5.24k
          rgb_pixelsize[cinfo->out_color_space] == 3)
857
5.24k
        cconvert->pub._color_convert = null_convert;
858
1.29k
      else
859
1.29k
        cconvert->pub._color_convert = rgb_rgb_convert;
860
6.53k
    } else
861
1.09k
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
862
15.2k
    break;
863
864
0
  case JCS_RGB565:
865
0
#ifdef D_LOSSLESS_SUPPORTED
866
0
    if (cinfo->master->lossless)
867
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
868
0
#endif
869
0
    cinfo->out_color_components = 3;
870
0
    if (cinfo->dither_mode == JDITHER_NONE) {
871
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
872
#ifdef WITH_SIMD
873
0
        if (jsimd_can_ycc_rgb565())
874
0
          cconvert->pub._color_convert = jsimd_ycc_rgb565_convert;
875
0
        else
876
0
#endif
877
0
        {
878
0
          cconvert->pub._color_convert = ycc_rgb565_convert;
879
0
          build_ycc_rgb_table(cinfo);
880
0
        }
881
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
882
0
        cconvert->pub._color_convert = gray_rgb565_convert;
883
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
884
0
        cconvert->pub._color_convert = rgb_rgb565_convert;
885
0
      } else
886
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
887
0
    } else {
888
      /* only ordered dithering is supported */
889
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
890
0
        cconvert->pub._color_convert = ycc_rgb565D_convert;
891
0
        build_ycc_rgb_table(cinfo);
892
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
893
0
        cconvert->pub._color_convert = gray_rgb565D_convert;
894
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
895
0
        cconvert->pub._color_convert = rgb_rgb565D_convert;
896
0
      } else
897
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
898
0
    }
899
0
    break;
900
901
5.61k
  case JCS_CMYK:
902
5.61k
#ifdef D_LOSSLESS_SUPPORTED
903
5.61k
    if (cinfo->master->lossless &&
904
1.52k
        cinfo->jpeg_color_space != cinfo->out_color_space)
905
1.45k
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
906
5.61k
#endif
907
5.61k
    cinfo->out_color_components = 4;
908
5.61k
    if (cinfo->jpeg_color_space == JCS_YCCK) {
909
45
      cconvert->pub._color_convert = ycck_cmyk_convert;
910
45
      build_ycc_rgb_table(cinfo);
911
5.57k
    } else if (cinfo->jpeg_color_space == JCS_CMYK) {
912
184
      cconvert->pub._color_convert = null_convert;
913
184
    } else
914
5.38k
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
915
5.61k
    break;
916
917
0
  default:
918
    /* Permit null conversion to same output space */
919
0
    if (cinfo->out_color_space == cinfo->jpeg_color_space) {
920
0
      cinfo->out_color_components = cinfo->num_components;
921
0
      cconvert->pub._color_convert = null_convert;
922
0
    } else                      /* unsupported non-null conversion */
923
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
924
0
    break;
925
26.8k
  }
926
927
18.9k
  if (cinfo->quantize_colors)
928
0
    cinfo->output_components = 1; /* single colormapped output component */
929
18.9k
  else
930
18.9k
    cinfo->output_components = cinfo->out_color_components;
931
18.9k
}
j12init_color_deconverter
Line
Count
Source
758
9.58k
{
759
9.58k
  my_cconvert_ptr cconvert;
760
9.58k
  int ci;
761
762
9.58k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
763
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
764
765
9.58k
  cconvert = (my_cconvert_ptr)
766
9.58k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
767
9.58k
                                sizeof(my_color_deconverter));
768
9.58k
  cinfo->cconvert = (struct jpeg_color_deconverter *)cconvert;
769
9.58k
  cconvert->pub.start_pass = start_pass_dcolor;
770
771
  /* Make sure num_components agrees with jpeg_color_space */
772
9.58k
  switch (cinfo->jpeg_color_space) {
773
4.25k
  case JCS_GRAYSCALE:
774
4.25k
    if (cinfo->num_components != 1)
775
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
776
4.25k
    break;
777
778
3.18k
  case JCS_RGB:
779
4.95k
  case JCS_YCbCr:
780
4.95k
    if (cinfo->num_components != 3)
781
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
782
4.95k
    break;
783
784
264
  case JCS_CMYK:
785
352
  case JCS_YCCK:
786
352
    if (cinfo->num_components != 4)
787
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
788
352
    break;
789
790
16
  default:                      /* JCS_UNKNOWN can be anything */
791
16
    if (cinfo->num_components < 1)
792
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
793
16
    break;
794
9.58k
  }
795
796
  /* Set out_color_components and conversion method based on requested space.
797
   * Also clear the component_needed flags for any unused components,
798
   * so that earlier pipeline stages can avoid useless computation.
799
   * NOTE: We do not allow any lossy color conversion algorithms in lossless
800
   * mode.
801
   */
802
803
9.58k
  switch (cinfo->out_color_space) {
804
2.06k
  case JCS_GRAYSCALE:
805
2.06k
#ifdef D_LOSSLESS_SUPPORTED
806
2.06k
    if (cinfo->master->lossless &&
807
527
        cinfo->jpeg_color_space != cinfo->out_color_space)
808
430
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
809
2.06k
#endif
810
2.06k
    cinfo->out_color_components = 1;
811
2.06k
    if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
812
1.53k
        cinfo->jpeg_color_space == JCS_YCbCr) {
813
1.53k
      cconvert->pub._color_convert = grayscale_convert;
814
      /* For color->grayscale conversion, only the Y (0) component is needed */
815
2.44k
      for (ci = 1; ci < cinfo->num_components; ci++)
816
910
        cinfo->comp_info[ci].component_needed = FALSE;
817
1.53k
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
818
42
      cconvert->pub._color_convert = rgb_gray_convert;
819
42
      build_rgb_y_table(cinfo);
820
42
    } else
821
487
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
822
2.06k
    break;
823
824
1.47k
  case JCS_RGB:
825
3.43k
  case JCS_EXT_RGB:
826
3.43k
  case JCS_EXT_RGBX:
827
3.43k
  case JCS_EXT_BGR:
828
5.47k
  case JCS_EXT_BGRX:
829
5.47k
  case JCS_EXT_XBGR:
830
5.47k
  case JCS_EXT_XRGB:
831
5.47k
  case JCS_EXT_RGBA:
832
5.47k
  case JCS_EXT_BGRA:
833
5.47k
  case JCS_EXT_ABGR:
834
5.47k
  case JCS_EXT_ARGB:
835
5.47k
#ifdef D_LOSSLESS_SUPPORTED
836
5.47k
    if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB)
837
241
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
838
5.47k
#endif
839
5.47k
    cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
840
5.47k
    if (cinfo->jpeg_color_space == JCS_YCbCr) {
841
#ifdef WITH_SIMD
842
      if (jsimd_can_ycc_rgb())
843
        cconvert->pub._color_convert = jsimd_ycc_rgb_convert;
844
      else
845
#endif
846
824
      {
847
824
        cconvert->pub._color_convert = ycc_rgb_convert;
848
824
        build_ycc_rgb_table(cinfo);
849
824
      }
850
4.64k
    } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
851
1.97k
      cconvert->pub._color_convert = gray_rgb_convert;
852
2.67k
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
853
2.31k
      if (rgb_red[cinfo->out_color_space] == 0 &&
854
1.88k
          rgb_green[cinfo->out_color_space] == 1 &&
855
1.88k
          rgb_blue[cinfo->out_color_space] == 2 &&
856
1.88k
          rgb_pixelsize[cinfo->out_color_space] == 3)
857
1.88k
        cconvert->pub._color_convert = null_convert;
858
435
      else
859
435
        cconvert->pub._color_convert = rgb_rgb_convert;
860
2.31k
    } else
861
355
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
862
5.47k
    break;
863
864
0
  case JCS_RGB565:
865
0
#ifdef D_LOSSLESS_SUPPORTED
866
0
    if (cinfo->master->lossless)
867
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
868
0
#endif
869
0
    cinfo->out_color_components = 3;
870
0
    if (cinfo->dither_mode == JDITHER_NONE) {
871
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
872
#ifdef WITH_SIMD
873
        if (jsimd_can_ycc_rgb565())
874
          cconvert->pub._color_convert = jsimd_ycc_rgb565_convert;
875
        else
876
#endif
877
0
        {
878
0
          cconvert->pub._color_convert = ycc_rgb565_convert;
879
0
          build_ycc_rgb_table(cinfo);
880
0
        }
881
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
882
0
        cconvert->pub._color_convert = gray_rgb565_convert;
883
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
884
0
        cconvert->pub._color_convert = rgb_rgb565_convert;
885
0
      } else
886
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
887
0
    } else {
888
      /* only ordered dithering is supported */
889
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
890
0
        cconvert->pub._color_convert = ycc_rgb565D_convert;
891
0
        build_ycc_rgb_table(cinfo);
892
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
893
0
        cconvert->pub._color_convert = gray_rgb565D_convert;
894
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
895
0
        cconvert->pub._color_convert = rgb_rgb565D_convert;
896
0
      } else
897
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
898
0
    }
899
0
    break;
900
901
2.04k
  case JCS_CMYK:
902
2.04k
#ifdef D_LOSSLESS_SUPPORTED
903
2.04k
    if (cinfo->master->lossless &&
904
500
        cinfo->jpeg_color_space != cinfo->out_color_space)
905
467
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
906
2.04k
#endif
907
2.04k
    cinfo->out_color_components = 4;
908
2.04k
    if (cinfo->jpeg_color_space == JCS_YCCK) {
909
22
      cconvert->pub._color_convert = ycck_cmyk_convert;
910
22
      build_ycc_rgb_table(cinfo);
911
2.01k
    } else if (cinfo->jpeg_color_space == JCS_CMYK) {
912
66
      cconvert->pub._color_convert = null_convert;
913
66
    } else
914
1.95k
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
915
2.04k
    break;
916
917
0
  default:
918
    /* Permit null conversion to same output space */
919
0
    if (cinfo->out_color_space == cinfo->jpeg_color_space) {
920
0
      cinfo->out_color_components = cinfo->num_components;
921
0
      cconvert->pub._color_convert = null_convert;
922
0
    } else                      /* unsupported non-null conversion */
923
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
924
0
    break;
925
9.58k
  }
926
927
6.78k
  if (cinfo->quantize_colors)
928
0
    cinfo->output_components = 1; /* single colormapped output component */
929
6.78k
  else
930
6.78k
    cinfo->output_components = cinfo->out_color_components;
931
6.78k
}
j16init_color_deconverter
Line
Count
Source
758
3.62k
{
759
3.62k
  my_cconvert_ptr cconvert;
760
3.62k
  int ci;
761
762
3.62k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
763
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
764
765
3.62k
  cconvert = (my_cconvert_ptr)
766
3.62k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
767
3.62k
                                sizeof(my_color_deconverter));
768
3.62k
  cinfo->cconvert = (struct jpeg_color_deconverter *)cconvert;
769
3.62k
  cconvert->pub.start_pass = start_pass_dcolor;
770
771
  /* Make sure num_components agrees with jpeg_color_space */
772
3.62k
  switch (cinfo->jpeg_color_space) {
773
570
  case JCS_GRAYSCALE:
774
570
    if (cinfo->num_components != 1)
775
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
776
570
    break;
777
778
2.85k
  case JCS_RGB:
779
2.91k
  case JCS_YCbCr:
780
2.91k
    if (cinfo->num_components != 3)
781
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
782
2.91k
    break;
783
784
124
  case JCS_CMYK:
785
132
  case JCS_YCCK:
786
132
    if (cinfo->num_components != 4)
787
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
788
132
    break;
789
790
12
  default:                      /* JCS_UNKNOWN can be anything */
791
12
    if (cinfo->num_components < 1)
792
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
793
12
    break;
794
3.62k
  }
795
796
  /* Set out_color_components and conversion method based on requested space.
797
   * Also clear the component_needed flags for any unused components,
798
   * so that earlier pipeline stages can avoid useless computation.
799
   * NOTE: We do not allow any lossy color conversion algorithms in lossless
800
   * mode.
801
   */
802
803
3.62k
  switch (cinfo->out_color_space) {
804
613
  case JCS_GRAYSCALE:
805
613
#ifdef D_LOSSLESS_SUPPORTED
806
613
    if (cinfo->master->lossless &&
807
579
        cinfo->jpeg_color_space != cinfo->out_color_space)
808
409
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
809
613
#endif
810
613
    cinfo->out_color_components = 1;
811
613
    if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
812
186
        cinfo->jpeg_color_space == JCS_YCbCr) {
813
186
      cconvert->pub._color_convert = grayscale_convert;
814
      /* For color->grayscale conversion, only the Y (0) component is needed */
815
210
      for (ci = 1; ci < cinfo->num_components; ci++)
816
24
        cinfo->comp_info[ci].component_needed = FALSE;
817
427
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
818
4
      cconvert->pub._color_convert = rgb_gray_convert;
819
4
      build_rgb_y_table(cinfo);
820
4
    } else
821
423
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
822
613
    break;
823
824
1.29k
  case JCS_RGB:
825
1.86k
  case JCS_EXT_RGB:
826
1.86k
  case JCS_EXT_RGBX:
827
1.86k
  case JCS_EXT_BGR:
828
2.44k
  case JCS_EXT_BGRX:
829
2.44k
  case JCS_EXT_XBGR:
830
2.44k
  case JCS_EXT_XRGB:
831
2.44k
  case JCS_EXT_RGBA:
832
2.44k
  case JCS_EXT_BGRA:
833
2.44k
  case JCS_EXT_ABGR:
834
2.44k
  case JCS_EXT_ARGB:
835
2.44k
#ifdef D_LOSSLESS_SUPPORTED
836
2.44k
    if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB)
837
311
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
838
2.44k
#endif
839
2.44k
    cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
840
2.44k
    if (cinfo->jpeg_color_space == JCS_YCbCr) {
841
#ifdef WITH_SIMD
842
      if (jsimd_can_ycc_rgb())
843
        cconvert->pub._color_convert = jsimd_ycc_rgb_convert;
844
      else
845
#endif
846
23
      {
847
23
        cconvert->pub._color_convert = ycc_rgb_convert;
848
23
        build_ycc_rgb_table(cinfo);
849
23
      }
850
2.41k
    } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
851
8
      cconvert->pub._color_convert = gray_rgb_convert;
852
2.40k
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
853
2.07k
      if (rgb_red[cinfo->out_color_space] == 0 &&
854
1.68k
          rgb_green[cinfo->out_color_space] == 1 &&
855
1.68k
          rgb_blue[cinfo->out_color_space] == 2 &&
856
1.68k
          rgb_pixelsize[cinfo->out_color_space] == 3)
857
1.68k
        cconvert->pub._color_convert = null_convert;
858
390
      else
859
390
        cconvert->pub._color_convert = rgb_rgb_convert;
860
2.07k
    } else
861
339
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
862
2.44k
    break;
863
864
0
  case JCS_RGB565:
865
0
#ifdef D_LOSSLESS_SUPPORTED
866
0
    if (cinfo->master->lossless)
867
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
868
0
#endif
869
0
    cinfo->out_color_components = 3;
870
0
    if (cinfo->dither_mode == JDITHER_NONE) {
871
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
872
#ifdef WITH_SIMD
873
        if (jsimd_can_ycc_rgb565())
874
          cconvert->pub._color_convert = jsimd_ycc_rgb565_convert;
875
        else
876
#endif
877
0
        {
878
0
          cconvert->pub._color_convert = ycc_rgb565_convert;
879
0
          build_ycc_rgb_table(cinfo);
880
0
        }
881
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
882
0
        cconvert->pub._color_convert = gray_rgb565_convert;
883
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
884
0
        cconvert->pub._color_convert = rgb_rgb565_convert;
885
0
      } else
886
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
887
0
    } else {
888
      /* only ordered dithering is supported */
889
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
890
0
        cconvert->pub._color_convert = ycc_rgb565D_convert;
891
0
        build_ycc_rgb_table(cinfo);
892
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
893
0
        cconvert->pub._color_convert = gray_rgb565D_convert;
894
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
895
0
        cconvert->pub._color_convert = rgb_rgb565D_convert;
896
0
      } else
897
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
898
0
    }
899
0
    break;
900
901
571
  case JCS_CMYK:
902
571
#ifdef D_LOSSLESS_SUPPORTED
903
571
    if (cinfo->master->lossless &&
904
537
        cinfo->jpeg_color_space != cinfo->out_color_space)
905
518
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
906
571
#endif
907
571
    cinfo->out_color_components = 4;
908
571
    if (cinfo->jpeg_color_space == JCS_YCCK) {
909
1
      cconvert->pub._color_convert = ycck_cmyk_convert;
910
1
      build_ycc_rgb_table(cinfo);
911
570
    } else if (cinfo->jpeg_color_space == JCS_CMYK) {
912
31
      cconvert->pub._color_convert = null_convert;
913
31
    } else
914
539
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
915
571
    break;
916
917
0
  default:
918
    /* Permit null conversion to same output space */
919
0
    if (cinfo->out_color_space == cinfo->jpeg_color_space) {
920
0
      cinfo->out_color_components = cinfo->num_components;
921
0
      cconvert->pub._color_convert = null_convert;
922
0
    } else                      /* unsupported non-null conversion */
923
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
924
0
    break;
925
3.62k
  }
926
927
2.29k
  if (cinfo->quantize_colors)
928
0
    cinfo->output_components = 1; /* single colormapped output component */
929
2.29k
  else
930
2.29k
    cinfo->output_components = cinfo->out_color_components;
931
2.29k
}
jinit_color_deconverter
Line
Count
Source
758
13.6k
{
759
13.6k
  my_cconvert_ptr cconvert;
760
13.6k
  int ci;
761
762
13.6k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
763
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
764
765
13.6k
  cconvert = (my_cconvert_ptr)
766
13.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
767
13.6k
                                sizeof(my_color_deconverter));
768
13.6k
  cinfo->cconvert = (struct jpeg_color_deconverter *)cconvert;
769
13.6k
  cconvert->pub.start_pass = start_pass_dcolor;
770
771
  /* Make sure num_components agrees with jpeg_color_space */
772
13.6k
  switch (cinfo->jpeg_color_space) {
773
5.86k
  case JCS_GRAYSCALE:
774
5.86k
    if (cinfo->num_components != 1)
775
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
776
5.86k
    break;
777
778
2.99k
  case JCS_RGB:
779
7.33k
  case JCS_YCbCr:
780
7.33k
    if (cinfo->num_components != 3)
781
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
782
7.33k
    break;
783
784
348
  case JCS_CMYK:
785
440
  case JCS_YCCK:
786
440
    if (cinfo->num_components != 4)
787
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
788
440
    break;
789
790
36
  default:                      /* JCS_UNKNOWN can be anything */
791
36
    if (cinfo->num_components < 1)
792
0
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
793
36
    break;
794
13.6k
  }
795
796
  /* Set out_color_components and conversion method based on requested space.
797
   * Also clear the component_needed flags for any unused components,
798
   * so that earlier pipeline stages can avoid useless computation.
799
   * NOTE: We do not allow any lossy color conversion algorithms in lossless
800
   * mode.
801
   */
802
803
13.6k
  switch (cinfo->out_color_space) {
804
3.32k
  case JCS_GRAYSCALE:
805
3.32k
#ifdef D_LOSSLESS_SUPPORTED
806
3.32k
    if (cinfo->master->lossless &&
807
586
        cinfo->jpeg_color_space != cinfo->out_color_space)
808
405
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
809
3.32k
#endif
810
3.32k
    cinfo->out_color_components = 1;
811
3.32k
    if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
812
2.76k
        cinfo->jpeg_color_space == JCS_YCbCr) {
813
2.76k
      cconvert->pub._color_convert = grayscale_convert;
814
      /* For color->grayscale conversion, only the Y (0) component is needed */
815
5.17k
      for (ci = 1; ci < cinfo->num_components; ci++)
816
2.40k
        cinfo->comp_info[ci].component_needed = FALSE;
817
2.76k
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
818
55
      cconvert->pub._color_convert = rgb_gray_convert;
819
55
      build_rgb_y_table(cinfo);
820
55
    } else
821
503
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
822
3.32k
    break;
823
824
1.27k
  case JCS_RGB:
825
4.01k
  case JCS_EXT_RGB:
826
4.01k
  case JCS_EXT_RGBX:
827
4.18k
  case JCS_EXT_BGR:
828
7.18k
  case JCS_EXT_BGRX:
829
7.18k
  case JCS_EXT_XBGR:
830
7.33k
  case JCS_EXT_XRGB:
831
7.33k
  case JCS_EXT_RGBA:
832
7.33k
  case JCS_EXT_BGRA:
833
7.33k
  case JCS_EXT_ABGR:
834
7.33k
  case JCS_EXT_ARGB:
835
7.33k
#ifdef D_LOSSLESS_SUPPORTED
836
7.33k
    if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB)
837
207
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
838
7.33k
#endif
839
7.33k
    cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
840
7.33k
    if (cinfo->jpeg_color_space == JCS_YCbCr) {
841
2.01k
#ifdef WITH_SIMD
842
2.01k
      if (jsimd_can_ycc_rgb())
843
2.01k
        cconvert->pub._color_convert = jsimd_ycc_rgb_convert;
844
0
      else
845
0
#endif
846
0
      {
847
0
        cconvert->pub._color_convert = ycc_rgb_convert;
848
0
        build_ycc_rgb_table(cinfo);
849
0
      }
850
5.32k
    } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
851
2.77k
      cconvert->pub._color_convert = gray_rgb_convert;
852
2.77k
    } else if (cinfo->jpeg_color_space == JCS_RGB) {
853
2.14k
      if (rgb_red[cinfo->out_color_space] == 0 &&
854
1.68k
          rgb_green[cinfo->out_color_space] == 1 &&
855
1.68k
          rgb_blue[cinfo->out_color_space] == 2 &&
856
1.68k
          rgb_pixelsize[cinfo->out_color_space] == 3)
857
1.68k
        cconvert->pub._color_convert = null_convert;
858
466
      else
859
466
        cconvert->pub._color_convert = rgb_rgb_convert;
860
2.14k
    } else
861
403
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
862
7.33k
    break;
863
864
0
  case JCS_RGB565:
865
0
#ifdef D_LOSSLESS_SUPPORTED
866
0
    if (cinfo->master->lossless)
867
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
868
0
#endif
869
0
    cinfo->out_color_components = 3;
870
0
    if (cinfo->dither_mode == JDITHER_NONE) {
871
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
872
0
#ifdef WITH_SIMD
873
0
        if (jsimd_can_ycc_rgb565())
874
0
          cconvert->pub._color_convert = jsimd_ycc_rgb565_convert;
875
0
        else
876
0
#endif
877
0
        {
878
0
          cconvert->pub._color_convert = ycc_rgb565_convert;
879
0
          build_ycc_rgb_table(cinfo);
880
0
        }
881
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
882
0
        cconvert->pub._color_convert = gray_rgb565_convert;
883
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
884
0
        cconvert->pub._color_convert = rgb_rgb565_convert;
885
0
      } else
886
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
887
0
    } else {
888
      /* only ordered dithering is supported */
889
0
      if (cinfo->jpeg_color_space == JCS_YCbCr) {
890
0
        cconvert->pub._color_convert = ycc_rgb565D_convert;
891
0
        build_ycc_rgb_table(cinfo);
892
0
      } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
893
0
        cconvert->pub._color_convert = gray_rgb565D_convert;
894
0
      } else if (cinfo->jpeg_color_space == JCS_RGB) {
895
0
        cconvert->pub._color_convert = rgb_rgb565D_convert;
896
0
      } else
897
0
        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
898
0
    }
899
0
    break;
900
901
3.00k
  case JCS_CMYK:
902
3.00k
#ifdef D_LOSSLESS_SUPPORTED
903
3.00k
    if (cinfo->master->lossless &&
904
484
        cinfo->jpeg_color_space != cinfo->out_color_space)
905
465
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
906
3.00k
#endif
907
3.00k
    cinfo->out_color_components = 4;
908
3.00k
    if (cinfo->jpeg_color_space == JCS_YCCK) {
909
22
      cconvert->pub._color_convert = ycck_cmyk_convert;
910
22
      build_ycc_rgb_table(cinfo);
911
2.98k
    } else if (cinfo->jpeg_color_space == JCS_CMYK) {
912
87
      cconvert->pub._color_convert = null_convert;
913
87
    } else
914
2.89k
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
915
3.00k
    break;
916
917
0
  default:
918
    /* Permit null conversion to same output space */
919
0
    if (cinfo->out_color_space == cinfo->jpeg_color_space) {
920
0
      cinfo->out_color_components = cinfo->num_components;
921
0
      cconvert->pub._color_convert = null_convert;
922
0
    } else                      /* unsupported non-null conversion */
923
0
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
924
0
    break;
925
13.6k
  }
926
927
9.86k
  if (cinfo->quantize_colors)
928
0
    cinfo->output_components = 1; /* single colormapped output component */
929
9.86k
  else
930
9.86k
    cinfo->output_components = cinfo->out_color_components;
931
9.86k
}
932
933
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */