10 #define JPEG_INTERNALS 51 if (cinfo->image_height <= 0 || cinfo->image_width <= 0
52 || cinfo->num_components <= 0 || cinfo->input_components <= 0)
53 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
61 samplesperrow = (long) cinfo->image_width * (
long) cinfo->input_components;
63 if ((
long) jd_samplesperrow != samplesperrow)
64 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
68 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
72 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
76 cinfo->max_h_samp_factor = 1;
77 cinfo->max_v_samp_factor = 1;
78 for (ci = 0,
compptr = cinfo->comp_info; ci < cinfo->num_components;
82 ERREXIT(cinfo, JERR_BAD_SAMPLING);
83 cinfo->max_h_samp_factor =
MAX(cinfo->max_h_samp_factor,
85 cinfo->max_v_samp_factor =
MAX(cinfo->max_v_samp_factor,
90 for (ci = 0,
compptr = cinfo->comp_info; ci < cinfo->num_components;
99 (
long) (cinfo->max_h_samp_factor *
DCTSIZE));
102 (
long) (cinfo->max_v_samp_factor *
DCTSIZE));
106 (
long) cinfo->max_h_samp_factor);
109 (
long) cinfo->max_v_samp_factor);
119 (long) (cinfo->max_v_samp_factor*
DCTSIZE));
123 #ifdef C_MULTISCAN_FILES_SUPPORTED 132 int scanno, ncomps, ci, coefi, thisi;
135 #ifdef C_PROGRESSIVE_SUPPORTED 136 int * last_bitpos_ptr;
141 if (cinfo->num_scans <= 0)
142 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
147 scanptr = cinfo->scan_info;
149 #ifdef C_PROGRESSIVE_SUPPORTED 150 cinfo->progressive_mode =
TRUE;
151 last_bitpos_ptr = & last_bitpos[0][0];
152 for (ci = 0; ci < cinfo->num_components; ci++)
153 for (coefi = 0; coefi <
DCTSIZE2; coefi++)
154 *last_bitpos_ptr++ = -1;
156 ERREXIT(cinfo, JERR_NOT_COMPILED);
159 cinfo->progressive_mode =
FALSE;
160 for (ci = 0; ci < cinfo->num_components; ci++)
161 component_sent[ci] =
FALSE;
164 for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
169 for (ci = 0; ci < ncomps; ci++) {
171 if (thisi < 0 || thisi >= cinfo->num_components)
172 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
174 if (ci > 0 && thisi <= scanptr->component_index[ci-1])
175 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
182 if (cinfo->progressive_mode) {
183 #ifdef C_PROGRESSIVE_SUPPORTED 191 #if BITS_IN_JSAMPLE == 8 198 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
201 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
204 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
206 for (ci = 0; ci < ncomps; ci++) {
208 if (Ss != 0 && last_bitpos_ptr[0] < 0)
209 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
210 for (coefi = Ss; coefi <= Se; coefi++) {
211 if (last_bitpos_ptr[coefi] < 0) {
214 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
217 if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
218 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
220 last_bitpos_ptr[coefi] = Al;
226 if (Ss != 0 || Se !=
DCTSIZE2-1 || Ah != 0 || Al != 0)
227 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
229 for (ci = 0; ci < ncomps; ci++) {
231 if (component_sent[thisi])
232 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
233 component_sent[thisi] =
TRUE;
239 if (cinfo->progressive_mode) {
240 #ifdef C_PROGRESSIVE_SUPPORTED 246 for (ci = 0; ci < cinfo->num_components; ci++) {
247 if (last_bitpos[ci][0] < 0)
248 ERREXIT(cinfo, JERR_MISSING_DATA);
252 for (ci = 0; ci < cinfo->num_components; ci++) {
253 if (! component_sent[ci])
254 ERREXIT(cinfo, JERR_MISSING_DATA);
268 #ifdef C_MULTISCAN_FILES_SUPPORTED 269 if (cinfo->scan_info != NULL) {
274 cinfo->comps_in_scan = scanptr->comps_in_scan;
275 for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
276 cinfo->cur_comp_info[ci] =
277 &cinfo->comp_info[scanptr->component_index[ci]];
279 cinfo->Ss = scanptr->Ss;
280 cinfo->Se = scanptr->Se;
281 cinfo->Ah = scanptr->Ah;
282 cinfo->Al = scanptr->Al;
289 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
291 cinfo->comps_in_scan = cinfo->num_components;
292 for (ci = 0; ci < cinfo->num_components; ci++) {
293 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
308 int ci, mcublks, tmp;
311 if (cinfo->comps_in_scan == 1) {
314 compptr = cinfo->cur_comp_info[0];
334 cinfo->blocks_in_MCU = 1;
335 cinfo->MCU_membership[0] = 0;
341 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
347 (long) (cinfo->max_h_samp_factor*
DCTSIZE));
350 (long) (cinfo->max_v_samp_factor*
DCTSIZE));
352 cinfo->blocks_in_MCU = 0;
354 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
355 compptr = cinfo->cur_comp_info[ci];
371 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
372 while (mcublks-- > 0) {
373 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
381 if (cinfo->restart_in_rows > 0) {
382 long nominal = (long) cinfo->restart_in_rows * (
long) cinfo->MCUs_per_row;
383 cinfo->restart_interval = (
unsigned int)
MIN(nominal, 65535L);
408 if (! cinfo->raw_data_in) {
409 (*cinfo->cconvert->start_pass) (cinfo);
410 (*cinfo->downsample->start_pass) (cinfo);
413 (*cinfo->fdct->start_pass) (cinfo);
414 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
415 (*cinfo->coef->start_pass) (cinfo,
419 if (cinfo->optimize_coding) {
427 #ifdef ENTROPY_OPT_SUPPORTED 432 if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
433 (*cinfo->entropy->start_pass) (cinfo,
TRUE);
448 if (! cinfo->optimize_coding) {
452 (*cinfo->entropy->start_pass) (cinfo,
FALSE);
456 (*cinfo->marker->write_frame_header) (cinfo);
457 (*cinfo->marker->write_scan_header) (cinfo);
461 ERREXIT(cinfo, JERR_NOT_COMPILED);
467 if (cinfo->progress != NULL) {
468 cinfo->progress->completed_passes = master->
pass_number;
487 cinfo->master->call_pass_startup =
FALSE;
489 (*cinfo->marker->write_frame_header) (cinfo);
490 (*cinfo->marker->write_scan_header) (cinfo);
506 (*cinfo->entropy->finish_pass) (cinfo);
515 if (! cinfo->optimize_coding)
524 if (cinfo->optimize_coding)
555 if (cinfo->scan_info != NULL) {
556 #ifdef C_MULTISCAN_FILES_SUPPORTED 559 ERREXIT(cinfo, JERR_NOT_COMPILED);
562 cinfo->progressive_mode =
FALSE;
563 cinfo->num_scans = 1;
566 if (cinfo->progressive_mode)
567 cinfo->optimize_coding =
TRUE;
572 if (cinfo->optimize_coding)
582 if (cinfo->optimize_coding)
jdiv_round_up(long a, long b)
JDIMENSION downsampled_width
#define MAX_COMPS_IN_SCAN
prepare_for_pass(j_compress_ptr cinfo)
struct jpeg_common_struct * j_common_ptr
pass_startup(j_compress_ptr cinfo)
#define ERREXIT(cinfo, code)
boolean call_pass_startup
jpeg_component_info * compptr
int component_index[MAX_COMPS_IN_SCAN]
JDIMENSION width_in_blocks
struct jpeg_comp_master pub
validate_script(j_compress_ptr cinfo)
JDIMENSION height_in_blocks
#define JPEG_MAX_DIMENSION
select_scan_parameters(j_compress_ptr cinfo)
#define C_MAX_BLOCKS_IN_MCU
per_scan_setup(j_compress_ptr cinfo)
#define ERREXIT1(cinfo, code, p1)
finish_pass_master(j_compress_ptr cinfo)
jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
my_comp_master * my_master_ptr
#define ERREXIT2(cinfo, code, p1, p2)
initial_setup(j_compress_ptr cinfo)
JDIMENSION downsampled_height