OLD | NEW |
1 /* | 1 /* |
2 * jdinput.c | 2 * jdinput.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. |
| 6 * Copyright (C) 2010, D. R. Commander. |
5 * This file is part of the Independent JPEG Group's software. | 7 * This file is part of the Independent JPEG Group's software. |
6 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README file. |
7 * | 9 * |
8 * This file contains input control logic for the JPEG decompressor. | 10 * This file contains input control logic for the JPEG decompressor. |
9 * These routines are concerned with controlling the decompressor's input | 11 * These routines are concerned with controlling the decompressor's input |
10 * processing (marker reading and coefficient decoding). The actual input | 12 * processing (marker reading and coefficient decoding). The actual input |
11 * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. | 13 * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. |
12 */ | 14 */ |
13 | 15 |
14 #define JPEG_INTERNALS | 16 #define JPEG_INTERNALS |
15 #include "jinclude.h" | 17 #include "jinclude.h" |
16 #include "jpeglib.h" | 18 #include "jpeglib.h" |
| 19 #include "jpegcomp.h" |
17 | 20 |
18 | 21 |
19 /* Private state */ | 22 /* Private state */ |
20 | 23 |
21 typedef struct { | 24 typedef struct { |
22 struct jpeg_input_controller pub; /* public fields */ | 25 struct jpeg_input_controller pub; /* public fields */ |
23 | 26 |
24 boolean inheaders; /* TRUE until first SOS is reached */ | 27 boolean inheaders; /* TRUE until first SOS is reached */ |
25 } my_input_controller; | 28 } my_input_controller; |
26 | 29 |
27 typedef my_input_controller * my_inputctl_ptr; | 30 typedef my_input_controller * my_inputctl_ptr; |
28 | 31 |
29 | 32 |
30 /* Forward declarations */ | 33 /* Forward declarations */ |
31 METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo)); | 34 METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo)); |
32 | 35 |
33 | 36 |
34 /* | 37 /* |
35 * Routines to calculate various quantities related to the size of the image. | 38 * Routines to calculate various quantities related to the size of the image. |
36 */ | 39 */ |
37 | 40 |
| 41 |
| 42 #if JPEG_LIB_VERSION >= 80 |
| 43 /* |
| 44 * Compute output image dimensions and related values. |
| 45 * NOTE: this is exported for possible use by application. |
| 46 * Hence it mustn't do anything that can't be done twice. |
| 47 */ |
| 48 |
| 49 GLOBAL(void) |
| 50 jpeg_core_output_dimensions (j_decompress_ptr cinfo) |
| 51 /* Do computations that are needed before master selection phase. |
| 52 * This function is used for transcoding and full decompression. |
| 53 */ |
| 54 { |
| 55 #ifdef IDCT_SCALING_SUPPORTED |
| 56 int ci; |
| 57 jpeg_component_info *compptr; |
| 58 |
| 59 /* Compute actual output image dimensions and DCT scaling choices. */ |
| 60 if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) { |
| 61 /* Provide 1/block_size scaling */ |
| 62 cinfo->output_width = (JDIMENSION) |
| 63 jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size); |
| 64 cinfo->output_height = (JDIMENSION) |
| 65 jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size); |
| 66 cinfo->min_DCT_h_scaled_size = 1; |
| 67 cinfo->min_DCT_v_scaled_size = 1; |
| 68 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) { |
| 69 /* Provide 2/block_size scaling */ |
| 70 cinfo->output_width = (JDIMENSION) |
| 71 jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size); |
| 72 cinfo->output_height = (JDIMENSION) |
| 73 jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size); |
| 74 cinfo->min_DCT_h_scaled_size = 2; |
| 75 cinfo->min_DCT_v_scaled_size = 2; |
| 76 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) { |
| 77 /* Provide 4/block_size scaling */ |
| 78 cinfo->output_width = (JDIMENSION) |
| 79 jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size); |
| 80 cinfo->output_height = (JDIMENSION) |
| 81 jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size); |
| 82 cinfo->min_DCT_h_scaled_size = 4; |
| 83 cinfo->min_DCT_v_scaled_size = 4; |
| 84 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) { |
| 85 /* Provide 8/block_size scaling */ |
| 86 cinfo->output_width = (JDIMENSION) |
| 87 jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size); |
| 88 cinfo->output_height = (JDIMENSION) |
| 89 jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size); |
| 90 cinfo->min_DCT_h_scaled_size = 8; |
| 91 cinfo->min_DCT_v_scaled_size = 8; |
| 92 } |
| 93 /* Recompute dimensions of components */ |
| 94 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 95 ci++, compptr++) { |
| 96 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size; |
| 97 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size; |
| 98 } |
| 99 |
| 100 #else /* !IDCT_SCALING_SUPPORTED */ |
| 101 |
| 102 /* Hardwire it to "no scaling" */ |
| 103 cinfo->output_width = cinfo->image_width; |
| 104 cinfo->output_height = cinfo->image_height; |
| 105 /* jdinput.c has already initialized DCT_scaled_size, |
| 106 * and has computed unscaled downsampled_width and downsampled_height. |
| 107 */ |
| 108 |
| 109 #endif /* IDCT_SCALING_SUPPORTED */ |
| 110 } |
| 111 #endif |
| 112 |
| 113 |
38 LOCAL(void) | 114 LOCAL(void) |
39 initial_setup (j_decompress_ptr cinfo) | 115 initial_setup (j_decompress_ptr cinfo) |
40 /* Called once, when first SOS marker is reached */ | 116 /* Called once, when first SOS marker is reached */ |
41 { | 117 { |
42 int ci; | 118 int ci; |
43 jpeg_component_info *compptr; | 119 jpeg_component_info *compptr; |
44 | 120 |
45 /* Make sure image isn't bigger than I can handle */ | 121 /* Make sure image isn't bigger than I can handle */ |
46 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || | 122 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || |
47 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) | 123 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) |
(...skipping 15 matching lines...) Expand all Loading... |
63 ci++, compptr++) { | 139 ci++, compptr++) { |
64 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || | 140 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || |
65 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) | 141 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) |
66 ERREXIT(cinfo, JERR_BAD_SAMPLING); | 142 ERREXIT(cinfo, JERR_BAD_SAMPLING); |
67 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, | 143 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, |
68 compptr->h_samp_factor); | 144 compptr->h_samp_factor); |
69 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, | 145 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, |
70 compptr->v_samp_factor); | 146 compptr->v_samp_factor); |
71 } | 147 } |
72 | 148 |
| 149 #if JPEG_LIB_VERSION >=80 |
| 150 cinfo->block_size = DCTSIZE; |
| 151 cinfo->natural_order = jpeg_natural_order; |
| 152 cinfo->lim_Se = DCTSIZE2-1; |
| 153 #endif |
| 154 |
73 /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. | 155 /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. |
74 * In the full decompressor, this will be overridden by jdmaster.c; | 156 * In the full decompressor, this will be overridden by jdmaster.c; |
75 * but in the transcoder, jdmaster.c is not used, so we must do it here. | 157 * but in the transcoder, jdmaster.c is not used, so we must do it here. |
76 */ | 158 */ |
| 159 #if JPEG_LIB_VERSION >= 70 |
| 160 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; |
| 161 #else |
77 cinfo->min_DCT_scaled_size = DCTSIZE; | 162 cinfo->min_DCT_scaled_size = DCTSIZE; |
| 163 #endif |
78 | 164 |
79 /* Compute dimensions of components */ | 165 /* Compute dimensions of components */ |
80 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 166 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
81 ci++, compptr++) { | 167 ci++, compptr++) { |
| 168 #if JPEG_LIB_VERSION >= 70 |
| 169 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; |
| 170 #else |
82 compptr->DCT_scaled_size = DCTSIZE; | 171 compptr->DCT_scaled_size = DCTSIZE; |
| 172 #endif |
83 /* Size in DCT blocks */ | 173 /* Size in DCT blocks */ |
84 compptr->width_in_blocks = (JDIMENSION) | 174 compptr->width_in_blocks = (JDIMENSION) |
85 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, | 175 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, |
86 (long) (cinfo->max_h_samp_factor * DCTSIZE)); | 176 (long) (cinfo->max_h_samp_factor * DCTSIZE)); |
87 compptr->height_in_blocks = (JDIMENSION) | 177 compptr->height_in_blocks = (JDIMENSION) |
88 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, | 178 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, |
89 (long) (cinfo->max_v_samp_factor * DCTSIZE)); | 179 (long) (cinfo->max_v_samp_factor * DCTSIZE)); |
90 /* downsampled_width and downsampled_height will also be overridden by | 180 /* downsampled_width and downsampled_height will also be overridden by |
91 * jdmaster.c if we are doing full decompression. The transcoder library | 181 * jdmaster.c if we are doing full decompression. The transcoder library |
92 * doesn't use these values, but the calling application might. | 182 * doesn't use these values, but the calling application might. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 compptr = cinfo->cur_comp_info[0]; | 221 compptr = cinfo->cur_comp_info[0]; |
132 | 222 |
133 /* Overall image size in MCUs */ | 223 /* Overall image size in MCUs */ |
134 cinfo->MCUs_per_row = compptr->width_in_blocks; | 224 cinfo->MCUs_per_row = compptr->width_in_blocks; |
135 cinfo->MCU_rows_in_scan = compptr->height_in_blocks; | 225 cinfo->MCU_rows_in_scan = compptr->height_in_blocks; |
136 | 226 |
137 /* For noninterleaved scan, always one block per MCU */ | 227 /* For noninterleaved scan, always one block per MCU */ |
138 compptr->MCU_width = 1; | 228 compptr->MCU_width = 1; |
139 compptr->MCU_height = 1; | 229 compptr->MCU_height = 1; |
140 compptr->MCU_blocks = 1; | 230 compptr->MCU_blocks = 1; |
141 compptr->MCU_sample_width = compptr->DCT_scaled_size; | 231 compptr->MCU_sample_width = compptr->_DCT_scaled_size; |
142 compptr->last_col_width = 1; | 232 compptr->last_col_width = 1; |
143 /* For noninterleaved scans, it is convenient to define last_row_height | 233 /* For noninterleaved scans, it is convenient to define last_row_height |
144 * as the number of block rows present in the last iMCU row. | 234 * as the number of block rows present in the last iMCU row. |
145 */ | 235 */ |
146 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); | 236 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); |
147 if (tmp == 0) tmp = compptr->v_samp_factor; | 237 if (tmp == 0) tmp = compptr->v_samp_factor; |
148 compptr->last_row_height = tmp; | 238 compptr->last_row_height = tmp; |
149 | 239 |
150 /* Prepare array describing MCU composition */ | 240 /* Prepare array describing MCU composition */ |
151 cinfo->blocks_in_MCU = 1; | 241 cinfo->blocks_in_MCU = 1; |
(...skipping 15 matching lines...) Expand all Loading... |
167 (long) (cinfo->max_v_samp_factor*DCTSIZE)); | 257 (long) (cinfo->max_v_samp_factor*DCTSIZE)); |
168 | 258 |
169 cinfo->blocks_in_MCU = 0; | 259 cinfo->blocks_in_MCU = 0; |
170 | 260 |
171 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 261 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
172 compptr = cinfo->cur_comp_info[ci]; | 262 compptr = cinfo->cur_comp_info[ci]; |
173 /* Sampling factors give # of blocks of component in each MCU */ | 263 /* Sampling factors give # of blocks of component in each MCU */ |
174 compptr->MCU_width = compptr->h_samp_factor; | 264 compptr->MCU_width = compptr->h_samp_factor; |
175 compptr->MCU_height = compptr->v_samp_factor; | 265 compptr->MCU_height = compptr->v_samp_factor; |
176 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; | 266 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; |
177 compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size; | 267 compptr->MCU_sample_width = compptr->MCU_width * compptr->_DCT_scaled_size
; |
178 /* Figure number of non-dummy blocks in last MCU column & row */ | 268 /* Figure number of non-dummy blocks in last MCU column & row */ |
179 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); | 269 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); |
180 if (tmp == 0) tmp = compptr->MCU_width; | 270 if (tmp == 0) tmp = compptr->MCU_width; |
181 compptr->last_col_width = tmp; | 271 compptr->last_col_width = tmp; |
182 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); | 272 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); |
183 if (tmp == 0) tmp = compptr->MCU_height; | 273 if (tmp == 0) tmp = compptr->MCU_height; |
184 compptr->last_row_height = tmp; | 274 compptr->last_row_height = tmp; |
185 /* Prepare array describing MCU composition */ | 275 /* Prepare array describing MCU composition */ |
186 mcublks = compptr->MCU_blocks; | 276 mcublks = compptr->MCU_blocks; |
187 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) | 277 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 inputctl->pub.reset_input_controller = reset_input_controller; | 462 inputctl->pub.reset_input_controller = reset_input_controller; |
373 inputctl->pub.start_input_pass = start_input_pass; | 463 inputctl->pub.start_input_pass = start_input_pass; |
374 inputctl->pub.finish_input_pass = finish_input_pass; | 464 inputctl->pub.finish_input_pass = finish_input_pass; |
375 /* Initialize state: can't use reset_input_controller since we don't | 465 /* Initialize state: can't use reset_input_controller since we don't |
376 * want to try to reset other modules yet. | 466 * want to try to reset other modules yet. |
377 */ | 467 */ |
378 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ | 468 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ |
379 inputctl->pub.eoi_reached = FALSE; | 469 inputctl->pub.eoi_reached = FALSE; |
380 inputctl->inheaders = TRUE; | 470 inputctl->inheaders = TRUE; |
381 } | 471 } |
OLD | NEW |