10 #define JPEG_INTERNALS 50 if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
51 cinfo->num_components <= 0 || cinfo->input_components <= 0)
52 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
60 samplesperrow = (long)cinfo->image_width * (
long)cinfo->input_components;
62 if ((
long)jd_samplesperrow != samplesperrow)
63 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
67 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
72 cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS);
75 cinfo->max_h_samp_factor = 1;
76 cinfo->max_v_samp_factor = 1;
77 for (ci = 0,
compptr = cinfo->comp_info; ci < cinfo->num_components;
84 ERREXIT(cinfo, JERR_BAD_SAMPLING);
85 cinfo->max_h_samp_factor =
87 cinfo->max_v_samp_factor =
92 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);
123 (
long)cinfo->image_height, (long)(cinfo->max_v_samp_factor *
DCTSIZE));
126 #ifdef C_MULTISCAN_FILES_SUPPORTED 135 int scanno, ncomps, ci, coefi, thisi;
138 #ifdef C_PROGRESSIVE_SUPPORTED 139 int* last_bitpos_ptr;
144 if (cinfo->num_scans <= 0)
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
149 scanptr = cinfo->scan_info;
152 #ifdef C_PROGRESSIVE_SUPPORTED 153 cinfo->progressive_mode =
TRUE;
154 last_bitpos_ptr = &last_bitpos[0][0];
155 for (ci = 0; ci < cinfo->num_components; ci++)
156 for (coefi = 0; coefi <
DCTSIZE2; coefi++) *last_bitpos_ptr++ = -1;
158 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++)
174 for (ci = 0; ci < ncomps; ci++)
177 if (thisi < 0 || thisi >= cinfo->num_components)
178 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
180 if (ci > 0 && thisi <= scanptr->component_index[ci - 1])
181 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
188 if (cinfo->progressive_mode)
190 #ifdef C_PROGRESSIVE_SUPPORTED 198 #if BITS_IN_JSAMPLE == 8 205 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
209 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
214 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
216 for (ci = 0; ci < ncomps; ci++)
220 last_bitpos_ptr[0] < 0)
221 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
222 for (coefi = Ss; coefi <= Se; coefi++)
224 if (last_bitpos_ptr[coefi] < 0)
228 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
233 if (Ah != last_bitpos_ptr[coefi] || Al != Ah - 1)
234 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
236 last_bitpos_ptr[coefi] = Al;
244 if (Ss != 0 || Se !=
DCTSIZE2 - 1 || Ah != 0 || Al != 0)
245 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
247 for (ci = 0; ci < ncomps; ci++)
250 if (component_sent[thisi])
251 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
252 component_sent[thisi] =
TRUE;
258 if (cinfo->progressive_mode)
260 #ifdef C_PROGRESSIVE_SUPPORTED 266 for (ci = 0; ci < cinfo->num_components; ci++)
268 if (last_bitpos[ci][0] < 0)
ERREXIT(cinfo, JERR_MISSING_DATA);
274 for (ci = 0; ci < cinfo->num_components; ci++)
276 if (!component_sent[ci])
ERREXIT(cinfo, JERR_MISSING_DATA);
289 #ifdef C_MULTISCAN_FILES_SUPPORTED 290 if (cinfo->scan_info !=
nullptr)
296 cinfo->comps_in_scan = scanptr->comps_in_scan;
297 for (ci = 0; ci < scanptr->comps_in_scan; ci++)
299 cinfo->cur_comp_info[ci] =
300 &cinfo->comp_info[scanptr->component_index[ci]];
302 cinfo->Ss = scanptr->Ss;
303 cinfo->Se = scanptr->Se;
304 cinfo->Ah = scanptr->Ah;
305 cinfo->Al = scanptr->Al;
313 cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
315 cinfo->comps_in_scan = cinfo->num_components;
316 for (ci = 0; ci < cinfo->num_components; ci++)
318 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
332 int ci, mcublks, tmp;
335 if (cinfo->comps_in_scan == 1)
338 compptr = cinfo->cur_comp_info[0];
358 cinfo->blocks_in_MCU = 1;
359 cinfo->MCU_membership[0] = 0;
364 if (cinfo->comps_in_scan <= 0 ||
367 cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
372 (
long)cinfo->image_width,
373 (long)(cinfo->max_h_samp_factor *
DCTSIZE));
375 (
long)cinfo->image_height,
376 (long)(cinfo->max_v_samp_factor *
DCTSIZE));
378 cinfo->blocks_in_MCU = 0;
380 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
382 compptr = cinfo->cur_comp_info[ci];
398 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
399 while (mcublks-- > 0)
401 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
408 if (cinfo->restart_in_rows > 0)
410 long nominal = (long)cinfo->restart_in_rows * (
long)cinfo->MCUs_per_row;
411 cinfo->restart_interval = (
unsigned int)
MIN(nominal, 65535L);
436 if (!cinfo->raw_data_in)
438 (*cinfo->cconvert->start_pass)(cinfo);
439 (*cinfo->downsample->start_pass)(cinfo);
442 (*cinfo->fdct->start_pass)(cinfo);
443 (*cinfo->entropy->start_pass)(cinfo, cinfo->optimize_coding);
444 (*cinfo->coef->start_pass)(
448 if (cinfo->optimize_coding)
461 #ifdef ENTROPY_OPT_SUPPORTED 466 if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code)
468 (*cinfo->entropy->start_pass)(cinfo,
TRUE);
484 if (!cinfo->optimize_coding)
489 (*cinfo->entropy->start_pass)(cinfo,
FALSE);
493 (*cinfo->marker->write_frame_header)(cinfo);
494 (*cinfo->marker->write_scan_header)(cinfo);
498 ERREXIT(cinfo, JERR_NOT_COMPILED);
505 if (cinfo->progress !=
nullptr)
507 cinfo->progress->completed_passes = master->
pass_number;
525 cinfo->master->call_pass_startup =
FALSE;
527 (*cinfo->marker->write_frame_header)(cinfo);
528 (*cinfo->marker->write_scan_header)(cinfo);
543 (*cinfo->entropy->finish_pass)(cinfo);
553 if (!cinfo->optimize_coding) master->
scan_number++;
589 if (cinfo->scan_info !=
nullptr)
591 #ifdef C_MULTISCAN_FILES_SUPPORTED 594 ERREXIT(cinfo, JERR_NOT_COMPILED);
599 cinfo->progressive_mode =
FALSE;
600 cinfo->num_scans = 1;
603 if (cinfo->progressive_mode)
604 cinfo->optimize_coding =
611 if (cinfo->optimize_coding)
623 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)
for(ctr=DCTSIZE;ctr > 0;ctr--)
boolean call_pass_startup
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)
jpeg_component_info * compptr
JDIMENSION downsampled_height