#include "jinclude.h"
#include "jpeglib.h"
Go to the source code of this file.
Data Structures | |
struct | my_comp_master |
Defines | |
#define | JPEG_INTERNALS |
Typedefs | |
typedef my_comp_master * | my_master_ptr |
Enumerations | |
enum | c_pass_type { main_pass, huff_opt_pass, output_pass } |
Functions | |
finish_pass_master (j_compress_ptr cinfo) | |
initial_setup (j_compress_ptr cinfo) | |
jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) | |
pass_startup (j_compress_ptr cinfo) | |
per_scan_setup (j_compress_ptr cinfo) | |
prepare_for_pass (j_compress_ptr cinfo) | |
select_scan_parameters (j_compress_ptr cinfo) |
#define JPEG_INTERNALS |
Definition at line 14 of file jcmaster.c.
typedef my_comp_master* my_master_ptr |
Definition at line 38 of file jcmaster.c.
enum c_pass_type |
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;
finish_pass_master | ( | j_compress_ptr | cinfo | ) |
Definition at line 503 of file jcmaster.c.
References huff_opt_pass, main_pass, output_pass, my_comp_master::pass_number, my_comp_master::pass_type, and my_comp_master::scan_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 }
initial_setup | ( | j_compress_ptr | cinfo | ) |
Definition at line 46 of file jcmaster.c.
References BITS_IN_JSAMPLE, jpeg_component_info::component_index, jpeg_component_info::component_needed, compptr, 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, jdiv_round_up(), JPEG_MAX_DIMENSION, MAX, MAX_COMPONENTS, MAX_SAMP_FACTOR, TRUE, jpeg_component_info::v_samp_factor, and jpeg_component_info::width_in_blocks.
Referenced by consume_markers(), and jinit_c_master_control().
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 }
jinit_c_master_control | ( | j_compress_ptr | cinfo, | |
boolean | transcode_only | |||
) |
Definition at line 543 of file jcmaster.c.
References ERREXIT, FALSE, finish_pass_master(), huff_opt_pass, initial_setup(), jpeg_comp_master::is_last_pass, JPOOL_IMAGE, main_pass, output_pass, my_comp_master::pass_number, pass_startup(), my_comp_master::pass_type, prepare_for_pass(), my_comp_master::pub, my_comp_master::scan_number, SIZEOF, my_comp_master::total_passes, and TRUE.
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 }
pass_startup | ( | j_compress_ptr | cinfo | ) |
Definition at line 489 of file jcmaster.c.
References FALSE.
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 }
per_scan_setup | ( | j_compress_ptr | cinfo | ) |
Definition at line 308 of file jcmaster.c.
References C_MAX_BLOCKS_IN_MCU, compptr, DCTSIZE, ERREXIT, ERREXIT2, jpeg_component_info::h_samp_factor, jpeg_component_info::height_in_blocks, jdiv_round_up(), jpeg_component_info::last_col_width, jpeg_component_info::last_row_height, jpeg_component_info::MCU_blocks, jpeg_component_info::MCU_height, jpeg_component_info::MCU_sample_width, jpeg_component_info::MCU_width, MIN, jpeg_component_info::v_samp_factor, and jpeg_component_info::width_in_blocks.
Referenced by prepare_for_pass(), and start_input_pass().
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 }
prepare_for_pass | ( | j_compress_ptr | cinfo | ) |
Definition at line 401 of file jcmaster.c.
References jpeg_comp_master::call_pass_startup, ERREXIT, FALSE, huff_opt_pass, jpeg_comp_master::is_last_pass, JBUF_CRANK_DEST, JBUF_PASS_THRU, JBUF_SAVE_AND_PASS, main_pass, output_pass, my_comp_master::pass_number, my_comp_master::pass_type, per_scan_setup(), my_comp_master::pub, my_comp_master::scan_number, select_scan_parameters(), my_comp_master::total_passes, and TRUE.
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 }
select_scan_parameters | ( | j_compress_ptr | cinfo | ) |
Definition at line 267 of file jcmaster.c.
References jpeg_scan_info::Ah, jpeg_scan_info::Al, jpeg_scan_info::component_index, jpeg_scan_info::comps_in_scan, DCTSIZE2, ERREXIT2, my_comp_master::scan_number, jpeg_scan_info::Se, and jpeg_scan_info::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 }