14 #define JPEG_INTERNALS 55 if (cinfo->image_height <= 0 || cinfo->image_width <= 0
56 || cinfo->num_components <= 0 || cinfo->input_components <= 0)
57 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
62 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (
unsigned int) JPEG_MAX_DIMENSION);
65 samplesperrow = (
long) cinfo->image_width * (
long) cinfo->input_components;
67 if ((
long) jd_samplesperrow != samplesperrow)
68 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
72 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
76 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
80 cinfo->max_h_samp_factor = 1;
81 cinfo->max_v_samp_factor = 1;
82 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
86 ERREXIT(cinfo, JERR_BAD_SAMPLING);
87 cinfo->max_h_samp_factor =
MAX(cinfo->max_h_samp_factor,
89 cinfo->max_v_samp_factor =
MAX(cinfo->max_v_samp_factor,
94 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
103 (
long) (cinfo->max_h_samp_factor *
DCTSIZE));
106 (
long) (cinfo->max_v_samp_factor *
DCTSIZE));
110 (
long) cinfo->max_h_samp_factor);
113 (
long) cinfo->max_v_samp_factor);
127 #ifdef C_MULTISCAN_FILES_SUPPORTED 136 int scanno, ncomps, ci, coefi, thisi;
139 #ifdef C_PROGRESSIVE_SUPPORTED 140 int * last_bitpos_ptr;
145 if (cinfo->num_scans <= 0)
146 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
151 scanptr = cinfo->scan_info;
153 #ifdef C_PROGRESSIVE_SUPPORTED 154 cinfo->progressive_mode =
TRUE;
155 last_bitpos_ptr = & last_bitpos[0][0];
156 for (ci = 0; ci < cinfo->num_components; ci++)
157 for (coefi = 0; coefi <
DCTSIZE2; coefi++)
158 *last_bitpos_ptr++ = -1;
160 ERREXIT(cinfo, JERR_NOT_COMPILED);
163 cinfo->progressive_mode =
FALSE;
164 for (ci = 0; ci < cinfo->num_components; ci++)
165 component_sent[ci] =
FALSE;
168 for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
172 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
173 for (ci = 0; ci < ncomps; ci++) {
175 if (thisi < 0 || thisi >= cinfo->num_components)
176 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
178 if (ci > 0 && thisi <= scanptr->component_index[ci-1])
179 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
186 if (cinfo->progressive_mode) {
187 #ifdef C_PROGRESSIVE_SUPPORTED 195 #if BITS_IN_JSAMPLE == 8 202 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
205 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
208 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
210 for (ci = 0; ci < ncomps; ci++) {
212 if (Ss != 0 && last_bitpos_ptr[0] < 0)
213 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
214 for (coefi = Ss; coefi <= Se; coefi++) {
215 if (last_bitpos_ptr[coefi] < 0) {
218 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
221 if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
222 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
224 last_bitpos_ptr[coefi] = Al;
230 if (Ss != 0 || Se !=
DCTSIZE2-1 || Ah != 0 || Al != 0)
231 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
233 for (ci = 0; ci < ncomps; ci++) {
235 if (component_sent[thisi])
236 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
237 component_sent[thisi] =
TRUE;
243 if (cinfo->progressive_mode) {
244 #ifdef C_PROGRESSIVE_SUPPORTED 250 for (ci = 0; ci < cinfo->num_components; ci++) {
251 if (last_bitpos[ci][0] < 0)
252 ERREXIT(cinfo, JERR_MISSING_DATA);
256 for (ci = 0; ci < cinfo->num_components; ci++) {
257 if (! component_sent[ci])
258 ERREXIT(cinfo, JERR_MISSING_DATA);
272 #ifdef C_MULTISCAN_FILES_SUPPORTED 273 if (cinfo->scan_info !=
NULL) {
276 const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
280 cinfo->cur_comp_info[ci] =
283 cinfo->Ss = scanptr->
Ss;
284 cinfo->Se = scanptr->
Se;
285 cinfo->Ah = scanptr->
Ah;
286 cinfo->Al = scanptr->
Al;
293 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
295 cinfo->comps_in_scan = cinfo->num_components;
296 for (ci = 0; ci < cinfo->num_components; ci++) {
297 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
312 int ci, mcublks, tmp;
315 if (cinfo->comps_in_scan == 1) {
318 compptr = cinfo->cur_comp_info[0];
338 cinfo->blocks_in_MCU = 1;
339 cinfo->MCU_membership[0] = 0;
345 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
356 cinfo->blocks_in_MCU = 0;
358 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
359 compptr = cinfo->cur_comp_info[ci];
375 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
376 while (mcublks-- > 0) {
377 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
385 if (cinfo->restart_in_rows > 0) {
386 long nominal = (
long) cinfo->restart_in_rows * (
long) cinfo->MCUs_per_row;
387 cinfo->restart_interval = (
unsigned int)
MIN(nominal, 65535L);
405 switch (master->pass_type) {
412 if (! cinfo->raw_data_in) {
413 (*cinfo->cconvert->start_pass) (cinfo);
414 (*cinfo->downsample->start_pass) (cinfo);
417 (*cinfo->fdct->start_pass) (cinfo);
418 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
419 (*cinfo->coef->start_pass) (cinfo,
420 (master->total_passes > 1 ?
422 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
423 if (cinfo->optimize_coding) {
425 master->pub.call_pass_startup =
FALSE;
428 master->pub.call_pass_startup =
TRUE;
431 #ifdef ENTROPY_OPT_SUPPORTED 436 if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
437 (*cinfo->entropy->start_pass) (cinfo,
TRUE);
439 master->pub.call_pass_startup =
FALSE;
446 master->pass_number++;
452 if (! cinfo->optimize_coding) {
456 (*cinfo->entropy->start_pass) (cinfo,
FALSE);
459 if (master->scan_number == 0)
460 (*cinfo->marker->write_frame_header) (cinfo);
461 (*cinfo->marker->write_scan_header) (cinfo);
462 master->pub.call_pass_startup =
FALSE;
465 ERREXIT(cinfo, JERR_NOT_COMPILED);
468 master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
471 if (cinfo->progress !=
NULL) {
472 cinfo->progress->completed_passes = master->pass_number;
473 cinfo->progress->total_passes = master->total_passes;
491 cinfo->master->call_pass_startup =
FALSE;
493 (*cinfo->marker->write_frame_header) (cinfo);
494 (*cinfo->marker->write_scan_header) (cinfo);
510 (*cinfo->entropy->finish_pass) (cinfo);
513 switch (master->pass_type) {
519 if (! cinfo->optimize_coding)
520 master->scan_number++;
528 if (cinfo->optimize_coding)
530 master->scan_number++;
534 master->pass_number++;
554 master->pub.is_last_pass =
FALSE;
559 if (cinfo->scan_info !=
NULL) {
560 #ifdef C_MULTISCAN_FILES_SUPPORTED 563 ERREXIT(cinfo, JERR_NOT_COMPILED);
566 cinfo->progressive_mode =
FALSE;
567 cinfo->num_scans = 1;
570 if (cinfo->progressive_mode)
571 cinfo->optimize_coding =
TRUE;
576 if (cinfo->optimize_coding)
584 master->scan_number = 0;
585 master->pass_number = 0;
586 if (cinfo->optimize_coding)
587 master->total_passes = cinfo->num_scans * 2;
589 master->total_passes = cinfo->num_scans;
for(n=1;n< outline->n_points;n++)
JDIMENSION downsampled_width
my_comp_master * my_master_ptr
struct jpeg_common_struct * j_common_ptr
per_scan_setup(j_compress_ptr cinfo)
#define ERREXIT(cinfo, code)
jpeg_component_info * compptr
int component_index[MAX_COMPS_IN_SCAN]
JDIMENSION width_in_blocks
validate_script(j_compress_ptr cinfo)
finish_pass_master(j_compress_ptr cinfo)
JDIMENSION height_in_blocks
#define JPEG_MAX_DIMENSION
#define C_MAX_BLOCKS_IN_MCU
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
jdiv_round_up(long a, long b)
initial_setup(j_compress_ptr cinfo)
#define ERREXIT1(cinfo, code, p1)
pass_startup(j_compress_ptr cinfo)
jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
#define ERREXIT2(cinfo, code, p1, p2)
prepare_for_pass(j_compress_ptr cinfo)
#define MAX_COMPS_IN_SCAN
select_scan_parameters(j_compress_ptr cinfo)
JDIMENSION downsampled_height