OLD | NEW |
1 /* | 1 /* |
2 * jdinput.c | 2 * jdinput.c |
3 * | 3 * |
4 * This file was part of the Independent JPEG Group's software: | 4 * This file was part of the Independent JPEG Group's software: |
5 * Copyright (C) 1991-1997, Thomas G. Lane. | 5 * Copyright (C) 1991-1997, Thomas G. Lane. |
6 * libjpeg-turbo Modifications: | 6 * libjpeg-turbo Modifications: |
7 * Copyright (C) 2010, D. R. Commander. | 7 * Copyright (C) 2010, 2016, D. R. Commander. |
8 * For conditions of distribution and use, see the accompanying README file. | 8 * Copyright (C) 2015, Google, Inc. |
| 9 * For conditions of distribution and use, see the accompanying README.ijg |
| 10 * file. |
9 * | 11 * |
10 * This file contains input control logic for the JPEG decompressor. | 12 * This file contains input control logic for the JPEG decompressor. |
11 * These routines are concerned with controlling the decompressor's input | 13 * These routines are concerned with controlling the decompressor's input |
12 * processing (marker reading and coefficient decoding). The actual input | 14 * processing (marker reading and coefficient decoding). The actual input |
13 * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. | 15 * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. |
14 */ | 16 */ |
15 | 17 |
16 #define JPEG_INTERNALS | 18 #define JPEG_INTERNALS |
17 #include "jinclude.h" | 19 #include "jinclude.h" |
18 #include "jpeglib.h" | 20 #include "jpeglib.h" |
19 #include "jpegcomp.h" | 21 #include "jpegcomp.h" |
20 | 22 |
21 | 23 |
22 /* Private state */ | 24 /* Private state */ |
23 | 25 |
24 typedef struct { | 26 typedef struct { |
25 struct jpeg_input_controller pub; /* public fields */ | 27 struct jpeg_input_controller pub; /* public fields */ |
26 | 28 |
27 boolean inheaders;» » /* TRUE until first SOS is reached */ | 29 boolean inheaders; /* TRUE until first SOS is reached */ |
28 } my_input_controller; | 30 } my_input_controller; |
29 | 31 |
30 typedef my_input_controller * my_inputctl_ptr; | 32 typedef my_input_controller *my_inputctl_ptr; |
31 | 33 |
32 | 34 |
33 /* Forward declarations */ | 35 /* Forward declarations */ |
34 METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo)); | 36 METHODDEF(int) consume_markers (j_decompress_ptr cinfo); |
35 | 37 |
36 | 38 |
37 /* | 39 /* |
38 * Routines to calculate various quantities related to the size of the image. | 40 * Routines to calculate various quantities related to the size of the image. |
39 */ | 41 */ |
40 | 42 |
41 LOCAL(void) | 43 LOCAL(void) |
42 initial_setup (j_decompress_ptr cinfo) | 44 initial_setup (j_decompress_ptr cinfo) |
43 /* Called once, when first SOS marker is reached */ | 45 /* Called once, when first SOS marker is reached */ |
44 { | 46 { |
45 int ci; | 47 int ci; |
46 jpeg_component_info *compptr; | 48 jpeg_component_info *compptr; |
47 | 49 |
48 /* Make sure image isn't bigger than I can handle */ | 50 /* Make sure image isn't bigger than I can handle */ |
49 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || | 51 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || |
50 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) | 52 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) |
51 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); | 53 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); |
52 | 54 |
53 /* For now, precision must match compiled-in value... */ | 55 /* For now, precision must match compiled-in value... */ |
54 if (cinfo->data_precision != BITS_IN_JSAMPLE) | 56 if (cinfo->data_precision != BITS_IN_JSAMPLE) |
55 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 57 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
56 | 58 |
57 /* Check that number of components won't exceed internal array sizes */ | 59 /* Check that number of components won't exceed internal array sizes */ |
58 if (cinfo->num_components > MAX_COMPONENTS) | 60 if (cinfo->num_components > MAX_COMPONENTS) |
59 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, | 61 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, |
60 » MAX_COMPONENTS); | 62 MAX_COMPONENTS); |
61 | 63 |
62 /* Compute maximum sampling factors; check factor validity */ | 64 /* Compute maximum sampling factors; check factor validity */ |
63 cinfo->max_h_samp_factor = 1; | 65 cinfo->max_h_samp_factor = 1; |
64 cinfo->max_v_samp_factor = 1; | 66 cinfo->max_v_samp_factor = 1; |
65 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 67 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
66 ci++, compptr++) { | 68 ci++, compptr++) { |
67 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || | 69 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || |
68 » compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) | 70 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) |
69 ERREXIT(cinfo, JERR_BAD_SAMPLING); | 71 ERREXIT(cinfo, JERR_BAD_SAMPLING); |
70 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, | 72 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, |
71 » » » » compptr->h_samp_factor); | 73 compptr->h_samp_factor); |
72 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, | 74 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, |
73 » » » » compptr->v_samp_factor); | 75 compptr->v_samp_factor); |
74 } | 76 } |
75 | 77 |
76 #if JPEG_LIB_VERSION >=80 | 78 #if JPEG_LIB_VERSION >=80 |
77 cinfo->block_size = DCTSIZE; | 79 cinfo->block_size = DCTSIZE; |
78 cinfo->natural_order = jpeg_natural_order; | 80 cinfo->natural_order = jpeg_natural_order; |
79 cinfo->lim_Se = DCTSIZE2-1; | 81 cinfo->lim_Se = DCTSIZE2-1; |
80 #endif | 82 #endif |
81 | 83 |
82 /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. | 84 /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. |
83 * In the full decompressor, this will be overridden by jdmaster.c; | 85 * In the full decompressor, this will be overridden by jdmaster.c; |
84 * but in the transcoder, jdmaster.c is not used, so we must do it here. | 86 * but in the transcoder, jdmaster.c is not used, so we must do it here. |
85 */ | 87 */ |
86 #if JPEG_LIB_VERSION >= 70 | 88 #if JPEG_LIB_VERSION >= 70 |
87 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; | 89 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; |
88 #else | 90 #else |
89 cinfo->min_DCT_scaled_size = DCTSIZE; | 91 cinfo->min_DCT_scaled_size = DCTSIZE; |
90 #endif | 92 #endif |
91 | 93 |
92 /* Compute dimensions of components */ | 94 /* Compute dimensions of components */ |
93 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 95 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
94 ci++, compptr++) { | 96 ci++, compptr++) { |
95 #if JPEG_LIB_VERSION >= 70 | 97 #if JPEG_LIB_VERSION >= 70 |
96 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; | 98 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; |
97 #else | 99 #else |
98 compptr->DCT_scaled_size = DCTSIZE; | 100 compptr->DCT_scaled_size = DCTSIZE; |
99 #endif | 101 #endif |
100 /* Size in DCT blocks */ | 102 /* Size in DCT blocks */ |
101 compptr->width_in_blocks = (JDIMENSION) | 103 compptr->width_in_blocks = (JDIMENSION) |
102 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, | 104 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, |
103 » » (long) (cinfo->max_h_samp_factor * DCTSIZE)); | 105 (long) (cinfo->max_h_samp_factor * DCTSIZE)); |
104 compptr->height_in_blocks = (JDIMENSION) | 106 compptr->height_in_blocks = (JDIMENSION) |
105 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, | 107 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, |
106 » » (long) (cinfo->max_v_samp_factor * DCTSIZE)); | 108 (long) (cinfo->max_v_samp_factor * DCTSIZE)); |
| 109 /* Set the first and last MCU columns to decompress from multi-scan images. |
| 110 * By default, decompress all of the MCU columns. |
| 111 */ |
| 112 cinfo->master->first_MCU_col[ci] = 0; |
| 113 cinfo->master->last_MCU_col[ci] = compptr->width_in_blocks - 1; |
107 /* downsampled_width and downsampled_height will also be overridden by | 114 /* downsampled_width and downsampled_height will also be overridden by |
108 * jdmaster.c if we are doing full decompression. The transcoder library | 115 * jdmaster.c if we are doing full decompression. The transcoder library |
109 * doesn't use these values, but the calling application might. | 116 * doesn't use these values, but the calling application might. |
110 */ | 117 */ |
111 /* Size in samples */ | 118 /* Size in samples */ |
112 compptr->downsampled_width = (JDIMENSION) | 119 compptr->downsampled_width = (JDIMENSION) |
113 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, | 120 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, |
114 » » (long) cinfo->max_h_samp_factor); | 121 (long) cinfo->max_h_samp_factor); |
115 compptr->downsampled_height = (JDIMENSION) | 122 compptr->downsampled_height = (JDIMENSION) |
116 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, | 123 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, |
117 » » (long) cinfo->max_v_samp_factor); | 124 (long) cinfo->max_v_samp_factor); |
118 /* Mark component needed, until color conversion says otherwise */ | 125 /* Mark component needed, until color conversion says otherwise */ |
119 compptr->component_needed = TRUE; | 126 compptr->component_needed = TRUE; |
120 /* Mark no quantization table yet saved for component */ | 127 /* Mark no quantization table yet saved for component */ |
121 compptr->quant_table = NULL; | 128 compptr->quant_table = NULL; |
122 } | 129 } |
123 | 130 |
124 /* Compute number of fully interleaved MCU rows. */ | 131 /* Compute number of fully interleaved MCU rows. */ |
125 cinfo->total_iMCU_rows = (JDIMENSION) | 132 cinfo->total_iMCU_rows = (JDIMENSION) |
126 jdiv_round_up((long) cinfo->image_height, | 133 jdiv_round_up((long) cinfo->image_height, |
127 » » (long) (cinfo->max_v_samp_factor*DCTSIZE)); | 134 (long) (cinfo->max_v_samp_factor*DCTSIZE)); |
128 | 135 |
129 /* Decide whether file contains multiple scans */ | 136 /* Decide whether file contains multiple scans */ |
130 if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode) | 137 if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode) |
131 cinfo->inputctl->has_multiple_scans = TRUE; | 138 cinfo->inputctl->has_multiple_scans = TRUE; |
132 else | 139 else |
133 cinfo->inputctl->has_multiple_scans = FALSE; | 140 cinfo->inputctl->has_multiple_scans = FALSE; |
134 } | 141 } |
135 | 142 |
136 | 143 |
137 LOCAL(void) | 144 LOCAL(void) |
138 per_scan_setup (j_decompress_ptr cinfo) | 145 per_scan_setup (j_decompress_ptr cinfo) |
139 /* Do computations that are needed before processing a JPEG scan */ | 146 /* Do computations that are needed before processing a JPEG scan */ |
140 /* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */ | 147 /* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */ |
141 { | 148 { |
142 int ci, mcublks, tmp; | 149 int ci, mcublks, tmp; |
143 jpeg_component_info *compptr; | 150 jpeg_component_info *compptr; |
144 | 151 |
145 if (cinfo->comps_in_scan == 1) { | 152 if (cinfo->comps_in_scan == 1) { |
146 | 153 |
147 /* Noninterleaved (single-component) scan */ | 154 /* Noninterleaved (single-component) scan */ |
148 compptr = cinfo->cur_comp_info[0]; | 155 compptr = cinfo->cur_comp_info[0]; |
149 | 156 |
150 /* Overall image size in MCUs */ | 157 /* Overall image size in MCUs */ |
151 cinfo->MCUs_per_row = compptr->width_in_blocks; | 158 cinfo->MCUs_per_row = compptr->width_in_blocks; |
152 cinfo->MCU_rows_in_scan = compptr->height_in_blocks; | 159 cinfo->MCU_rows_in_scan = compptr->height_in_blocks; |
153 | 160 |
154 /* For noninterleaved scan, always one block per MCU */ | 161 /* For noninterleaved scan, always one block per MCU */ |
155 compptr->MCU_width = 1; | 162 compptr->MCU_width = 1; |
156 compptr->MCU_height = 1; | 163 compptr->MCU_height = 1; |
157 compptr->MCU_blocks = 1; | 164 compptr->MCU_blocks = 1; |
158 compptr->MCU_sample_width = compptr->_DCT_scaled_size; | 165 compptr->MCU_sample_width = compptr->_DCT_scaled_size; |
159 compptr->last_col_width = 1; | 166 compptr->last_col_width = 1; |
160 /* For noninterleaved scans, it is convenient to define last_row_height | 167 /* For noninterleaved scans, it is convenient to define last_row_height |
161 * as the number of block rows present in the last iMCU row. | 168 * as the number of block rows present in the last iMCU row. |
162 */ | 169 */ |
163 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); | 170 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); |
164 if (tmp == 0) tmp = compptr->v_samp_factor; | 171 if (tmp == 0) tmp = compptr->v_samp_factor; |
165 compptr->last_row_height = tmp; | 172 compptr->last_row_height = tmp; |
166 | 173 |
167 /* Prepare array describing MCU composition */ | 174 /* Prepare array describing MCU composition */ |
168 cinfo->blocks_in_MCU = 1; | 175 cinfo->blocks_in_MCU = 1; |
169 cinfo->MCU_membership[0] = 0; | 176 cinfo->MCU_membership[0] = 0; |
170 | 177 |
171 } else { | 178 } else { |
172 | 179 |
173 /* Interleaved (multi-component) scan */ | 180 /* Interleaved (multi-component) scan */ |
174 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) | 181 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) |
175 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, | 182 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, |
176 » MAX_COMPS_IN_SCAN); | 183 MAX_COMPS_IN_SCAN); |
177 | 184 |
178 /* Overall image size in MCUs */ | 185 /* Overall image size in MCUs */ |
179 cinfo->MCUs_per_row = (JDIMENSION) | 186 cinfo->MCUs_per_row = (JDIMENSION) |
180 jdiv_round_up((long) cinfo->image_width, | 187 jdiv_round_up((long) cinfo->image_width, |
181 » » (long) (cinfo->max_h_samp_factor*DCTSIZE)); | 188 (long) (cinfo->max_h_samp_factor*DCTSIZE)); |
182 cinfo->MCU_rows_in_scan = (JDIMENSION) | 189 cinfo->MCU_rows_in_scan = (JDIMENSION) |
183 jdiv_round_up((long) cinfo->image_height, | 190 jdiv_round_up((long) cinfo->image_height, |
184 » » (long) (cinfo->max_v_samp_factor*DCTSIZE)); | 191 (long) (cinfo->max_v_samp_factor*DCTSIZE)); |
185 | 192 |
186 cinfo->blocks_in_MCU = 0; | 193 cinfo->blocks_in_MCU = 0; |
187 | 194 |
188 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 195 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
189 compptr = cinfo->cur_comp_info[ci]; | 196 compptr = cinfo->cur_comp_info[ci]; |
190 /* Sampling factors give # of blocks of component in each MCU */ | 197 /* Sampling factors give # of blocks of component in each MCU */ |
191 compptr->MCU_width = compptr->h_samp_factor; | 198 compptr->MCU_width = compptr->h_samp_factor; |
192 compptr->MCU_height = compptr->v_samp_factor; | 199 compptr->MCU_height = compptr->v_samp_factor; |
193 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; | 200 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; |
194 compptr->MCU_sample_width = compptr->MCU_width * compptr->_DCT_scaled_size
; | 201 compptr->MCU_sample_width = compptr->MCU_width * compptr->_DCT_scaled_size
; |
195 /* Figure number of non-dummy blocks in last MCU column & row */ | 202 /* Figure number of non-dummy blocks in last MCU column & row */ |
196 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); | 203 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); |
197 if (tmp == 0) tmp = compptr->MCU_width; | 204 if (tmp == 0) tmp = compptr->MCU_width; |
198 compptr->last_col_width = tmp; | 205 compptr->last_col_width = tmp; |
199 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); | 206 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); |
200 if (tmp == 0) tmp = compptr->MCU_height; | 207 if (tmp == 0) tmp = compptr->MCU_height; |
201 compptr->last_row_height = tmp; | 208 compptr->last_row_height = tmp; |
202 /* Prepare array describing MCU composition */ | 209 /* Prepare array describing MCU composition */ |
203 mcublks = compptr->MCU_blocks; | 210 mcublks = compptr->MCU_blocks; |
204 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) | 211 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) |
205 » ERREXIT(cinfo, JERR_BAD_MCU_SIZE); | 212 ERREXIT(cinfo, JERR_BAD_MCU_SIZE); |
206 while (mcublks-- > 0) { | 213 while (mcublks-- > 0) { |
207 » cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; | 214 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; |
208 } | 215 } |
209 } | 216 } |
210 | 217 |
211 } | 218 } |
212 } | 219 } |
213 | 220 |
214 | 221 |
215 /* | 222 /* |
216 * Save away a copy of the Q-table referenced by each component present | 223 * Save away a copy of the Q-table referenced by each component present |
217 * in the current scan, unless already saved during a prior scan. | 224 * in the current scan, unless already saved during a prior scan. |
218 * | 225 * |
219 * In a multiple-scan JPEG file, the encoder could assign different components | 226 * In a multiple-scan JPEG file, the encoder could assign different components |
220 * the same Q-table slot number, but change table definitions between scans | 227 * the same Q-table slot number, but change table definitions between scans |
(...skipping 10 matching lines...) Expand all Loading... |
231 * | 238 * |
232 * The decompressor output side looks only at the saved quant tables, | 239 * The decompressor output side looks only at the saved quant tables, |
233 * not at the current Q-table slots. | 240 * not at the current Q-table slots. |
234 */ | 241 */ |
235 | 242 |
236 LOCAL(void) | 243 LOCAL(void) |
237 latch_quant_tables (j_decompress_ptr cinfo) | 244 latch_quant_tables (j_decompress_ptr cinfo) |
238 { | 245 { |
239 int ci, qtblno; | 246 int ci, qtblno; |
240 jpeg_component_info *compptr; | 247 jpeg_component_info *compptr; |
241 JQUANT_TBL * qtbl; | 248 JQUANT_TBL *qtbl; |
242 | 249 |
243 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 250 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
244 compptr = cinfo->cur_comp_info[ci]; | 251 compptr = cinfo->cur_comp_info[ci]; |
245 /* No work if we already saved Q-table for this component */ | 252 /* No work if we already saved Q-table for this component */ |
246 if (compptr->quant_table != NULL) | 253 if (compptr->quant_table != NULL) |
247 continue; | 254 continue; |
248 /* Make sure specified quantization table is present */ | 255 /* Make sure specified quantization table is present */ |
249 qtblno = compptr->quant_tbl_no; | 256 qtblno = compptr->quant_tbl_no; |
250 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || | 257 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || |
251 » cinfo->quant_tbl_ptrs[qtblno] == NULL) | 258 cinfo->quant_tbl_ptrs[qtblno] == NULL) |
252 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); | 259 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); |
253 /* OK, save away the quantization table */ | 260 /* OK, save away the quantization table */ |
254 qtbl = (JQUANT_TBL *) | 261 qtbl = (JQUANT_TBL *) |
255 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 262 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
256 » » » » SIZEOF(JQUANT_TBL)); | 263 sizeof(JQUANT_TBL)); |
257 MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL)); | 264 MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], sizeof(JQUANT_TBL)); |
258 compptr->quant_table = qtbl; | 265 compptr->quant_table = qtbl; |
259 } | 266 } |
260 } | 267 } |
261 | 268 |
262 | 269 |
263 /* | 270 /* |
264 * Initialize the input modules to read a scan of compressed data. | 271 * Initialize the input modules to read a scan of compressed data. |
265 * The first call to this is done by jdmaster.c after initializing | 272 * The first call to this is done by jdmaster.c after initializing |
266 * the entire decompressor (during jpeg_start_decompress). | 273 * the entire decompressor (during jpeg_start_decompress). |
267 * Subsequent calls come from consume_markers, below. | 274 * Subsequent calls come from consume_markers, below. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 { | 313 { |
307 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; | 314 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; |
308 int val; | 315 int val; |
309 | 316 |
310 if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */ | 317 if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */ |
311 return JPEG_REACHED_EOI; | 318 return JPEG_REACHED_EOI; |
312 | 319 |
313 val = (*cinfo->marker->read_markers) (cinfo); | 320 val = (*cinfo->marker->read_markers) (cinfo); |
314 | 321 |
315 switch (val) { | 322 switch (val) { |
316 case JPEG_REACHED_SOS:» /* Found SOS */ | 323 case JPEG_REACHED_SOS: /* Found SOS */ |
317 if (inputctl->inheaders) {» /* 1st SOS */ | 324 if (inputctl->inheaders) { /* 1st SOS */ |
318 initial_setup(cinfo); | 325 initial_setup(cinfo); |
319 inputctl->inheaders = FALSE; | 326 inputctl->inheaders = FALSE; |
320 /* Note: start_input_pass must be called by jdmaster.c | 327 /* Note: start_input_pass must be called by jdmaster.c |
321 * before any more input can be consumed. jdapimin.c is | 328 * before any more input can be consumed. jdapimin.c is |
322 * responsible for enforcing this sequencing. | 329 * responsible for enforcing this sequencing. |
323 */ | 330 */ |
324 } else {» » » /* 2nd or later SOS marker */ | 331 } else { /* 2nd or later SOS marker */ |
325 if (! inputctl->pub.has_multiple_scans) | 332 if (! inputctl->pub.has_multiple_scans) |
326 » ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ | 333 ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ |
327 start_input_pass(cinfo); | 334 start_input_pass(cinfo); |
328 } | 335 } |
329 break; | 336 break; |
330 case JPEG_REACHED_EOI:» /* Found EOI */ | 337 case JPEG_REACHED_EOI: /* Found EOI */ |
331 inputctl->pub.eoi_reached = TRUE; | 338 inputctl->pub.eoi_reached = TRUE; |
332 if (inputctl->inheaders) {» /* Tables-only datastream, apparently */ | 339 if (inputctl->inheaders) { /* Tables-only datastream, apparently */ |
333 if (cinfo->marker->saw_SOF) | 340 if (cinfo->marker->saw_SOF) |
334 » ERREXIT(cinfo, JERR_SOF_NO_SOS); | 341 ERREXIT(cinfo, JERR_SOF_NO_SOS); |
335 } else { | 342 } else { |
336 /* Prevent infinite loop in coef ctlr's decompress_data routine | 343 /* Prevent infinite loop in coef ctlr's decompress_data routine |
337 * if user set output_scan_number larger than number of scans. | 344 * if user set output_scan_number larger than number of scans. |
338 */ | 345 */ |
339 if (cinfo->output_scan_number > cinfo->input_scan_number) | 346 if (cinfo->output_scan_number > cinfo->input_scan_number) |
340 » cinfo->output_scan_number = cinfo->input_scan_number; | 347 cinfo->output_scan_number = cinfo->input_scan_number; |
341 } | 348 } |
342 break; | 349 break; |
343 case JPEG_SUSPENDED: | 350 case JPEG_SUSPENDED: |
344 break; | 351 break; |
345 } | 352 } |
346 | 353 |
347 return val; | 354 return val; |
348 } | 355 } |
349 | 356 |
350 | 357 |
(...skipping 24 matching lines...) Expand all Loading... |
375 */ | 382 */ |
376 | 383 |
377 GLOBAL(void) | 384 GLOBAL(void) |
378 jinit_input_controller (j_decompress_ptr cinfo) | 385 jinit_input_controller (j_decompress_ptr cinfo) |
379 { | 386 { |
380 my_inputctl_ptr inputctl; | 387 my_inputctl_ptr inputctl; |
381 | 388 |
382 /* Create subobject in permanent pool */ | 389 /* Create subobject in permanent pool */ |
383 inputctl = (my_inputctl_ptr) | 390 inputctl = (my_inputctl_ptr) |
384 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, | 391 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, |
385 » » » » SIZEOF(my_input_controller)); | 392 sizeof(my_input_controller)); |
386 cinfo->inputctl = (struct jpeg_input_controller *) inputctl; | 393 cinfo->inputctl = (struct jpeg_input_controller *) inputctl; |
387 /* Initialize method pointers */ | 394 /* Initialize method pointers */ |
388 inputctl->pub.consume_input = consume_markers; | 395 inputctl->pub.consume_input = consume_markers; |
389 inputctl->pub.reset_input_controller = reset_input_controller; | 396 inputctl->pub.reset_input_controller = reset_input_controller; |
390 inputctl->pub.start_input_pass = start_input_pass; | 397 inputctl->pub.start_input_pass = start_input_pass; |
391 inputctl->pub.finish_input_pass = finish_input_pass; | 398 inputctl->pub.finish_input_pass = finish_input_pass; |
392 /* Initialize state: can't use reset_input_controller since we don't | 399 /* Initialize state: can't use reset_input_controller since we don't |
393 * want to try to reset other modules yet. | 400 * want to try to reset other modules yet. |
394 */ | 401 */ |
395 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ | 402 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ |
396 inputctl->pub.eoi_reached = FALSE; | 403 inputctl->pub.eoi_reached = FALSE; |
397 inputctl->inheaders = TRUE; | 404 inputctl->inheaders = TRUE; |
398 } | 405 } |
OLD | NEW |