Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

575 lines
20 KiB

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