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.

578 lines
19 KiB

  1. /*
  2. * jcmaster.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 compressor.
  9. * These routines are concerned with parameter validation, initial setup,
  10. * and inter-pass control (determining the number of passes and the work
  11. * to be done in each pass).
  12. */
  13. #define JPEG_INTERNALS
  14. #include "jinclude.h"
  15. #include "jpeglib.h"
  16. /* Private state */
  17. typedef enum {
  18. main_pass, /* input data, also do first output step */
  19. huff_opt_pass, /* Huffman code optimization pass */
  20. output_pass /* data output pass */
  21. } c_pass_type;
  22. typedef struct {
  23. struct jpeg_comp_master pub; /* public fields */
  24. c_pass_type pass_type; /* the type of the current pass */
  25. int pass_number; /* # of passes completed */
  26. int total_passes; /* total # of passes needed */
  27. int scan_number; /* current index in scan_info[] */
  28. } my_comp_master;
  29. typedef my_comp_master * my_master_ptr;
  30. /*
  31. * Support routines that do various essential calculations.
  32. */
  33. LOCAL void
  34. initial_setup (j_compress_ptr cinfo)
  35. /* Do computations that are needed before master selection phase */
  36. {
  37. int ci;
  38. jpeg_component_info *compptr;
  39. long samplesperrow;
  40. JDIMENSION jd_samplesperrow;
  41. /* Sanity check on image dimensions */
  42. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  43. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  44. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  45. /* Make sure image isn't bigger than I can handle */
  46. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  47. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  48. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  49. /* Width of an input scanline must be representable as JDIMENSION. */
  50. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  51. jd_samplesperrow = (JDIMENSION) samplesperrow;
  52. if ((long) jd_samplesperrow != samplesperrow)
  53. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  54. /* For now, precision must match compiled-in value... */
  55. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  56. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  57. /* Check that number of components won't exceed internal array sizes */
  58. if (cinfo->num_components > MAX_COMPONENTS)
  59. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  60. MAX_COMPONENTS);
  61. /* Compute maximum sampling factors; check factor validity */
  62. cinfo->max_h_samp_factor = 1;
  63. cinfo->max_v_samp_factor = 1;
  64. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  65. ci++, compptr++) {
  66. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  67. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  68. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  69. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  70. compptr->h_samp_factor);
  71. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  72. compptr->v_samp_factor);
  73. }
  74. /* Compute dimensions of components */
  75. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  76. ci++, compptr++) {
  77. /* Fill in the correct component_index value; don't rely on application */
  78. compptr->component_index = ci;
  79. /* For compression, we never do DCT scaling. */
  80. compptr->DCT_scaled_size = DCTSIZE;
  81. /* Size in DCT blocks */
  82. compptr->width_in_blocks = (JDIMENSION)
  83. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  84. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  85. compptr->height_in_blocks = (JDIMENSION)
  86. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  87. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  88. /* Size in samples */
  89. compptr->downsampled_width = (JDIMENSION)
  90. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  91. (long) cinfo->max_h_samp_factor);
  92. compptr->downsampled_height = (JDIMENSION)
  93. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  94. (long) cinfo->max_v_samp_factor);
  95. /* Mark component needed (this flag isn't actually used for compression) */
  96. compptr->component_needed = TRUE;
  97. }
  98. /* Compute number of fully interleaved MCU rows (number of times that
  99. * main controller will call coefficient controller).
  100. */
  101. cinfo->total_iMCU_rows = (JDIMENSION)
  102. jdiv_round_up((long) cinfo->image_height,
  103. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  104. }
  105. #ifdef C_MULTISCAN_FILES_SUPPORTED
  106. LOCAL void
  107. validate_script (j_compress_ptr cinfo)
  108. /* Verify that the scan script in cinfo->scan_info[] is valid; also
  109. * determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
  110. */
  111. {
  112. const jpeg_scan_info * scanptr;
  113. int scanno, ncomps, ci, coefi, thisi;
  114. int Ss, Se, Ah, Al;
  115. boolean component_sent[MAX_COMPONENTS];
  116. #ifdef C_PROGRESSIVE_SUPPORTED
  117. int * last_bitpos_ptr;
  118. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  119. /* -1 until that coefficient has been seen; then last Al for it */
  120. #endif
  121. if (cinfo->num_scans <= 0)
  122. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  123. /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
  124. * for progressive JPEG, no scan can have this.
  125. */
  126. scanptr = cinfo->scan_info;
  127. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  128. #ifdef C_PROGRESSIVE_SUPPORTED
  129. cinfo->progressive_mode = TRUE;
  130. last_bitpos_ptr = & last_bitpos[0][0];
  131. for (ci = 0; ci < cinfo->num_components; ci++)
  132. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  133. *last_bitpos_ptr++ = -1;
  134. #else
  135. ERREXIT(cinfo, JERR_NOT_COMPILED);
  136. #endif
  137. } else {
  138. cinfo->progressive_mode = FALSE;
  139. for (ci = 0; ci < cinfo->num_components; ci++)
  140. component_sent[ci] = FALSE;
  141. }
  142. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  143. /* Validate component indexes */
  144. ncomps = scanptr->comps_in_scan;
  145. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  146. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  147. for (ci = 0; ci < ncomps; ci++) {
  148. thisi = scanptr->component_index[ci];
  149. if (thisi < 0 || thisi >= cinfo->num_components)
  150. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  151. /* Components must appear in SOF order within each scan */
  152. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  153. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  154. }
  155. /* Validate progression parameters */
  156. Ss = scanptr->Ss;
  157. Se = scanptr->Se;
  158. Ah = scanptr->Ah;
  159. Al = scanptr->Al;
  160. if (cinfo->progressive_mode) {
  161. #ifdef C_PROGRESSIVE_SUPPORTED
  162. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  163. Ah < 0 || Ah > 13 || Al < 0 || Al > 13)
  164. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  165. if (Ss == 0) {
  166. if (Se != 0) /* DC and AC together not OK */
  167. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  168. } else {
  169. if (ncomps != 1) /* AC scans must be for only one component */
  170. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  171. }
  172. for (ci = 0; ci < ncomps; ci++) {
  173. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  174. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  175. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  176. for (coefi = Ss; coefi <= Se; coefi++) {
  177. if (last_bitpos_ptr[coefi] < 0) {
  178. /* first scan of this coefficient */
  179. if (Ah != 0)
  180. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  181. } else {
  182. /* not first scan */
  183. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  184. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  185. }
  186. last_bitpos_ptr[coefi] = Al;
  187. }
  188. }
  189. #endif
  190. } else {
  191. /* For sequential JPEG, all progression parameters must be these: */
  192. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  193. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  194. /* Make sure components are not sent twice */
  195. for (ci = 0; ci < ncomps; ci++) {
  196. thisi = scanptr->component_index[ci];
  197. if (component_sent[thisi])
  198. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  199. component_sent[thisi] = TRUE;
  200. }
  201. }
  202. }
  203. /* Now verify that everything got sent. */
  204. if (cinfo->progressive_mode) {
  205. #ifdef C_PROGRESSIVE_SUPPORTED
  206. /* For progressive mode, we only check that at least some DC data
  207. * got sent for each component; the spec does not require that all bits
  208. * of all coefficients be transmitted. Would it be wiser to enforce
  209. * transmission of all coefficient bits??
  210. */
  211. for (ci = 0; ci < cinfo->num_components; ci++) {
  212. if (last_bitpos[ci][0] < 0)
  213. ERREXIT(cinfo, JERR_MISSING_DATA);
  214. }
  215. #endif
  216. } else {
  217. for (ci = 0; ci < cinfo->num_components; ci++) {
  218. if (! component_sent[ci])
  219. ERREXIT(cinfo, JERR_MISSING_DATA);
  220. }
  221. }
  222. }
  223. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  224. LOCAL void
  225. select_scan_parameters (j_compress_ptr cinfo)
  226. /* Set up the scan parameters for the current scan */
  227. {
  228. int ci;
  229. #ifdef C_MULTISCAN_FILES_SUPPORTED
  230. if (cinfo->scan_info != NULL) {
  231. /* Prepare for current scan --- the script is already validated */
  232. my_master_ptr master = (my_master_ptr) cinfo->master;
  233. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  234. cinfo->comps_in_scan = scanptr->comps_in_scan;
  235. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  236. cinfo->cur_comp_info[ci] =
  237. &cinfo->comp_info[scanptr->component_index[ci]];
  238. }
  239. cinfo->Ss = scanptr->Ss;
  240. cinfo->Se = scanptr->Se;
  241. cinfo->Ah = scanptr->Ah;
  242. cinfo->Al = scanptr->Al;
  243. }
  244. else
  245. #endif
  246. {
  247. /* Prepare for single sequential-JPEG scan containing all components */
  248. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  249. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  250. MAX_COMPS_IN_SCAN);
  251. cinfo->comps_in_scan = cinfo->num_components;
  252. for (ci = 0; ci < cinfo->num_components; ci++) {
  253. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  254. }
  255. cinfo->Ss = 0;
  256. cinfo->Se = DCTSIZE2-1;
  257. cinfo->Ah = 0;
  258. cinfo->Al = 0;
  259. }
  260. }
  261. LOCAL void
  262. per_scan_setup (j_compress_ptr cinfo)
  263. /* Do computations that are needed before processing a JPEG scan */
  264. /* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
  265. {
  266. int ci, mcublks, tmp;
  267. jpeg_component_info *compptr;
  268. if (cinfo->comps_in_scan == 1) {
  269. /* Noninterleaved (single-component) scan */
  270. compptr = cinfo->cur_comp_info[0];
  271. /* Overall image size in MCUs */
  272. cinfo->MCUs_per_row = compptr->width_in_blocks;
  273. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  274. /* For noninterleaved scan, always one block per MCU */
  275. compptr->MCU_width = 1;
  276. compptr->MCU_height = 1;
  277. compptr->MCU_blocks = 1;
  278. compptr->MCU_sample_width = DCTSIZE;
  279. compptr->last_col_width = 1;
  280. /* For noninterleaved scans, it is convenient to define last_row_height
  281. * as the number of block rows present in the last iMCU row.
  282. */
  283. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  284. if (tmp == 0) tmp = compptr->v_samp_factor;
  285. compptr->last_row_height = tmp;
  286. /* Prepare array describing MCU composition */
  287. cinfo->blocks_in_MCU = 1;
  288. cinfo->MCU_membership[0] = 0;
  289. } else {
  290. /* Interleaved (multi-component) scan */
  291. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  292. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  293. MAX_COMPS_IN_SCAN);
  294. /* Overall image size in MCUs */
  295. cinfo->MCUs_per_row = (JDIMENSION)
  296. jdiv_round_up((long) cinfo->image_width,
  297. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  298. cinfo->MCU_rows_in_scan = (JDIMENSION)
  299. jdiv_round_up((long) cinfo->image_height,
  300. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  301. cinfo->blocks_in_MCU = 0;
  302. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  303. compptr = cinfo->cur_comp_info[ci];
  304. /* Sampling factors give # of blocks of component in each MCU */
  305. compptr->MCU_width = compptr->h_samp_factor;
  306. compptr->MCU_height = compptr->v_samp_factor;
  307. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  308. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  309. /* Figure number of non-dummy blocks in last MCU column & row */
  310. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  311. if (tmp == 0) tmp = compptr->MCU_width;
  312. compptr->last_col_width = tmp;
  313. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  314. if (tmp == 0) tmp = compptr->MCU_height;
  315. compptr->last_row_height = tmp;
  316. /* Prepare array describing MCU composition */
  317. mcublks = compptr->MCU_blocks;
  318. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  319. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  320. while (mcublks-- > 0) {
  321. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  322. }
  323. }
  324. }
  325. /* Convert restart specified in rows to actual MCU count. */
  326. /* Note that count must fit in 16 bits, so we provide limiting. */
  327. if (cinfo->restart_in_rows > 0) {
  328. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  329. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  330. }
  331. }
  332. /*
  333. * Per-pass setup.
  334. * This is called at the beginning of each pass. We determine which modules
  335. * will be active during this pass and give them appropriate start_pass calls.
  336. * We also set is_last_pass to indicate whether any more passes will be
  337. * required.
  338. */
  339. METHODDEF void
  340. prepare_for_pass (j_compress_ptr cinfo)
  341. {
  342. my_master_ptr master = (my_master_ptr) cinfo->master;
  343. switch (master->pass_type) {
  344. case main_pass:
  345. /* Initial pass: will collect input data, and do either Huffman
  346. * optimization or data output for the first scan.
  347. */
  348. select_scan_parameters(cinfo);
  349. per_scan_setup(cinfo);
  350. if (! cinfo->raw_data_in) {
  351. (*cinfo->cconvert->start_pass) (cinfo);
  352. (*cinfo->downsample->start_pass) (cinfo);
  353. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  354. }
  355. (*cinfo->fdct->start_pass) (cinfo);
  356. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  357. (*cinfo->coef->start_pass) (cinfo,
  358. (master->total_passes > 1 ?
  359. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  360. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  361. if (cinfo->optimize_coding) {
  362. /* No immediate data output; postpone writing frame/scan headers */
  363. master->pub.call_pass_startup = FALSE;
  364. } else {
  365. /* Will write frame/scan headers at first jpeg_write_scanlines call */
  366. master->pub.call_pass_startup = TRUE;
  367. }
  368. break;
  369. #ifdef ENTROPY_OPT_SUPPORTED
  370. case huff_opt_pass:
  371. /* Do Huffman optimization for a scan after the first one. */
  372. select_scan_parameters(cinfo);
  373. per_scan_setup(cinfo);
  374. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  375. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  376. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  377. master->pub.call_pass_startup = FALSE;
  378. break;
  379. }
  380. /* Special case: Huffman DC refinement scans need no Huffman table
  381. * and therefore we can skip the optimization pass for them.
  382. */
  383. master->pass_type = output_pass;
  384. master->pass_number++;
  385. /*FALLTHROUGH*/
  386. #endif
  387. case output_pass:
  388. /* Do a data-output pass. */
  389. /* We need not repeat per-scan setup if prior optimization pass did it. */
  390. if (! cinfo->optimize_coding) {
  391. select_scan_parameters(cinfo);
  392. per_scan_setup(cinfo);
  393. }
  394. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  395. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  396. /* We emit frame/scan headers now */
  397. if (master->scan_number == 0)
  398. (*cinfo->marker->write_frame_header) (cinfo);
  399. (*cinfo->marker->write_scan_header) (cinfo);
  400. master->pub.call_pass_startup = FALSE;
  401. break;
  402. default:
  403. ERREXIT(cinfo, JERR_NOT_COMPILED);
  404. }
  405. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  406. /* Set up progress monitor's pass info if present */
  407. if (cinfo->progress != NULL) {
  408. cinfo->progress->completed_passes = master->pass_number;
  409. cinfo->progress->total_passes = master->total_passes;
  410. }
  411. }
  412. /*
  413. * Special start-of-pass hook.
  414. * This is called by jpeg_write_scanlines if call_pass_startup is TRUE.
  415. * In single-pass processing, we need this hook because we don't want to
  416. * write frame/scan headers during jpeg_start_compress; we want to let the
  417. * application write COM markers etc. between jpeg_start_compress and the
  418. * jpeg_write_scanlines loop.
  419. * In multi-pass processing, this routine is not used.
  420. */
  421. METHODDEF void
  422. pass_startup (j_compress_ptr cinfo)
  423. {
  424. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  425. (*cinfo->marker->write_frame_header) (cinfo);
  426. (*cinfo->marker->write_scan_header) (cinfo);
  427. }
  428. /*
  429. * Finish up at end of pass.
  430. */
  431. METHODDEF void
  432. finish_pass_master (j_compress_ptr cinfo)
  433. {
  434. my_master_ptr master = (my_master_ptr) cinfo->master;
  435. /* The entropy coder always needs an end-of-pass call,
  436. * either to analyze statistics or to flush its output buffer.
  437. */
  438. (*cinfo->entropy->finish_pass) (cinfo);
  439. /* Update state for next pass */
  440. switch (master->pass_type) {
  441. case main_pass:
  442. /* next pass is either output of scan 0 (after optimization)
  443. * or output of scan 1 (if no optimization).
  444. */
  445. master->pass_type = output_pass;
  446. if (! cinfo->optimize_coding)
  447. master->scan_number++;
  448. break;
  449. case huff_opt_pass:
  450. /* next pass is always output of current scan */
  451. master->pass_type = output_pass;
  452. break;
  453. case output_pass:
  454. /* next pass is either optimization or output of next scan */
  455. if (cinfo->optimize_coding)
  456. master->pass_type = huff_opt_pass;
  457. master->scan_number++;
  458. break;
  459. }
  460. master->pass_number++;
  461. }
  462. /*
  463. * Initialize master compression control.
  464. */
  465. GLOBAL void
  466. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  467. {
  468. my_master_ptr master;
  469. master = (my_master_ptr)
  470. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  471. SIZEOF(my_comp_master));
  472. cinfo->master = (struct jpeg_comp_master *) master;
  473. master->pub.prepare_for_pass = prepare_for_pass;
  474. master->pub.pass_startup = pass_startup;
  475. master->pub.finish_pass = finish_pass_master;
  476. master->pub.is_last_pass = FALSE;
  477. /* Validate parameters, determine derived values */
  478. initial_setup(cinfo);
  479. if (cinfo->scan_info != NULL) {
  480. #ifdef C_MULTISCAN_FILES_SUPPORTED
  481. validate_script(cinfo);
  482. #else
  483. ERREXIT(cinfo, JERR_NOT_COMPILED);
  484. #endif
  485. } else {
  486. cinfo->progressive_mode = FALSE;
  487. cinfo->num_scans = 1;
  488. }
  489. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  490. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  491. /* Initialize my private state */
  492. if (transcode_only) {
  493. /* no main pass in transcoding */
  494. if (cinfo->optimize_coding)
  495. master->pass_type = huff_opt_pass;
  496. else
  497. master->pass_type = output_pass;
  498. } else {
  499. /* for normal compression, first pass is always this type: */
  500. master->pass_type = main_pass;
  501. }
  502. master->scan_number = 0;
  503. master->pass_number = 0;
  504. if (cinfo->optimize_coding)
  505. master->total_passes = cinfo->num_scans * 2;
  506. else
  507. master->total_passes = cinfo->num_scans;
  508. }