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 * Modified 2002-2009 by Guido Vollbeding. |
5 * Copyright (C) 2009-2011, D. R. Commander. | 6 * Copyright (C) 2009-2011, D. R. Commander. |
6 * This file is part of the Independent JPEG Group's software. | 7 * This file is part of the Independent JPEG Group's software. |
7 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README file. |
8 * | 9 * |
9 * This file contains master control logic for the JPEG decompressor. | 10 * This file contains master control logic for the JPEG decompressor. |
10 * These routines are concerned with selecting the modules to be executed | 11 * 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 | 12 * and with determining the number of passes and the work to be done in each |
12 * pass. | 13 * pass. |
13 */ | 14 */ |
14 | 15 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 #else | 83 #else |
83 return FALSE; | 84 return FALSE; |
84 #endif | 85 #endif |
85 } | 86 } |
86 | 87 |
87 | 88 |
88 /* | 89 /* |
89 * Compute output image dimensions and related values. | 90 * Compute output image dimensions and related values. |
90 * NOTE: this is exported for possible use by application. | 91 * NOTE: this is exported for possible use by application. |
91 * Hence it mustn't do anything that can't be done twice. | 92 * Hence it mustn't do anything that can't be done twice. |
| 93 */ |
| 94 |
| 95 #if JPEG_LIB_VERSION >= 80 |
| 96 GLOBAL(void) |
| 97 #else |
| 98 LOCAL(void) |
| 99 #endif |
| 100 jpeg_core_output_dimensions (j_decompress_ptr cinfo) |
| 101 /* Do computations that are needed before master selection phase. |
| 102 * This function is used for transcoding and full decompression. |
| 103 */ |
| 104 { |
| 105 #ifdef IDCT_SCALING_SUPPORTED |
| 106 int ci; |
| 107 jpeg_component_info *compptr; |
| 108 |
| 109 /* Compute actual output image dimensions and DCT scaling choices. */ |
| 110 if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) { |
| 111 /* Provide 1/block_size scaling */ |
| 112 cinfo->output_width = (JDIMENSION) |
| 113 jdiv_round_up((long) cinfo->image_width, (long) DCTSIZE); |
| 114 cinfo->output_height = (JDIMENSION) |
| 115 jdiv_round_up((long) cinfo->image_height, (long) DCTSIZE); |
| 116 cinfo->_min_DCT_h_scaled_size = 1; |
| 117 cinfo->_min_DCT_v_scaled_size = 1; |
| 118 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) { |
| 119 /* Provide 2/block_size scaling */ |
| 120 cinfo->output_width = (JDIMENSION) |
| 121 jdiv_round_up((long) cinfo->image_width * 2L, (long) DCTSIZE); |
| 122 cinfo->output_height = (JDIMENSION) |
| 123 jdiv_round_up((long) cinfo->image_height * 2L, (long) DCTSIZE); |
| 124 cinfo->_min_DCT_h_scaled_size = 2; |
| 125 cinfo->_min_DCT_v_scaled_size = 2; |
| 126 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) { |
| 127 /* Provide 3/block_size scaling */ |
| 128 cinfo->output_width = (JDIMENSION) |
| 129 jdiv_round_up((long) cinfo->image_width * 3L, (long) DCTSIZE); |
| 130 cinfo->output_height = (JDIMENSION) |
| 131 jdiv_round_up((long) cinfo->image_height * 3L, (long) DCTSIZE); |
| 132 cinfo->_min_DCT_h_scaled_size = 3; |
| 133 cinfo->_min_DCT_v_scaled_size = 3; |
| 134 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) { |
| 135 /* Provide 4/block_size scaling */ |
| 136 cinfo->output_width = (JDIMENSION) |
| 137 jdiv_round_up((long) cinfo->image_width * 4L, (long) DCTSIZE); |
| 138 cinfo->output_height = (JDIMENSION) |
| 139 jdiv_round_up((long) cinfo->image_height * 4L, (long) DCTSIZE); |
| 140 cinfo->_min_DCT_h_scaled_size = 4; |
| 141 cinfo->_min_DCT_v_scaled_size = 4; |
| 142 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) { |
| 143 /* Provide 5/block_size scaling */ |
| 144 cinfo->output_width = (JDIMENSION) |
| 145 jdiv_round_up((long) cinfo->image_width * 5L, (long) DCTSIZE); |
| 146 cinfo->output_height = (JDIMENSION) |
| 147 jdiv_round_up((long) cinfo->image_height * 5L, (long) DCTSIZE); |
| 148 cinfo->_min_DCT_h_scaled_size = 5; |
| 149 cinfo->_min_DCT_v_scaled_size = 5; |
| 150 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) { |
| 151 /* Provide 6/block_size scaling */ |
| 152 cinfo->output_width = (JDIMENSION) |
| 153 jdiv_round_up((long) cinfo->image_width * 6L, (long) DCTSIZE); |
| 154 cinfo->output_height = (JDIMENSION) |
| 155 jdiv_round_up((long) cinfo->image_height * 6L, (long) DCTSIZE); |
| 156 cinfo->_min_DCT_h_scaled_size = 6; |
| 157 cinfo->_min_DCT_v_scaled_size = 6; |
| 158 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) { |
| 159 /* Provide 7/block_size scaling */ |
| 160 cinfo->output_width = (JDIMENSION) |
| 161 jdiv_round_up((long) cinfo->image_width * 7L, (long) DCTSIZE); |
| 162 cinfo->output_height = (JDIMENSION) |
| 163 jdiv_round_up((long) cinfo->image_height * 7L, (long) DCTSIZE); |
| 164 cinfo->_min_DCT_h_scaled_size = 7; |
| 165 cinfo->_min_DCT_v_scaled_size = 7; |
| 166 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) { |
| 167 /* Provide 8/block_size scaling */ |
| 168 cinfo->output_width = (JDIMENSION) |
| 169 jdiv_round_up((long) cinfo->image_width * 8L, (long) DCTSIZE); |
| 170 cinfo->output_height = (JDIMENSION) |
| 171 jdiv_round_up((long) cinfo->image_height * 8L, (long) DCTSIZE); |
| 172 cinfo->_min_DCT_h_scaled_size = 8; |
| 173 cinfo->_min_DCT_v_scaled_size = 8; |
| 174 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) { |
| 175 /* Provide 9/block_size scaling */ |
| 176 cinfo->output_width = (JDIMENSION) |
| 177 jdiv_round_up((long) cinfo->image_width * 9L, (long) DCTSIZE); |
| 178 cinfo->output_height = (JDIMENSION) |
| 179 jdiv_round_up((long) cinfo->image_height * 9L, (long) DCTSIZE); |
| 180 cinfo->_min_DCT_h_scaled_size = 9; |
| 181 cinfo->_min_DCT_v_scaled_size = 9; |
| 182 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) { |
| 183 /* Provide 10/block_size scaling */ |
| 184 cinfo->output_width = (JDIMENSION) |
| 185 jdiv_round_up((long) cinfo->image_width * 10L, (long) DCTSIZE); |
| 186 cinfo->output_height = (JDIMENSION) |
| 187 jdiv_round_up((long) cinfo->image_height * 10L, (long) DCTSIZE); |
| 188 cinfo->_min_DCT_h_scaled_size = 10; |
| 189 cinfo->_min_DCT_v_scaled_size = 10; |
| 190 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) { |
| 191 /* Provide 11/block_size scaling */ |
| 192 cinfo->output_width = (JDIMENSION) |
| 193 jdiv_round_up((long) cinfo->image_width * 11L, (long) DCTSIZE); |
| 194 cinfo->output_height = (JDIMENSION) |
| 195 jdiv_round_up((long) cinfo->image_height * 11L, (long) DCTSIZE); |
| 196 cinfo->_min_DCT_h_scaled_size = 11; |
| 197 cinfo->_min_DCT_v_scaled_size = 11; |
| 198 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) { |
| 199 /* Provide 12/block_size scaling */ |
| 200 cinfo->output_width = (JDIMENSION) |
| 201 jdiv_round_up((long) cinfo->image_width * 12L, (long) DCTSIZE); |
| 202 cinfo->output_height = (JDIMENSION) |
| 203 jdiv_round_up((long) cinfo->image_height * 12L, (long) DCTSIZE); |
| 204 cinfo->_min_DCT_h_scaled_size = 12; |
| 205 cinfo->_min_DCT_v_scaled_size = 12; |
| 206 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) { |
| 207 /* Provide 13/block_size scaling */ |
| 208 cinfo->output_width = (JDIMENSION) |
| 209 jdiv_round_up((long) cinfo->image_width * 13L, (long) DCTSIZE); |
| 210 cinfo->output_height = (JDIMENSION) |
| 211 jdiv_round_up((long) cinfo->image_height * 13L, (long) DCTSIZE); |
| 212 cinfo->_min_DCT_h_scaled_size = 13; |
| 213 cinfo->_min_DCT_v_scaled_size = 13; |
| 214 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) { |
| 215 /* Provide 14/block_size scaling */ |
| 216 cinfo->output_width = (JDIMENSION) |
| 217 jdiv_round_up((long) cinfo->image_width * 14L, (long) DCTSIZE); |
| 218 cinfo->output_height = (JDIMENSION) |
| 219 jdiv_round_up((long) cinfo->image_height * 14L, (long) DCTSIZE); |
| 220 cinfo->_min_DCT_h_scaled_size = 14; |
| 221 cinfo->_min_DCT_v_scaled_size = 14; |
| 222 } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) { |
| 223 /* Provide 15/block_size scaling */ |
| 224 cinfo->output_width = (JDIMENSION) |
| 225 jdiv_round_up((long) cinfo->image_width * 15L, (long) DCTSIZE); |
| 226 cinfo->output_height = (JDIMENSION) |
| 227 jdiv_round_up((long) cinfo->image_height * 15L, (long) DCTSIZE); |
| 228 cinfo->_min_DCT_h_scaled_size = 15; |
| 229 cinfo->_min_DCT_v_scaled_size = 15; |
| 230 } else { |
| 231 /* Provide 16/block_size scaling */ |
| 232 cinfo->output_width = (JDIMENSION) |
| 233 jdiv_round_up((long) cinfo->image_width * 16L, (long) DCTSIZE); |
| 234 cinfo->output_height = (JDIMENSION) |
| 235 jdiv_round_up((long) cinfo->image_height * 16L, (long) DCTSIZE); |
| 236 cinfo->_min_DCT_h_scaled_size = 16; |
| 237 cinfo->_min_DCT_v_scaled_size = 16; |
| 238 } |
| 239 |
| 240 /* Recompute dimensions of components */ |
| 241 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 242 ci++, compptr++) { |
| 243 compptr->_DCT_h_scaled_size = cinfo->_min_DCT_h_scaled_size; |
| 244 compptr->_DCT_v_scaled_size = cinfo->_min_DCT_v_scaled_size; |
| 245 } |
| 246 |
| 247 #else /* !IDCT_SCALING_SUPPORTED */ |
| 248 |
| 249 /* Hardwire it to "no scaling" */ |
| 250 cinfo->output_width = cinfo->image_width; |
| 251 cinfo->output_height = cinfo->image_height; |
| 252 /* jdinput.c has already initialized DCT_scaled_size, |
| 253 * and has computed unscaled downsampled_width and downsampled_height. |
| 254 */ |
| 255 |
| 256 #endif /* IDCT_SCALING_SUPPORTED */ |
| 257 } |
| 258 |
| 259 |
| 260 /* |
| 261 * Compute output image dimensions and related values. |
| 262 * NOTE: this is exported for possible use by application. |
| 263 * Hence it mustn't do anything that can't be done twice. |
92 * Also note that it may be called before the master module is initialized! | 264 * Also note that it may be called before the master module is initialized! |
93 */ | 265 */ |
94 | 266 |
95 GLOBAL(void) | 267 GLOBAL(void) |
96 jpeg_calc_output_dimensions (j_decompress_ptr cinfo) | 268 jpeg_calc_output_dimensions (j_decompress_ptr cinfo) |
97 /* Do computations that are needed before master selection phase */ | 269 /* Do computations that are needed before master selection phase */ |
98 { | 270 { |
99 #ifdef IDCT_SCALING_SUPPORTED | 271 #ifdef IDCT_SCALING_SUPPORTED |
100 int ci; | 272 int ci; |
101 jpeg_component_info *compptr; | 273 jpeg_component_info *compptr; |
102 #endif | 274 #endif |
103 | 275 |
104 /* Prevent application from calling me at wrong times */ | 276 /* Prevent application from calling me at wrong times */ |
105 if (cinfo->global_state != DSTATE_READY) | 277 if (cinfo->global_state != DSTATE_READY) |
106 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 278 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
107 | 279 |
| 280 /* Compute core output image dimensions and DCT scaling choices. */ |
| 281 jpeg_core_output_dimensions(cinfo); |
| 282 |
108 #ifdef IDCT_SCALING_SUPPORTED | 283 #ifdef IDCT_SCALING_SUPPORTED |
109 | 284 |
110 /* Compute actual output image dimensions and DCT scaling choices. */ | |
111 if (cinfo->scale_num * 8 <= cinfo->scale_denom) { | |
112 /* Provide 1/8 scaling */ | |
113 cinfo->output_width = (JDIMENSION) | |
114 jdiv_round_up((long) cinfo->image_width, 8L); | |
115 cinfo->output_height = (JDIMENSION) | |
116 jdiv_round_up((long) cinfo->image_height, 8L); | |
117 #if JPEG_LIB_VERSION >= 70 | |
118 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 1; | |
119 #else | |
120 cinfo->min_DCT_scaled_size = 1; | |
121 #endif | |
122 } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) { | |
123 /* Provide 1/4 scaling */ | |
124 cinfo->output_width = (JDIMENSION) | |
125 jdiv_round_up((long) cinfo->image_width, 4L); | |
126 cinfo->output_height = (JDIMENSION) | |
127 jdiv_round_up((long) cinfo->image_height, 4L); | |
128 #if JPEG_LIB_VERSION >= 70 | |
129 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 2; | |
130 #else | |
131 cinfo->min_DCT_scaled_size = 2; | |
132 #endif | |
133 } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) { | |
134 /* Provide 1/2 scaling */ | |
135 cinfo->output_width = (JDIMENSION) | |
136 jdiv_round_up((long) cinfo->image_width, 2L); | |
137 cinfo->output_height = (JDIMENSION) | |
138 jdiv_round_up((long) cinfo->image_height, 2L); | |
139 #if JPEG_LIB_VERSION >= 70 | |
140 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 4; | |
141 #else | |
142 cinfo->min_DCT_scaled_size = 4; | |
143 #endif | |
144 } else { | |
145 /* Provide 1/1 scaling */ | |
146 cinfo->output_width = cinfo->image_width; | |
147 cinfo->output_height = cinfo->image_height; | |
148 #if JPEG_LIB_VERSION >= 70 | |
149 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; | |
150 #else | |
151 cinfo->min_DCT_scaled_size = DCTSIZE; | |
152 #endif | |
153 } | |
154 /* In selecting the actual DCT scaling for each component, we try to | 285 /* In selecting the actual DCT scaling for each component, we try to |
155 * scale up the chroma components via IDCT scaling rather than upsampling. | 286 * scale up the chroma components via IDCT scaling rather than upsampling. |
156 * This saves time if the upsampler gets to use 1:1 scaling. | 287 * This saves time if the upsampler gets to use 1:1 scaling. |
157 * Note this code assumes that the supported DCT scalings are powers of 2. | 288 * Note this code adapts subsampling ratios which are powers of 2. |
158 */ | 289 */ |
159 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 290 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
160 ci++, compptr++) { | 291 ci++, compptr++) { |
161 int ssize = cinfo->_min_DCT_scaled_size; | 292 int ssize = cinfo->_min_DCT_scaled_size; |
162 while (ssize < DCTSIZE && | 293 while (ssize < DCTSIZE && |
163 » (compptr->h_samp_factor * ssize * 2 <= | 294 » ((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) % |
164 » cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) && | 295 » (compptr->h_samp_factor * ssize * 2) == 0) && |
165 » (compptr->v_samp_factor * ssize * 2 <= | 296 » ((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) % |
166 » cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size)) { | 297 » (compptr->v_samp_factor * ssize * 2) == 0)) { |
167 ssize = ssize * 2; | 298 ssize = ssize * 2; |
168 } | 299 } |
169 #if JPEG_LIB_VERSION >= 70 | 300 #if JPEG_LIB_VERSION >= 70 |
170 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize; | 301 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize; |
171 #else | 302 #else |
172 compptr->DCT_scaled_size = ssize; | 303 compptr->DCT_scaled_size = ssize; |
173 #endif | 304 #endif |
174 } | 305 } |
175 | 306 |
176 /* Recompute downsampled dimensions of components; | 307 /* Recompute downsampled dimensions of components; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 723 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
593 SIZEOF(my_decomp_master)); | 724 SIZEOF(my_decomp_master)); |
594 cinfo->master = (struct jpeg_decomp_master *) master; | 725 cinfo->master = (struct jpeg_decomp_master *) master; |
595 master->pub.prepare_for_output_pass = prepare_for_output_pass; | 726 master->pub.prepare_for_output_pass = prepare_for_output_pass; |
596 master->pub.finish_output_pass = finish_output_pass; | 727 master->pub.finish_output_pass = finish_output_pass; |
597 | 728 |
598 master->pub.is_dummy_pass = FALSE; | 729 master->pub.is_dummy_pass = FALSE; |
599 | 730 |
600 master_selection(cinfo); | 731 master_selection(cinfo); |
601 } | 732 } |
OLD | NEW |