Coverage Report

Created: 2023-06-07 06:03

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