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

Side by Side Diff: rdswitch.c

Issue 1953443002: Update to libjpeg_turbo 1.4.90 (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
« no previous file with comments | « rdrle.c ('k') | rdtarga.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * rdswitch.c 2 * rdswitch.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-1996, Thomas G. Lane. 5 * Copyright (C) 1991-1996, Thomas G. Lane.
6 * libjpeg-turbo Modifications: 6 * libjpeg-turbo Modifications:
7 * Copyright (C) 2010, D. R. Commander. 7 * Copyright (C) 2010, D. R. Commander.
8 * For conditions of distribution and use, see the accompanying README file. 8 * For conditions of distribution and use, see the accompanying README.ijg
9 * file.
9 * 10 *
10 * This file contains routines to process some of cjpeg's more complicated 11 * This file contains routines to process some of cjpeg's more complicated
11 * command-line switches. Switches processed here are: 12 * command-line switches. Switches processed here are:
12 *» -qtables file» » Read quantization tables from text file 13 * -qtables file Read quantization tables from text file
13 *» -scans file» » Read scan script from text file 14 * -scans file Read scan script from text file
14 *» -quality N[,N,...]» Set quality ratings 15 * -quality N[,N,...] Set quality ratings
15 *» -qslots N[,N,...]» Set component quantization table selectors 16 * -qslots N[,N,...] Set component quantization table selectors
16 *» -sample HxV[,HxV,...]» Set component sampling factors 17 * -sample HxV[,HxV,...] Set component sampling factors
17 */ 18 */
18 19
19 #include "cdjpeg.h"» » /* Common decls for cjpeg/djpeg applications */ 20 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
20 #include <ctype.h>» » /* to declare isdigit(), isspace() */ 21 #include <ctype.h> /* to declare isdigit(), isspace() */
21 22
22 23
23 LOCAL(int) 24 LOCAL(int)
24 text_getc (FILE * file) 25 text_getc (FILE *file)
25 /* Read next char, skipping over any comments (# to end of line) */ 26 /* Read next char, skipping over any comments (# to end of line) */
26 /* A comment/newline sequence is returned as a newline */ 27 /* A comment/newline sequence is returned as a newline */
27 { 28 {
28 register int ch; 29 register int ch;
29 30
30 ch = getc(file); 31 ch = getc(file);
31 if (ch == '#') { 32 if (ch == '#') {
32 do { 33 do {
33 ch = getc(file); 34 ch = getc(file);
34 } while (ch != '\n' && ch != EOF); 35 } while (ch != '\n' && ch != EOF);
35 } 36 }
36 return ch; 37 return ch;
37 } 38 }
38 39
39 40
40 LOCAL(boolean) 41 LOCAL(boolean)
41 read_text_integer (FILE * file, long * result, int * termchar) 42 read_text_integer (FILE *file, long *result, int *termchar)
42 /* Read an unsigned decimal integer from a file, store it in result */ 43 /* Read an unsigned decimal integer from a file, store it in result */
43 /* Reads one trailing character after the integer; returns it in termchar */ 44 /* Reads one trailing character after the integer; returns it in termchar */
44 { 45 {
45 register int ch; 46 register int ch;
46 register long val; 47 register long val;
47 48
48 /* Skip any leading whitespace, detect EOF */ 49 /* Skip any leading whitespace, detect EOF */
49 do { 50 do {
50 ch = text_getc(file); 51 ch = text_getc(file);
51 if (ch == EOF) { 52 if (ch == EOF) {
52 *termchar = ch; 53 *termchar = ch;
53 return FALSE; 54 return FALSE;
54 } 55 }
55 } while (isspace(ch)); 56 } while (isspace(ch));
56 57
57 if (! isdigit(ch)) { 58 if (! isdigit(ch)) {
58 *termchar = ch; 59 *termchar = ch;
59 return FALSE; 60 return FALSE;
60 } 61 }
61 62
62 val = ch - '0'; 63 val = ch - '0';
63 while ((ch = text_getc(file)) != EOF) { 64 while ((ch = text_getc(file)) != EOF) {
64 if (! isdigit(ch)) 65 if (! isdigit(ch))
65 break; 66 break;
66 val *= 10; 67 val *= 10;
67 val += ch - '0'; 68 val += ch - '0';
68 } 69 }
69 *result = val; 70 *result = val;
70 *termchar = ch; 71 *termchar = ch;
71 return TRUE; 72 return TRUE;
72 } 73 }
73 74
74 75
75 #if JPEG_LIB_VERSION < 70 76 #if JPEG_LIB_VERSION < 70
76 static int q_scale_factor[NUM_QUANT_TBLS] = {100, 100, 100, 100}; 77 static int q_scale_factor[NUM_QUANT_TBLS] = {100, 100, 100, 100};
77 #endif 78 #endif
78 79
79 GLOBAL(boolean) 80 GLOBAL(boolean)
80 read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline ) 81 read_quant_tables (j_compress_ptr cinfo, char *filename,
82 boolean force_baseline)
81 /* Read a set of quantization tables from the specified file. 83 /* Read a set of quantization tables from the specified file.
82 * The file is plain ASCII text: decimal numbers with whitespace between. 84 * The file is plain ASCII text: decimal numbers with whitespace between.
83 * Comments preceded by '#' may be included in the file. 85 * Comments preceded by '#' may be included in the file.
84 * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. 86 * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
85 * The tables are implicitly numbered 0,1,etc. 87 * The tables are implicitly numbered 0,1,etc.
86 * NOTE: does not affect the qslots mapping, which will default to selecting 88 * NOTE: does not affect the qslots mapping, which will default to selecting
87 * table 0 for luminance (or primary) components, 1 for chrominance components. 89 * table 0 for luminance (or primary) components, 1 for chrominance components.
88 * You must use -qslots if you want a different component->table mapping. 90 * You must use -qslots if you want a different component->table mapping.
89 */ 91 */
90 { 92 {
91 FILE * fp; 93 FILE *fp;
92 int tblno, i, termchar; 94 int tblno, i, termchar;
93 long val; 95 long val;
94 unsigned int table[DCTSIZE2]; 96 unsigned int table[DCTSIZE2];
95 97
96 if ((fp = fopen(filename, "r")) == NULL) { 98 if ((fp = fopen(filename, "r")) == NULL) {
97 fprintf(stderr, "Can't open table file %s\n", filename); 99 fprintf(stderr, "Can't open table file %s\n", filename);
98 return FALSE; 100 return FALSE;
99 } 101 }
100 tblno = 0; 102 tblno = 0;
101 103
102 while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ 104 while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
103 if (tblno >= NUM_QUANT_TBLS) { 105 if (tblno >= NUM_QUANT_TBLS) {
104 fprintf(stderr, "Too many tables in file %s\n", filename); 106 fprintf(stderr, "Too many tables in file %s\n", filename);
105 fclose(fp); 107 fclose(fp);
106 return FALSE; 108 return FALSE;
107 } 109 }
108 table[0] = (unsigned int) val; 110 table[0] = (unsigned int) val;
109 for (i = 1; i < DCTSIZE2; i++) { 111 for (i = 1; i < DCTSIZE2; i++) {
110 if (! read_text_integer(fp, &val, &termchar)) { 112 if (! read_text_integer(fp, &val, &termchar)) {
111 » fprintf(stderr, "Invalid table data in file %s\n", filename); 113 fprintf(stderr, "Invalid table data in file %s\n", filename);
112 » fclose(fp); 114 fclose(fp);
113 » return FALSE; 115 return FALSE;
114 } 116 }
115 table[i] = (unsigned int) val; 117 table[i] = (unsigned int) val;
116 } 118 }
117 #if JPEG_LIB_VERSION >= 70 119 #if JPEG_LIB_VERSION >= 70
118 jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], 120 jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],
119 » » » force_baseline); 121 force_baseline);
120 #else 122 #else
121 jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno], 123 jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno],
122 force_baseline); 124 force_baseline);
123 #endif 125 #endif
124 tblno++; 126 tblno++;
125 } 127 }
126 128
127 if (termchar != EOF) { 129 if (termchar != EOF) {
128 fprintf(stderr, "Non-numeric data in file %s\n", filename); 130 fprintf(stderr, "Non-numeric data in file %s\n", filename);
129 fclose(fp); 131 fclose(fp);
130 return FALSE; 132 return FALSE;
131 } 133 }
132 134
133 fclose(fp); 135 fclose(fp);
134 return TRUE; 136 return TRUE;
135 } 137 }
136 138
137 139
138 #ifdef C_MULTISCAN_FILES_SUPPORTED 140 #ifdef C_MULTISCAN_FILES_SUPPORTED
139 141
140 LOCAL(boolean) 142 LOCAL(boolean)
141 read_scan_integer (FILE * file, long * result, int * termchar) 143 read_scan_integer (FILE *file, long *result, int *termchar)
142 /* Variant of read_text_integer that always looks for a non-space termchar; 144 /* Variant of read_text_integer that always looks for a non-space termchar;
143 * this simplifies parsing of punctuation in scan scripts. 145 * this simplifies parsing of punctuation in scan scripts.
144 */ 146 */
145 { 147 {
146 register int ch; 148 register int ch;
147 149
148 if (! read_text_integer(file, result, termchar)) 150 if (! read_text_integer(file, result, termchar))
149 return FALSE; 151 return FALSE;
150 ch = *termchar; 152 ch = *termchar;
151 while (ch != EOF && isspace(ch)) 153 while (ch != EOF && isspace(ch))
152 ch = text_getc(file); 154 ch = text_getc(file);
153 if (isdigit(ch)) {» » /* oops, put it back */ 155 if (isdigit(ch)) { /* oops, put it back */
154 if (ungetc(ch, file) == EOF) 156 if (ungetc(ch, file) == EOF)
155 return FALSE; 157 return FALSE;
156 ch = ' '; 158 ch = ' ';
157 } else { 159 } else {
158 /* Any separators other than ';' and ':' are ignored; 160 /* Any separators other than ';' and ':' are ignored;
159 * this allows user to insert commas, etc, if desired. 161 * this allows user to insert commas, etc, if desired.
160 */ 162 */
161 if (ch != EOF && ch != ';' && ch != ':') 163 if (ch != EOF && ch != ';' && ch != ':')
162 ch = ' '; 164 ch = ' ';
163 } 165 }
164 *termchar = ch; 166 *termchar = ch;
165 return TRUE; 167 return TRUE;
166 } 168 }
167 169
168 170
169 GLOBAL(boolean) 171 GLOBAL(boolean)
170 read_scan_script (j_compress_ptr cinfo, char * filename) 172 read_scan_script (j_compress_ptr cinfo, char *filename)
171 /* Read a scan script from the specified text file. 173 /* Read a scan script from the specified text file.
172 * Each entry in the file defines one scan to be emitted. 174 * Each entry in the file defines one scan to be emitted.
173 * Entries are separated by semicolons ';'. 175 * Entries are separated by semicolons ';'.
174 * An entry contains one to four component indexes, 176 * An entry contains one to four component indexes,
175 * optionally followed by a colon ':' and four progressive-JPEG parameters. 177 * optionally followed by a colon ':' and four progressive-JPEG parameters.
176 * The component indexes denote which component(s) are to be transmitted 178 * The component indexes denote which component(s) are to be transmitted
177 * in the current scan. The first component has index 0. 179 * in the current scan. The first component has index 0.
178 * Sequential JPEG is used if the progressive-JPEG parameters are omitted. 180 * Sequential JPEG is used if the progressive-JPEG parameters are omitted.
179 * The file is free format text: any whitespace may appear between numbers 181 * The file is free format text: any whitespace may appear between numbers
180 * and the ':' and ';' punctuation marks. Also, other punctuation (such 182 * and the ':' and ';' punctuation marks. Also, other punctuation (such
181 * as commas or dashes) can be placed between numbers if desired. 183 * as commas or dashes) can be placed between numbers if desired.
182 * Comments preceded by '#' may be included in the file. 184 * Comments preceded by '#' may be included in the file.
183 * Note: we do very little validity checking here; 185 * Note: we do very little validity checking here;
184 * jcmaster.c will validate the script parameters. 186 * jcmaster.c will validate the script parameters.
185 */ 187 */
186 { 188 {
187 FILE * fp; 189 FILE *fp;
188 int scanno, ncomps, termchar; 190 int scanno, ncomps, termchar;
189 long val; 191 long val;
190 jpeg_scan_info * scanptr; 192 jpeg_scan_info *scanptr;
191 #define MAX_SCANS 100» » /* quite arbitrary limit */ 193 #define MAX_SCANS 100 /* quite arbitrary limit */
192 jpeg_scan_info scans[MAX_SCANS]; 194 jpeg_scan_info scans[MAX_SCANS];
193 195
194 if ((fp = fopen(filename, "r")) == NULL) { 196 if ((fp = fopen(filename, "r")) == NULL) {
195 fprintf(stderr, "Can't open scan definition file %s\n", filename); 197 fprintf(stderr, "Can't open scan definition file %s\n", filename);
196 return FALSE; 198 return FALSE;
197 } 199 }
198 scanptr = scans; 200 scanptr = scans;
199 scanno = 0; 201 scanno = 0;
200 202
201 while (read_scan_integer(fp, &val, &termchar)) { 203 while (read_scan_integer(fp, &val, &termchar)) {
202 if (scanno >= MAX_SCANS) { 204 if (scanno >= MAX_SCANS) {
203 fprintf(stderr, "Too many scans defined in file %s\n", filename); 205 fprintf(stderr, "Too many scans defined in file %s\n", filename);
204 fclose(fp); 206 fclose(fp);
205 return FALSE; 207 return FALSE;
206 } 208 }
207 scanptr->component_index[0] = (int) val; 209 scanptr->component_index[0] = (int) val;
208 ncomps = 1; 210 ncomps = 1;
209 while (termchar == ' ') { 211 while (termchar == ' ') {
210 if (ncomps >= MAX_COMPS_IN_SCAN) { 212 if (ncomps >= MAX_COMPS_IN_SCAN) {
211 » fprintf(stderr, "Too many components in one scan in file %s\n", 213 fprintf(stderr, "Too many components in one scan in file %s\n",
212 » » filename); 214 filename);
213 » fclose(fp); 215 fclose(fp);
214 » return FALSE; 216 return FALSE;
215 } 217 }
216 if (! read_scan_integer(fp, &val, &termchar)) 218 if (! read_scan_integer(fp, &val, &termchar))
217 » goto bogus; 219 goto bogus;
218 scanptr->component_index[ncomps] = (int) val; 220 scanptr->component_index[ncomps] = (int) val;
219 ncomps++; 221 ncomps++;
220 } 222 }
221 scanptr->comps_in_scan = ncomps; 223 scanptr->comps_in_scan = ncomps;
222 if (termchar == ':') { 224 if (termchar == ':') {
223 if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') 225 if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
224 » goto bogus; 226 goto bogus;
225 scanptr->Ss = (int) val; 227 scanptr->Ss = (int) val;
226 if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') 228 if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
227 » goto bogus; 229 goto bogus;
228 scanptr->Se = (int) val; 230 scanptr->Se = (int) val;
229 if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') 231 if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
230 » goto bogus; 232 goto bogus;
231 scanptr->Ah = (int) val; 233 scanptr->Ah = (int) val;
232 if (! read_scan_integer(fp, &val, &termchar)) 234 if (! read_scan_integer(fp, &val, &termchar))
233 » goto bogus; 235 goto bogus;
234 scanptr->Al = (int) val; 236 scanptr->Al = (int) val;
235 } else { 237 } else {
236 /* set non-progressive parameters */ 238 /* set non-progressive parameters */
237 scanptr->Ss = 0; 239 scanptr->Ss = 0;
238 scanptr->Se = DCTSIZE2-1; 240 scanptr->Se = DCTSIZE2-1;
239 scanptr->Ah = 0; 241 scanptr->Ah = 0;
240 scanptr->Al = 0; 242 scanptr->Al = 0;
241 } 243 }
242 if (termchar != ';' && termchar != EOF) { 244 if (termchar != ';' && termchar != EOF) {
243 bogus: 245 bogus:
(...skipping 10 matching lines...) Expand all
254 return FALSE; 256 return FALSE;
255 } 257 }
256 258
257 if (scanno > 0) { 259 if (scanno > 0) {
258 /* Stash completed scan list in cinfo structure. 260 /* Stash completed scan list in cinfo structure.
259 * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, 261 * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data,
260 * but if you want to compress multiple images you'd want JPOOL_PERMANENT. 262 * but if you want to compress multiple images you'd want JPOOL_PERMANENT.
261 */ 263 */
262 scanptr = (jpeg_scan_info *) 264 scanptr = (jpeg_scan_info *)
263 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 265 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
264 » » » » scanno * SIZEOF(jpeg_scan_info)); 266 scanno * sizeof(jpeg_scan_info));
265 MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); 267 MEMCOPY(scanptr, scans, scanno * sizeof(jpeg_scan_info));
266 cinfo->scan_info = scanptr; 268 cinfo->scan_info = scanptr;
267 cinfo->num_scans = scanno; 269 cinfo->num_scans = scanno;
268 } 270 }
269 271
270 fclose(fp); 272 fclose(fp);
271 return TRUE; 273 return TRUE;
272 } 274 }
273 275
274 #endif /* C_MULTISCAN_FILES_SUPPORTED */ 276 #endif /* C_MULTISCAN_FILES_SUPPORTED */
275 277
(...skipping 22 matching lines...) Expand all
298 99, 99, 99, 99, 99, 99, 99, 99, 300 99, 99, 99, 99, 99, 99, 99, 99,
299 99, 99, 99, 99, 99, 99, 99, 99, 301 99, 99, 99, 99, 99, 99, 99, 99,
300 99, 99, 99, 99, 99, 99, 99, 99 302 99, 99, 99, 99, 99, 99, 99, 99
301 }; 303 };
302 304
303 305
304 LOCAL(void) 306 LOCAL(void)
305 jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) 307 jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
306 { 308 {
307 jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, 309 jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
308 » » q_scale_factor[0], force_baseline); 310 q_scale_factor[0], force_baseline);
309 jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, 311 jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
310 » » q_scale_factor[1], force_baseline); 312 q_scale_factor[1], force_baseline);
311 } 313 }
312 #endif 314 #endif
313 315
314 316
315 GLOBAL(boolean) 317 GLOBAL(boolean)
316 set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline) 318 set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
317 /* Process a quality-ratings parameter string, of the form 319 /* Process a quality-ratings parameter string, of the form
318 * N[,N,...] 320 * N[,N,...]
319 * If there are more q-table slots than parameters, the last value is replicated . 321 * If there are more q-table slots than parameters, the last value is replicated .
320 */ 322 */
321 { 323 {
322 int val = 75;»» » /* default value */ 324 int val = 75; /* default value */
323 int tblno; 325 int tblno;
324 char ch; 326 char ch;
325 327
326 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { 328 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
327 if (*arg) { 329 if (*arg) {
328 ch = ',';»» » /* if not set by sscanf, will be ',' */ 330 ch = ','; /* if not set by sscanf, will be ',' */
329 if (sscanf(arg, "%d%c", &val, &ch) < 1) 331 if (sscanf(arg, "%d%c", &val, &ch) < 1)
330 » return FALSE; 332 return FALSE;
331 if (ch != ',')» » /* syntax check */ 333 if (ch != ',') /* syntax check */
332 » return FALSE; 334 return FALSE;
333 /* Convert user 0-100 rating to percentage scaling */ 335 /* Convert user 0-100 rating to percentage scaling */
334 #if JPEG_LIB_VERSION >= 70 336 #if JPEG_LIB_VERSION >= 70
335 cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); 337 cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
336 #else 338 #else
337 q_scale_factor[tblno] = jpeg_quality_scaling(val); 339 q_scale_factor[tblno] = jpeg_quality_scaling(val);
338 #endif 340 #endif
339 while (*arg && *arg++ != ',') /* advance to next segment of arg string */ 341 while (*arg && *arg++ != ',') /* advance to next segment of arg string */
340 » ; 342 ;
341 } else { 343 } else {
342 /* reached end of parameter, set remaining factors to last value */ 344 /* reached end of parameter, set remaining factors to last value */
343 #if JPEG_LIB_VERSION >= 70 345 #if JPEG_LIB_VERSION >= 70
344 cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); 346 cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
345 #else 347 #else
346 q_scale_factor[tblno] = jpeg_quality_scaling(val); 348 q_scale_factor[tblno] = jpeg_quality_scaling(val);
347 #endif 349 #endif
348 } 350 }
349 } 351 }
350 jpeg_default_qtables(cinfo, force_baseline); 352 jpeg_default_qtables(cinfo, force_baseline);
351 return TRUE; 353 return TRUE;
352 } 354 }
353 355
354 356
355 GLOBAL(boolean) 357 GLOBAL(boolean)
356 set_quant_slots (j_compress_ptr cinfo, char *arg) 358 set_quant_slots (j_compress_ptr cinfo, char *arg)
357 /* Process a quantization-table-selectors parameter string, of the form 359 /* Process a quantization-table-selectors parameter string, of the form
358 * N[,N,...] 360 * N[,N,...]
359 * If there are more components than parameters, the last value is replicated. 361 * If there are more components than parameters, the last value is replicated.
360 */ 362 */
361 { 363 {
362 int val = 0;» » » /* default table # */ 364 int val = 0; /* default table # */
363 int ci; 365 int ci;
364 char ch; 366 char ch;
365 367
366 for (ci = 0; ci < MAX_COMPONENTS; ci++) { 368 for (ci = 0; ci < MAX_COMPONENTS; ci++) {
367 if (*arg) { 369 if (*arg) {
368 ch = ',';»» » /* if not set by sscanf, will be ',' */ 370 ch = ','; /* if not set by sscanf, will be ',' */
369 if (sscanf(arg, "%d%c", &val, &ch) < 1) 371 if (sscanf(arg, "%d%c", &val, &ch) < 1)
370 » return FALSE; 372 return FALSE;
371 if (ch != ',')» » /* syntax check */ 373 if (ch != ',') /* syntax check */
372 » return FALSE; 374 return FALSE;
373 if (val < 0 || val >= NUM_QUANT_TBLS) { 375 if (val < 0 || val >= NUM_QUANT_TBLS) {
374 » fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", 376 fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
375 » » NUM_QUANT_TBLS-1); 377 NUM_QUANT_TBLS-1);
376 » return FALSE; 378 return FALSE;
377 } 379 }
378 cinfo->comp_info[ci].quant_tbl_no = val; 380 cinfo->comp_info[ci].quant_tbl_no = val;
379 while (*arg && *arg++ != ',') /* advance to next segment of arg string */ 381 while (*arg && *arg++ != ',') /* advance to next segment of arg string */
380 » ; 382 ;
381 } else { 383 } else {
382 /* reached end of parameter, set remaining components to last table */ 384 /* reached end of parameter, set remaining components to last table */
383 cinfo->comp_info[ci].quant_tbl_no = val; 385 cinfo->comp_info[ci].quant_tbl_no = val;
384 } 386 }
385 } 387 }
386 return TRUE; 388 return TRUE;
387 } 389 }
388 390
389 391
390 GLOBAL(boolean) 392 GLOBAL(boolean)
391 set_sample_factors (j_compress_ptr cinfo, char *arg) 393 set_sample_factors (j_compress_ptr cinfo, char *arg)
392 /* Process a sample-factors parameter string, of the form 394 /* Process a sample-factors parameter string, of the form
393 * HxV[,HxV,...] 395 * HxV[,HxV,...]
394 * If there are more components than parameters, "1x1" is assumed for the rest. 396 * If there are more components than parameters, "1x1" is assumed for the rest.
395 */ 397 */
396 { 398 {
397 int ci, val1, val2; 399 int ci, val1, val2;
398 char ch1, ch2; 400 char ch1, ch2;
399 401
400 for (ci = 0; ci < MAX_COMPONENTS; ci++) { 402 for (ci = 0; ci < MAX_COMPONENTS; ci++) {
401 if (*arg) { 403 if (*arg) {
402 ch2 = ',';» » /* if not set by sscanf, will be ',' */ 404 ch2 = ','; /* if not set by sscanf, will be ',' */
403 if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) 405 if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
404 » return FALSE; 406 return FALSE;
405 if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ 407 if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
406 » return FALSE; 408 return FALSE;
407 if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { 409 if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
408 » fprintf(stderr, "JPEG sampling factors must be 1..4\n"); 410 fprintf(stderr, "JPEG sampling factors must be 1..4\n");
409 » return FALSE; 411 return FALSE;
410 } 412 }
411 cinfo->comp_info[ci].h_samp_factor = val1; 413 cinfo->comp_info[ci].h_samp_factor = val1;
412 cinfo->comp_info[ci].v_samp_factor = val2; 414 cinfo->comp_info[ci].v_samp_factor = val2;
413 while (*arg && *arg++ != ',') /* advance to next segment of arg string */ 415 while (*arg && *arg++ != ',') /* advance to next segment of arg string */
414 » ; 416 ;
415 } else { 417 } else {
416 /* reached end of parameter, set remaining components to 1x1 sampling */ 418 /* reached end of parameter, set remaining components to 1x1 sampling */
417 cinfo->comp_info[ci].h_samp_factor = 1; 419 cinfo->comp_info[ci].h_samp_factor = 1;
418 cinfo->comp_info[ci].v_samp_factor = 1; 420 cinfo->comp_info[ci].v_samp_factor = 1;
419 } 421 }
420 } 422 }
421 return TRUE; 423 return TRUE;
422 } 424 }
OLDNEW
« no previous file with comments | « rdrle.c ('k') | rdtarga.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698