| OLD | NEW |
| 1 /* | 1 /* |
| 2 * jdmaster.c | 2 * jdmaster.c |
| 3 * | 3 * |
| 4 * Copyright (C) 1991-1997, Thomas G. Lane. | 4 * Copyright (C) 1991-1997, Thomas G. Lane. |
| 5 * Copyright (C) 2009, D. R. Commander. | 5 * Copyright (C) 2009-2010, D. R. Commander. |
| 6 * This file is part of the Independent JPEG Group's software. | 6 * This file is part of the Independent JPEG Group's software. |
| 7 * For conditions of distribution and use, see the accompanying README file. | 7 * For conditions of distribution and use, see the accompanying README file. |
| 8 * | 8 * |
| 9 * This file contains master control logic for the JPEG decompressor. | 9 * This file contains master control logic for the JPEG decompressor. |
| 10 * These routines are concerned with selecting the modules to be executed | 10 * These routines are concerned with selecting the modules to be executed |
| 11 * and with determining the number of passes and the work to be done in each | 11 * and with determining the number of passes and the work to be done in each |
| 12 * pass. | 12 * pass. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 #define JPEG_INTERNALS | 15 #define JPEG_INTERNALS |
| 16 #include "jinclude.h" | 16 #include "jinclude.h" |
| 17 #include "jpeglib.h" | 17 #include "jpeglib.h" |
| 18 #include "jpegcomp.h" |
| 18 | 19 |
| 19 | 20 |
| 20 /* Private state */ | 21 /* Private state */ |
| 21 | 22 |
| 22 typedef struct { | 23 typedef struct { |
| 23 struct jpeg_decomp_master pub; /* public fields */ | 24 struct jpeg_decomp_master pub; /* public fields */ |
| 24 | 25 |
| 25 int pass_number; /* # of passes completed */ | 26 int pass_number; /* # of passes completed */ |
| 26 | 27 |
| 27 boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */ | 28 boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */ |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 return FALSE; | 62 return FALSE; |
| 62 /* and it only handles 2h1v or 2h2v sampling ratios */ | 63 /* and it only handles 2h1v or 2h2v sampling ratios */ |
| 63 if (cinfo->comp_info[0].h_samp_factor != 2 || | 64 if (cinfo->comp_info[0].h_samp_factor != 2 || |
| 64 cinfo->comp_info[1].h_samp_factor != 1 || | 65 cinfo->comp_info[1].h_samp_factor != 1 || |
| 65 cinfo->comp_info[2].h_samp_factor != 1 || | 66 cinfo->comp_info[2].h_samp_factor != 1 || |
| 66 cinfo->comp_info[0].v_samp_factor > 2 || | 67 cinfo->comp_info[0].v_samp_factor > 2 || |
| 67 cinfo->comp_info[1].v_samp_factor != 1 || | 68 cinfo->comp_info[1].v_samp_factor != 1 || |
| 68 cinfo->comp_info[2].v_samp_factor != 1) | 69 cinfo->comp_info[2].v_samp_factor != 1) |
| 69 return FALSE; | 70 return FALSE; |
| 70 /* furthermore, it doesn't work if we've scaled the IDCTs differently */ | 71 /* furthermore, it doesn't work if we've scaled the IDCTs differently */ |
| 71 if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size || | 72 if (cinfo->comp_info[0]._DCT_scaled_size != cinfo->_min_DCT_scaled_size || |
| 72 cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size || | 73 cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size || |
| 73 cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size) | 74 cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size) |
| 74 return FALSE; | 75 return FALSE; |
| 75 /* ??? also need to test for upsample-time rescaling, when & if supported */ | 76 /* ??? also need to test for upsample-time rescaling, when & if supported */ |
| 76 return TRUE; /* by golly, it'll work... */ | 77 return TRUE; /* by golly, it'll work... */ |
| 77 #else | 78 #else |
| 78 return FALSE; | 79 return FALSE; |
| 79 #endif | 80 #endif |
| 80 } | 81 } |
| 81 | 82 |
| 82 | 83 |
| 83 /* | 84 /* |
| (...skipping 18 matching lines...) Expand all Loading... |
| 102 | 103 |
| 103 #ifdef IDCT_SCALING_SUPPORTED | 104 #ifdef IDCT_SCALING_SUPPORTED |
| 104 | 105 |
| 105 /* Compute actual output image dimensions and DCT scaling choices. */ | 106 /* Compute actual output image dimensions and DCT scaling choices. */ |
| 106 if (cinfo->scale_num * 8 <= cinfo->scale_denom) { | 107 if (cinfo->scale_num * 8 <= cinfo->scale_denom) { |
| 107 /* Provide 1/8 scaling */ | 108 /* Provide 1/8 scaling */ |
| 108 cinfo->output_width = (JDIMENSION) | 109 cinfo->output_width = (JDIMENSION) |
| 109 jdiv_round_up((long) cinfo->image_width, 8L); | 110 jdiv_round_up((long) cinfo->image_width, 8L); |
| 110 cinfo->output_height = (JDIMENSION) | 111 cinfo->output_height = (JDIMENSION) |
| 111 jdiv_round_up((long) cinfo->image_height, 8L); | 112 jdiv_round_up((long) cinfo->image_height, 8L); |
| 113 #if JPEG_LIB_VERSION >= 70 |
| 114 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 1; |
| 115 #else |
| 112 cinfo->min_DCT_scaled_size = 1; | 116 cinfo->min_DCT_scaled_size = 1; |
| 117 #endif |
| 113 } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) { | 118 } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) { |
| 114 /* Provide 1/4 scaling */ | 119 /* Provide 1/4 scaling */ |
| 115 cinfo->output_width = (JDIMENSION) | 120 cinfo->output_width = (JDIMENSION) |
| 116 jdiv_round_up((long) cinfo->image_width, 4L); | 121 jdiv_round_up((long) cinfo->image_width, 4L); |
| 117 cinfo->output_height = (JDIMENSION) | 122 cinfo->output_height = (JDIMENSION) |
| 118 jdiv_round_up((long) cinfo->image_height, 4L); | 123 jdiv_round_up((long) cinfo->image_height, 4L); |
| 124 #if JPEG_LIB_VERSION >= 70 |
| 125 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 2; |
| 126 #else |
| 119 cinfo->min_DCT_scaled_size = 2; | 127 cinfo->min_DCT_scaled_size = 2; |
| 128 #endif |
| 120 } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) { | 129 } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) { |
| 121 /* Provide 1/2 scaling */ | 130 /* Provide 1/2 scaling */ |
| 122 cinfo->output_width = (JDIMENSION) | 131 cinfo->output_width = (JDIMENSION) |
| 123 jdiv_round_up((long) cinfo->image_width, 2L); | 132 jdiv_round_up((long) cinfo->image_width, 2L); |
| 124 cinfo->output_height = (JDIMENSION) | 133 cinfo->output_height = (JDIMENSION) |
| 125 jdiv_round_up((long) cinfo->image_height, 2L); | 134 jdiv_round_up((long) cinfo->image_height, 2L); |
| 135 #if JPEG_LIB_VERSION >= 70 |
| 136 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 4; |
| 137 #else |
| 126 cinfo->min_DCT_scaled_size = 4; | 138 cinfo->min_DCT_scaled_size = 4; |
| 139 #endif |
| 127 } else { | 140 } else { |
| 128 /* Provide 1/1 scaling */ | 141 /* Provide 1/1 scaling */ |
| 129 cinfo->output_width = cinfo->image_width; | 142 cinfo->output_width = cinfo->image_width; |
| 130 cinfo->output_height = cinfo->image_height; | 143 cinfo->output_height = cinfo->image_height; |
| 144 #if JPEG_LIB_VERSION >= 70 |
| 145 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; |
| 146 #else |
| 131 cinfo->min_DCT_scaled_size = DCTSIZE; | 147 cinfo->min_DCT_scaled_size = DCTSIZE; |
| 148 #endif |
| 132 } | 149 } |
| 133 /* In selecting the actual DCT scaling for each component, we try to | 150 /* In selecting the actual DCT scaling for each component, we try to |
| 134 * scale up the chroma components via IDCT scaling rather than upsampling. | 151 * scale up the chroma components via IDCT scaling rather than upsampling. |
| 135 * This saves time if the upsampler gets to use 1:1 scaling. | 152 * This saves time if the upsampler gets to use 1:1 scaling. |
| 136 * Note this code assumes that the supported DCT scalings are powers of 2. | 153 * Note this code assumes that the supported DCT scalings are powers of 2. |
| 137 */ | 154 */ |
| 138 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 155 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 139 ci++, compptr++) { | 156 ci++, compptr++) { |
| 140 int ssize = cinfo->min_DCT_scaled_size; | 157 int ssize = cinfo->_min_DCT_scaled_size; |
| 141 while (ssize < DCTSIZE && | 158 while (ssize < DCTSIZE && |
| 142 (compptr->h_samp_factor * ssize * 2 <= | 159 (compptr->h_samp_factor * ssize * 2 <= |
| 143 » cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) && | 160 » cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) && |
| 144 (compptr->v_samp_factor * ssize * 2 <= | 161 (compptr->v_samp_factor * ssize * 2 <= |
| 145 » cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) { | 162 » cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size)) { |
| 146 ssize = ssize * 2; | 163 ssize = ssize * 2; |
| 147 } | 164 } |
| 165 #if JPEG_LIB_VERSION >= 70 |
| 166 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize; |
| 167 #else |
| 148 compptr->DCT_scaled_size = ssize; | 168 compptr->DCT_scaled_size = ssize; |
| 169 #endif |
| 149 } | 170 } |
| 150 | 171 |
| 151 /* Recompute downsampled dimensions of components; | 172 /* Recompute downsampled dimensions of components; |
| 152 * application needs to know these if using raw downsampled data. | 173 * application needs to know these if using raw downsampled data. |
| 153 */ | 174 */ |
| 154 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 175 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 155 ci++, compptr++) { | 176 ci++, compptr++) { |
| 156 /* Size in samples, after IDCT scaling */ | 177 /* Size in samples, after IDCT scaling */ |
| 157 compptr->downsampled_width = (JDIMENSION) | 178 compptr->downsampled_width = (JDIMENSION) |
| 158 jdiv_round_up((long) cinfo->image_width * | 179 jdiv_round_up((long) cinfo->image_width * |
| 159 » » (long) (compptr->h_samp_factor * compptr->DCT_scaled_size), | 180 » » (long) (compptr->h_samp_factor * compptr->_DCT_scaled_size), |
| 160 (long) (cinfo->max_h_samp_factor * DCTSIZE)); | 181 (long) (cinfo->max_h_samp_factor * DCTSIZE)); |
| 161 compptr->downsampled_height = (JDIMENSION) | 182 compptr->downsampled_height = (JDIMENSION) |
| 162 jdiv_round_up((long) cinfo->image_height * | 183 jdiv_round_up((long) cinfo->image_height * |
| 163 » » (long) (compptr->v_samp_factor * compptr->DCT_scaled_size), | 184 » » (long) (compptr->v_samp_factor * compptr->_DCT_scaled_size), |
| 164 (long) (cinfo->max_v_samp_factor * DCTSIZE)); | 185 (long) (cinfo->max_v_samp_factor * DCTSIZE)); |
| 165 } | 186 } |
| 166 | 187 |
| 167 #else /* !IDCT_SCALING_SUPPORTED */ | 188 #else /* !IDCT_SCALING_SUPPORTED */ |
| 168 | 189 |
| 169 /* Hardwire it to "no scaling" */ | 190 /* Hardwire it to "no scaling" */ |
| 170 cinfo->output_width = cinfo->image_width; | 191 cinfo->output_width = cinfo->image_width; |
| 171 cinfo->output_height = cinfo->image_height; | 192 cinfo->output_height = cinfo->image_height; |
| 172 /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE, | 193 /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE, |
| 173 * and has computed unscaled downsampled_width and downsampled_height. | 194 * and has computed unscaled downsampled_width and downsampled_height. |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } else { | 398 } else { |
| 378 jinit_color_deconverter(cinfo); | 399 jinit_color_deconverter(cinfo); |
| 379 jinit_upsampler(cinfo); | 400 jinit_upsampler(cinfo); |
| 380 } | 401 } |
| 381 jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); | 402 jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); |
| 382 } | 403 } |
| 383 /* Inverse DCT */ | 404 /* Inverse DCT */ |
| 384 jinit_inverse_dct(cinfo); | 405 jinit_inverse_dct(cinfo); |
| 385 /* Entropy decoding: either Huffman or arithmetic coding. */ | 406 /* Entropy decoding: either Huffman or arithmetic coding. */ |
| 386 if (cinfo->arith_code) { | 407 if (cinfo->arith_code) { |
| 408 #ifdef D_ARITH_CODING_SUPPORTED |
| 409 jinit_arith_decoder(cinfo); |
| 410 #else |
| 387 ERREXIT(cinfo, JERR_ARITH_NOTIMPL); | 411 ERREXIT(cinfo, JERR_ARITH_NOTIMPL); |
| 412 #endif |
| 388 } else { | 413 } else { |
| 389 if (cinfo->progressive_mode) { | 414 if (cinfo->progressive_mode) { |
| 390 #ifdef D_PROGRESSIVE_SUPPORTED | 415 #ifdef D_PROGRESSIVE_SUPPORTED |
| 391 jinit_phuff_decoder(cinfo); | 416 jinit_phuff_decoder(cinfo); |
| 392 #else | 417 #else |
| 393 ERREXIT(cinfo, JERR_NOT_COMPILED); | 418 ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 394 #endif | 419 #endif |
| 395 } else | 420 } else |
| 396 jinit_huff_decoder(cinfo); | 421 jinit_huff_decoder(cinfo); |
| 397 } | 422 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 584 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 560 SIZEOF(my_decomp_master)); | 585 SIZEOF(my_decomp_master)); |
| 561 cinfo->master = (struct jpeg_decomp_master *) master; | 586 cinfo->master = (struct jpeg_decomp_master *) master; |
| 562 master->pub.prepare_for_output_pass = prepare_for_output_pass; | 587 master->pub.prepare_for_output_pass = prepare_for_output_pass; |
| 563 master->pub.finish_output_pass = finish_output_pass; | 588 master->pub.finish_output_pass = finish_output_pass; |
| 564 | 589 |
| 565 master->pub.is_dummy_pass = FALSE; | 590 master->pub.is_dummy_pass = FALSE; |
| 566 | 591 |
| 567 master_selection(cinfo); | 592 master_selection(cinfo); |
| 568 } | 593 } |
| OLD | NEW |