Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

jcmaster.c File Reference

#include "jinclude.h"
#include "jpeglib.h"

Include dependency graph for jcmaster.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  my_comp_master

Defines

#define JPEG_INTERNALS

Typedefs

typedef my_comp_mastermy_master_ptr

Enumerations

enum  c_pass_type { main_pass, huff_opt_pass, output_pass }

Functions

METHODDEF void finish_pass_master (j_compress_ptr cinfo)
LOCAL void initial_setup (j_compress_ptr cinfo)
GLOBAL void jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
METHODDEF void pass_startup (j_compress_ptr cinfo)
LOCAL void per_scan_setup (j_compress_ptr cinfo)
METHODDEF void prepare_for_pass (j_compress_ptr cinfo)
LOCAL void select_scan_parameters (j_compress_ptr cinfo)
LOCAL void validate_script (j_compress_ptr cinfo)


Define Documentation

#define JPEG_INTERNALS
 

Definition at line 14 of file jcmaster.c.


Typedef Documentation

typedef my_comp_master* my_master_ptr
 

Definition at line 38 of file jcmaster.c.

Referenced by finish_output_pass(), finish_pass_master(), jinit_c_master_control(), jinit_master_decompress(), master_selection(), prepare_for_output_pass(), prepare_for_pass(), and select_scan_parameters().


Enumeration Type Documentation

enum c_pass_type
 

Enumeration values:
main_pass 
huff_opt_pass 
output_pass 

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

METHODDEF void finish_pass_master j_compress_ptr  cinfo  ) 
 

Definition at line 491 of file jcmaster.c.

References jpeg_compress_struct::entropy, huff_opt_pass, j_compress_ptr, main_pass, jpeg_compress_struct::master, my_master_ptr, jpeg_compress_struct::optimize_coding, output_pass, my_comp_master::pass_number, my_comp_master::pass_type, and my_comp_master::scan_number.

00492 {
00493   my_master_ptr master = (my_master_ptr) cinfo->master;
00494 
00495   /* The entropy coder always needs an end-of-pass call,
00496    * either to analyze statistics or to flush its output buffer.
00497    */
00498   (*cinfo->entropy->finish_pass) (cinfo);
00499 
00500   /* Update state for next pass */
00501   switch (master->pass_type) {
00502   case main_pass:
00503     /* next pass is either output of scan 0 (after optimization)
00504      * or output of scan 1 (if no optimization).
00505      */
00506     master->pass_type = output_pass;
00507     if (! cinfo->optimize_coding)
00508       master->scan_number++;
00509     break;
00510   case huff_opt_pass:
00511     /* next pass is always output of current scan */
00512     master->pass_type = output_pass;
00513     break;
00514   case output_pass:
00515     /* next pass is either optimization or output of next scan */
00516     if (cinfo->optimize_coding)
00517       master->pass_type = huff_opt_pass;
00518     master->scan_number++;
00519     break;
00520   }
00521 
00522   master->pass_number++;
00523 }

LOCAL void initial_setup j_compress_ptr  cinfo  ) 
 

Definition at line 46 of file jcmaster.c.

References jpeg_compress_struct::comp_info, jpeg_component_info::component_index, jpeg_component_info::component_needed, jpeg_compress_struct::data_precision, jpeg_component_info::DCT_scaled_size, DCTSIZE, 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, j_compress_ptr, JDIMENSION, jdiv_round_up(), JERR_BAD_PRECISION, JERR_EMPTY_IMAGE, JERR_IMAGE_TOO_BIG, JERR_WIDTH_OVERFLOW, 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 }

Here is the call graph for this function:

GLOBAL void jinit_c_master_control j_compress_ptr  cinfo,
boolean  transcode_only
 

Definition at line 531 of file jcmaster.c.

References ERREXIT, initial_setup(), jpeg_comp_master::is_last_pass, j_common_ptr, j_compress_ptr, JERR_NOT_COMPILED, jpeg_compress_struct::master, my_master_ptr, jpeg_compress_struct::num_scans, jpeg_compress_struct::optimize_coding, my_comp_master::pass_number, my_comp_master::pass_type, jpeg_compress_struct::progressive_mode, my_comp_master::pub, jpeg_compress_struct::scan_info, my_comp_master::scan_number, SIZEOF, my_comp_master::total_passes, and validate_script().

Referenced by jinit_compress_master(), and transencode_master_selection().

00532 {
00533   my_master_ptr master;
00534 
00535   master = (my_master_ptr)
00536       (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00537                   SIZEOF(my_comp_master));
00538   cinfo->master = (struct jpeg_comp_master *) master;
00539   master->pub.prepare_for_pass = prepare_for_pass;
00540   master->pub.pass_startup = pass_startup;
00541   master->pub.finish_pass = finish_pass_master;
00542   master->pub.is_last_pass = FALSE;
00543 
00544   /* Validate parameters, determine derived values */
00545   initial_setup(cinfo);
00546 
00547   if (cinfo->scan_info != NULL) {
00548 #ifdef C_MULTISCAN_FILES_SUPPORTED
00549     validate_script(cinfo);
00550 #else
00551     ERREXIT(cinfo, JERR_NOT_COMPILED);
00552 #endif
00553   } else {
00554     cinfo->progressive_mode = FALSE;
00555     cinfo->num_scans = 1;
00556   }
00557 
00558   if (cinfo->progressive_mode)  /*  TEMPORARY HACK ??? */
00559     cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
00560 
00561   /* Initialize my private state */
00562   if (transcode_only) {
00563     /* no main pass in transcoding */
00564     if (cinfo->optimize_coding)
00565       master->pass_type = huff_opt_pass;
00566     else
00567       master->pass_type = output_pass;
00568   } else {
00569     /* for normal compression, first pass is always this type: */
00570     master->pass_type = main_pass;
00571   }
00572   master->scan_number = 0;
00573   master->pass_number = 0;
00574   if (cinfo->optimize_coding)
00575     master->total_passes = cinfo->num_scans * 2;
00576   else
00577     master->total_passes = cinfo->num_scans;
00578 }

Here is the call graph for this function:

METHODDEF void pass_startup j_compress_ptr  cinfo  ) 
 

Definition at line 477 of file jcmaster.c.

References jpeg_comp_master::call_pass_startup, j_compress_ptr, jpeg_compress_struct::marker, and jpeg_compress_struct::master.

00478 {
00479   cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
00480 
00481   (*cinfo->marker->write_frame_header) (cinfo);
00482   (*cinfo->marker->write_scan_header) (cinfo);
00483 }

LOCAL void per_scan_setup j_compress_ptr  cinfo  ) 
 

Definition at line 296 of file jcmaster.c.

References jpeg_compress_struct::blocks_in_MCU, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, DCTSIZE, ERREXIT, ERREXIT2, jpeg_component_info::h_samp_factor, jpeg_component_info::height_in_blocks, jpeg_compress_struct::image_height, jpeg_compress_struct::image_width, j_compress_ptr, JDIMENSION, jdiv_round_up(), JERR_BAD_MCU_SIZE, 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.

00299 {
00300   int ci, mcublks, tmp;
00301   jpeg_component_info *compptr;
00302   
00303   if (cinfo->comps_in_scan == 1) {
00304     
00305     /* Noninterleaved (single-component) scan */
00306     compptr = cinfo->cur_comp_info[0];
00307     
00308     /* Overall image size in MCUs */
00309     cinfo->MCUs_per_row = compptr->width_in_blocks;
00310     cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
00311     
00312     /* For noninterleaved scan, always one block per MCU */
00313     compptr->MCU_width = 1;
00314     compptr->MCU_height = 1;
00315     compptr->MCU_blocks = 1;
00316     compptr->MCU_sample_width = DCTSIZE;
00317     compptr->last_col_width = 1;
00318     /* For noninterleaved scans, it is convenient to define last_row_height
00319      * as the number of block rows present in the last iMCU row.
00320      */
00321     tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
00322     if (tmp == 0) tmp = compptr->v_samp_factor;
00323     compptr->last_row_height = tmp;
00324     
00325     /* Prepare array describing MCU composition */
00326     cinfo->blocks_in_MCU = 1;
00327     cinfo->MCU_membership[0] = 0;
00328     
00329   } else {
00330     
00331     /* Interleaved (multi-component) scan */
00332     if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
00333       ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
00334            MAX_COMPS_IN_SCAN);
00335     
00336     /* Overall image size in MCUs */
00337     cinfo->MCUs_per_row = (JDIMENSION)
00338       jdiv_round_up((long) cinfo->image_width,
00339             (long) (cinfo->max_h_samp_factor*DCTSIZE));
00340     cinfo->MCU_rows_in_scan = (JDIMENSION)
00341       jdiv_round_up((long) cinfo->image_height,
00342             (long) (cinfo->max_v_samp_factor*DCTSIZE));
00343     
00344     cinfo->blocks_in_MCU = 0;
00345     
00346     for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
00347       compptr = cinfo->cur_comp_info[ci];
00348       /* Sampling factors give # of blocks of component in each MCU */
00349       compptr->MCU_width = compptr->h_samp_factor;
00350       compptr->MCU_height = compptr->v_samp_factor;
00351       compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
00352       compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
00353       /* Figure number of non-dummy blocks in last MCU column & row */
00354       tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
00355       if (tmp == 0) tmp = compptr->MCU_width;
00356       compptr->last_col_width = tmp;
00357       tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
00358       if (tmp == 0) tmp = compptr->MCU_height;
00359       compptr->last_row_height = tmp;
00360       /* Prepare array describing MCU composition */
00361       mcublks = compptr->MCU_blocks;
00362       if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
00363     ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
00364       while (mcublks-- > 0) {
00365     cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
00366       }
00367     }
00368     
00369   }
00370 
00371   /* Convert restart specified in rows to actual MCU count. */
00372   /* Note that count must fit in 16 bits, so we provide limiting. */
00373   if (cinfo->restart_in_rows > 0) {
00374     long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
00375     cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
00376   }
00377 }

Here is the call graph for this function:

METHODDEF void prepare_for_pass j_compress_ptr  cinfo  ) 
 

Definition at line 389 of file jcmaster.c.

References jpeg_compress_struct::Ah, jpeg_compress_struct::arith_code, jpeg_comp_master::call_pass_startup, jpeg_compress_struct::cconvert, jpeg_compress_struct::coef, jpeg_compress_struct::downsample, jpeg_compress_struct::entropy, ERREXIT, jpeg_compress_struct::fdct, huff_opt_pass, jpeg_comp_master::is_last_pass, j_compress_ptr, JBUF_SAVE_AND_PASS, JERR_NOT_COMPILED, jpeg_compress_struct::main, main_pass, jpeg_compress_struct::marker, jpeg_compress_struct::master, my_master_ptr, jpeg_compress_struct::optimize_coding, output_pass, my_comp_master::pass_number, my_comp_master::pass_type, per_scan_setup(), jpeg_compress_struct::prep, my_comp_master::pub, jpeg_compress_struct::raw_data_in, my_comp_master::scan_number, select_scan_parameters(), jpeg_compress_struct::Ss, and my_comp_master::total_passes.

00390 {
00391   my_master_ptr master = (my_master_ptr) cinfo->master;
00392 
00393   switch (master->pass_type) {
00394   case main_pass:
00395     /* Initial pass: will collect input data, and do either Huffman
00396      * optimization or data output for the first scan.
00397      */
00398     select_scan_parameters(cinfo);
00399     per_scan_setup(cinfo);
00400     if (! cinfo->raw_data_in) {
00401       (*cinfo->cconvert->start_pass) (cinfo);
00402       (*cinfo->downsample->start_pass) (cinfo);
00403       (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
00404     }
00405     (*cinfo->fdct->start_pass) (cinfo);
00406     (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
00407     (*cinfo->coef->start_pass) (cinfo,
00408                 (master->total_passes > 1 ?
00409                  JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
00410     (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
00411     if (cinfo->optimize_coding) {
00412       /* No immediate data output; postpone writing frame/scan headers */
00413       master->pub.call_pass_startup = FALSE;
00414     } else {
00415       /* Will write frame/scan headers at first jpeg_write_scanlines call */
00416       master->pub.call_pass_startup = TRUE;
00417     }
00418     break;
00419 #ifdef ENTROPY_OPT_SUPPORTED
00420   case huff_opt_pass:
00421     /* Do Huffman optimization for a scan after the first one. */
00422     select_scan_parameters(cinfo);
00423     per_scan_setup(cinfo);
00424     if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
00425       (*cinfo->entropy->start_pass) (cinfo, TRUE);
00426       (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
00427       master->pub.call_pass_startup = FALSE;
00428       break;
00429     }
00430     /* Special case: Huffman DC refinement scans need no Huffman table
00431      * and therefore we can skip the optimization pass for them.
00432      */
00433     master->pass_type = output_pass;
00434     master->pass_number++;
00435     /*FALLTHROUGH*/
00436 #endif
00437   case output_pass:
00438     /* Do a data-output pass. */
00439     /* We need not repeat per-scan setup if prior optimization pass did it. */
00440     if (! cinfo->optimize_coding) {
00441       select_scan_parameters(cinfo);
00442       per_scan_setup(cinfo);
00443     }
00444     (*cinfo->entropy->start_pass) (cinfo, FALSE);
00445     (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
00446     /* We emit frame/scan headers now */
00447     if (master->scan_number == 0)
00448       (*cinfo->marker->write_frame_header) (cinfo);
00449     (*cinfo->marker->write_scan_header) (cinfo);
00450     master->pub.call_pass_startup = FALSE;
00451     break;
00452   default:
00453     ERREXIT(cinfo, JERR_NOT_COMPILED);
00454   }
00455 
00456   master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
00457 
00458   /* Set up progress monitor's pass info if present */
00459   if (cinfo->progress != NULL) {
00460     cinfo->progress->completed_passes = master->pass_number;
00461     cinfo->progress->total_passes = master->total_passes;
00462   }
00463 }

Here is the call graph for this function:

LOCAL void select_scan_parameters j_compress_ptr  cinfo  ) 
 

Definition at line 255 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, DCTSIZE2, ERREXIT2, j_compress_ptr, jpeg_compress_struct::master, MAX_COMPS_IN_SCAN, my_master_ptr, jpeg_compress_struct::num_components, jpeg_compress_struct::scan_info, my_comp_master::scan_number, jpeg_scan_info::Se, jpeg_compress_struct::Se, jpeg_scan_info::Ss, and jpeg_compress_struct::Ss.

Referenced by prepare_for_pass().

00257 {
00258   int ci;
00259 
00260 #ifdef C_MULTISCAN_FILES_SUPPORTED
00261   if (cinfo->scan_info != NULL) {
00262     /* Prepare for current scan --- the script is already validated */
00263     my_master_ptr master = (my_master_ptr) cinfo->master;
00264     const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
00265 
00266     cinfo->comps_in_scan = scanptr->comps_in_scan;
00267     for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
00268       cinfo->cur_comp_info[ci] =
00269     &cinfo->comp_info[scanptr->component_index[ci]];
00270     }
00271     cinfo->Ss = scanptr->Ss;
00272     cinfo->Se = scanptr->Se;
00273     cinfo->Ah = scanptr->Ah;
00274     cinfo->Al = scanptr->Al;
00275   }
00276   else
00277 #endif
00278   {
00279     /* Prepare for single sequential-JPEG scan containing all components */
00280     if (cinfo->num_components > MAX_COMPS_IN_SCAN)
00281       ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
00282            MAX_COMPS_IN_SCAN);
00283     cinfo->comps_in_scan = cinfo->num_components;
00284     for (ci = 0; ci < cinfo->num_components; ci++) {
00285       cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
00286     }
00287     cinfo->Ss = 0;
00288     cinfo->Se = DCTSIZE2-1;
00289     cinfo->Ah = 0;
00290     cinfo->Al = 0;
00291   }
00292 }

LOCAL void validate_script j_compress_ptr  cinfo  ) 
 

Definition at line 130 of file jcmaster.c.

References jpeg_scan_info::Ah, Ah, jpeg_scan_info::Al, Al, jpeg_scan_info::component_index, jpeg_scan_info::comps_in_scan, DCTSIZE2, ERREXIT, ERREXIT1, ERREXIT2, j_compress_ptr, JERR_MISSING_DATA, JERR_NOT_COMPILED, MAX_COMPS_IN_SCAN, jpeg_compress_struct::num_components, jpeg_compress_struct::num_scans, jpeg_compress_struct::progressive_mode, jpeg_compress_struct::scan_info, Se, jpeg_scan_info::Se, Ss, and jpeg_scan_info::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       if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
00189       Ah < 0 || Ah > 13 || Al < 0 || Al > 13)
00190     ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00191       if (Ss == 0) {
00192     if (Se != 0)        /* DC and AC together not OK */
00193       ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00194       } else {
00195     if (ncomps != 1)    /* AC scans must be for only one component */
00196       ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00197       }
00198       for (ci = 0; ci < ncomps; ci++) {
00199     last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
00200     if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
00201       ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00202     for (coefi = Ss; coefi <= Se; coefi++) {
00203       if (last_bitpos_ptr[coefi] < 0) {
00204         /* first scan of this coefficient */
00205         if (Ah != 0)
00206           ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00207       } else {
00208         /* not first scan */
00209         if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
00210           ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00211       }
00212       last_bitpos_ptr[coefi] = Al;
00213     }
00214       }
00215 #endif
00216     } else {
00217       /* For sequential JPEG, all progression parameters must be these: */
00218       if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
00219     ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
00220       /* Make sure components are not sent twice */
00221       for (ci = 0; ci < ncomps; ci++) {
00222     thisi = scanptr->component_index[ci];
00223     if (component_sent[thisi])
00224       ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
00225     component_sent[thisi] = TRUE;
00226       }
00227     }
00228   }
00229 
00230   /* Now verify that everything got sent. */
00231   if (cinfo->progressive_mode) {
00232 #ifdef C_PROGRESSIVE_SUPPORTED
00233     /* For progressive mode, we only check that at least some DC data
00234      * got sent for each component; the spec does not require that all bits
00235      * of all coefficients be transmitted.  Would it be wiser to enforce
00236      * transmission of all coefficient bits??
00237      */
00238     for (ci = 0; ci < cinfo->num_components; ci++) {
00239       if (last_bitpos[ci][0] < 0)
00240     ERREXIT(cinfo, JERR_MISSING_DATA);
00241     }
00242 #endif
00243   } else {
00244     for (ci = 0; ci < cinfo->num_components; ci++) {
00245       if (! component_sent[ci])
00246     ERREXIT(cinfo, JERR_MISSING_DATA);
00247     }
00248   }
00249 }


Generated on Thu Aug 25 14:00:35 2005 for Quake III Arena by  doxygen 1.3.9.1