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.

581 lines
19 KiB

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