Doxygen Source Code Documentation
jcmaster.c File Reference
#include "jinclude.h"#include "jpeglib.h"Go to the source code of this file.
Data Structures | |
| struct | my_comp_master |
Defines | |
| #define | JPEG_INTERNALS |
| #define | MAX_AH_AL 10 |
Typedefs | |
| typedef my_comp_master * | my_master_ptr |
Enumerations | |
| enum | c_pass_type { main_pass, huff_opt_pass, output_pass } |
Functions | |
| initial_setup (j_compress_ptr cinfo) | |
| validate_script (j_compress_ptr cinfo) | |
| select_scan_parameters (j_compress_ptr cinfo) | |
| per_scan_setup (j_compress_ptr cinfo) | |
| prepare_for_pass (j_compress_ptr cinfo) | |
| pass_startup (j_compress_ptr cinfo) | |
| finish_pass_master (j_compress_ptr cinfo) | |
| jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) | |
Define Documentation
|
|
Definition at line 14 of file jcmaster.c. |
|
|
|
Typedef Documentation
|
|
Definition at line 38 of file jcmaster.c. |
Enumeration Type Documentation
|
|
Definition at line 21 of file jcmaster.c.
00021 {
00022 main_pass, /* input data, also do first output step */
00023 huff_opt_pass, /* Huffman code optimization pass */
00024 output_pass /* data output pass */
00025 } c_pass_type;
|
Function Documentation
|
|
Definition at line 503 of file jcmaster.c. References jpeg_compress_struct::entropy, huff_opt_pass, main_pass, jpeg_compress_struct::master, jpeg_compress_struct::optimize_coding, output_pass, and my_decomp_master::pass_number. Referenced by jinit_c_master_control().
00504 {
00505 my_master_ptr master = (my_master_ptr) cinfo->master;
00506
00507 /* The entropy coder always needs an end-of-pass call,
00508 * either to analyze statistics or to flush its output buffer.
00509 */
00510 (*cinfo->entropy->finish_pass) (cinfo);
00511
00512 /* Update state for next pass */
00513 switch (master->pass_type) {
00514 case main_pass:
00515 /* next pass is either output of scan 0 (after optimization)
00516 * or output of scan 1 (if no optimization).
00517 */
00518 master->pass_type = output_pass;
00519 if (! cinfo->optimize_coding)
00520 master->scan_number++;
00521 break;
00522 case huff_opt_pass:
00523 /* next pass is always output of current scan */
00524 master->pass_type = output_pass;
00525 break;
00526 case output_pass:
00527 /* next pass is either optimization or output of next scan */
00528 if (cinfo->optimize_coding)
00529 master->pass_type = huff_opt_pass;
00530 master->scan_number++;
00531 break;
00532 }
00533
00534 master->pass_number++;
00535 }
|
|
|
Definition at line 46 of file jcmaster.c. References BITS_IN_JSAMPLE, jpeg_compress_struct::comp_info, jpeg_component_info::component_index, jpeg_component_info::component_needed, compptr, jpeg_compress_struct::data_precision, jpeg_component_info::DCT_scaled_size, jpeg_component_info::downsampled_height, jpeg_component_info::downsampled_width, ERREXIT, ERREXIT1, ERREXIT2, jpeg_component_info::h_samp_factor, jpeg_component_info::height_in_blocks, jpeg_compress_struct::image_height, jpeg_compress_struct::image_width, jpeg_compress_struct::input_components, JDIMENSION, jdiv_round_up(), JERR_EMPTY_IMAGE, JPEG_MAX_DIMENSION, MAX, MAX_COMPONENTS, jpeg_compress_struct::max_h_samp_factor, MAX_SAMP_FACTOR, jpeg_compress_struct::max_v_samp_factor, jpeg_compress_struct::num_components, jpeg_compress_struct::total_iMCU_rows, jpeg_component_info::v_samp_factor, and jpeg_component_info::width_in_blocks.
00048 {
00049 int ci;
00050 jpeg_component_info *compptr;
00051 long samplesperrow;
00052 JDIMENSION jd_samplesperrow;
00053
00054 /* Sanity check on image dimensions */
00055 if (cinfo->image_height <= 0 || cinfo->image_width <= 0
00056 || cinfo->num_components <= 0 || cinfo->input_components <= 0)
00057 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
00058
00059 /* Make sure image isn't bigger than I can handle */
00060 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
00061 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
00062 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
00063
00064 /* Width of an input scanline must be representable as JDIMENSION. */
00065 samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
00066 jd_samplesperrow = (JDIMENSION) samplesperrow;
00067 if ((long) jd_samplesperrow != samplesperrow)
00068 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
00069
00070 /* For now, precision must match compiled-in value... */
00071 if (cinfo->data_precision != BITS_IN_JSAMPLE)
00072 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
00073
00074 /* Check that number of components won't exceed internal array sizes */
00075 if (cinfo->num_components > MAX_COMPONENTS)
00076 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
00077 MAX_COMPONENTS);
00078
00079 /* Compute maximum sampling factors; check factor validity */
00080 cinfo->max_h_samp_factor = 1;
00081 cinfo->max_v_samp_factor = 1;
00082 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00083 ci++, compptr++) {
00084 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
00085 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
00086 ERREXIT(cinfo, JERR_BAD_SAMPLING);
00087 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
00088 compptr->h_samp_factor);
00089 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
00090 compptr->v_samp_factor);
00091 }
00092
00093 /* Compute dimensions of components */
00094 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00095 ci++, compptr++) {
00096 /* Fill in the correct component_index value; don't rely on application */
00097 compptr->component_index = ci;
00098 /* For compression, we never do DCT scaling. */
00099 compptr->DCT_scaled_size = DCTSIZE;
00100 /* Size in DCT blocks */
00101 compptr->width_in_blocks = (JDIMENSION)
00102 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
00103 (long) (cinfo->max_h_samp_factor * DCTSIZE));
00104 compptr->height_in_blocks = (JDIMENSION)
00105 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
00106 (long) (cinfo->max_v_samp_factor * DCTSIZE));
00107 /* Size in samples */
00108 compptr->downsampled_width = (JDIMENSION)
00109 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
00110 (long) cinfo->max_h_samp_factor);
00111 compptr->downsampled_height = (JDIMENSION)
00112 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
00113 (long) cinfo->max_v_samp_factor);
00114 /* Mark component needed (this flag isn't actually used for compression) */
00115 compptr->component_needed = TRUE;
00116 }
00117
00118 /* Compute number of fully interleaved MCU rows (number of times that
00119 * main controller will call coefficient controller).
00120 */
00121 cinfo->total_iMCU_rows = (JDIMENSION)
00122 jdiv_round_up((long) cinfo->image_height,
00123 (long) (cinfo->max_v_samp_factor*DCTSIZE));
00124 }
|
|
||||||||||||
|
Definition at line 543 of file jcmaster.c. References ERREXIT, finish_pass_master(), huff_opt_pass, initial_setup(), jpeg_comp_master::is_last_pass, JPOOL_IMAGE, main_pass, output_pass, pass_startup(), prepare_for_pass(), SIZEOF, transcode_only, and validate_script(). Referenced by jinit_compress_master(), and transencode_master_selection().
00544 {
00545 my_master_ptr master;
00546
00547 master = (my_master_ptr)
00548 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00549 SIZEOF(my_comp_master));
00550 cinfo->master = (struct jpeg_comp_master *) master;
00551 master->pub.prepare_for_pass = prepare_for_pass;
00552 master->pub.pass_startup = pass_startup;
00553 master->pub.finish_pass = finish_pass_master;
00554 master->pub.is_last_pass = FALSE;
00555
00556 /* Validate parameters, determine derived values */
00557 initial_setup(cinfo);
00558
00559 if (cinfo->scan_info != NULL) {
00560 #ifdef C_MULTISCAN_FILES_SUPPORTED
00561 validate_script(cinfo);
00562 #else
00563 ERREXIT(cinfo, JERR_NOT_COMPILED);
00564 #endif
00565 } else {
00566 cinfo->progressive_mode = FALSE;
00567 cinfo->num_scans = 1;
00568 }
00569
00570 if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
00571 cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
00572
00573 /* Initialize my private state */
00574 if (transcode_only) {
00575 /* no main pass in transcoding */
00576 if (cinfo->optimize_coding)
00577 master->pass_type = huff_opt_pass;
00578 else
00579 master->pass_type = output_pass;
00580 } else {
00581 /* for normal compression, first pass is always this type: */
00582 master->pass_type = main_pass;
00583 }
00584 master->scan_number = 0;
00585 master->pass_number = 0;
00586 if (cinfo->optimize_coding)
00587 master->total_passes = cinfo->num_scans * 2;
00588 else
00589 master->total_passes = cinfo->num_scans;
00590 }
|
|
|
Definition at line 489 of file jcmaster.c. References jpeg_comp_master::call_pass_startup, jpeg_compress_struct::marker, and jpeg_compress_struct::master. Referenced by jinit_c_master_control().
00490 {
00491 cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
00492
00493 (*cinfo->marker->write_frame_header) (cinfo);
00494 (*cinfo->marker->write_scan_header) (cinfo);
00495 }
|
|
|
Definition at line 308 of file jcmaster.c. References jpeg_compress_struct::blocks_in_MCU, C_MAX_BLOCKS_IN_MCU, compptr, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, ERREXIT, ERREXIT2, jpeg_component_info::h_samp_factor, jpeg_component_info::height_in_blocks, jpeg_compress_struct::image_height, jpeg_compress_struct::image_width, jdiv_round_up(), L, jpeg_component_info::last_col_width, jpeg_component_info::last_row_height, MAX_COMPS_IN_SCAN, jpeg_compress_struct::max_h_samp_factor, jpeg_compress_struct::max_v_samp_factor, jpeg_component_info::MCU_blocks, jpeg_component_info::MCU_height, jpeg_compress_struct::MCU_membership, jpeg_compress_struct::MCU_rows_in_scan, jpeg_component_info::MCU_sample_width, jpeg_component_info::MCU_width, jpeg_compress_struct::MCUs_per_row, MIN, jpeg_compress_struct::restart_in_rows, jpeg_compress_struct::restart_interval, jpeg_component_info::v_samp_factor, and jpeg_component_info::width_in_blocks.
00311 {
00312 int ci, mcublks, tmp;
00313 jpeg_component_info *compptr;
00314
00315 if (cinfo->comps_in_scan == 1) {
00316
00317 /* Noninterleaved (single-component) scan */
00318 compptr = cinfo->cur_comp_info[0];
00319
00320 /* Overall image size in MCUs */
00321 cinfo->MCUs_per_row = compptr->width_in_blocks;
00322 cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
00323
00324 /* For noninterleaved scan, always one block per MCU */
00325 compptr->MCU_width = 1;
00326 compptr->MCU_height = 1;
00327 compptr->MCU_blocks = 1;
00328 compptr->MCU_sample_width = DCTSIZE;
00329 compptr->last_col_width = 1;
00330 /* For noninterleaved scans, it is convenient to define last_row_height
00331 * as the number of block rows present in the last iMCU row.
00332 */
00333 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
00334 if (tmp == 0) tmp = compptr->v_samp_factor;
00335 compptr->last_row_height = tmp;
00336
00337 /* Prepare array describing MCU composition */
00338 cinfo->blocks_in_MCU = 1;
00339 cinfo->MCU_membership[0] = 0;
00340
00341 } else {
00342
00343 /* Interleaved (multi-component) scan */
00344 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
00345 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
00346 MAX_COMPS_IN_SCAN);
00347
00348 /* Overall image size in MCUs */
00349 cinfo->MCUs_per_row = (JDIMENSION)
00350 jdiv_round_up((long) cinfo->image_width,
00351 (long) (cinfo->max_h_samp_factor*DCTSIZE));
00352 cinfo->MCU_rows_in_scan = (JDIMENSION)
00353 jdiv_round_up((long) cinfo->image_height,
00354 (long) (cinfo->max_v_samp_factor*DCTSIZE));
00355
00356 cinfo->blocks_in_MCU = 0;
00357
00358 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
00359 compptr = cinfo->cur_comp_info[ci];
00360 /* Sampling factors give # of blocks of component in each MCU */
00361 compptr->MCU_width = compptr->h_samp_factor;
00362 compptr->MCU_height = compptr->v_samp_factor;
00363 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
00364 compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
00365 /* Figure number of non-dummy blocks in last MCU column & row */
00366 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
00367 if (tmp == 0) tmp = compptr->MCU_width;
00368 compptr->last_col_width = tmp;
00369 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
00370 if (tmp == 0) tmp = compptr->MCU_height;
00371 compptr->last_row_height = tmp;
00372 /* Prepare array describing MCU composition */
00373 mcublks = compptr->MCU_blocks;
00374 if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
00375 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
00376 while (mcublks-- > 0) {
00377 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
00378 }
00379 }
00380
00381 }
00382
00383 /* Convert restart specified in rows to actual MCU count. */
00384 /* Note that count must fit in 16 bits, so we provide limiting. */
00385 if (cinfo->restart_in_rows > 0) {
00386 long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
00387 cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
00388 }
00389 }
|
|
|
Definition at line 401 of file jcmaster.c. References jpeg_compress_struct::Ah, jpeg_compress_struct::arith_code, jpeg_compress_struct::cconvert, jpeg_compress_struct::coef, jpeg_compress_struct::downsample, jpeg_compress_struct::entropy, ERREXIT, jpeg_compress_struct::fdct, huff_opt_pass, JBUF_CRANK_DEST, JBUF_PASS_THRU, JBUF_SAVE_AND_PASS, jpeg_compress_struct::main, main_pass, jpeg_compress_struct::marker, jpeg_compress_struct::master, jpeg_compress_struct::optimize_coding, output_pass, my_decomp_master::pass_number, per_scan_setup(), jpeg_compress_struct::prep, my_decomp_master::pub, jpeg_compress_struct::raw_data_in, select_scan_parameters(), and jpeg_compress_struct::Ss. Referenced by jinit_c_master_control().
00402 {
00403 my_master_ptr master = (my_master_ptr) cinfo->master;
00404
00405 switch (master->pass_type) {
00406 case main_pass:
00407 /* Initial pass: will collect input data, and do either Huffman
00408 * optimization or data output for the first scan.
00409 */
00410 select_scan_parameters(cinfo);
00411 per_scan_setup(cinfo);
00412 if (! cinfo->raw_data_in) {
00413 (*cinfo->cconvert->start_pass) (cinfo);
00414 (*cinfo->downsample->start_pass) (cinfo);
00415 (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
00416 }
00417 (*cinfo->fdct->start_pass) (cinfo);
00418 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
00419 (*cinfo->coef->start_pass) (cinfo,
00420 (master->total_passes > 1 ?
00421 JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
00422 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
00423 if (cinfo->optimize_coding) {
00424 /* No immediate data output; postpone writing frame/scan headers */
00425 master->pub.call_pass_startup = FALSE;
00426 } else {
00427 /* Will write frame/scan headers at first jpeg_write_scanlines call */
00428 master->pub.call_pass_startup = TRUE;
00429 }
00430 break;
00431 #ifdef ENTROPY_OPT_SUPPORTED
00432 case huff_opt_pass:
00433 /* Do Huffman optimization for a scan after the first one. */
00434 select_scan_parameters(cinfo);
00435 per_scan_setup(cinfo);
00436 if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
00437 (*cinfo->entropy->start_pass) (cinfo, TRUE);
00438 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
00439 master->pub.call_pass_startup = FALSE;
00440 break;
00441 }
00442 /* Special case: Huffman DC refinement scans need no Huffman table
00443 * and therefore we can skip the optimization pass for them.
00444 */
00445 master->pass_type = output_pass;
00446 master->pass_number++;
00447 /*FALLTHROUGH*/
00448 #endif
00449 case output_pass:
00450 /* Do a data-output pass. */
00451 /* We need not repeat per-scan setup if prior optimization pass did it. */
00452 if (! cinfo->optimize_coding) {
00453 select_scan_parameters(cinfo);
00454 per_scan_setup(cinfo);
00455 }
00456 (*cinfo->entropy->start_pass) (cinfo, FALSE);
00457 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
00458 /* We emit frame/scan headers now */
00459 if (master->scan_number == 0)
00460 (*cinfo->marker->write_frame_header) (cinfo);
00461 (*cinfo->marker->write_scan_header) (cinfo);
00462 master->pub.call_pass_startup = FALSE;
00463 break;
00464 default:
00465 ERREXIT(cinfo, JERR_NOT_COMPILED);
00466 }
00467
00468 master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
00469
00470 /* Set up progress monitor's pass info if present */
00471 if (cinfo->progress != NULL) {
00472 cinfo->progress->completed_passes = master->pass_number;
00473 cinfo->progress->total_passes = master->total_passes;
00474 }
00475 }
|
|
|
Definition at line 267 of file jcmaster.c. References jpeg_scan_info::Ah, jpeg_compress_struct::Ah, jpeg_scan_info::Al, jpeg_compress_struct::Al, jpeg_compress_struct::comp_info, jpeg_scan_info::component_index, jpeg_scan_info::comps_in_scan, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, ERREXIT2, jpeg_compress_struct::master, MAX_COMPS_IN_SCAN, jpeg_compress_struct::num_components, jpeg_compress_struct::scan_info, jpeg_scan_info::Se, jpeg_compress_struct::Se, jpeg_scan_info::Ss, and jpeg_compress_struct::Ss. Referenced by prepare_for_pass().
00269 {
00270 int ci;
00271
00272 #ifdef C_MULTISCAN_FILES_SUPPORTED
00273 if (cinfo->scan_info != NULL) {
00274 /* Prepare for current scan --- the script is already validated */
00275 my_master_ptr master = (my_master_ptr) cinfo->master;
00276 const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
00277
00278 cinfo->comps_in_scan = scanptr->comps_in_scan;
00279 for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
00280 cinfo->cur_comp_info[ci] =
00281 &cinfo->comp_info[scanptr->component_index[ci]];
00282 }
00283 cinfo->Ss = scanptr->Ss;
00284 cinfo->Se = scanptr->Se;
00285 cinfo->Ah = scanptr->Ah;
00286 cinfo->Al = scanptr->Al;
00287 }
00288 else
00289 #endif
00290 {
00291 /* Prepare for single sequential-JPEG scan containing all components */
00292 if (cinfo->num_components > MAX_COMPS_IN_SCAN)
00293 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
00294 MAX_COMPS_IN_SCAN);
00295 cinfo->comps_in_scan = cinfo->num_components;
00296 for (ci = 0; ci < cinfo->num_components; ci++) {
00297 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
00298 }
00299 cinfo->Ss = 0;
00300 cinfo->Se = DCTSIZE2-1;
00301 cinfo->Ah = 0;
00302 cinfo->Al = 0;
00303 }
00304 }
|
|
|
Definition at line 130 of file jcmaster.c. References jpeg_scan_info::Ah, jpeg_scan_info::Al, jpeg_scan_info::component_index, jpeg_scan_info::comps_in_scan, ERREXIT, ERREXIT1, ERREXIT2, MAX_COMPONENTS, MAX_COMPS_IN_SCAN, jpeg_compress_struct::num_components, jpeg_compress_struct::num_scans, jpeg_compress_struct::progressive_mode, jpeg_compress_struct::scan_info, jpeg_scan_info::Se, jpeg_scan_info::Ss, and Ss. Referenced by jinit_c_master_control().
00134 {
00135 const jpeg_scan_info * scanptr;
00136 int scanno, ncomps, ci, coefi, thisi;
00137 int Ss, Se, Ah, Al;
00138 boolean component_sent[MAX_COMPONENTS];
00139 #ifdef C_PROGRESSIVE_SUPPORTED
00140 int * last_bitpos_ptr;
00141 int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
00142 /* -1 until that coefficient has been seen; then last Al for it */
00143 #endif
00144
00145 if (cinfo->num_scans <= 0)
00146 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
00147
00148 /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
00149 * for progressive JPEG, no scan can have this.
00150 */
00151 scanptr = cinfo->scan_info;
00152 if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
00153 #ifdef C_PROGRESSIVE_SUPPORTED
00154 cinfo->progressive_mode = TRUE;
00155 last_bitpos_ptr = & last_bitpos[0][0];
00156 for (ci = 0; ci < cinfo->num_components; ci++)
00157 for (coefi = 0; coefi < DCTSIZE2; coefi++)
00158 *last_bitpos_ptr++ = -1;
00159 #else
00160 ERREXIT(cinfo, JERR_NOT_COMPILED);
00161 #endif
00162 } else {
00163 cinfo->progressive_mode = FALSE;
00164 for (ci = 0; ci < cinfo->num_components; ci++)
00165 component_sent[ci] = FALSE;
00166 }
00167
00168 for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
00169 /* Validate component indexes */
00170 ncomps = scanptr->comps_in_scan;
00171 if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
00172 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
00173 for (ci = 0; ci < ncomps; ci++) {
00174 thisi = scanptr->component_index[ci];
00175 if (thisi < 0 || thisi >= cinfo->num_components)
00176 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
00177 /* Components must appear in SOF order within each scan */
00178 if (ci > 0 && thisi <= scanptr->component_index[ci-1])
00179 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
00180 }
00181 /* Validate progression parameters */
00182 Ss = scanptr->Ss;
00183 Se = scanptr->Se;
00184 Ah = scanptr->Ah;
00185 Al = scanptr->Al;
00186 if (cinfo->progressive_mode) {
00187 #ifdef C_PROGRESSIVE_SUPPORTED
00188 /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
00189 * seems wrong: the upper bound ought to depend on data precision.
00190 * Perhaps they really meant 0..N+1 for N-bit precision.
00191 * Here we allow 0..10 for 8-bit data; Al larger than 10 results in
00192 * out-of-range reconstructed DC values during the first DC scan,
00193 * which might cause problems for some decoders.
00194 */
00195 #if BITS_IN_JSAMPLE == 8
00196 #define MAX_AH_AL 10
00197 #else
00198 #define MAX_AH_AL 13
00199 #endif
00200 if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
00201 Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
00202 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00203 if (Ss == 0) {
00204 if (Se != 0) /* DC and AC together not OK */
00205 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00206 } else {
00207 if (ncomps != 1) /* AC scans must be for only one component */
00208 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00209 }
00210 for (ci = 0; ci < ncomps; ci++) {
00211 last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
00212 if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
00213 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00214 for (coefi = Ss; coefi <= Se; coefi++) {
00215 if (last_bitpos_ptr[coefi] < 0) {
00216 /* first scan of this coefficient */
00217 if (Ah != 0)
00218 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00219 } else {
00220 /* not first scan */
00221 if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
00222 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00223 }
00224 last_bitpos_ptr[coefi] = Al;
00225 }
00226 }
00227 #endif
00228 } else {
00229 /* For sequential JPEG, all progression parameters must be these: */
00230 if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
00231 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00232 /* Make sure components are not sent twice */
00233 for (ci = 0; ci < ncomps; ci++) {
00234 thisi = scanptr->component_index[ci];
00235 if (component_sent[thisi])
00236 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
00237 component_sent[thisi] = TRUE;
00238 }
00239 }
00240 }
00241
00242 /* Now verify that everything got sent. */
00243 if (cinfo->progressive_mode) {
00244 #ifdef C_PROGRESSIVE_SUPPORTED
00245 /* For progressive mode, we only check that at least some DC data
00246 * got sent for each component; the spec does not require that all bits
00247 * of all coefficients be transmitted. Would it be wiser to enforce
00248 * transmission of all coefficient bits??
00249 */
00250 for (ci = 0; ci < cinfo->num_components; ci++) {
00251 if (last_bitpos[ci][0] < 0)
00252 ERREXIT(cinfo, JERR_MISSING_DATA);
00253 }
00254 #endif
00255 } else {
00256 for (ci = 0; ci < cinfo->num_components; ci++) {
00257 if (! component_sent[ci])
00258 ERREXIT(cinfo, JERR_MISSING_DATA);
00259 }
00260 }
00261 }
|