Coverage Report

Created: 2026-03-12 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/jdmaster.c
Line
Count
Source
1
/*
2
 * jdmaster.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
6
 * Modified 2002-2009 by Guido Vollbeding.
7
 * Lossless JPEG Modifications:
8
 * Copyright (C) 1999, Ken Murchison.
9
 * libjpeg-turbo Modifications:
10
 * Copyright (C) 2009-2011, 2016, 2019, 2022-2024, D. R. Commander.
11
 * Copyright (C) 2013, Linaro Limited.
12
 * Copyright (C) 2015, Google, Inc.
13
 * For conditions of distribution and use, see the accompanying README.ijg
14
 * file.
15
 *
16
 * This file contains master control logic for the JPEG decompressor.
17
 * These routines are concerned with selecting the modules to be executed
18
 * and with determining the number of passes and the work to be done in each
19
 * pass.
20
 */
21
22
#define JPEG_INTERNALS
23
#include "jinclude.h"
24
#include "jpeglib.h"
25
#include "jpegapicomp.h"
26
#include "jdmaster.h"
27
#ifdef WITH_PROFILE
28
#include "tjutil.h"
29
#endif
30
31
32
/*
33
 * Determine whether merged upsample/color conversion should be used.
34
 * CRUCIAL: this must match the actual capabilities of jdmerge.c!
35
 */
36
37
LOCAL(boolean)
38
use_merged_upsample(j_decompress_ptr cinfo)
39
48.3k
{
40
48.3k
#ifdef UPSAMPLE_MERGING_SUPPORTED
41
  /* Colorspace conversion is not supported with lossless JPEG images */
42
48.3k
  if (cinfo->master->lossless)
43
12.1k
    return FALSE;
44
  /* Merging is the equivalent of plain box-filter upsampling */
45
36.1k
  if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
46
28.1k
    return FALSE;
47
  /* jdmerge.c only supports YCC=>RGB and YCC=>RGB565 color conversion */
48
8.01k
  if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
49
3.48k
      (cinfo->out_color_space != JCS_RGB &&
50
608
       cinfo->out_color_space != JCS_RGB565 &&
51
608
       cinfo->out_color_space != JCS_EXT_RGB &&
52
608
       cinfo->out_color_space != JCS_EXT_RGBX &&
53
608
       cinfo->out_color_space != JCS_EXT_BGR &&
54
444
       cinfo->out_color_space != JCS_EXT_BGRX &&
55
444
       cinfo->out_color_space != JCS_EXT_XBGR &&
56
444
       cinfo->out_color_space != JCS_EXT_XRGB &&
57
296
       cinfo->out_color_space != JCS_EXT_RGBA &&
58
148
       cinfo->out_color_space != JCS_EXT_BGRA &&
59
148
       cinfo->out_color_space != JCS_EXT_ABGR &&
60
148
       cinfo->out_color_space != JCS_EXT_ARGB))
61
4.68k
    return FALSE;
62
3.33k
  if ((cinfo->out_color_space == JCS_RGB565 &&
63
0
       cinfo->out_color_components != 3) ||
64
3.33k
      (cinfo->out_color_space != JCS_RGB565 &&
65
3.33k
       cinfo->out_color_components != rgb_pixelsize[cinfo->out_color_space]))
66
0
    return FALSE;
67
  /* and it only handles 2h1v or 2h2v sampling ratios */
68
3.33k
  if (cinfo->comp_info[0].h_samp_factor != 2 ||
69
2.82k
      cinfo->comp_info[1].h_samp_factor != 1 ||
70
2.59k
      cinfo->comp_info[2].h_samp_factor != 1 ||
71
2.59k
      cinfo->comp_info[0].v_samp_factor >  2 ||
72
2.59k
      cinfo->comp_info[1].v_samp_factor != 1 ||
73
2.57k
      cinfo->comp_info[2].v_samp_factor != 1)
74
758
    return FALSE;
75
  /* furthermore, it doesn't work if we've scaled the IDCTs differently */
76
2.57k
  if (cinfo->comp_info[0]._DCT_scaled_size != cinfo->_min_DCT_scaled_size ||
77
2.57k
      cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size ||
78
2.57k
      cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size)
79
0
    return FALSE;
80
  /* ??? also need to test for upsample-time rescaling, when & if supported */
81
2.57k
  return TRUE;                  /* by golly, it'll work... */
82
#else
83
  return FALSE;
84
#endif
85
2.57k
}
86
87
88
/*
89
 * Compute output image dimensions and related values.
90
 * NOTE: this is exported for possible use by application.
91
 * Hence it mustn't do anything that can't be done twice.
92
 */
93
94
#if JPEG_LIB_VERSION >= 80
95
GLOBAL(void)
96
#else
97
LOCAL(void)
98
#endif
99
jpeg_core_output_dimensions(j_decompress_ptr cinfo)
100
/* Do computations that are needed before master selection phase.
101
 * This function is used for transcoding and full decompression.
102
 */
103
31.9k
{
104
31.9k
#ifdef IDCT_SCALING_SUPPORTED
105
31.9k
  int ci;
106
31.9k
  jpeg_component_info *compptr;
107
108
31.9k
  if (!cinfo->master->lossless) {
109
    /* Compute actual output image dimensions and DCT scaling choices. */
110
23.8k
    if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) {
111
      /* Provide 1/block_size scaling */
112
0
      cinfo->output_width = (JDIMENSION)
113
0
        jdiv_round_up((long)cinfo->image_width, (long)DCTSIZE);
114
0
      cinfo->output_height = (JDIMENSION)
115
0
        jdiv_round_up((long)cinfo->image_height, (long)DCTSIZE);
116
0
      cinfo->_min_DCT_h_scaled_size = 1;
117
0
      cinfo->_min_DCT_v_scaled_size = 1;
118
23.8k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) {
119
      /* Provide 2/block_size scaling */
120
5.52k
      cinfo->output_width = (JDIMENSION)
121
5.52k
        jdiv_round_up((long)cinfo->image_width * 2L, (long)DCTSIZE);
122
5.52k
      cinfo->output_height = (JDIMENSION)
123
5.52k
        jdiv_round_up((long)cinfo->image_height * 2L, (long)DCTSIZE);
124
5.52k
      cinfo->_min_DCT_h_scaled_size = 2;
125
5.52k
      cinfo->_min_DCT_v_scaled_size = 2;
126
18.3k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) {
127
      /* Provide 3/block_size scaling */
128
0
      cinfo->output_width = (JDIMENSION)
129
0
        jdiv_round_up((long)cinfo->image_width * 3L, (long)DCTSIZE);
130
0
      cinfo->output_height = (JDIMENSION)
131
0
        jdiv_round_up((long)cinfo->image_height * 3L, (long)DCTSIZE);
132
0
      cinfo->_min_DCT_h_scaled_size = 3;
133
0
      cinfo->_min_DCT_v_scaled_size = 3;
134
18.3k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) {
135
      /* Provide 4/block_size scaling */
136
0
      cinfo->output_width = (JDIMENSION)
137
0
        jdiv_round_up((long)cinfo->image_width * 4L, (long)DCTSIZE);
138
0
      cinfo->output_height = (JDIMENSION)
139
0
        jdiv_round_up((long)cinfo->image_height * 4L, (long)DCTSIZE);
140
0
      cinfo->_min_DCT_h_scaled_size = 4;
141
0
      cinfo->_min_DCT_v_scaled_size = 4;
142
18.3k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) {
143
      /* Provide 5/block_size scaling */
144
0
      cinfo->output_width = (JDIMENSION)
145
0
        jdiv_round_up((long)cinfo->image_width * 5L, (long)DCTSIZE);
146
0
      cinfo->output_height = (JDIMENSION)
147
0
        jdiv_round_up((long)cinfo->image_height * 5L, (long)DCTSIZE);
148
0
      cinfo->_min_DCT_h_scaled_size = 5;
149
0
      cinfo->_min_DCT_v_scaled_size = 5;
150
18.3k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) {
151
      /* Provide 6/block_size scaling */
152
5.52k
      cinfo->output_width = (JDIMENSION)
153
5.52k
        jdiv_round_up((long)cinfo->image_width * 6L, (long)DCTSIZE);
154
5.52k
      cinfo->output_height = (JDIMENSION)
155
5.52k
        jdiv_round_up((long)cinfo->image_height * 6L, (long)DCTSIZE);
156
5.52k
      cinfo->_min_DCT_h_scaled_size = 6;
157
5.52k
      cinfo->_min_DCT_v_scaled_size = 6;
158
12.8k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) {
159
      /* Provide 7/block_size scaling */
160
0
      cinfo->output_width = (JDIMENSION)
161
0
        jdiv_round_up((long)cinfo->image_width * 7L, (long)DCTSIZE);
162
0
      cinfo->output_height = (JDIMENSION)
163
0
        jdiv_round_up((long)cinfo->image_height * 7L, (long)DCTSIZE);
164
0
      cinfo->_min_DCT_h_scaled_size = 7;
165
0
      cinfo->_min_DCT_v_scaled_size = 7;
166
12.8k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) {
167
      /* Provide 8/block_size scaling */
168
12.8k
      cinfo->output_width = (JDIMENSION)
169
12.8k
        jdiv_round_up((long)cinfo->image_width * 8L, (long)DCTSIZE);
170
12.8k
      cinfo->output_height = (JDIMENSION)
171
12.8k
        jdiv_round_up((long)cinfo->image_height * 8L, (long)DCTSIZE);
172
12.8k
      cinfo->_min_DCT_h_scaled_size = 8;
173
12.8k
      cinfo->_min_DCT_v_scaled_size = 8;
174
12.8k
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) {
175
      /* Provide 9/block_size scaling */
176
0
      cinfo->output_width = (JDIMENSION)
177
0
        jdiv_round_up((long)cinfo->image_width * 9L, (long)DCTSIZE);
178
0
      cinfo->output_height = (JDIMENSION)
179
0
        jdiv_round_up((long)cinfo->image_height * 9L, (long)DCTSIZE);
180
0
      cinfo->_min_DCT_h_scaled_size = 9;
181
0
      cinfo->_min_DCT_v_scaled_size = 9;
182
0
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) {
183
      /* Provide 10/block_size scaling */
184
0
      cinfo->output_width = (JDIMENSION)
185
0
        jdiv_round_up((long)cinfo->image_width * 10L, (long)DCTSIZE);
186
0
      cinfo->output_height = (JDIMENSION)
187
0
        jdiv_round_up((long)cinfo->image_height * 10L, (long)DCTSIZE);
188
0
      cinfo->_min_DCT_h_scaled_size = 10;
189
0
      cinfo->_min_DCT_v_scaled_size = 10;
190
0
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) {
191
      /* Provide 11/block_size scaling */
192
0
      cinfo->output_width = (JDIMENSION)
193
0
        jdiv_round_up((long)cinfo->image_width * 11L, (long)DCTSIZE);
194
0
      cinfo->output_height = (JDIMENSION)
195
0
        jdiv_round_up((long)cinfo->image_height * 11L, (long)DCTSIZE);
196
0
      cinfo->_min_DCT_h_scaled_size = 11;
197
0
      cinfo->_min_DCT_v_scaled_size = 11;
198
0
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) {
199
      /* Provide 12/block_size scaling */
200
0
      cinfo->output_width = (JDIMENSION)
201
0
        jdiv_round_up((long)cinfo->image_width * 12L, (long)DCTSIZE);
202
0
      cinfo->output_height = (JDIMENSION)
203
0
        jdiv_round_up((long)cinfo->image_height * 12L, (long)DCTSIZE);
204
0
      cinfo->_min_DCT_h_scaled_size = 12;
205
0
      cinfo->_min_DCT_v_scaled_size = 12;
206
0
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) {
207
      /* Provide 13/block_size scaling */
208
0
      cinfo->output_width = (JDIMENSION)
209
0
        jdiv_round_up((long)cinfo->image_width * 13L, (long)DCTSIZE);
210
0
      cinfo->output_height = (JDIMENSION)
211
0
        jdiv_round_up((long)cinfo->image_height * 13L, (long)DCTSIZE);
212
0
      cinfo->_min_DCT_h_scaled_size = 13;
213
0
      cinfo->_min_DCT_v_scaled_size = 13;
214
0
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) {
215
      /* Provide 14/block_size scaling */
216
0
      cinfo->output_width = (JDIMENSION)
217
0
        jdiv_round_up((long)cinfo->image_width * 14L, (long)DCTSIZE);
218
0
      cinfo->output_height = (JDIMENSION)
219
0
        jdiv_round_up((long)cinfo->image_height * 14L, (long)DCTSIZE);
220
0
      cinfo->_min_DCT_h_scaled_size = 14;
221
0
      cinfo->_min_DCT_v_scaled_size = 14;
222
0
    } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) {
223
      /* Provide 15/block_size scaling */
224
0
      cinfo->output_width = (JDIMENSION)
225
0
        jdiv_round_up((long)cinfo->image_width * 15L, (long)DCTSIZE);
226
0
      cinfo->output_height = (JDIMENSION)
227
0
        jdiv_round_up((long)cinfo->image_height * 15L, (long)DCTSIZE);
228
0
      cinfo->_min_DCT_h_scaled_size = 15;
229
0
      cinfo->_min_DCT_v_scaled_size = 15;
230
0
    } else {
231
      /* Provide 16/block_size scaling */
232
0
      cinfo->output_width = (JDIMENSION)
233
0
        jdiv_round_up((long)cinfo->image_width * 16L, (long)DCTSIZE);
234
0
      cinfo->output_height = (JDIMENSION)
235
0
        jdiv_round_up((long)cinfo->image_height * 16L, (long)DCTSIZE);
236
0
      cinfo->_min_DCT_h_scaled_size = 16;
237
0
      cinfo->_min_DCT_v_scaled_size = 16;
238
0
    }
239
240
    /* Recompute dimensions of components */
241
67.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
242
43.5k
         ci++, compptr++) {
243
43.5k
      compptr->_DCT_h_scaled_size = cinfo->_min_DCT_h_scaled_size;
244
43.5k
      compptr->_DCT_v_scaled_size = cinfo->_min_DCT_v_scaled_size;
245
43.5k
    }
246
23.8k
  } else
247
8.11k
#endif /* !IDCT_SCALING_SUPPORTED */
248
8.11k
  {
249
    /* Hardwire it to "no scaling" */
250
8.11k
    cinfo->output_width = cinfo->image_width;
251
8.11k
    cinfo->output_height = cinfo->image_height;
252
    /* jdinput.c has already initialized DCT_scaled_size,
253
     * and has computed unscaled downsampled_width and downsampled_height.
254
     */
255
8.11k
  }
256
31.9k
}
257
258
259
/*
260
 * Compute output image dimensions and related values.
261
 * NOTE: this is exported for possible use by application.
262
 * Hence it mustn't do anything that can't be done twice.
263
 * Also note that it may be called before the master module is initialized!
264
 */
265
266
GLOBAL(void)
267
jpeg_calc_output_dimensions(j_decompress_ptr cinfo)
268
/* Do computations that are needed before master selection phase */
269
31.9k
{
270
31.9k
#ifdef IDCT_SCALING_SUPPORTED
271
31.9k
  int ci;
272
31.9k
  jpeg_component_info *compptr;
273
31.9k
#endif
274
275
  /* Prevent application from calling me at wrong times */
276
31.9k
  if (cinfo->global_state != DSTATE_READY)
277
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
278
279
  /* Compute core output image dimensions and DCT scaling choices. */
280
31.9k
  jpeg_core_output_dimensions(cinfo);
281
282
31.9k
#ifdef IDCT_SCALING_SUPPORTED
283
284
31.9k
  if (!cinfo->master->lossless) {
285
    /* In selecting the actual DCT scaling for each component, we try to
286
     * scale up the chroma components via IDCT scaling rather than upsampling.
287
     * This saves time if the upsampler gets to use 1:1 scaling.
288
     * Note this code adapts subsampling ratios which are powers of 2.
289
     */
290
67.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
291
43.5k
         ci++, compptr++) {
292
43.5k
      int ssize = cinfo->_min_DCT_scaled_size;
293
49.1k
      while (ssize < DCTSIZE &&
294
22.4k
             ((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
295
22.4k
              (compptr->h_samp_factor * ssize * 2) == 0) &&
296
6.92k
             ((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
297
6.92k
              (compptr->v_samp_factor * ssize * 2) == 0)) {
298
5.62k
        ssize = ssize * 2;
299
5.62k
      }
300
#if JPEG_LIB_VERSION >= 70
301
      compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize;
302
#else
303
43.5k
      compptr->DCT_scaled_size = ssize;
304
43.5k
#endif
305
43.5k
    }
306
307
    /* Recompute downsampled dimensions of components;
308
     * application needs to know these if using raw downsampled data.
309
     */
310
67.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
311
43.5k
         ci++, compptr++) {
312
      /* Size in samples, after IDCT scaling */
313
43.5k
      compptr->downsampled_width = (JDIMENSION)
314
43.5k
        jdiv_round_up((long)cinfo->image_width *
315
43.5k
                      (long)(compptr->h_samp_factor *
316
43.5k
                             compptr->_DCT_scaled_size),
317
43.5k
                      (long)(cinfo->max_h_samp_factor * DCTSIZE));
318
43.5k
      compptr->downsampled_height = (JDIMENSION)
319
43.5k
        jdiv_round_up((long)cinfo->image_height *
320
43.5k
                      (long)(compptr->v_samp_factor *
321
43.5k
                             compptr->_DCT_scaled_size),
322
43.5k
                      (long)(cinfo->max_v_samp_factor * DCTSIZE));
323
43.5k
    }
324
23.8k
  } else
325
8.11k
#endif /* IDCT_SCALING_SUPPORTED */
326
8.11k
  {
327
    /* Hardwire it to "no scaling" */
328
8.11k
    cinfo->output_width = cinfo->image_width;
329
8.11k
    cinfo->output_height = cinfo->image_height;
330
    /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
331
     * and has computed unscaled downsampled_width and downsampled_height.
332
     */
333
8.11k
  }
334
335
  /* Report number of components in selected colorspace. */
336
  /* Probably this should be in the color conversion module... */
337
31.9k
  switch (cinfo->out_color_space) {
338
14.3k
  case JCS_GRAYSCALE:
339
14.3k
    cinfo->out_color_components = 1;
340
14.3k
    break;
341
17.0k
  case JCS_RGB:
342
17.0k
  case JCS_EXT_RGB:
343
17.0k
  case JCS_EXT_RGBX:
344
17.2k
  case JCS_EXT_BGR:
345
17.2k
  case JCS_EXT_BGRX:
346
17.2k
  case JCS_EXT_XBGR:
347
17.4k
  case JCS_EXT_XRGB:
348
17.6k
  case JCS_EXT_RGBA:
349
17.6k
  case JCS_EXT_BGRA:
350
17.6k
  case JCS_EXT_ABGR:
351
17.6k
  case JCS_EXT_ARGB:
352
17.6k
    cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
353
17.6k
    break;
354
0
  case JCS_YCbCr:
355
0
  case JCS_RGB565:
356
0
    cinfo->out_color_components = 3;
357
0
    break;
358
0
  case JCS_CMYK:
359
0
  case JCS_YCCK:
360
0
    cinfo->out_color_components = 4;
361
0
    break;
362
0
  default:                      /* else must be same colorspace as in file */
363
0
    cinfo->out_color_components = cinfo->num_components;
364
0
    break;
365
31.9k
  }
366
31.9k
  cinfo->output_components = (cinfo->quantize_colors ? 1 :
367
31.9k
                              cinfo->out_color_components);
368
369
  /* See if upsampler will want to emit more than one row at a time */
370
31.9k
  if (use_merged_upsample(cinfo))
371
1.28k
    cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
372
30.7k
  else
373
30.7k
    cinfo->rec_outbuf_height = 1;
374
31.9k
}
375
376
377
/*
378
 * Several decompression processes need to range-limit values to the range
379
 * 0..MAXJSAMPLE; the input value may fall somewhat outside this range
380
 * due to noise introduced by quantization, roundoff error, etc.  These
381
 * processes are inner loops and need to be as fast as possible.  On most
382
 * machines, particularly CPUs with pipelines or instruction prefetch,
383
 * a (subscript-check-less) C table lookup
384
 *              x = sample_range_limit[x];
385
 * is faster than explicit tests
386
 *              if (x < 0)  x = 0;
387
 *              else if (x > MAXJSAMPLE)  x = MAXJSAMPLE;
388
 * These processes all use a common table prepared by the routine below.
389
 *
390
 * For most steps we can mathematically guarantee that the initial value
391
 * of x is within MAXJSAMPLE+1 of the legal range, so a table running from
392
 * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient.  But for the initial
393
 * limiting step (just after the IDCT), a wildly out-of-range value is
394
 * possible if the input data is corrupt.  To avoid any chance of indexing
395
 * off the end of memory and getting a bad-pointer trap, we perform the
396
 * post-IDCT limiting thus:
397
 *              x = range_limit[x & MASK];
398
 * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
399
 * samples.  Under normal circumstances this is more than enough range and
400
 * a correct output will be generated; with bogus input data the mask will
401
 * cause wraparound, and we will safely generate a bogus-but-in-range output.
402
 * For the post-IDCT step, we want to convert the data from signed to unsigned
403
 * representation by adding CENTERJSAMPLE at the same time that we limit it.
404
 * So the post-IDCT limiting table ends up looking like this:
405
 *   CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
406
 *   MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
407
 *   0          (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
408
 *   0,1,...,CENTERJSAMPLE-1
409
 * Negative inputs select values from the upper half of the table after
410
 * masking.
411
 *
412
 * We can save some space by overlapping the start of the post-IDCT table
413
 * with the simpler range limiting table.  The post-IDCT table begins at
414
 * sample_range_limit + CENTERJSAMPLE.
415
 */
416
417
LOCAL(void)
418
prepare_range_limit_table(j_decompress_ptr cinfo)
419
/* Allocate and fill in the sample_range_limit table */
420
16.3k
{
421
16.3k
  JSAMPLE *table;
422
16.3k
  J12SAMPLE *table12;
423
16.3k
#ifdef D_LOSSLESS_SUPPORTED
424
16.3k
  J16SAMPLE *table16;
425
16.3k
#endif
426
16.3k
  int i;
427
428
16.3k
  if (cinfo->data_precision <= 8) {
429
12.7k
    table = (JSAMPLE *)
430
12.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
431
12.7k
                  (5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
432
12.7k
    table += (MAXJSAMPLE + 1);  /* allow negative subscripts of simple table */
433
12.7k
    cinfo->sample_range_limit = table;
434
    /* First segment of "simple" table: limit[x] = 0 for x < 0 */
435
12.7k
    memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE));
436
    /* Main part of "simple" table: limit[x] = x */
437
3.27M
    for (i = 0; i <= MAXJSAMPLE; i++)
438
3.26M
      table[i] = (JSAMPLE)i;
439
12.7k
    table += CENTERJSAMPLE;     /* Point to where post-IDCT table starts */
440
    /* End of simple table, rest of first half of post-IDCT table */
441
4.91M
    for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
442
4.89M
      table[i] = MAXJSAMPLE;
443
    /* Second half of post-IDCT table */
444
12.7k
    memset(table + (2 * (MAXJSAMPLE + 1)), 0,
445
12.7k
           (2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
446
12.7k
    memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
447
12.7k
           cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
448
12.7k
  } else if (cinfo->data_precision <= 12) {
449
2.32k
    table12 = (J12SAMPLE *)
450
2.32k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
451
2.32k
                  (5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) *
452
2.32k
                  sizeof(J12SAMPLE));
453
2.32k
    table12 += (MAXJ12SAMPLE + 1);  /* allow negative subscripts of simple
454
                                       table */
455
2.32k
    cinfo->sample_range_limit = (JSAMPLE *)table12;
456
    /* First segment of "simple" table: limit[x] = 0 for x < 0 */
457
2.32k
    memset(table12 - (MAXJ12SAMPLE + 1), 0,
458
2.32k
           (MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE));
459
    /* Main part of "simple" table: limit[x] = x */
460
9.54M
    for (i = 0; i <= MAXJ12SAMPLE; i++)
461
9.53M
      table12[i] = (J12SAMPLE)i;
462
2.32k
    table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */
463
    /* End of simple table, rest of first half of post-IDCT table */
464
14.3M
    for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++)
465
14.3M
      table12[i] = MAXJ12SAMPLE;
466
    /* Second half of post-IDCT table */
467
2.32k
    memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0,
468
2.32k
           (2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE));
469
2.32k
    memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE),
470
2.32k
           cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE));
471
2.32k
  } else {
472
1.27k
#ifdef D_LOSSLESS_SUPPORTED
473
1.27k
    table16 = (J16SAMPLE *)
474
1.27k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
475
1.27k
                  (5 * (MAXJ16SAMPLE + 1) + CENTERJ16SAMPLE) *
476
1.27k
                  sizeof(J16SAMPLE));
477
1.27k
    table16 += (MAXJ16SAMPLE + 1);  /* allow negative subscripts of simple
478
                                       table */
479
1.27k
    cinfo->sample_range_limit = (JSAMPLE *)table16;
480
    /* First segment of "simple" table: limit[x] = 0 for x < 0 */
481
1.27k
    memset(table16 - (MAXJ16SAMPLE + 1), 0,
482
1.27k
           (MAXJ16SAMPLE + 1) * sizeof(J16SAMPLE));
483
    /* Main part of "simple" table: limit[x] = x */
484
83.2M
    for (i = 0; i <= MAXJ16SAMPLE; i++)
485
83.2M
      table16[i] = (J16SAMPLE)i;
486
1.27k
    table16 += CENTERJ16SAMPLE; /* Point to where post-IDCT table starts */
487
    /* End of simple table, rest of first half of post-IDCT table */
488
124M
    for (i = CENTERJ16SAMPLE; i < 2 * (MAXJ16SAMPLE + 1); i++)
489
124M
      table16[i] = MAXJ16SAMPLE;
490
    /* Second half of post-IDCT table */
491
1.27k
    memset(table16 + (2 * (MAXJ16SAMPLE + 1)), 0,
492
1.27k
           (2 * (MAXJ16SAMPLE + 1) - CENTERJ16SAMPLE) * sizeof(J16SAMPLE));
493
1.27k
    memcpy(table16 + (4 * (MAXJ16SAMPLE + 1) - CENTERJ16SAMPLE),
494
1.27k
           cinfo->sample_range_limit, CENTERJ16SAMPLE * sizeof(J16SAMPLE));
495
#else
496
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
497
#endif
498
1.27k
  }
499
16.3k
}
500
501
502
/*
503
 * Master selection of decompression modules.
504
 * This is done once at jpeg_start_decompress time.  We determine
505
 * which modules will be used and give them appropriate initialization calls.
506
 * We also initialize the decompressor input side to begin consuming data.
507
 *
508
 * Since jpeg_read_header has finished, we know what is in the SOF
509
 * and (first) SOS markers.  We also have all the application parameter
510
 * settings.
511
 */
512
513
LOCAL(void)
514
master_selection(j_decompress_ptr cinfo)
515
16.3k
{
516
16.3k
  my_master_ptr master = (my_master_ptr)cinfo->master;
517
16.3k
  boolean use_c_buffer;
518
16.3k
  long samplesperrow;
519
16.3k
  JDIMENSION jd_samplesperrow;
520
521
  /* Disable IDCT scaling and raw (downsampled) data output in lossless mode.
522
   * IDCT scaling is not useful in lossless mode, and it must be disabled in
523
   * order to properly calculate the output dimensions.  Raw data output isn't
524
   * particularly useful without subsampling and has not been tested in
525
   * lossless mode.
526
   */
527
16.3k
#ifdef D_LOSSLESS_SUPPORTED
528
16.3k
  if (cinfo->master->lossless) {
529
4.05k
    cinfo->raw_data_out = FALSE;
530
4.05k
    cinfo->scale_num = cinfo->scale_denom = 1;
531
4.05k
  }
532
16.3k
#endif
533
534
  /* Initialize dimensions and other stuff */
535
16.3k
  jpeg_calc_output_dimensions(cinfo);
536
16.3k
  prepare_range_limit_table(cinfo);
537
538
  /* Width of an output scanline must be representable as JDIMENSION. */
539
16.3k
  samplesperrow = (long)cinfo->output_width *
540
16.3k
                  (long)cinfo->out_color_components;
541
16.3k
  jd_samplesperrow = (JDIMENSION)samplesperrow;
542
16.3k
  if ((long)jd_samplesperrow != samplesperrow)
543
0
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
544
545
  /* Initialize my private state */
546
16.3k
  master->pass_number = 0;
547
16.3k
  master->using_merged_upsample = use_merged_upsample(cinfo);
548
549
  /* Color quantizer selection */
550
16.3k
  master->quantizer_1pass = NULL;
551
16.3k
  master->quantizer_2pass = NULL;
552
  /* No mode changes if not using buffered-image mode. */
553
16.3k
  if (!cinfo->quantize_colors || !cinfo->buffered_image) {
554
16.3k
    cinfo->enable_1pass_quant = FALSE;
555
16.3k
    cinfo->enable_external_quant = FALSE;
556
16.3k
    cinfo->enable_2pass_quant = FALSE;
557
16.3k
  }
558
16.3k
  if (cinfo->quantize_colors) {
559
0
    if (cinfo->raw_data_out)
560
0
      ERREXIT(cinfo, JERR_NOTIMPL);
561
    /* 2-pass quantizer only works in 3-component color space. */
562
0
    if (cinfo->out_color_components != 3 ||
563
0
        cinfo->out_color_space == JCS_RGB565) {
564
0
      cinfo->enable_1pass_quant = TRUE;
565
0
      cinfo->enable_external_quant = FALSE;
566
0
      cinfo->enable_2pass_quant = FALSE;
567
0
      cinfo->colormap = NULL;
568
0
    } else if (cinfo->colormap != NULL) {
569
0
      cinfo->enable_external_quant = TRUE;
570
0
    } else if (cinfo->two_pass_quantize) {
571
0
      cinfo->enable_2pass_quant = TRUE;
572
0
    } else {
573
0
      cinfo->enable_1pass_quant = TRUE;
574
0
    }
575
576
0
    if (cinfo->enable_1pass_quant) {
577
0
#ifdef QUANT_1PASS_SUPPORTED
578
0
      if (cinfo->data_precision == 8)
579
0
        jinit_1pass_quantizer(cinfo);
580
0
      else if (cinfo->data_precision == 12)
581
0
        j12init_1pass_quantizer(cinfo);
582
0
      else
583
0
        ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
584
0
      master->quantizer_1pass = cinfo->cquantize;
585
#else
586
      ERREXIT(cinfo, JERR_NOT_COMPILED);
587
#endif
588
0
    }
589
590
    /* We use the 2-pass code to map to external colormaps. */
591
0
    if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
592
0
#ifdef QUANT_2PASS_SUPPORTED
593
0
      if (cinfo->data_precision == 8)
594
0
        jinit_2pass_quantizer(cinfo);
595
0
      else if (cinfo->data_precision == 12)
596
0
        j12init_2pass_quantizer(cinfo);
597
0
      else
598
0
        ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
599
0
      master->quantizer_2pass = cinfo->cquantize;
600
#else
601
      ERREXIT(cinfo, JERR_NOT_COMPILED);
602
#endif
603
0
    }
604
    /* If both quantizers are initialized, the 2-pass one is left active;
605
     * this is necessary for starting with quantization to an external map.
606
     */
607
0
  }
608
609
  /* Post-processing: in particular, color conversion first */
610
16.3k
  if (!cinfo->raw_data_out) {
611
4.77k
    if (master->using_merged_upsample) {
612
108
#ifdef UPSAMPLE_MERGING_SUPPORTED
613
108
      if (cinfo->data_precision == 8)
614
108
        jinit_merged_upsampler(cinfo); /* does color conversion too */
615
0
      else if (cinfo->data_precision == 12)
616
0
        j12init_merged_upsampler(cinfo); /* does color conversion too */
617
0
      else
618
0
        ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
619
#else
620
      ERREXIT(cinfo, JERR_NOT_COMPILED);
621
#endif
622
4.66k
    } else {
623
4.66k
      if (cinfo->data_precision <= 8) {
624
2.01k
        jinit_color_deconverter(cinfo);
625
2.01k
        jinit_upsampler(cinfo);
626
2.65k
      } else if (cinfo->data_precision <= 12) {
627
1.37k
        j12init_color_deconverter(cinfo);
628
1.37k
        j12init_upsampler(cinfo);
629
1.37k
      } else {
630
1.27k
#ifdef D_LOSSLESS_SUPPORTED
631
1.27k
        j16init_color_deconverter(cinfo);
632
1.27k
        j16init_upsampler(cinfo);
633
#else
634
        ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
635
#endif
636
1.27k
      }
637
4.66k
    }
638
4.77k
    if (cinfo->data_precision <= 8)
639
2.12k
      jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
640
2.65k
    else if (cinfo->data_precision <= 12)
641
1.37k
      j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
642
1.27k
    else
643
1.27k
#ifdef D_LOSSLESS_SUPPORTED
644
1.27k
      j16init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
645
#else
646
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
647
#endif
648
4.77k
  }
649
650
16.3k
  if (cinfo->master->lossless) {
651
4.04k
#ifdef D_LOSSLESS_SUPPORTED
652
    /* Prediction, sample undifferencing, point transform, and sample size
653
     * scaling
654
     */
655
4.04k
    if (cinfo->data_precision <= 8)
656
1.40k
      jinit_lossless_decompressor(cinfo);
657
2.64k
    else if (cinfo->data_precision <= 12)
658
1.37k
      j12init_lossless_decompressor(cinfo);
659
1.26k
    else
660
1.26k
      j16init_lossless_decompressor(cinfo);
661
    /* Entropy decoding: either Huffman or arithmetic coding. */
662
4.04k
    if (cinfo->arith_code) {
663
52
      ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
664
3.99k
    } else {
665
3.99k
      jinit_lhuff_decoder(cinfo);
666
3.99k
    }
667
668
    /* Initialize principal buffer controllers. */
669
4.04k
    use_c_buffer = cinfo->inputctl->has_multiple_scans ||
670
220
                   cinfo->buffered_image;
671
4.04k
    if (cinfo->data_precision <= 8)
672
1.37k
      jinit_d_diff_controller(cinfo, use_c_buffer);
673
2.67k
    else if (cinfo->data_precision <= 12)
674
1.36k
      j12init_d_diff_controller(cinfo, use_c_buffer);
675
1.31k
    else
676
1.31k
      j16init_d_diff_controller(cinfo, use_c_buffer);
677
#else
678
    ERREXIT(cinfo, JERR_NOT_COMPILED);
679
#endif
680
12.3k
  } else {
681
    /* Inverse DCT */
682
12.3k
    if (cinfo->data_precision == 8)
683
11.3k
      jinit_inverse_dct(cinfo);
684
962
    else if (cinfo->data_precision == 12)
685
950
      j12init_inverse_dct(cinfo);
686
12
    else
687
12
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
688
    /* Entropy decoding: either Huffman or arithmetic coding. */
689
12.3k
    if (cinfo->arith_code) {
690
5.09k
#ifdef D_ARITH_CODING_SUPPORTED
691
5.09k
      jinit_arith_decoder(cinfo);
692
#else
693
      ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
694
#endif
695
7.22k
    } else {
696
7.22k
      if (cinfo->progressive_mode) {
697
2.72k
#ifdef D_PROGRESSIVE_SUPPORTED
698
2.72k
        jinit_phuff_decoder(cinfo);
699
#else
700
        ERREXIT(cinfo, JERR_NOT_COMPILED);
701
#endif
702
2.72k
      } else
703
4.49k
        jinit_huff_decoder(cinfo);
704
7.22k
    }
705
706
    /* Initialize principal buffer controllers. */
707
12.3k
    use_c_buffer = cinfo->inputctl->has_multiple_scans ||
708
3.86k
                   cinfo->buffered_image;
709
12.3k
    if (cinfo->data_precision == 12)
710
950
      j12init_d_coef_controller(cinfo, use_c_buffer);
711
11.3k
    else
712
11.3k
      jinit_d_coef_controller(cinfo, use_c_buffer);
713
12.3k
  }
714
715
16.3k
  if (!cinfo->raw_data_out) {
716
4.71k
    if (cinfo->data_precision <= 8)
717
2.08k
      jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
718
2.62k
    else if (cinfo->data_precision <= 12)
719
1.36k
      j12init_d_main_controller(cinfo,
720
1.36k
                                FALSE /* never need full buffer here */);
721
1.25k
    else
722
1.25k
#ifdef D_LOSSLESS_SUPPORTED
723
1.25k
      j16init_d_main_controller(cinfo,
724
1.25k
                                FALSE /* never need full buffer here */);
725
#else
726
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
727
#endif
728
4.71k
  }
729
730
  /* We can now tell the memory manager to allocate virtual arrays. */
731
16.3k
  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
732
733
  /* Initialize input side of decompressor to consume first scan. */
734
16.3k
  (*cinfo->inputctl->start_input_pass) (cinfo);
735
736
  /* Set the first and last iMCU columns to decompress from single-scan images.
737
   * By default, decompress all of the iMCU columns.
738
   */
739
16.3k
  cinfo->master->first_iMCU_col = 0;
740
16.3k
  cinfo->master->last_iMCU_col = cinfo->MCUs_per_row - 1;
741
16.3k
  cinfo->master->last_good_iMCU_row = 0;
742
743
16.3k
#ifdef D_MULTISCAN_FILES_SUPPORTED
744
  /* If jpeg_start_decompress will read the whole file, initialize
745
   * progress monitoring appropriately.  The input step is counted
746
   * as one pass.
747
   */
748
16.3k
  if (cinfo->progress != NULL && !cinfo->buffered_image &&
749
12.6k
      cinfo->inputctl->has_multiple_scans) {
750
10.0k
    int nscans;
751
    /* Estimate number of scans to set pass_limit. */
752
10.0k
    if (cinfo->progressive_mode) {
753
      /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
754
5.30k
      nscans = 2 + 3 * cinfo->num_components;
755
5.30k
    } else {
756
      /* For a nonprogressive multiscan file, estimate 1 scan per component. */
757
4.71k
      nscans = cinfo->num_components;
758
4.71k
    }
759
10.0k
    cinfo->progress->pass_counter = 0L;
760
10.0k
    cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows * nscans;
761
10.0k
    cinfo->progress->completed_passes = 0;
762
10.0k
    cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
763
    /* Count the input pass as done */
764
10.0k
    master->pass_number++;
765
10.0k
  }
766
16.3k
#endif /* D_MULTISCAN_FILES_SUPPORTED */
767
16.3k
}
768
769
770
/*
771
 * Per-pass setup.
772
 * This is called at the beginning of each output pass.  We determine which
773
 * modules will be active during this pass and give them appropriate
774
 * start_pass calls.  We also set is_dummy_pass to indicate whether this
775
 * is a "real" output pass or a dummy pass for color quantization.
776
 * (In the latter case, jdapistd.c will crank the pass to completion.)
777
 */
778
779
METHODDEF(void)
780
prepare_for_output_pass(j_decompress_ptr cinfo)
781
9.36k
{
782
9.36k
  my_master_ptr master = (my_master_ptr)cinfo->master;
783
784
9.36k
  if (master->pub.is_dummy_pass) {
785
0
#ifdef QUANT_2PASS_SUPPORTED
786
    /* Final pass of 2-pass quantization */
787
0
    master->pub.is_dummy_pass = FALSE;
788
0
    (*cinfo->cquantize->start_pass) (cinfo, FALSE);
789
0
    (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
790
0
    (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
791
#else
792
    ERREXIT(cinfo, JERR_NOT_COMPILED);
793
#endif /* QUANT_2PASS_SUPPORTED */
794
9.36k
  } else {
795
9.36k
    if (cinfo->quantize_colors && cinfo->colormap == NULL) {
796
      /* Select new quantization method */
797
0
      if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
798
0
        cinfo->cquantize = master->quantizer_2pass;
799
0
        master->pub.is_dummy_pass = TRUE;
800
0
      } else if (cinfo->enable_1pass_quant) {
801
0
        cinfo->cquantize = master->quantizer_1pass;
802
0
      } else {
803
0
        ERREXIT(cinfo, JERR_MODE_CHANGE);
804
0
      }
805
0
    }
806
9.36k
    (*cinfo->idct->start_pass) (cinfo);
807
9.36k
    (*cinfo->coef->start_output_pass) (cinfo);
808
9.36k
    if (!cinfo->raw_data_out) {
809
2.36k
      if (!master->using_merged_upsample)
810
2.36k
        (*cinfo->cconvert->start_pass) (cinfo);
811
2.36k
      (*cinfo->upsample->start_pass) (cinfo);
812
2.36k
      if (cinfo->quantize_colors)
813
0
        (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
814
2.36k
      (*cinfo->post->start_pass) (cinfo,
815
2.36k
            (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
816
2.36k
      (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
817
2.36k
    }
818
9.36k
  }
819
820
  /* Set up progress monitor's pass info if present */
821
9.36k
  if (cinfo->progress != NULL) {
822
9.36k
    cinfo->progress->completed_passes = master->pass_number;
823
9.36k
    cinfo->progress->total_passes = master->pass_number +
824
9.36k
                                    (master->pub.is_dummy_pass ? 2 : 1);
825
    /* In buffered-image mode, we assume one more output pass if EOI not
826
     * yet reached, but no more passes if EOI has been reached.
827
     */
828
9.36k
    if (cinfo->buffered_image && !cinfo->inputctl->eoi_reached) {
829
0
      cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
830
0
    }
831
9.36k
  }
832
9.36k
}
833
834
835
/*
836
 * Finish up at end of an output pass.
837
 */
838
839
METHODDEF(void)
840
finish_output_pass(j_decompress_ptr cinfo)
841
6.41k
{
842
6.41k
  my_master_ptr master = (my_master_ptr)cinfo->master;
843
844
6.41k
  if (cinfo->quantize_colors)
845
0
    (*cinfo->cquantize->finish_pass) (cinfo);
846
6.41k
  master->pass_number++;
847
6.41k
}
848
849
850
#ifdef D_MULTISCAN_FILES_SUPPORTED
851
852
/*
853
 * Switch to a new external colormap between output passes.
854
 */
855
856
GLOBAL(void)
857
jpeg_new_colormap(j_decompress_ptr cinfo)
858
0
{
859
0
  my_master_ptr master = (my_master_ptr)cinfo->master;
860
861
  /* Prevent application from calling me at wrong times */
862
0
  if (cinfo->global_state != DSTATE_BUFIMAGE)
863
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
864
865
0
  if (cinfo->quantize_colors && cinfo->enable_external_quant &&
866
0
      cinfo->colormap != NULL) {
867
    /* Select 2-pass quantizer for external colormap use */
868
0
    cinfo->cquantize = master->quantizer_2pass;
869
    /* Notify quantizer of colormap change */
870
0
    (*cinfo->cquantize->new_color_map) (cinfo);
871
0
    master->pub.is_dummy_pass = FALSE; /* just in case */
872
0
  } else
873
0
    ERREXIT(cinfo, JERR_MODE_CHANGE);
874
0
}
875
876
#endif /* D_MULTISCAN_FILES_SUPPORTED */
877
878
879
/*
880
 * Initialize master decompression control and select active modules.
881
 * This is performed at the start of jpeg_start_decompress.
882
 */
883
884
GLOBAL(void)
885
jinit_master_decompress(j_decompress_ptr cinfo)
886
16.3k
{
887
16.3k
  my_master_ptr master = (my_master_ptr)cinfo->master;
888
889
#ifdef WITH_PROFILE
890
  master->pub.total_start = getTime();
891
#endif
892
893
16.3k
  master->pub.prepare_for_output_pass = prepare_for_output_pass;
894
16.3k
  master->pub.finish_output_pass = finish_output_pass;
895
896
16.3k
  master->pub.is_dummy_pass = FALSE;
897
16.3k
  master->pub.jinit_upsampler_no_alloc = FALSE;
898
899
16.3k
  master_selection(cinfo);
900
16.3k
}