| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#define JPEG_INTERNALS |
| 15 |
#include "jinclude.h" |
| 16 |
#include "jpeglib.h" |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
typedef enum { |
| 22 |
main_pass, |
| 23 |
huff_opt_pass, |
| 24 |
output_pass |
| 25 |
} c_pass_type; |
| 26 |
|
| 27 |
typedef struct { |
| 28 |
struct jpeg_comp_master pub; |
| 29 |
|
| 30 |
c_pass_type pass_type; |
| 31 |
|
| 32 |
int pass_number; |
| 33 |
int total_passes; |
| 34 |
|
| 35 |
int scan_number; |
| 36 |
} my_comp_master; |
| 37 |
|
| 38 |
typedef my_comp_master * my_master_ptr; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
LOCAL(void) |
| 46 |
initial_setup (j_compress_ptr cinfo) |
| 47 |
|
| 48 |
{ |
| 49 |
int ci; |
| 50 |
jpeg_component_info *compptr; |
| 51 |
long samplesperrow; |
| 52 |
JDIMENSION jd_samplesperrow; |
| 53 |
|
| 54 |
|
| 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); |
| 58 |
|
| 59 |
|
| 60 |
if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || |
| 61 |
(long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) |
| 62 |
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); |
| 63 |
|
| 64 |
|
| 65 |
samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components; |
| 66 |
jd_samplesperrow = (JDIMENSION) samplesperrow; |
| 67 |
if ((long) jd_samplesperrow != samplesperrow) |
| 68 |
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); |
| 69 |
|
| 70 |
|
| 71 |
if (cinfo->data_precision != BITS_IN_JSAMPLE) |
| 72 |
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
| 73 |
|
| 74 |
|
| 75 |
if (cinfo->num_components > MAX_COMPONENTS) |
| 76 |
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, |
| 77 |
MAX_COMPONENTS); |
| 78 |
|
| 79 |
|
| 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; |
| 83 |
ci++, compptr++) { |
| 84 |
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || |
| 85 |
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) |
| 86 |
ERREXIT(cinfo, JERR_BAD_SAMPLING); |
| 87 |
cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, |
| 88 |
compptr->h_samp_factor); |
| 89 |
cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, |
| 90 |
compptr->v_samp_factor); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 95 |
ci++, compptr++) { |
| 96 |
|
| 97 |
compptr->component_index = ci; |
| 98 |
|
| 99 |
compptr->DCT_scaled_size = DCTSIZE; |
| 100 |
|
| 101 |
compptr->width_in_blocks = (JDIMENSION) |
| 102 |
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, |
| 103 |
(long) (cinfo->max_h_samp_factor * DCTSIZE)); |
| 104 |
compptr->height_in_blocks = (JDIMENSION) |
| 105 |
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, |
| 106 |
(long) (cinfo->max_v_samp_factor * DCTSIZE)); |
| 107 |
|
| 108 |
compptr->downsampled_width = (JDIMENSION) |
| 109 |
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, |
| 110 |
(long) cinfo->max_h_samp_factor); |
| 111 |
compptr->downsampled_height = (JDIMENSION) |
| 112 |
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, |
| 113 |
(long) cinfo->max_v_samp_factor); |
| 114 |
|
| 115 |
compptr->component_needed = TRUE; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
cinfo->total_iMCU_rows = (JDIMENSION) |
| 122 |
jdiv_round_up((long) cinfo->image_height, |
| 123 |
(long) (cinfo->max_v_samp_factor*DCTSIZE)); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
#ifdef C_MULTISCAN_FILES_SUPPORTED |
| 128 |
|
| 129 |
LOCAL(void) |
| 130 |
validate_script (j_compress_ptr cinfo) |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
{ |
| 135 |
const jpeg_scan_info * scanptr; |
| 136 |
int scanno, ncomps, ci, coefi, thisi; |
| 137 |
int Ss, Se, Ah, Al; |
| 138 |
boolean component_sent[MAX_COMPONENTS]; |
| 139 |
#ifdef C_PROGRESSIVE_SUPPORTED |
| 140 |
int * last_bitpos_ptr; |
| 141 |
int last_bitpos[MAX_COMPONENTS][DCTSIZE2]; |
| 142 |
|
| 143 |
#endif |
| 144 |
|
| 145 |
if (cinfo->num_scans <= 0) |
| 146 |
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0); |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
scanptr = cinfo->scan_info; |
| 152 |
if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) { |
| 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; |
| 159 |
#else |
| 160 |
ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 161 |
#endif |
| 162 |
} else { |
| 163 |
cinfo->progressive_mode = FALSE; |
| 164 |
for (ci = 0; ci < cinfo->num_components; ci++) |
| 165 |
component_sent[ci] = FALSE; |
| 166 |
} |
| 167 |
|
| 168 |
for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) { |
| 169 |
|
| 170 |
ncomps = scanptr->comps_in_scan; |
| 171 |
if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN) |
| 172 |
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN); |
| 173 |
for (ci = 0; ci < ncomps; ci++) { |
| 174 |
thisi = scanptr->component_index[ci]; |
| 175 |
if (thisi < 0 || thisi >= cinfo->num_components) |
| 176 |
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); |
| 177 |
|
| 178 |
if (ci > 0 && thisi <= scanptr->component_index[ci-1]) |
| 179 |
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); |
| 180 |
} |
| 181 |
|
| 182 |
Ss = scanptr->Ss; |
| 183 |
Se = scanptr->Se; |
| 184 |
Ah = scanptr->Ah; |
| 185 |
Al = scanptr->Al; |
| 186 |
if (cinfo->progressive_mode) { |
| 187 |
#ifdef C_PROGRESSIVE_SUPPORTED |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
#if BITS_IN_JSAMPLE == 8 |
| 196 |
#define MAX_AH_AL 10 |
| 197 |
#else |
| 198 |
#define MAX_AH_AL 13 |
| 199 |
#endif |
| 200 |
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || |
| 201 |
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL) |
| 202 |
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); |
| 203 |
if (Ss == 0) { |
| 204 |
if (Se != 0) |
| 205 |
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); |
| 206 |
} else { |
| 207 |
if (ncomps != 1) |
| 208 |
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); |
| 209 |
} |
| 210 |
for (ci = 0; ci < ncomps; ci++) { |
| 211 |
last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0]; |
| 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) { |
| 216 |
|
| 217 |
if (Ah != 0) |
| 218 |
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); |
| 219 |
} else { |
| 220 |
|
| 221 |
if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1) |
| 222 |
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); |
| 223 |
} |
| 224 |
last_bitpos_ptr[coefi] = Al; |
| 225 |
} |
| 226 |
} |
| 227 |
#endif |
| 228 |
} else { |
| 229 |
|
| 230 |
if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0) |
| 231 |
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); |
| 232 |
|
| 233 |
for (ci = 0; ci < ncomps; ci++) { |
| 234 |
thisi = scanptr->component_index[ci]; |
| 235 |
if (component_sent[thisi]) |
| 236 |
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); |
| 237 |
component_sent[thisi] = TRUE; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
if (cinfo->progressive_mode) { |
| 244 |
#ifdef C_PROGRESSIVE_SUPPORTED |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
for (ci = 0; ci < cinfo->num_components; ci++) { |
| 251 |
if (last_bitpos[ci][0] < 0) |
| 252 |
ERREXIT(cinfo, JERR_MISSING_DATA); |
| 253 |
} |
| 254 |
#endif |
| 255 |
} else { |
| 256 |
for (ci = 0; ci < cinfo->num_components; ci++) { |
| 257 |
if (! component_sent[ci]) |
| 258 |
ERREXIT(cinfo, JERR_MISSING_DATA); |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
#endif |
| 264 |
|
| 265 |
|
| 266 |
LOCAL(void) |
| 267 |
select_scan_parameters (j_compress_ptr cinfo) |
| 268 |
|
| 269 |
{ |
| 270 |
int ci; |
| 271 |
|
| 272 |
#ifdef C_MULTISCAN_FILES_SUPPORTED |
| 273 |
if (cinfo->scan_info != NULL) { |
| 274 |
|
| 275 |
my_master_ptr master = (my_master_ptr) cinfo->master; |
| 276 |
const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number; |
| 277 |
|
| 278 |
cinfo->comps_in_scan = scanptr->comps_in_scan; |
| 279 |
for (ci = 0; ci < scanptr->comps_in_scan; ci++) { |
| 280 |
cinfo->cur_comp_info[ci] = |
| 281 |
&cinfo->comp_info[scanptr->component_index[ci]]; |
| 282 |
} |
| 283 |
cinfo->Ss = scanptr->Ss; |
| 284 |
cinfo->Se = scanptr->Se; |
| 285 |
cinfo->Ah = scanptr->Ah; |
| 286 |
cinfo->Al = scanptr->Al; |
| 287 |
} |
| 288 |
else |
| 289 |
#endif |
| 290 |
{ |
| 291 |
|
| 292 |
if (cinfo->num_components > MAX_COMPS_IN_SCAN) |
| 293 |
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, |
| 294 |
MAX_COMPS_IN_SCAN); |
| 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]; |
| 298 |
} |
| 299 |
cinfo->Ss = 0; |
| 300 |
cinfo->Se = DCTSIZE2-1; |
| 301 |
cinfo->Ah = 0; |
| 302 |
cinfo->Al = 0; |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
LOCAL(void) |
| 308 |
per_scan_setup (j_compress_ptr cinfo) |
| 309 |
|
| 310 |
|
| 311 |
{ |
| 312 |
int ci, mcublks, tmp; |
| 313 |
jpeg_component_info *compptr; |
| 314 |
|
| 315 |
if (cinfo->comps_in_scan == 1) { |
| 316 |
|
| 317 |
|
| 318 |
compptr = cinfo->cur_comp_info[0]; |
| 319 |
|
| 320 |
|
| 321 |
cinfo->MCUs_per_row = compptr->width_in_blocks; |
| 322 |
cinfo->MCU_rows_in_scan = compptr->height_in_blocks; |
| 323 |
|
| 324 |
|
| 325 |
compptr->MCU_width = 1; |
| 326 |
compptr->MCU_height = 1; |
| 327 |
compptr->MCU_blocks = 1; |
| 328 |
compptr->MCU_sample_width = DCTSIZE; |
| 329 |
compptr->last_col_width = 1; |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); |
| 334 |
if (tmp == 0) tmp = compptr->v_samp_factor; |
| 335 |
compptr->last_row_height = tmp; |
| 336 |
|
| 337 |
|
| 338 |
cinfo->blocks_in_MCU = 1; |
| 339 |
cinfo->MCU_membership[0] = 0; |
| 340 |
|
| 341 |
} else { |
| 342 |
|
| 343 |
|
| 344 |
if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) |
| 345 |
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, |
| 346 |
MAX_COMPS_IN_SCAN); |
| 347 |
|
| 348 |
|
| 349 |
cinfo->MCUs_per_row = (JDIMENSION) |
| 350 |
jdiv_round_up((long) cinfo->image_width, |
| 351 |
(long) (cinfo->max_h_samp_factor*DCTSIZE)); |
| 352 |
cinfo->MCU_rows_in_scan = (JDIMENSION) |
| 353 |
jdiv_round_up((long) cinfo->image_height, |
| 354 |
(long) (cinfo->max_v_samp_factor*DCTSIZE)); |
| 355 |
|
| 356 |
cinfo->blocks_in_MCU = 0; |
| 357 |
|
| 358 |
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
| 359 |
compptr = cinfo->cur_comp_info[ci]; |
| 360 |
|
| 361 |
compptr->MCU_width = compptr->h_samp_factor; |
| 362 |
compptr->MCU_height = compptr->v_samp_factor; |
| 363 |
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; |
| 364 |
compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE; |
| 365 |
|
| 366 |
tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); |
| 367 |
if (tmp == 0) tmp = compptr->MCU_width; |
| 368 |
compptr->last_col_width = tmp; |
| 369 |
tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); |
| 370 |
if (tmp == 0) tmp = compptr->MCU_height; |
| 371 |
compptr->last_row_height = tmp; |
| 372 |
|
| 373 |
mcublks = compptr->MCU_blocks; |
| 374 |
if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) |
| 375 |
ERREXIT(cinfo, JERR_BAD_MCU_SIZE); |
| 376 |
while (mcublks-- > 0) { |
| 377 |
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 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); |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
METHODDEF(void) |
| 401 |
prepare_for_pass (j_compress_ptr cinfo) |
| 402 |
{ |
| 403 |
my_master_ptr master = (my_master_ptr) cinfo->master; |
| 404 |
|
| 405 |
switch (master->pass_type) { |
| 406 |
case main_pass: |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
select_scan_parameters(cinfo); |
| 411 |
per_scan_setup(cinfo); |
| 412 |
if (! cinfo->raw_data_in) { |
| 413 |
(*cinfo->cconvert->start_pass) (cinfo); |
| 414 |
(*cinfo->downsample->start_pass) (cinfo); |
| 415 |
(*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU); |
| 416 |
} |
| 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 ? |
| 421 |
JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); |
| 422 |
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); |
| 423 |
if (cinfo->optimize_coding) { |
| 424 |
|
| 425 |
master->pub.call_pass_startup = FALSE; |
| 426 |
} else { |
| 427 |
|
| 428 |
master->pub.call_pass_startup = TRUE; |
| 429 |
} |
| 430 |
break; |
| 431 |
#ifdef ENTROPY_OPT_SUPPORTED |
| 432 |
case huff_opt_pass: |
| 433 |
|
| 434 |
select_scan_parameters(cinfo); |
| 435 |
per_scan_setup(cinfo); |
| 436 |
if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) { |
| 437 |
(*cinfo->entropy->start_pass) (cinfo, TRUE); |
| 438 |
(*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); |
| 439 |
master->pub.call_pass_startup = FALSE; |
| 440 |
break; |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
master->pass_type = output_pass; |
| 446 |
master->pass_number++; |
| 447 |
|
| 448 |
#endif |
| 449 |
case output_pass: |
| 450 |
|
| 451 |
|
| 452 |
if (! cinfo->optimize_coding) { |
| 453 |
select_scan_parameters(cinfo); |
| 454 |
per_scan_setup(cinfo); |
| 455 |
} |
| 456 |
(*cinfo->entropy->start_pass) (cinfo, FALSE); |
| 457 |
(*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); |
| 458 |
|
| 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; |
| 463 |
break; |
| 464 |
default: |
| 465 |
ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 466 |
} |
| 467 |
|
| 468 |
master->pub.is_last_pass = (master->pass_number == master->total_passes-1); |
| 469 |
|
| 470 |
|
| 471 |
if (cinfo->progress != NULL) { |
| 472 |
cinfo->progress->completed_passes = master->pass_number; |
| 473 |
cinfo->progress->total_passes = master->total_passes; |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
METHODDEF(void) |
| 489 |
pass_startup (j_compress_ptr cinfo) |
| 490 |
{ |
| 491 |
cinfo->master->call_pass_startup = FALSE; |
| 492 |
|
| 493 |
(*cinfo->marker->write_frame_header) (cinfo); |
| 494 |
(*cinfo->marker->write_scan_header) (cinfo); |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
METHODDEF(void) |
| 503 |
finish_pass_master (j_compress_ptr cinfo) |
| 504 |
{ |
| 505 |
my_master_ptr master = (my_master_ptr) cinfo->master; |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
(*cinfo->entropy->finish_pass) (cinfo); |
| 511 |
|
| 512 |
|
| 513 |
switch (master->pass_type) { |
| 514 |
case main_pass: |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
master->pass_type = output_pass; |
| 519 |
if (! cinfo->optimize_coding) |
| 520 |
master->scan_number++; |
| 521 |
break; |
| 522 |
case huff_opt_pass: |
| 523 |
|
| 524 |
master->pass_type = output_pass; |
| 525 |
break; |
| 526 |
case output_pass: |
| 527 |
|
| 528 |
if (cinfo->optimize_coding) |
| 529 |
master->pass_type = huff_opt_pass; |
| 530 |
master->scan_number++; |
| 531 |
break; |
| 532 |
} |
| 533 |
|
| 534 |
master->pass_number++; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
GLOBAL(void) |
| 543 |
jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) |
| 544 |
{ |
| 545 |
my_master_ptr master; |
| 546 |
|
| 547 |
master = (my_master_ptr) |
| 548 |
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 549 |
SIZEOF(my_comp_master)); |
| 550 |
cinfo->master = (struct jpeg_comp_master *) master; |
| 551 |
master->pub.prepare_for_pass = prepare_for_pass; |
| 552 |
master->pub.pass_startup = pass_startup; |
| 553 |
master->pub.finish_pass = finish_pass_master; |
| 554 |
master->pub.is_last_pass = FALSE; |
| 555 |
|
| 556 |
|
| 557 |
initial_setup(cinfo); |
| 558 |
|
| 559 |
if (cinfo->scan_info != NULL) { |
| 560 |
#ifdef C_MULTISCAN_FILES_SUPPORTED |
| 561 |
validate_script(cinfo); |
| 562 |
#else |
| 563 |
ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 564 |
#endif |
| 565 |
} else { |
| 566 |
cinfo->progressive_mode = FALSE; |
| 567 |
cinfo->num_scans = 1; |
| 568 |
} |
| 569 |
|
| 570 |
if (cinfo->progressive_mode) |
| 571 |
cinfo->optimize_coding = TRUE; |
| 572 |
|
| 573 |
|
| 574 |
if (transcode_only) { |
| 575 |
|
| 576 |
if (cinfo->optimize_coding) |
| 577 |
master->pass_type = huff_opt_pass; |
| 578 |
else |
| 579 |
master->pass_type = output_pass; |
| 580 |
} else { |
| 581 |
|
| 582 |
master->pass_type = main_pass; |
| 583 |
} |
| 584 |
master->scan_number = 0; |
| 585 |
master->pass_number = 0; |
| 586 |
if (cinfo->optimize_coding) |
| 587 |
master->total_passes = cinfo->num_scans * 2; |
| 588 |
else |
| 589 |
master->total_passes = cinfo->num_scans; |
| 590 |
} |