dda9f903e5e92e173b3806242cc55802d3f764fa
[oweals/cde.git] / cde / lib / DtHelp / jpeg / jdmaster.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: jdmaster.c /main/2 1996/05/09 03:48:58 drk $ */
24 /*
25  * jdmaster.c
26  *
27  * Copyright (C) 1991-1996, Thomas G. Lane.
28  * This file is part of the Independent JPEG Group's software.
29  * For conditions of distribution and use, see the accompanying README file.
30  *
31  * This file contains master control logic for the JPEG decompressor.
32  * These routines are concerned with selecting the modules to be executed
33  * and with determining the number of passes and the work to be done in each
34  * pass.
35  */
36
37 #define JPEG_INTERNALS
38 #include "jinclude.h"
39 #include "jpeglib.h"
40
41
42 /* Private state */
43
44 typedef struct {
45   struct jpeg_decomp_master pub; /* public fields */
46
47   int pass_number;              /* # of passes completed */
48
49   boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
50
51   /* Saved references to initialized quantizer modules,
52    * in case we need to switch modes.
53    */
54   struct jpeg_color_quantizer * quantizer_1pass;
55   struct jpeg_color_quantizer * quantizer_2pass;
56 } my_decomp_master;
57
58 typedef my_decomp_master * my_master_ptr;
59
60
61 /*
62  * Determine whether merged upsample/color conversion should be used.
63  * CRUCIAL: this must match the actual capabilities of jdmerge.c!
64  */
65
66 LOCAL(boolean)
67 use_merged_upsample (j_decompress_ptr cinfo)
68 {
69 #ifdef UPSAMPLE_MERGING_SUPPORTED
70   /* Merging is the equivalent of plain box-filter upsampling */
71   if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
72     return FALSE;
73   /* jdmerge.c only supports YCC=>RGB color conversion */
74   if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
75       cinfo->out_color_space != JCS_RGB ||
76       cinfo->out_color_components != RGB_PIXELSIZE)
77     return FALSE;
78   /* and it only handles 2h1v or 2h2v sampling ratios */
79   if (cinfo->comp_info[0].h_samp_factor != 2 ||
80       cinfo->comp_info[1].h_samp_factor != 1 ||
81       cinfo->comp_info[2].h_samp_factor != 1 ||
82       cinfo->comp_info[0].v_samp_factor >  2 ||
83       cinfo->comp_info[1].v_samp_factor != 1 ||
84       cinfo->comp_info[2].v_samp_factor != 1)
85     return FALSE;
86   /* furthermore, it doesn't work if we've scaled the IDCTs differently */
87   if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
88       cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
89       cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
90     return FALSE;
91   /* ??? also need to test for upsample-time rescaling, when & if supported */
92   return TRUE;                  /* by golly, it'll work... */
93 #else
94   return FALSE;
95 #endif
96 }
97
98
99 /*
100  * Compute output image dimensions and related values.
101  * NOTE: this is exported for possible use by application.
102  * Hence it mustn't do anything that can't be done twice.
103  * Also note that it may be called before the master module is initialized!
104  */
105
106 GLOBAL(void)
107 jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
108 /* Do computations that are needed before master selection phase */
109 {
110   int ci;
111   jpeg_component_info *compptr;
112
113   /* Prevent application from calling me at wrong times */
114   if (cinfo->global_state != DSTATE_READY)
115     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
116
117 #ifdef IDCT_SCALING_SUPPORTED
118
119   /* Compute actual output image dimensions and DCT scaling choices. */
120   if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
121     /* Provide 1/8 scaling */
122     cinfo->output_width = (JDIMENSION)
123       jdiv_round_up((long) cinfo->image_width, 8L);
124     cinfo->output_height = (JDIMENSION)
125       jdiv_round_up((long) cinfo->image_height, 8L);
126     cinfo->min_DCT_scaled_size = 1;
127   } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
128     /* Provide 1/4 scaling */
129     cinfo->output_width = (JDIMENSION)
130       jdiv_round_up((long) cinfo->image_width, 4L);
131     cinfo->output_height = (JDIMENSION)
132       jdiv_round_up((long) cinfo->image_height, 4L);
133     cinfo->min_DCT_scaled_size = 2;
134   } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
135     /* Provide 1/2 scaling */
136     cinfo->output_width = (JDIMENSION)
137       jdiv_round_up((long) cinfo->image_width, 2L);
138     cinfo->output_height = (JDIMENSION)
139       jdiv_round_up((long) cinfo->image_height, 2L);
140     cinfo->min_DCT_scaled_size = 4;
141   } else {
142     /* Provide 1/1 scaling */
143     cinfo->output_width = cinfo->image_width;
144     cinfo->output_height = cinfo->image_height;
145     cinfo->min_DCT_scaled_size = DCTSIZE;
146   }
147   /* In selecting the actual DCT scaling for each component, we try to
148    * scale up the chroma components via IDCT scaling rather than upsampling.
149    * This saves time if the upsampler gets to use 1:1 scaling.
150    * Note this code assumes that the supported DCT scalings are powers of 2.
151    */
152   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
153        ci++, compptr++) {
154     int ssize = cinfo->min_DCT_scaled_size;
155     while (ssize < DCTSIZE &&
156            (compptr->h_samp_factor * ssize * 2 <=
157             cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
158            (compptr->v_samp_factor * ssize * 2 <=
159             cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
160       ssize = ssize * 2;
161     }
162     compptr->DCT_scaled_size = ssize;
163   }
164
165   /* Recompute downsampled dimensions of components;
166    * application needs to know these if using raw downsampled data.
167    */
168   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
169        ci++, compptr++) {
170     /* Size in samples, after IDCT scaling */
171     compptr->downsampled_width = (JDIMENSION)
172       jdiv_round_up((long) cinfo->image_width *
173                     (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
174                     (long) (cinfo->max_h_samp_factor * DCTSIZE));
175     compptr->downsampled_height = (JDIMENSION)
176       jdiv_round_up((long) cinfo->image_height *
177                     (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
178                     (long) (cinfo->max_v_samp_factor * DCTSIZE));
179   }
180
181 #else /* !IDCT_SCALING_SUPPORTED */
182
183   /* Hardwire it to "no scaling" */
184   cinfo->output_width = cinfo->image_width;
185   cinfo->output_height = cinfo->image_height;
186   /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
187    * and has computed unscaled downsampled_width and downsampled_height.
188    */
189
190 #endif /* IDCT_SCALING_SUPPORTED */
191
192   /* Report number of components in selected colorspace. */
193   /* Probably this should be in the color conversion module... */
194   switch (cinfo->out_color_space) {
195   case JCS_GRAYSCALE:
196     cinfo->out_color_components = 1;
197     break;
198   case JCS_RGB:
199 #if RGB_PIXELSIZE != 3
200     cinfo->out_color_components = RGB_PIXELSIZE;
201     break;
202 #endif /* else share code with YCbCr */
203   case JCS_YCbCr:
204     cinfo->out_color_components = 3;
205     break;
206   case JCS_CMYK:
207   case JCS_YCCK:
208     cinfo->out_color_components = 4;
209     break;
210   default:                      /* else must be same colorspace as in file */
211     cinfo->out_color_components = cinfo->num_components;
212     break;
213   }
214   cinfo->output_components = (cinfo->quantize_colors ? 1 :
215                               cinfo->out_color_components);
216
217   /* See if upsampler will want to emit more than one row at a time */
218   if (use_merged_upsample(cinfo))
219     cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
220   else
221     cinfo->rec_outbuf_height = 1;
222 }
223
224
225 /*
226  * Several decompression processes need to range-limit values to the range
227  * 0..MAXJSAMPLE; the input value may fall somewhat outside this range
228  * due to noise introduced by quantization, roundoff error, etc.  These
229  * processes are inner loops and need to be as fast as possible.  On most
230  * machines, particularly CPUs with pipelines or instruction prefetch,
231  * a (subscript-check-less) C table lookup
232  *              x = sample_range_limit[x];
233  * is faster than explicit tests
234  *              if (x < 0)  x = 0;
235  *              else if (x > MAXJSAMPLE)  x = MAXJSAMPLE;
236  * These processes all use a common table prepared by the routine below.
237  *
238  * For most steps we can mathematically guarantee that the initial value
239  * of x is within MAXJSAMPLE+1 of the legal range, so a table running from
240  * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient.  But for the initial
241  * limiting step (just after the IDCT), a wildly out-of-range value is 
242  * possible if the input data is corrupt.  To avoid any chance of indexing
243  * off the end of memory and getting a bad-pointer trap, we perform the
244  * post-IDCT limiting thus:
245  *              x = range_limit[x & MASK];
246  * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
247  * samples.  Under normal circumstances this is more than enough range and
248  * a correct output will be generated; with bogus input data the mask will
249  * cause wraparound, and we will safely generate a bogus-but-in-range output.
250  * For the post-IDCT step, we want to convert the data from signed to unsigned
251  * representation by adding CENTERJSAMPLE at the same time that we limit it.
252  * So the post-IDCT limiting table ends up looking like this:
253  *   CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
254  *   MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
255  *   0          (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
256  *   0,1,...,CENTERJSAMPLE-1
257  * Negative inputs select values from the upper half of the table after
258  * masking.
259  *
260  * We can save some space by overlapping the start of the post-IDCT table
261  * with the simpler range limiting table.  The post-IDCT table begins at
262  * sample_range_limit + CENTERJSAMPLE.
263  *
264  * Note that the table is allocated in near data space on PCs; it's small
265  * enough and used often enough to justify this.
266  */
267
268 LOCAL(void)
269 prepare_range_limit_table (j_decompress_ptr cinfo)
270 /* Allocate and fill in the sample_range_limit table */
271 {
272   JSAMPLE * table;
273   int i;
274
275   table = (JSAMPLE *)
276     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
277                 (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
278   table += (MAXJSAMPLE+1);      /* allow negative subscripts of simple table */
279   cinfo->sample_range_limit = table;
280   /* First segment of "simple" table: limit[x] = 0 for x < 0 */
281   MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
282   /* Main part of "simple" table: limit[x] = x */
283   for (i = 0; i <= MAXJSAMPLE; i++)
284     table[i] = (JSAMPLE) i;
285   table += CENTERJSAMPLE;       /* Point to where post-IDCT table starts */
286   /* End of simple table, rest of first half of post-IDCT table */
287   for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
288     table[i] = MAXJSAMPLE;
289   /* Second half of post-IDCT table */
290   MEMZERO(table + (2 * (MAXJSAMPLE+1)),
291           (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
292   MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
293           cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
294 }
295
296
297 /*
298  * Master selection of decompression modules.
299  * This is done once at jpeg_start_decompress time.  We determine
300  * which modules will be used and give them appropriate initialization calls.
301  * We also initialize the decompressor input side to begin consuming data.
302  *
303  * Since jpeg_read_header has finished, we know what is in the SOF
304  * and (first) SOS markers.  We also have all the application parameter
305  * settings.
306  */
307
308 LOCAL(void)
309 master_selection (j_decompress_ptr cinfo)
310 {
311   my_master_ptr master = (my_master_ptr) cinfo->master;
312   boolean use_c_buffer;
313   long samplesperrow;
314   JDIMENSION jd_samplesperrow;
315
316   /* Initialize dimensions and other stuff */
317   jpeg_calc_output_dimensions(cinfo);
318   prepare_range_limit_table(cinfo);
319
320   /* Width of an output scanline must be representable as JDIMENSION. */
321   samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
322   jd_samplesperrow = (JDIMENSION) samplesperrow;
323   if ((long) jd_samplesperrow != samplesperrow)
324     ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
325
326   /* Initialize my private state */
327   master->pass_number = 0;
328   master->using_merged_upsample = use_merged_upsample(cinfo);
329
330   /* Color quantizer selection */
331   master->quantizer_1pass = NULL;
332   master->quantizer_2pass = NULL;
333   /* No mode changes if not using buffered-image mode. */
334   if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
335     cinfo->enable_1pass_quant = FALSE;
336     cinfo->enable_external_quant = FALSE;
337     cinfo->enable_2pass_quant = FALSE;
338   }
339   if (cinfo->quantize_colors) {
340     if (cinfo->raw_data_out)
341       ERREXIT(cinfo, JERR_NOTIMPL);
342     /* 2-pass quantizer only works in 3-component color space. */
343     if (cinfo->out_color_components != 3) {
344       cinfo->enable_1pass_quant = TRUE;
345       cinfo->enable_external_quant = FALSE;
346       cinfo->enable_2pass_quant = FALSE;
347       cinfo->colormap = NULL;
348     } else if (cinfo->colormap != NULL) {
349       cinfo->enable_external_quant = TRUE;
350     } else if (cinfo->two_pass_quantize) {
351       cinfo->enable_2pass_quant = TRUE;
352     } else {
353       cinfo->enable_1pass_quant = TRUE;
354     }
355
356     if (cinfo->enable_1pass_quant) {
357 #ifdef QUANT_1PASS_SUPPORTED
358       jinit_1pass_quantizer(cinfo);
359       master->quantizer_1pass = cinfo->cquantize;
360 #else
361       ERREXIT(cinfo, JERR_NOT_COMPILED);
362 #endif
363     }
364
365     /* We use the 2-pass code to map to external colormaps. */
366     if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
367 #ifdef QUANT_2PASS_SUPPORTED
368       jinit_2pass_quantizer(cinfo);
369       master->quantizer_2pass = cinfo->cquantize;
370 #else
371       ERREXIT(cinfo, JERR_NOT_COMPILED);
372 #endif
373     }
374     /* If both quantizers are initialized, the 2-pass one is left active;
375      * this is necessary for starting with quantization to an external map.
376      */
377   }
378
379   /* Post-processing: in particular, color conversion first */
380   if (! cinfo->raw_data_out) {
381     if (master->using_merged_upsample) {
382 #ifdef UPSAMPLE_MERGING_SUPPORTED
383       jinit_merged_upsampler(cinfo); /* does color conversion too */
384 #else
385       ERREXIT(cinfo, JERR_NOT_COMPILED);
386 #endif
387     } else {
388       jinit_color_deconverter(cinfo);
389       jinit_upsampler(cinfo);
390     }
391     jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
392   }
393   /* Inverse DCT */
394   jinit_inverse_dct(cinfo);
395   /* Entropy decoding: either Huffman or arithmetic coding. */
396   if (cinfo->arith_code) {
397     ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
398   } else {
399     if (cinfo->progressive_mode) {
400 #ifdef D_PROGRESSIVE_SUPPORTED
401       jinit_phuff_decoder(cinfo);
402 #else
403       ERREXIT(cinfo, JERR_NOT_COMPILED);
404 #endif
405     } else
406       jinit_huff_decoder(cinfo);
407   }
408
409   /* Initialize principal buffer controllers. */
410   use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
411   jinit_d_coef_controller(cinfo, use_c_buffer);
412
413   if (! cinfo->raw_data_out)
414     jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
415
416   /* We can now tell the memory manager to allocate virtual arrays. */
417   (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
418
419   /* Initialize input side of decompressor to consume first scan. */
420   (*cinfo->inputctl->start_input_pass) (cinfo);
421
422 #ifdef D_MULTISCAN_FILES_SUPPORTED
423   /* If jpeg_start_decompress will read the whole file, initialize
424    * progress monitoring appropriately.  The input step is counted
425    * as one pass.
426    */
427   if (cinfo->progress != NULL && ! cinfo->buffered_image &&
428       cinfo->inputctl->has_multiple_scans) {
429     int nscans;
430     /* Estimate number of scans to set pass_limit. */
431     if (cinfo->progressive_mode) {
432       /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
433       nscans = 2 + 3 * cinfo->num_components;
434     } else {
435       /* For a nonprogressive multiscan file, estimate 1 scan per component. */
436       nscans = cinfo->num_components;
437     }
438     cinfo->progress->pass_counter = 0L;
439     cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
440     cinfo->progress->completed_passes = 0;
441     cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
442     /* Count the input pass as done */
443     master->pass_number++;
444   }
445 #endif /* D_MULTISCAN_FILES_SUPPORTED */
446 }
447
448
449 /*
450  * Per-pass setup.
451  * This is called at the beginning of each output pass.  We determine which
452  * modules will be active during this pass and give them appropriate
453  * start_pass calls.  We also set is_dummy_pass to indicate whether this
454  * is a "real" output pass or a dummy pass for color quantization.
455  * (In the latter case, jdapi.c will crank the pass to completion.)
456  */
457
458 METHODDEF(void)
459 prepare_for_output_pass (j_decompress_ptr cinfo)
460 {
461   my_master_ptr master = (my_master_ptr) cinfo->master;
462
463   if (master->pub.is_dummy_pass) {
464 #ifdef QUANT_2PASS_SUPPORTED
465     /* Final pass of 2-pass quantization */
466     master->pub.is_dummy_pass = FALSE;
467     (*cinfo->cquantize->start_pass) (cinfo, FALSE);
468     (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
469     (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
470 #else
471     ERREXIT(cinfo, JERR_NOT_COMPILED);
472 #endif /* QUANT_2PASS_SUPPORTED */
473   } else {
474     if (cinfo->quantize_colors && cinfo->colormap == NULL) {
475       /* Select new quantization method */
476       if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
477         cinfo->cquantize = master->quantizer_2pass;
478         master->pub.is_dummy_pass = TRUE;
479       } else if (cinfo->enable_1pass_quant) {
480         cinfo->cquantize = master->quantizer_1pass;
481       } else {
482         ERREXIT(cinfo, JERR_MODE_CHANGE);
483       }
484     }
485     (*cinfo->idct->start_pass) (cinfo);
486     (*cinfo->coef->start_output_pass) (cinfo);
487     if (! cinfo->raw_data_out) {
488       if (! master->using_merged_upsample)
489         (*cinfo->cconvert->start_pass) (cinfo);
490       (*cinfo->upsample->start_pass) (cinfo);
491       if (cinfo->quantize_colors)
492         (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
493       (*cinfo->post->start_pass) (cinfo,
494             (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
495       (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
496     }
497   }
498
499   /* Set up progress monitor's pass info if present */
500   if (cinfo->progress != NULL) {
501     cinfo->progress->completed_passes = master->pass_number;
502     cinfo->progress->total_passes = master->pass_number +
503                                     (master->pub.is_dummy_pass ? 2 : 1);
504     /* In buffered-image mode, we assume one more output pass if EOI not
505      * yet reached, but no more passes if EOI has been reached.
506      */
507     if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
508       cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
509     }
510   }
511 }
512
513
514 /*
515  * Finish up at end of an output pass.
516  */
517
518 METHODDEF(void)
519 finish_output_pass (j_decompress_ptr cinfo)
520 {
521   my_master_ptr master = (my_master_ptr) cinfo->master;
522
523   if (cinfo->quantize_colors)
524     (*cinfo->cquantize->finish_pass) (cinfo);
525   master->pass_number++;
526 }
527
528
529 #ifdef D_MULTISCAN_FILES_SUPPORTED
530
531 /*
532  * Switch to a new external colormap between output passes.
533  */
534
535 GLOBAL(void)
536 jpeg_new_colormap (j_decompress_ptr cinfo)
537 {
538   my_master_ptr master = (my_master_ptr) cinfo->master;
539
540   /* Prevent application from calling me at wrong times */
541   if (cinfo->global_state != DSTATE_BUFIMAGE)
542     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
543
544   if (cinfo->quantize_colors && cinfo->enable_external_quant &&
545       cinfo->colormap != NULL) {
546     /* Select 2-pass quantizer for external colormap use */
547     cinfo->cquantize = master->quantizer_2pass;
548     /* Notify quantizer of colormap change */
549     (*cinfo->cquantize->new_color_map) (cinfo);
550     master->pub.is_dummy_pass = FALSE; /* just in case */
551   } else
552     ERREXIT(cinfo, JERR_MODE_CHANGE);
553 }
554
555 #endif /* D_MULTISCAN_FILES_SUPPORTED */
556
557
558 /*
559  * Initialize master decompression control and select active modules.
560  * This is performed at the start of jpeg_start_decompress.
561  */
562
563 GLOBAL(void)
564 jinit_master_decompress (j_decompress_ptr cinfo)
565 {
566   my_master_ptr master;
567
568   master = (my_master_ptr)
569       (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
570                                   SIZEOF(my_decomp_master));
571   cinfo->master = (struct jpeg_decomp_master *) master;
572   master->pub.prepare_for_output_pass = prepare_for_output_pass;
573   master->pub.finish_output_pass = finish_output_pass;
574
575   master->pub.is_dummy_pass = FALSE;
576
577   master_selection(cinfo);
578 }