OSDN Git Service

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