Changeset 846 for trunk/src/3rdparty/libjpeg/jcmaster.c
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/3rdparty/libjpeg/jcmaster.c
r2 r846 3 3 * 4 4 * Copyright (C) 1991-1997, Thomas G. Lane. 5 * Modified 2003-2010 by Guido Vollbeding. 5 6 * This file is part of the Independent JPEG Group's software. 6 7 * For conditions of distribution and use, see the accompanying README file. … … 43 44 */ 44 45 46 /* 47 * Compute JPEG image dimensions and related values. 48 * NOTE: this is exported for possible use by application. 49 * Hence it mustn't do anything that can't be done twice. 50 */ 51 52 GLOBAL(void) 53 jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo) 54 /* Do computations that are needed before master selection phase */ 55 { 56 #ifdef DCT_SCALING_SUPPORTED 57 58 /* Compute actual JPEG image dimensions and DCT scaling choices. */ 59 if (cinfo->scale_num >= cinfo->scale_denom * 8) { 60 /* Provide 8/1 scaling */ 61 cinfo->jpeg_width = cinfo->image_width << 3; 62 cinfo->jpeg_height = cinfo->image_height << 3; 63 cinfo->min_DCT_h_scaled_size = 1; 64 cinfo->min_DCT_v_scaled_size = 1; 65 } else if (cinfo->scale_num >= cinfo->scale_denom * 4) { 66 /* Provide 4/1 scaling */ 67 cinfo->jpeg_width = cinfo->image_width << 2; 68 cinfo->jpeg_height = cinfo->image_height << 2; 69 cinfo->min_DCT_h_scaled_size = 2; 70 cinfo->min_DCT_v_scaled_size = 2; 71 } else if (cinfo->scale_num * 3 >= cinfo->scale_denom * 8) { 72 /* Provide 8/3 scaling */ 73 cinfo->jpeg_width = (cinfo->image_width << 1) + (JDIMENSION) 74 jdiv_round_up((long) cinfo->image_width * 2, 3L); 75 cinfo->jpeg_height = (cinfo->image_height << 1) + (JDIMENSION) 76 jdiv_round_up((long) cinfo->image_height * 2, 3L); 77 cinfo->min_DCT_h_scaled_size = 3; 78 cinfo->min_DCT_v_scaled_size = 3; 79 } else if (cinfo->scale_num >= cinfo->scale_denom * 2) { 80 /* Provide 2/1 scaling */ 81 cinfo->jpeg_width = cinfo->image_width << 1; 82 cinfo->jpeg_height = cinfo->image_height << 1; 83 cinfo->min_DCT_h_scaled_size = 4; 84 cinfo->min_DCT_v_scaled_size = 4; 85 } else if (cinfo->scale_num * 5 >= cinfo->scale_denom * 8) { 86 /* Provide 8/5 scaling */ 87 cinfo->jpeg_width = cinfo->image_width + (JDIMENSION) 88 jdiv_round_up((long) cinfo->image_width * 3, 5L); 89 cinfo->jpeg_height = cinfo->image_height + (JDIMENSION) 90 jdiv_round_up((long) cinfo->image_height * 3, 5L); 91 cinfo->min_DCT_h_scaled_size = 5; 92 cinfo->min_DCT_v_scaled_size = 5; 93 } else if (cinfo->scale_num * 3 >= cinfo->scale_denom * 4) { 94 /* Provide 4/3 scaling */ 95 cinfo->jpeg_width = cinfo->image_width + (JDIMENSION) 96 jdiv_round_up((long) cinfo->image_width, 3L); 97 cinfo->jpeg_height = cinfo->image_height + (JDIMENSION) 98 jdiv_round_up((long) cinfo->image_height, 3L); 99 cinfo->min_DCT_h_scaled_size = 6; 100 cinfo->min_DCT_v_scaled_size = 6; 101 } else if (cinfo->scale_num * 7 >= cinfo->scale_denom * 8) { 102 /* Provide 8/7 scaling */ 103 cinfo->jpeg_width = cinfo->image_width + (JDIMENSION) 104 jdiv_round_up((long) cinfo->image_width, 7L); 105 cinfo->jpeg_height = cinfo->image_height + (JDIMENSION) 106 jdiv_round_up((long) cinfo->image_height, 7L); 107 cinfo->min_DCT_h_scaled_size = 7; 108 cinfo->min_DCT_v_scaled_size = 7; 109 } else if (cinfo->scale_num >= cinfo->scale_denom) { 110 /* Provide 1/1 scaling */ 111 cinfo->jpeg_width = cinfo->image_width; 112 cinfo->jpeg_height = cinfo->image_height; 113 cinfo->min_DCT_h_scaled_size = 8; 114 cinfo->min_DCT_v_scaled_size = 8; 115 } else if (cinfo->scale_num * 9 >= cinfo->scale_denom * 8) { 116 /* Provide 8/9 scaling */ 117 cinfo->jpeg_width = (JDIMENSION) 118 jdiv_round_up((long) cinfo->image_width * 8, 9L); 119 cinfo->jpeg_height = (JDIMENSION) 120 jdiv_round_up((long) cinfo->image_height * 8, 9L); 121 cinfo->min_DCT_h_scaled_size = 9; 122 cinfo->min_DCT_v_scaled_size = 9; 123 } else if (cinfo->scale_num * 5 >= cinfo->scale_denom * 4) { 124 /* Provide 4/5 scaling */ 125 cinfo->jpeg_width = (JDIMENSION) 126 jdiv_round_up((long) cinfo->image_width * 4, 5L); 127 cinfo->jpeg_height = (JDIMENSION) 128 jdiv_round_up((long) cinfo->image_height * 4, 5L); 129 cinfo->min_DCT_h_scaled_size = 10; 130 cinfo->min_DCT_v_scaled_size = 10; 131 } else if (cinfo->scale_num * 11 >= cinfo->scale_denom * 8) { 132 /* Provide 8/11 scaling */ 133 cinfo->jpeg_width = (JDIMENSION) 134 jdiv_round_up((long) cinfo->image_width * 8, 11L); 135 cinfo->jpeg_height = (JDIMENSION) 136 jdiv_round_up((long) cinfo->image_height * 8, 11L); 137 cinfo->min_DCT_h_scaled_size = 11; 138 cinfo->min_DCT_v_scaled_size = 11; 139 } else if (cinfo->scale_num * 3 >= cinfo->scale_denom * 2) { 140 /* Provide 2/3 scaling */ 141 cinfo->jpeg_width = (JDIMENSION) 142 jdiv_round_up((long) cinfo->image_width * 2, 3L); 143 cinfo->jpeg_height = (JDIMENSION) 144 jdiv_round_up((long) cinfo->image_height * 2, 3L); 145 cinfo->min_DCT_h_scaled_size = 12; 146 cinfo->min_DCT_v_scaled_size = 12; 147 } else if (cinfo->scale_num * 13 >= cinfo->scale_denom * 8) { 148 /* Provide 8/13 scaling */ 149 cinfo->jpeg_width = (JDIMENSION) 150 jdiv_round_up((long) cinfo->image_width * 8, 13L); 151 cinfo->jpeg_height = (JDIMENSION) 152 jdiv_round_up((long) cinfo->image_height * 8, 13L); 153 cinfo->min_DCT_h_scaled_size = 13; 154 cinfo->min_DCT_v_scaled_size = 13; 155 } else if (cinfo->scale_num * 7 >= cinfo->scale_denom * 4) { 156 /* Provide 4/7 scaling */ 157 cinfo->jpeg_width = (JDIMENSION) 158 jdiv_round_up((long) cinfo->image_width * 4, 7L); 159 cinfo->jpeg_height = (JDIMENSION) 160 jdiv_round_up((long) cinfo->image_height * 4, 7L); 161 cinfo->min_DCT_h_scaled_size = 14; 162 cinfo->min_DCT_v_scaled_size = 14; 163 } else if (cinfo->scale_num * 15 >= cinfo->scale_denom * 8) { 164 /* Provide 8/15 scaling */ 165 cinfo->jpeg_width = (JDIMENSION) 166 jdiv_round_up((long) cinfo->image_width * 8, 15L); 167 cinfo->jpeg_height = (JDIMENSION) 168 jdiv_round_up((long) cinfo->image_height * 8, 15L); 169 cinfo->min_DCT_h_scaled_size = 15; 170 cinfo->min_DCT_v_scaled_size = 15; 171 } else { 172 /* Provide 1/2 scaling */ 173 cinfo->jpeg_width = (JDIMENSION) 174 jdiv_round_up((long) cinfo->image_width, 2L); 175 cinfo->jpeg_height = (JDIMENSION) 176 jdiv_round_up((long) cinfo->image_height, 2L); 177 cinfo->min_DCT_h_scaled_size = 16; 178 cinfo->min_DCT_v_scaled_size = 16; 179 } 180 181 #else /* !DCT_SCALING_SUPPORTED */ 182 183 /* Hardwire it to "no scaling" */ 184 cinfo->jpeg_width = cinfo->image_width; 185 cinfo->jpeg_height = cinfo->image_height; 186 cinfo->min_DCT_h_scaled_size = DCTSIZE; 187 cinfo->min_DCT_v_scaled_size = DCTSIZE; 188 189 #endif /* DCT_SCALING_SUPPORTED */ 190 191 cinfo->block_size = DCTSIZE; 192 cinfo->natural_order = jpeg_natural_order; 193 cinfo->lim_Se = DCTSIZE2-1; 194 } 195 196 45 197 LOCAL(void) 46 initial_setup (j_compress_ptr cinfo) 198 jpeg_calc_trans_dimensions (j_compress_ptr cinfo) 199 { 200 if (cinfo->min_DCT_h_scaled_size < 1 || cinfo->min_DCT_h_scaled_size > 16 201 || cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size) 202 ERREXIT2(cinfo, JERR_BAD_DCTSIZE, 203 cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size); 204 205 cinfo->block_size = cinfo->min_DCT_h_scaled_size; 206 207 switch (cinfo->block_size) { 208 case 2: cinfo->natural_order = jpeg_natural_order2; break; 209 case 3: cinfo->natural_order = jpeg_natural_order3; break; 210 case 4: cinfo->natural_order = jpeg_natural_order4; break; 211 case 5: cinfo->natural_order = jpeg_natural_order5; break; 212 case 6: cinfo->natural_order = jpeg_natural_order6; break; 213 case 7: cinfo->natural_order = jpeg_natural_order7; break; 214 default: cinfo->natural_order = jpeg_natural_order; break; 215 } 216 217 cinfo->lim_Se = cinfo->block_size < DCTSIZE ? 218 cinfo->block_size * cinfo->block_size - 1 : DCTSIZE2-1; 219 } 220 221 222 LOCAL(void) 223 initial_setup (j_compress_ptr cinfo, boolean transcode_only) 47 224 /* Do computations that are needed before master selection phase */ 48 225 { 49 int ci ;226 int ci, ssize; 50 227 jpeg_component_info *compptr; 51 228 long samplesperrow; 52 229 JDIMENSION jd_samplesperrow; 53 230 231 if (transcode_only) 232 jpeg_calc_trans_dimensions(cinfo); 233 else 234 jpeg_calc_jpeg_dimensions(cinfo); 235 54 236 /* Sanity check on image dimensions */ 55 if (cinfo-> image_height <= 0 || cinfo->image_width <= 056 ||cinfo->num_components <= 0 || cinfo->input_components <= 0)237 if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 || 238 cinfo->num_components <= 0 || cinfo->input_components <= 0) 57 239 ERREXIT(cinfo, JERR_EMPTY_IMAGE); 58 240 59 241 /* Make sure image isn't bigger than I can handle */ 60 if ((long) cinfo-> image_height > (long) JPEG_MAX_DIMENSION ||61 (long) cinfo-> image_width > (long) JPEG_MAX_DIMENSION)242 if ((long) cinfo->jpeg_height > (long) JPEG_MAX_DIMENSION || 243 (long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION) 62 244 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); 63 245 … … 96 278 /* Fill in the correct component_index value; don't rely on application */ 97 279 compptr->component_index = ci; 98 /* For compression, we never do DCT scaling. */ 99 compptr->DCT_scaled_size = DCTSIZE; 280 /* In selecting the actual DCT scaling for each component, we try to 281 * scale down the chroma components via DCT scaling rather than downsampling. 282 * This saves time if the downsampler gets to use 1:1 scaling. 283 * Note this code adapts subsampling ratios which are powers of 2. 284 */ 285 ssize = 1; 286 #ifdef DCT_SCALING_SUPPORTED 287 while (cinfo->min_DCT_h_scaled_size * ssize <= 288 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) && 289 (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) { 290 ssize = ssize * 2; 291 } 292 #endif 293 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize; 294 ssize = 1; 295 #ifdef DCT_SCALING_SUPPORTED 296 while (cinfo->min_DCT_v_scaled_size * ssize <= 297 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) && 298 (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) { 299 ssize = ssize * 2; 300 } 301 #endif 302 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize; 303 304 /* We don't support DCT ratios larger than 2. */ 305 if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2) 306 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2; 307 else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2) 308 compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2; 309 100 310 /* Size in DCT blocks */ 101 311 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));312 jdiv_round_up((long) cinfo->jpeg_width * (long) compptr->h_samp_factor, 313 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 104 314 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));315 jdiv_round_up((long) cinfo->jpeg_height * (long) compptr->v_samp_factor, 316 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 107 317 /* Size in samples */ 108 318 compptr->downsampled_width = (JDIMENSION) 109 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, 110 (long) cinfo->max_h_samp_factor); 319 jdiv_round_up((long) cinfo->jpeg_width * 320 (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size), 321 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 111 322 compptr->downsampled_height = (JDIMENSION) 112 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, 113 (long) cinfo->max_v_samp_factor); 323 jdiv_round_up((long) cinfo->jpeg_height * 324 (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size), 325 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 114 326 /* Mark component needed (this flag isn't actually used for compression) */ 115 327 compptr->component_needed = TRUE; … … 120 332 */ 121 333 cinfo->total_iMCU_rows = (JDIMENSION) 122 jdiv_round_up((long) cinfo-> image_height,123 (long) (cinfo->max_v_samp_factor *DCTSIZE));334 jdiv_round_up((long) cinfo->jpeg_height, 335 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 124 336 } 125 337 … … 261 473 } 262 474 475 476 LOCAL(void) 477 reduce_script (j_compress_ptr cinfo) 478 /* Adapt scan script for use with reduced block size; 479 * assume that script has been validated before. 480 */ 481 { 482 jpeg_scan_info * scanptr; 483 int idxout, idxin; 484 485 /* Circumvent const declaration for this function */ 486 scanptr = (jpeg_scan_info *) cinfo->scan_info; 487 idxout = 0; 488 489 for (idxin = 0; idxin < cinfo->num_scans; idxin++) { 490 /* After skipping, idxout becomes smaller than idxin */ 491 if (idxin != idxout) 492 /* Copy rest of data; 493 * note we stay in given chunk of allocated memory. 494 */ 495 scanptr[idxout] = scanptr[idxin]; 496 if (scanptr[idxout].Ss > cinfo->lim_Se) 497 /* Entire scan out of range - skip this entry */ 498 continue; 499 if (scanptr[idxout].Se > cinfo->lim_Se) 500 /* Limit scan to end of block */ 501 scanptr[idxout].Se = cinfo->lim_Se; 502 idxout++; 503 } 504 505 cinfo->num_scans = idxout; 506 } 507 263 508 #endif /* C_MULTISCAN_FILES_SUPPORTED */ 264 509 … … 281 526 &cinfo->comp_info[scanptr->component_index[ci]]; 282 527 } 283 cinfo->Ss = scanptr->Ss; 284 cinfo->Se = scanptr->Se; 285 cinfo->Ah = scanptr->Ah; 286 cinfo->Al = scanptr->Al; 528 if (cinfo->progressive_mode) { 529 cinfo->Ss = scanptr->Ss; 530 cinfo->Se = scanptr->Se; 531 cinfo->Ah = scanptr->Ah; 532 cinfo->Al = scanptr->Al; 533 return; 534 } 287 535 } 288 536 else … … 297 545 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; 298 546 } 299 cinfo->Ss = 0;300 cinfo->Se = DCTSIZE2-1;301 cinfo->Ah = 0;302 cinfo->Al= 0;303 }547 } 548 cinfo->Ss = 0; 549 cinfo->Se = cinfo->block_size * cinfo->block_size - 1; 550 cinfo->Ah = 0; 551 cinfo->Al = 0; 304 552 } 305 553 … … 326 574 compptr->MCU_height = 1; 327 575 compptr->MCU_blocks = 1; 328 compptr->MCU_sample_width = DCTSIZE;576 compptr->MCU_sample_width = compptr->DCT_h_scaled_size; 329 577 compptr->last_col_width = 1; 330 578 /* For noninterleaved scans, it is convenient to define last_row_height … … 348 596 /* Overall image size in MCUs */ 349 597 cinfo->MCUs_per_row = (JDIMENSION) 350 jdiv_round_up((long) cinfo-> image_width,351 (long) (cinfo->max_h_samp_factor *DCTSIZE));598 jdiv_round_up((long) cinfo->jpeg_width, 599 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 352 600 cinfo->MCU_rows_in_scan = (JDIMENSION) 353 jdiv_round_up((long) cinfo-> image_height,354 (long) (cinfo->max_v_samp_factor *DCTSIZE));601 jdiv_round_up((long) cinfo->jpeg_height, 602 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 355 603 356 604 cinfo->blocks_in_MCU = 0; … … 362 610 compptr->MCU_height = compptr->v_samp_factor; 363 611 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; 364 compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;612 compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size; 365 613 /* Figure number of non-dummy blocks in last MCU column & row */ 366 614 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); … … 434 682 select_scan_parameters(cinfo); 435 683 per_scan_setup(cinfo); 436 if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {684 if (cinfo->Ss != 0 || cinfo->Ah == 0) { 437 685 (*cinfo->entropy->start_pass) (cinfo, TRUE); 438 686 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); … … 555 803 556 804 /* Validate parameters, determine derived values */ 557 initial_setup(cinfo );805 initial_setup(cinfo, transcode_only); 558 806 559 807 if (cinfo->scan_info != NULL) { 560 808 #ifdef C_MULTISCAN_FILES_SUPPORTED 561 809 validate_script(cinfo); 810 if (cinfo->block_size < DCTSIZE) 811 reduce_script(cinfo); 562 812 #else 563 813 ERREXIT(cinfo, JERR_NOT_COMPILED); … … 568 818 } 569 819 570 if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */ 571 cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */ 820 if ((cinfo->progressive_mode || cinfo->block_size < DCTSIZE) && 821 !cinfo->arith_code) /* TEMPORARY HACK ??? */ 822 /* assume default tables no good for progressive or downscale mode */ 823 cinfo->optimize_coding = TRUE; 572 824 573 825 /* Initialize my private state */
Note:
See TracChangeset
for help on using the changeset viewer.