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