Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: jcmaster.c

Issue 1934113002: Update libjpeg_turbo to 1.4.90 from https://github.com/libjpeg-turbo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * jcmaster.c 2 * jcmaster.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 * Modified 2003-2010 by Guido Vollbeding. 6 * Modified 2003-2010 by Guido Vollbeding.
7 * libjpeg-turbo Modifications: 7 * libjpeg-turbo Modifications:
8 * Copyright (C) 2010, D. R. Commander. 8 * Copyright (C) 2010, D. R. Commander.
9 * For conditions of distribution and use, see the accompanying README file. 9 * For conditions of distribution and use, see the accompanying README.ijg
10 * file.
10 * 11 *
11 * This file contains master control logic for the JPEG compressor. 12 * This file contains master control logic for the JPEG compressor.
12 * These routines are concerned with parameter validation, initial setup, 13 * These routines are concerned with parameter validation, initial setup,
13 * and inter-pass control (determining the number of passes and the work 14 * and inter-pass control (determining the number of passes and the work
14 * to be done in each pass). 15 * to be done in each pass).
15 */ 16 */
16 17
17 #define JPEG_INTERNALS 18 #define JPEG_INTERNALS
18 #include "jinclude.h" 19 #include "jinclude.h"
19 #include "jpeglib.h" 20 #include "jpeglib.h"
20 #include "jpegcomp.h" 21 #include "jpegcomp.h"
21 22
22 23
23 /* Private state */ 24 /* Private state */
24 25
25 typedef enum { 26 typedef enum {
26 » main_pass,» » /* input data, also do first output step */ 27 main_pass, /* input data, also do first output step */
27 » huff_opt_pass,» » /* Huffman code optimization pass */ 28 huff_opt_pass, /* Huffman code optimization pass */
28 » output_pass» » /* data output pass */ 29 output_pass /* data output pass */
29 } c_pass_type; 30 } c_pass_type;
30 31
31 typedef struct { 32 typedef struct {
32 struct jpeg_comp_master pub;» /* public fields */ 33 struct jpeg_comp_master pub; /* public fields */
33 34
34 c_pass_type pass_type;» /* the type of the current pass */ 35 c_pass_type pass_type; /* the type of the current pass */
35 36
36 int pass_number;» » /* # of passes completed */ 37 int pass_number; /* # of passes completed */
37 int total_passes;» » /* total # of passes needed */ 38 int total_passes; /* total # of passes needed */
38 39
39 int scan_number;» » /* current index in scan_info[] */ 40 int scan_number; /* current index in scan_info[] */
40 } my_comp_master; 41 } my_comp_master;
41 42
42 typedef my_comp_master * my_master_ptr; 43 typedef my_comp_master *my_master_ptr;
43 44
44 45
45 /* 46 /*
46 * Support routines that do various essential calculations. 47 * Support routines that do various essential calculations.
47 */ 48 */
48 49
49 #if JPEG_LIB_VERSION >= 70 50 #if JPEG_LIB_VERSION >= 70
50 /* 51 /*
51 * Compute JPEG image dimensions and related values. 52 * Compute JPEG image dimensions and related values.
52 * NOTE: this is exported for possible use by application. 53 * NOTE: this is exported for possible use by application.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if ((long) jd_samplesperrow != samplesperrow) 99 if ((long) jd_samplesperrow != samplesperrow)
99 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 100 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
100 101
101 /* For now, precision must match compiled-in value... */ 102 /* For now, precision must match compiled-in value... */
102 if (cinfo->data_precision != BITS_IN_JSAMPLE) 103 if (cinfo->data_precision != BITS_IN_JSAMPLE)
103 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); 104 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
104 105
105 /* Check that number of components won't exceed internal array sizes */ 106 /* Check that number of components won't exceed internal array sizes */
106 if (cinfo->num_components > MAX_COMPONENTS) 107 if (cinfo->num_components > MAX_COMPONENTS)
107 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, 108 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
108 » MAX_COMPONENTS); 109 MAX_COMPONENTS);
109 110
110 /* Compute maximum sampling factors; check factor validity */ 111 /* Compute maximum sampling factors; check factor validity */
111 cinfo->max_h_samp_factor = 1; 112 cinfo->max_h_samp_factor = 1;
112 cinfo->max_v_samp_factor = 1; 113 cinfo->max_v_samp_factor = 1;
113 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 114 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
114 ci++, compptr++) { 115 ci++, compptr++) {
115 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || 116 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
116 » compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) 117 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
117 ERREXIT(cinfo, JERR_BAD_SAMPLING); 118 ERREXIT(cinfo, JERR_BAD_SAMPLING);
118 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, 119 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
119 » » » » compptr->h_samp_factor); 120 compptr->h_samp_factor);
120 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, 121 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
121 » » » » compptr->v_samp_factor); 122 compptr->v_samp_factor);
122 } 123 }
123 124
124 /* Compute dimensions of components */ 125 /* Compute dimensions of components */
125 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 126 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
126 ci++, compptr++) { 127 ci++, compptr++) {
127 /* Fill in the correct component_index value; don't rely on application */ 128 /* Fill in the correct component_index value; don't rely on application */
128 compptr->component_index = ci; 129 compptr->component_index = ci;
129 /* For compression, we never do DCT scaling. */ 130 /* For compression, we never do DCT scaling. */
130 #if JPEG_LIB_VERSION >= 70 131 #if JPEG_LIB_VERSION >= 70
131 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; 132 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE;
132 #else 133 #else
133 compptr->DCT_scaled_size = DCTSIZE; 134 compptr->DCT_scaled_size = DCTSIZE;
134 #endif 135 #endif
135 /* Size in DCT blocks */ 136 /* Size in DCT blocks */
136 compptr->width_in_blocks = (JDIMENSION) 137 compptr->width_in_blocks = (JDIMENSION)
137 jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, 138 jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor,
138 » » (long) (cinfo->max_h_samp_factor * DCTSIZE)); 139 (long) (cinfo->max_h_samp_factor * DCTSIZE));
139 compptr->height_in_blocks = (JDIMENSION) 140 compptr->height_in_blocks = (JDIMENSION)
140 jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, 141 jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor,
141 » » (long) (cinfo->max_v_samp_factor * DCTSIZE)); 142 (long) (cinfo->max_v_samp_factor * DCTSIZE));
142 /* Size in samples */ 143 /* Size in samples */
143 compptr->downsampled_width = (JDIMENSION) 144 compptr->downsampled_width = (JDIMENSION)
144 jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, 145 jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor,
145 » » (long) cinfo->max_h_samp_factor); 146 (long) cinfo->max_h_samp_factor);
146 compptr->downsampled_height = (JDIMENSION) 147 compptr->downsampled_height = (JDIMENSION)
147 jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, 148 jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor,
148 » » (long) cinfo->max_v_samp_factor); 149 (long) cinfo->max_v_samp_factor);
149 /* Mark component needed (this flag isn't actually used for compression) */ 150 /* Mark component needed (this flag isn't actually used for compression) */
150 compptr->component_needed = TRUE; 151 compptr->component_needed = TRUE;
151 } 152 }
152 153
153 /* Compute number of fully interleaved MCU rows (number of times that 154 /* Compute number of fully interleaved MCU rows (number of times that
154 * main controller will call coefficient controller). 155 * main controller will call coefficient controller).
155 */ 156 */
156 cinfo->total_iMCU_rows = (JDIMENSION) 157 cinfo->total_iMCU_rows = (JDIMENSION)
157 jdiv_round_up((long) cinfo->_jpeg_height, 158 jdiv_round_up((long) cinfo->_jpeg_height,
158 » » (long) (cinfo->max_v_samp_factor*DCTSIZE)); 159 (long) (cinfo->max_v_samp_factor*DCTSIZE));
159 } 160 }
160 161
161 162
162 #ifdef C_MULTISCAN_FILES_SUPPORTED 163 #ifdef C_MULTISCAN_FILES_SUPPORTED
163 164
164 LOCAL(void) 165 LOCAL(void)
165 validate_script (j_compress_ptr cinfo) 166 validate_script (j_compress_ptr cinfo)
166 /* Verify that the scan script in cinfo->scan_info[] is valid; also 167 /* Verify that the scan script in cinfo->scan_info[] is valid; also
167 * determine whether it uses progressive JPEG, and set cinfo->progressive_mode. 168 * determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
168 */ 169 */
169 { 170 {
170 const jpeg_scan_info * scanptr; 171 const jpeg_scan_info *scanptr;
171 int scanno, ncomps, ci, coefi, thisi; 172 int scanno, ncomps, ci, coefi, thisi;
172 int Ss, Se, Ah, Al; 173 int Ss, Se, Ah, Al;
173 boolean component_sent[MAX_COMPONENTS]; 174 boolean component_sent[MAX_COMPONENTS];
174 #ifdef C_PROGRESSIVE_SUPPORTED 175 #ifdef C_PROGRESSIVE_SUPPORTED
175 int * last_bitpos_ptr; 176 int *last_bitpos_ptr;
176 int last_bitpos[MAX_COMPONENTS][DCTSIZE2]; 177 int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
177 /* -1 until that coefficient has been seen; then last Al for it */ 178 /* -1 until that coefficient has been seen; then last Al for it */
178 #endif 179 #endif
179 180
180 if (cinfo->num_scans <= 0) 181 if (cinfo->num_scans <= 0)
181 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0); 182 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
182 183
183 /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1; 184 /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
184 * for progressive JPEG, no scan can have this. 185 * for progressive JPEG, no scan can have this.
185 */ 186 */
186 scanptr = cinfo->scan_info; 187 scanptr = cinfo->scan_info;
187 if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) { 188 if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
188 #ifdef C_PROGRESSIVE_SUPPORTED 189 #ifdef C_PROGRESSIVE_SUPPORTED
189 cinfo->progressive_mode = TRUE; 190 cinfo->progressive_mode = TRUE;
190 last_bitpos_ptr = & last_bitpos[0][0]; 191 last_bitpos_ptr = & last_bitpos[0][0];
191 for (ci = 0; ci < cinfo->num_components; ci++) 192 for (ci = 0; ci < cinfo->num_components; ci++)
192 for (coefi = 0; coefi < DCTSIZE2; coefi++) 193 for (coefi = 0; coefi < DCTSIZE2; coefi++)
193 » *last_bitpos_ptr++ = -1; 194 *last_bitpos_ptr++ = -1;
194 #else 195 #else
195 ERREXIT(cinfo, JERR_NOT_COMPILED); 196 ERREXIT(cinfo, JERR_NOT_COMPILED);
196 #endif 197 #endif
197 } else { 198 } else {
198 cinfo->progressive_mode = FALSE; 199 cinfo->progressive_mode = FALSE;
199 for (ci = 0; ci < cinfo->num_components; ci++) 200 for (ci = 0; ci < cinfo->num_components; ci++)
200 component_sent[ci] = FALSE; 201 component_sent[ci] = FALSE;
201 } 202 }
202 203
203 for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) { 204 for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
204 /* Validate component indexes */ 205 /* Validate component indexes */
205 ncomps = scanptr->comps_in_scan; 206 ncomps = scanptr->comps_in_scan;
206 if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN) 207 if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
207 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN); 208 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
208 for (ci = 0; ci < ncomps; ci++) { 209 for (ci = 0; ci < ncomps; ci++) {
209 thisi = scanptr->component_index[ci]; 210 thisi = scanptr->component_index[ci];
210 if (thisi < 0 || thisi >= cinfo->num_components) 211 if (thisi < 0 || thisi >= cinfo->num_components)
211 » ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); 212 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
212 /* Components must appear in SOF order within each scan */ 213 /* Components must appear in SOF order within each scan */
213 if (ci > 0 && thisi <= scanptr->component_index[ci-1]) 214 if (ci > 0 && thisi <= scanptr->component_index[ci-1])
214 » ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); 215 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
215 } 216 }
216 /* Validate progression parameters */ 217 /* Validate progression parameters */
217 Ss = scanptr->Ss; 218 Ss = scanptr->Ss;
218 Se = scanptr->Se; 219 Se = scanptr->Se;
219 Ah = scanptr->Ah; 220 Ah = scanptr->Ah;
220 Al = scanptr->Al; 221 Al = scanptr->Al;
221 if (cinfo->progressive_mode) { 222 if (cinfo->progressive_mode) {
222 #ifdef C_PROGRESSIVE_SUPPORTED 223 #ifdef C_PROGRESSIVE_SUPPORTED
223 /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that 224 /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
224 * seems wrong: the upper bound ought to depend on data precision. 225 * seems wrong: the upper bound ought to depend on data precision.
225 * Perhaps they really meant 0..N+1 for N-bit precision. 226 * Perhaps they really meant 0..N+1 for N-bit precision.
226 * Here we allow 0..10 for 8-bit data; Al larger than 10 results in 227 * Here we allow 0..10 for 8-bit data; Al larger than 10 results in
227 * out-of-range reconstructed DC values during the first DC scan, 228 * out-of-range reconstructed DC values during the first DC scan,
228 * which might cause problems for some decoders. 229 * which might cause problems for some decoders.
229 */ 230 */
230 #if BITS_IN_JSAMPLE == 8 231 #if BITS_IN_JSAMPLE == 8
231 #define MAX_AH_AL 10 232 #define MAX_AH_AL 10
232 #else 233 #else
233 #define MAX_AH_AL 13 234 #define MAX_AH_AL 13
234 #endif 235 #endif
235 if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || 236 if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
236 » Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL) 237 Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
237 » ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 238 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
238 if (Ss == 0) { 239 if (Ss == 0) {
239 » if (Se != 0)» » /* DC and AC together not OK */ 240 if (Se != 0) /* DC and AC together not OK */
240 » ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 241 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
241 } else { 242 } else {
242 » if (ncomps != 1)» /* AC scans must be for only one component */ 243 if (ncomps != 1) /* AC scans must be for only one component */
243 » ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 244 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
244 } 245 }
245 for (ci = 0; ci < ncomps; ci++) { 246 for (ci = 0; ci < ncomps; ci++) {
246 » last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0]; 247 last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
247 » if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */ 248 if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
248 » ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 249 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
249 » for (coefi = Ss; coefi <= Se; coefi++) { 250 for (coefi = Ss; coefi <= Se; coefi++) {
250 » if (last_bitpos_ptr[coefi] < 0) { 251 if (last_bitpos_ptr[coefi] < 0) {
251 » /* first scan of this coefficient */ 252 /* first scan of this coefficient */
252 » if (Ah != 0) 253 if (Ah != 0)
253 » ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 254 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
254 » } else { 255 } else {
255 » /* not first scan */ 256 /* not first scan */
256 » if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1) 257 if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
257 » ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 258 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
258 » } 259 }
259 » last_bitpos_ptr[coefi] = Al; 260 last_bitpos_ptr[coefi] = Al;
260 » } 261 }
261 } 262 }
262 #endif 263 #endif
263 } else { 264 } else {
264 /* For sequential JPEG, all progression parameters must be these: */ 265 /* For sequential JPEG, all progression parameters must be these: */
265 if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0) 266 if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
266 » ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 267 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
267 /* Make sure components are not sent twice */ 268 /* Make sure components are not sent twice */
268 for (ci = 0; ci < ncomps; ci++) { 269 for (ci = 0; ci < ncomps; ci++) {
269 » thisi = scanptr->component_index[ci]; 270 thisi = scanptr->component_index[ci];
270 » if (component_sent[thisi]) 271 if (component_sent[thisi])
271 » ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); 272 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
272 » component_sent[thisi] = TRUE; 273 component_sent[thisi] = TRUE;
273 } 274 }
274 } 275 }
275 } 276 }
276 277
277 /* Now verify that everything got sent. */ 278 /* Now verify that everything got sent. */
278 if (cinfo->progressive_mode) { 279 if (cinfo->progressive_mode) {
279 #ifdef C_PROGRESSIVE_SUPPORTED 280 #ifdef C_PROGRESSIVE_SUPPORTED
280 /* For progressive mode, we only check that at least some DC data 281 /* For progressive mode, we only check that at least some DC data
281 * got sent for each component; the spec does not require that all bits 282 * got sent for each component; the spec does not require that all bits
282 * of all coefficients be transmitted. Would it be wiser to enforce 283 * of all coefficients be transmitted. Would it be wiser to enforce
283 * transmission of all coefficient bits?? 284 * transmission of all coefficient bits??
284 */ 285 */
285 for (ci = 0; ci < cinfo->num_components; ci++) { 286 for (ci = 0; ci < cinfo->num_components; ci++) {
286 if (last_bitpos[ci][0] < 0) 287 if (last_bitpos[ci][0] < 0)
287 » ERREXIT(cinfo, JERR_MISSING_DATA); 288 ERREXIT(cinfo, JERR_MISSING_DATA);
288 } 289 }
289 #endif 290 #endif
290 } else { 291 } else {
291 for (ci = 0; ci < cinfo->num_components; ci++) { 292 for (ci = 0; ci < cinfo->num_components; ci++) {
292 if (! component_sent[ci]) 293 if (! component_sent[ci])
293 » ERREXIT(cinfo, JERR_MISSING_DATA); 294 ERREXIT(cinfo, JERR_MISSING_DATA);
294 } 295 }
295 } 296 }
296 } 297 }
297 298
298 #endif /* C_MULTISCAN_FILES_SUPPORTED */ 299 #endif /* C_MULTISCAN_FILES_SUPPORTED */
299 300
300 301
301 LOCAL(void) 302 LOCAL(void)
302 select_scan_parameters (j_compress_ptr cinfo) 303 select_scan_parameters (j_compress_ptr cinfo)
303 /* Set up the scan parameters for the current scan */ 304 /* Set up the scan parameters for the current scan */
304 { 305 {
305 int ci; 306 int ci;
306 307
307 #ifdef C_MULTISCAN_FILES_SUPPORTED 308 #ifdef C_MULTISCAN_FILES_SUPPORTED
308 if (cinfo->scan_info != NULL) { 309 if (cinfo->scan_info != NULL) {
309 /* Prepare for current scan --- the script is already validated */ 310 /* Prepare for current scan --- the script is already validated */
310 my_master_ptr master = (my_master_ptr) cinfo->master; 311 my_master_ptr master = (my_master_ptr) cinfo->master;
311 const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number; 312 const jpeg_scan_info *scanptr = cinfo->scan_info + master->scan_number;
312 313
313 cinfo->comps_in_scan = scanptr->comps_in_scan; 314 cinfo->comps_in_scan = scanptr->comps_in_scan;
314 for (ci = 0; ci < scanptr->comps_in_scan; ci++) { 315 for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
315 cinfo->cur_comp_info[ci] = 316 cinfo->cur_comp_info[ci] =
316 » &cinfo->comp_info[scanptr->component_index[ci]]; 317 &cinfo->comp_info[scanptr->component_index[ci]];
317 } 318 }
318 cinfo->Ss = scanptr->Ss; 319 cinfo->Ss = scanptr->Ss;
319 cinfo->Se = scanptr->Se; 320 cinfo->Se = scanptr->Se;
320 cinfo->Ah = scanptr->Ah; 321 cinfo->Ah = scanptr->Ah;
321 cinfo->Al = scanptr->Al; 322 cinfo->Al = scanptr->Al;
322 } 323 }
323 else 324 else
324 #endif 325 #endif
325 { 326 {
326 /* Prepare for single sequential-JPEG scan containing all components */ 327 /* Prepare for single sequential-JPEG scan containing all components */
327 if (cinfo->num_components > MAX_COMPS_IN_SCAN) 328 if (cinfo->num_components > MAX_COMPS_IN_SCAN)
328 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, 329 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
329 » MAX_COMPS_IN_SCAN); 330 MAX_COMPS_IN_SCAN);
330 cinfo->comps_in_scan = cinfo->num_components; 331 cinfo->comps_in_scan = cinfo->num_components;
331 for (ci = 0; ci < cinfo->num_components; ci++) { 332 for (ci = 0; ci < cinfo->num_components; ci++) {
332 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; 333 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
333 } 334 }
334 cinfo->Ss = 0; 335 cinfo->Ss = 0;
335 cinfo->Se = DCTSIZE2-1; 336 cinfo->Se = DCTSIZE2-1;
336 cinfo->Ah = 0; 337 cinfo->Ah = 0;
337 cinfo->Al = 0; 338 cinfo->Al = 0;
338 } 339 }
339 } 340 }
340 341
341 342
342 LOCAL(void) 343 LOCAL(void)
343 per_scan_setup (j_compress_ptr cinfo) 344 per_scan_setup (j_compress_ptr cinfo)
344 /* Do computations that are needed before processing a JPEG scan */ 345 /* Do computations that are needed before processing a JPEG scan */
345 /* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */ 346 /* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
346 { 347 {
347 int ci, mcublks, tmp; 348 int ci, mcublks, tmp;
348 jpeg_component_info *compptr; 349 jpeg_component_info *compptr;
349 350
350 if (cinfo->comps_in_scan == 1) { 351 if (cinfo->comps_in_scan == 1) {
351 352
352 /* Noninterleaved (single-component) scan */ 353 /* Noninterleaved (single-component) scan */
353 compptr = cinfo->cur_comp_info[0]; 354 compptr = cinfo->cur_comp_info[0];
354 355
355 /* Overall image size in MCUs */ 356 /* Overall image size in MCUs */
356 cinfo->MCUs_per_row = compptr->width_in_blocks; 357 cinfo->MCUs_per_row = compptr->width_in_blocks;
357 cinfo->MCU_rows_in_scan = compptr->height_in_blocks; 358 cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
358 359
359 /* For noninterleaved scan, always one block per MCU */ 360 /* For noninterleaved scan, always one block per MCU */
360 compptr->MCU_width = 1; 361 compptr->MCU_width = 1;
361 compptr->MCU_height = 1; 362 compptr->MCU_height = 1;
362 compptr->MCU_blocks = 1; 363 compptr->MCU_blocks = 1;
363 compptr->MCU_sample_width = DCTSIZE; 364 compptr->MCU_sample_width = DCTSIZE;
364 compptr->last_col_width = 1; 365 compptr->last_col_width = 1;
365 /* For noninterleaved scans, it is convenient to define last_row_height 366 /* For noninterleaved scans, it is convenient to define last_row_height
366 * as the number of block rows present in the last iMCU row. 367 * as the number of block rows present in the last iMCU row.
367 */ 368 */
368 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); 369 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
369 if (tmp == 0) tmp = compptr->v_samp_factor; 370 if (tmp == 0) tmp = compptr->v_samp_factor;
370 compptr->last_row_height = tmp; 371 compptr->last_row_height = tmp;
371 372
372 /* Prepare array describing MCU composition */ 373 /* Prepare array describing MCU composition */
373 cinfo->blocks_in_MCU = 1; 374 cinfo->blocks_in_MCU = 1;
374 cinfo->MCU_membership[0] = 0; 375 cinfo->MCU_membership[0] = 0;
375 376
376 } else { 377 } else {
377 378
378 /* Interleaved (multi-component) scan */ 379 /* Interleaved (multi-component) scan */
379 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) 380 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
380 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, 381 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
381 » MAX_COMPS_IN_SCAN); 382 MAX_COMPS_IN_SCAN);
382 383
383 /* Overall image size in MCUs */ 384 /* Overall image size in MCUs */
384 cinfo->MCUs_per_row = (JDIMENSION) 385 cinfo->MCUs_per_row = (JDIMENSION)
385 jdiv_round_up((long) cinfo->_jpeg_width, 386 jdiv_round_up((long) cinfo->_jpeg_width,
386 » » (long) (cinfo->max_h_samp_factor*DCTSIZE)); 387 (long) (cinfo->max_h_samp_factor*DCTSIZE));
387 cinfo->MCU_rows_in_scan = (JDIMENSION) 388 cinfo->MCU_rows_in_scan = (JDIMENSION)
388 jdiv_round_up((long) cinfo->_jpeg_height, 389 jdiv_round_up((long) cinfo->_jpeg_height,
389 » » (long) (cinfo->max_v_samp_factor*DCTSIZE)); 390 (long) (cinfo->max_v_samp_factor*DCTSIZE));
390 391
391 cinfo->blocks_in_MCU = 0; 392 cinfo->blocks_in_MCU = 0;
392 393
393 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { 394 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
394 compptr = cinfo->cur_comp_info[ci]; 395 compptr = cinfo->cur_comp_info[ci];
395 /* Sampling factors give # of blocks of component in each MCU */ 396 /* Sampling factors give # of blocks of component in each MCU */
396 compptr->MCU_width = compptr->h_samp_factor; 397 compptr->MCU_width = compptr->h_samp_factor;
397 compptr->MCU_height = compptr->v_samp_factor; 398 compptr->MCU_height = compptr->v_samp_factor;
398 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; 399 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
399 compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE; 400 compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
400 /* Figure number of non-dummy blocks in last MCU column & row */ 401 /* Figure number of non-dummy blocks in last MCU column & row */
401 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); 402 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
402 if (tmp == 0) tmp = compptr->MCU_width; 403 if (tmp == 0) tmp = compptr->MCU_width;
403 compptr->last_col_width = tmp; 404 compptr->last_col_width = tmp;
404 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); 405 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
405 if (tmp == 0) tmp = compptr->MCU_height; 406 if (tmp == 0) tmp = compptr->MCU_height;
406 compptr->last_row_height = tmp; 407 compptr->last_row_height = tmp;
407 /* Prepare array describing MCU composition */ 408 /* Prepare array describing MCU composition */
408 mcublks = compptr->MCU_blocks; 409 mcublks = compptr->MCU_blocks;
409 if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) 410 if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
410 » ERREXIT(cinfo, JERR_BAD_MCU_SIZE); 411 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
411 while (mcublks-- > 0) { 412 while (mcublks-- > 0) {
412 » cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; 413 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
413 } 414 }
414 } 415 }
415 416
416 } 417 }
417 418
418 /* Convert restart specified in rows to actual MCU count. */ 419 /* Convert restart specified in rows to actual MCU count. */
419 /* Note that count must fit in 16 bits, so we provide limiting. */ 420 /* Note that count must fit in 16 bits, so we provide limiting. */
420 if (cinfo->restart_in_rows > 0) { 421 if (cinfo->restart_in_rows > 0) {
421 long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row; 422 long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
422 cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L); 423 cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
423 } 424 }
424 } 425 }
425 426
(...skipping 19 matching lines...) Expand all
445 select_scan_parameters(cinfo); 446 select_scan_parameters(cinfo);
446 per_scan_setup(cinfo); 447 per_scan_setup(cinfo);
447 if (! cinfo->raw_data_in) { 448 if (! cinfo->raw_data_in) {
448 (*cinfo->cconvert->start_pass) (cinfo); 449 (*cinfo->cconvert->start_pass) (cinfo);
449 (*cinfo->downsample->start_pass) (cinfo); 450 (*cinfo->downsample->start_pass) (cinfo);
450 (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU); 451 (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
451 } 452 }
452 (*cinfo->fdct->start_pass) (cinfo); 453 (*cinfo->fdct->start_pass) (cinfo);
453 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding); 454 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
454 (*cinfo->coef->start_pass) (cinfo, 455 (*cinfo->coef->start_pass) (cinfo,
455 » » » » (master->total_passes > 1 ? 456 (master->total_passes > 1 ?
456 » » » » JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); 457 JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
457 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); 458 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
458 if (cinfo->optimize_coding) { 459 if (cinfo->optimize_coding) {
459 /* No immediate data output; postpone writing frame/scan headers */ 460 /* No immediate data output; postpone writing frame/scan headers */
460 master->pub.call_pass_startup = FALSE; 461 master->pub.call_pass_startup = FALSE;
461 } else { 462 } else {
462 /* Will write frame/scan headers at first jpeg_write_scanlines call */ 463 /* Will write frame/scan headers at first jpeg_write_scanlines call */
463 master->pub.call_pass_startup = TRUE; 464 master->pub.call_pass_startup = TRUE;
464 } 465 }
465 break; 466 break;
466 #ifdef ENTROPY_OPT_SUPPORTED 467 #ifdef ENTROPY_OPT_SUPPORTED
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 * Initialize master compression control. 575 * Initialize master compression control.
575 */ 576 */
576 577
577 GLOBAL(void) 578 GLOBAL(void)
578 jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) 579 jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
579 { 580 {
580 my_master_ptr master; 581 my_master_ptr master;
581 582
582 master = (my_master_ptr) 583 master = (my_master_ptr)
583 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 584 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
584 » » » » SIZEOF(my_comp_master)); 585 sizeof(my_comp_master));
585 cinfo->master = (struct jpeg_comp_master *) master; 586 cinfo->master = (struct jpeg_comp_master *) master;
586 master->pub.prepare_for_pass = prepare_for_pass; 587 master->pub.prepare_for_pass = prepare_for_pass;
587 master->pub.pass_startup = pass_startup; 588 master->pub.pass_startup = pass_startup;
588 master->pub.finish_pass = finish_pass_master; 589 master->pub.finish_pass = finish_pass_master;
589 master->pub.is_last_pass = FALSE; 590 master->pub.is_last_pass = FALSE;
590 591
591 /* Validate parameters, determine derived values */ 592 /* Validate parameters, determine derived values */
592 initial_setup(cinfo, transcode_only); 593 initial_setup(cinfo, transcode_only);
593 594
594 if (cinfo->scan_info != NULL) { 595 if (cinfo->scan_info != NULL) {
595 #ifdef C_MULTISCAN_FILES_SUPPORTED 596 #ifdef C_MULTISCAN_FILES_SUPPORTED
596 validate_script(cinfo); 597 validate_script(cinfo);
597 #else 598 #else
598 ERREXIT(cinfo, JERR_NOT_COMPILED); 599 ERREXIT(cinfo, JERR_NOT_COMPILED);
599 #endif 600 #endif
600 } else { 601 } else {
601 cinfo->progressive_mode = FALSE; 602 cinfo->progressive_mode = FALSE;
602 cinfo->num_scans = 1; 603 cinfo->num_scans = 1;
603 } 604 }
604 605
605 if (cinfo->progressive_mode && !cinfo->arith_code)» /* TEMPORARY HACK ??? * / 606 if (cinfo->progressive_mode && !cinfo->arith_code) /* TEMPORARY HACK ??? */
606 cinfo->optimize_coding = TRUE; /* assume default tables no good for progress ive mode */ 607 cinfo->optimize_coding = TRUE; /* assume default tables no good for progress ive mode */
607 608
608 /* Initialize my private state */ 609 /* Initialize my private state */
609 if (transcode_only) { 610 if (transcode_only) {
610 /* no main pass in transcoding */ 611 /* no main pass in transcoding */
611 if (cinfo->optimize_coding) 612 if (cinfo->optimize_coding)
612 master->pass_type = huff_opt_pass; 613 master->pass_type = huff_opt_pass;
613 else 614 else
614 master->pass_type = output_pass; 615 master->pass_type = output_pass;
615 } else { 616 } else {
616 /* for normal compression, first pass is always this type: */ 617 /* for normal compression, first pass is always this type: */
617 master->pass_type = main_pass; 618 master->pass_type = main_pass;
618 } 619 }
619 master->scan_number = 0; 620 master->scan_number = 0;
620 master->pass_number = 0; 621 master->pass_number = 0;
621 if (cinfo->optimize_coding) 622 if (cinfo->optimize_coding)
622 master->total_passes = cinfo->num_scans * 2; 623 master->total_passes = cinfo->num_scans * 2;
623 else 624 else
624 master->total_passes = cinfo->num_scans; 625 master->total_passes = cinfo->num_scans;
625 } 626 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698