diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/jpeglib/rdswitch.c | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/jpeglib/rdswitch.c | 730 |
1 files changed, 365 insertions, 365 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/rdswitch.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/rdswitch.c index 5eebcc1..7a839af 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/rdswitch.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/rdswitch.c | |||
@@ -1,365 +1,365 @@ | |||
1 | /* | 1 | /* |
2 | * rdswitch.c | 2 | * rdswitch.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991-1996, Thomas G. Lane. | 4 | * Copyright (C) 1991-1996, Thomas G. Lane. |
5 | * This file is part of the Independent JPEG Group's software. | 5 | * This file is part of the Independent JPEG Group's software. |
6 | * For conditions of distribution and use, see the accompanying README file. | 6 | * For conditions of distribution and use, see the accompanying README file. |
7 | * | 7 | * |
8 | * This file contains routines to process some of cjpeg's more complicated | 8 | * This file contains routines to process some of cjpeg's more complicated |
9 | * command-line switches. Switches processed here are: | 9 | * command-line switches. Switches processed here are: |
10 | * -qtables file Read quantization tables from text file | 10 | * -qtables file Read quantization tables from text file |
11 | * -scans file Read scan script from text file | 11 | * -scans file Read scan script from text file |
12 | * -quality N[,N,...] Set quality ratings | 12 | * -quality N[,N,...] Set quality ratings |
13 | * -qslots N[,N,...] Set component quantization table selectors | 13 | * -qslots N[,N,...] Set component quantization table selectors |
14 | * -sample HxV[,HxV,...] Set component sampling factors | 14 | * -sample HxV[,HxV,...] Set component sampling factors |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ | 17 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
18 | #include <ctype.h> /* to declare isdigit(), isspace() */ | 18 | #include <ctype.h> /* to declare isdigit(), isspace() */ |
19 | 19 | ||
20 | 20 | ||
21 | LOCAL(int) | 21 | LOCAL(int) |
22 | text_getc (FILE * file) | 22 | text_getc (FILE * file) |
23 | /* Read next char, skipping over any comments (# to end of line) */ | 23 | /* Read next char, skipping over any comments (# to end of line) */ |
24 | /* A comment/newline sequence is returned as a newline */ | 24 | /* A comment/newline sequence is returned as a newline */ |
25 | { | 25 | { |
26 | register int ch; | 26 | register int ch; |
27 | 27 | ||
28 | ch = getc(file); | 28 | ch = getc(file); |
29 | if (ch == '#') { | 29 | if (ch == '#') { |
30 | do { | 30 | do { |
31 | ch = getc(file); | 31 | ch = getc(file); |
32 | } while (ch != '\n' && ch != EOF); | 32 | } while (ch != '\n' && ch != EOF); |
33 | } | 33 | } |
34 | return ch; | 34 | return ch; |
35 | } | 35 | } |
36 | 36 | ||
37 | 37 | ||
38 | LOCAL(boolean) | 38 | LOCAL(boolean) |
39 | read_text_integer (FILE * file, long * result, int * termchar) | 39 | read_text_integer (FILE * file, long * result, int * termchar) |
40 | /* Read an unsigned decimal integer from a file, store it in result */ | 40 | /* Read an unsigned decimal integer from a file, store it in result */ |
41 | /* Reads one trailing character after the integer; returns it in termchar */ | 41 | /* Reads one trailing character after the integer; returns it in termchar */ |
42 | { | 42 | { |
43 | register int ch; | 43 | register int ch; |
44 | register long val; | 44 | register long val; |
45 | 45 | ||
46 | /* Skip any leading whitespace, detect EOF */ | 46 | /* Skip any leading whitespace, detect EOF */ |
47 | do { | 47 | do { |
48 | ch = text_getc(file); | 48 | ch = text_getc(file); |
49 | if (ch == EOF) { | 49 | if (ch == EOF) { |
50 | *termchar = ch; | 50 | *termchar = ch; |
51 | return FALSE; | 51 | return FALSE; |
52 | } | 52 | } |
53 | } while (isspace(ch)); | 53 | } while (isspace(ch)); |
54 | 54 | ||
55 | if (! isdigit(ch)) { | 55 | if (! isdigit(ch)) { |
56 | *termchar = ch; | 56 | *termchar = ch; |
57 | return FALSE; | 57 | return FALSE; |
58 | } | 58 | } |
59 | 59 | ||
60 | val = ch - '0'; | 60 | val = ch - '0'; |
61 | while ((ch = text_getc(file)) != EOF) { | 61 | while ((ch = text_getc(file)) != EOF) { |
62 | if (! isdigit(ch)) | 62 | if (! isdigit(ch)) |
63 | break; | 63 | break; |
64 | val *= 10; | 64 | val *= 10; |
65 | val += ch - '0'; | 65 | val += ch - '0'; |
66 | } | 66 | } |
67 | *result = val; | 67 | *result = val; |
68 | *termchar = ch; | 68 | *termchar = ch; |
69 | return TRUE; | 69 | return TRUE; |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | GLOBAL(boolean) | 73 | GLOBAL(boolean) |
74 | read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline) | 74 | read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline) |
75 | /* Read a set of quantization tables from the specified file. | 75 | /* Read a set of quantization tables from the specified file. |
76 | * The file is plain ASCII text: decimal numbers with whitespace between. | 76 | * The file is plain ASCII text: decimal numbers with whitespace between. |
77 | * Comments preceded by '#' may be included in the file. | 77 | * Comments preceded by '#' may be included in the file. |
78 | * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. | 78 | * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. |
79 | * The tables are implicitly numbered 0,1,etc. | 79 | * The tables are implicitly numbered 0,1,etc. |
80 | * NOTE: does not affect the qslots mapping, which will default to selecting | 80 | * NOTE: does not affect the qslots mapping, which will default to selecting |
81 | * table 0 for luminance (or primary) components, 1 for chrominance components. | 81 | * table 0 for luminance (or primary) components, 1 for chrominance components. |
82 | * You must use -qslots if you want a different component->table mapping. | 82 | * You must use -qslots if you want a different component->table mapping. |
83 | */ | 83 | */ |
84 | { | 84 | { |
85 | FILE * fp; | 85 | FILE * fp; |
86 | int tblno, i, termchar; | 86 | int tblno, i, termchar; |
87 | long val; | 87 | long val; |
88 | unsigned int table[DCTSIZE2]; | 88 | unsigned int table[DCTSIZE2]; |
89 | 89 | ||
90 | if ((fp = fopen(filename, "r")) == NULL) { | 90 | if ((fp = fopen(filename, "r")) == NULL) { |
91 | fprintf(stderr, "Can't open table file %s\n", filename); | 91 | fprintf(stderr, "Can't open table file %s\n", filename); |
92 | return FALSE; | 92 | return FALSE; |
93 | } | 93 | } |
94 | tblno = 0; | 94 | tblno = 0; |
95 | 95 | ||
96 | while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ | 96 | while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ |
97 | if (tblno >= NUM_QUANT_TBLS) { | 97 | if (tblno >= NUM_QUANT_TBLS) { |
98 | fprintf(stderr, "Too many tables in file %s\n", filename); | 98 | fprintf(stderr, "Too many tables in file %s\n", filename); |
99 | fclose(fp); | 99 | fclose(fp); |
100 | return FALSE; | 100 | return FALSE; |
101 | } | 101 | } |
102 | table[0] = (unsigned int) val; | 102 | table[0] = (unsigned int) val; |
103 | for (i = 1; i < DCTSIZE2; i++) { | 103 | for (i = 1; i < DCTSIZE2; i++) { |
104 | if (! read_text_integer(fp, &val, &termchar)) { | 104 | if (! read_text_integer(fp, &val, &termchar)) { |
105 | fprintf(stderr, "Invalid table data in file %s\n", filename); | 105 | fprintf(stderr, "Invalid table data in file %s\n", filename); |
106 | fclose(fp); | 106 | fclose(fp); |
107 | return FALSE; | 107 | return FALSE; |
108 | } | 108 | } |
109 | table[i] = (unsigned int) val; | 109 | table[i] = (unsigned int) val; |
110 | } | 110 | } |
111 | jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], | 111 | jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], |
112 | force_baseline); | 112 | force_baseline); |
113 | tblno++; | 113 | tblno++; |
114 | } | 114 | } |
115 | 115 | ||
116 | if (termchar != EOF) { | 116 | if (termchar != EOF) { |
117 | fprintf(stderr, "Non-numeric data in file %s\n", filename); | 117 | fprintf(stderr, "Non-numeric data in file %s\n", filename); |
118 | fclose(fp); | 118 | fclose(fp); |
119 | return FALSE; | 119 | return FALSE; |
120 | } | 120 | } |
121 | 121 | ||
122 | fclose(fp); | 122 | fclose(fp); |
123 | return TRUE; | 123 | return TRUE; |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | #ifdef C_MULTISCAN_FILES_SUPPORTED | 127 | #ifdef C_MULTISCAN_FILES_SUPPORTED |
128 | 128 | ||
129 | LOCAL(boolean) | 129 | LOCAL(boolean) |
130 | read_scan_integer (FILE * file, long * result, int * termchar) | 130 | read_scan_integer (FILE * file, long * result, int * termchar) |
131 | /* Variant of read_text_integer that always looks for a non-space termchar; | 131 | /* Variant of read_text_integer that always looks for a non-space termchar; |
132 | * this simplifies parsing of punctuation in scan scripts. | 132 | * this simplifies parsing of punctuation in scan scripts. |
133 | */ | 133 | */ |
134 | { | 134 | { |
135 | register int ch; | 135 | register int ch; |
136 | 136 | ||
137 | if (! read_text_integer(file, result, termchar)) | 137 | if (! read_text_integer(file, result, termchar)) |
138 | return FALSE; | 138 | return FALSE; |
139 | ch = *termchar; | 139 | ch = *termchar; |
140 | while (ch != EOF && isspace(ch)) | 140 | while (ch != EOF && isspace(ch)) |
141 | ch = text_getc(file); | 141 | ch = text_getc(file); |
142 | if (isdigit(ch)) { /* oops, put it back */ | 142 | if (isdigit(ch)) { /* oops, put it back */ |
143 | if (ungetc(ch, file) == EOF) | 143 | if (ungetc(ch, file) == EOF) |
144 | return FALSE; | 144 | return FALSE; |
145 | ch = ' '; | 145 | ch = ' '; |
146 | } else { | 146 | } else { |
147 | /* Any separators other than ';' and ':' are ignored; | 147 | /* Any separators other than ';' and ':' are ignored; |
148 | * this allows user to insert commas, etc, if desired. | 148 | * this allows user to insert commas, etc, if desired. |
149 | */ | 149 | */ |
150 | if (ch != EOF && ch != ';' && ch != ':') | 150 | if (ch != EOF && ch != ';' && ch != ':') |
151 | ch = ' '; | 151 | ch = ' '; |
152 | } | 152 | } |
153 | *termchar = ch; | 153 | *termchar = ch; |
154 | return TRUE; | 154 | return TRUE; |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
158 | GLOBAL(boolean) | 158 | GLOBAL(boolean) |
159 | read_scan_script (j_compress_ptr cinfo, char * filename) | 159 | read_scan_script (j_compress_ptr cinfo, char * filename) |
160 | /* Read a scan script from the specified text file. | 160 | /* Read a scan script from the specified text file. |
161 | * Each entry in the file defines one scan to be emitted. | 161 | * Each entry in the file defines one scan to be emitted. |
162 | * Entries are separated by semicolons ';'. | 162 | * Entries are separated by semicolons ';'. |
163 | * An entry contains one to four component indexes, | 163 | * An entry contains one to four component indexes, |
164 | * optionally followed by a colon ':' and four progressive-JPEG parameters. | 164 | * optionally followed by a colon ':' and four progressive-JPEG parameters. |
165 | * The component indexes denote which component(s) are to be transmitted | 165 | * The component indexes denote which component(s) are to be transmitted |
166 | * in the current scan. The first component has index 0. | 166 | * in the current scan. The first component has index 0. |
167 | * Sequential JPEG is used if the progressive-JPEG parameters are omitted. | 167 | * Sequential JPEG is used if the progressive-JPEG parameters are omitted. |
168 | * The file is free format text: any whitespace may appear between numbers | 168 | * The file is free format text: any whitespace may appear between numbers |
169 | * and the ':' and ';' punctuation marks. Also, other punctuation (such | 169 | * and the ':' and ';' punctuation marks. Also, other punctuation (such |
170 | * as commas or dashes) can be placed between numbers if desired. | 170 | * as commas or dashes) can be placed between numbers if desired. |
171 | * Comments preceded by '#' may be included in the file. | 171 | * Comments preceded by '#' may be included in the file. |
172 | * Note: we do very little validity checking here; | 172 | * Note: we do very little validity checking here; |
173 | * jcmaster.c will validate the script parameters. | 173 | * jcmaster.c will validate the script parameters. |
174 | */ | 174 | */ |
175 | { | 175 | { |
176 | FILE * fp; | 176 | FILE * fp; |
177 | int scanno, ncomps, termchar; | 177 | int scanno, ncomps, termchar; |
178 | long val; | 178 | long val; |
179 | jpeg_scan_info * scanptr; | 179 | jpeg_scan_info * scanptr; |
180 | #define MAX_SCANS 100 /* quite arbitrary limit */ | 180 | #define MAX_SCANS 100 /* quite arbitrary limit */ |
181 | jpeg_scan_info scans[MAX_SCANS]; | 181 | jpeg_scan_info scans[MAX_SCANS]; |
182 | 182 | ||
183 | if ((fp = fopen(filename, "r")) == NULL) { | 183 | if ((fp = fopen(filename, "r")) == NULL) { |
184 | fprintf(stderr, "Can't open scan definition file %s\n", filename); | 184 | fprintf(stderr, "Can't open scan definition file %s\n", filename); |
185 | return FALSE; | 185 | return FALSE; |
186 | } | 186 | } |
187 | scanptr = scans; | 187 | scanptr = scans; |
188 | scanno = 0; | 188 | scanno = 0; |
189 | 189 | ||
190 | while (read_scan_integer(fp, &val, &termchar)) { | 190 | while (read_scan_integer(fp, &val, &termchar)) { |
191 | if (scanno >= MAX_SCANS) { | 191 | if (scanno >= MAX_SCANS) { |
192 | fprintf(stderr, "Too many scans defined in file %s\n", filename); | 192 | fprintf(stderr, "Too many scans defined in file %s\n", filename); |
193 | fclose(fp); | 193 | fclose(fp); |
194 | return FALSE; | 194 | return FALSE; |
195 | } | 195 | } |
196 | scanptr->component_index[0] = (int) val; | 196 | scanptr->component_index[0] = (int) val; |
197 | ncomps = 1; | 197 | ncomps = 1; |
198 | while (termchar == ' ') { | 198 | while (termchar == ' ') { |
199 | if (ncomps >= MAX_COMPS_IN_SCAN) { | 199 | if (ncomps >= MAX_COMPS_IN_SCAN) { |
200 | fprintf(stderr, "Too many components in one scan in file %s\n", | 200 | fprintf(stderr, "Too many components in one scan in file %s\n", |
201 | filename); | 201 | filename); |
202 | fclose(fp); | 202 | fclose(fp); |
203 | return FALSE; | 203 | return FALSE; |
204 | } | 204 | } |
205 | if (! read_scan_integer(fp, &val, &termchar)) | 205 | if (! read_scan_integer(fp, &val, &termchar)) |
206 | goto bogus; | 206 | goto bogus; |
207 | scanptr->component_index[ncomps] = (int) val; | 207 | scanptr->component_index[ncomps] = (int) val; |
208 | ncomps++; | 208 | ncomps++; |
209 | } | 209 | } |
210 | scanptr->comps_in_scan = ncomps; | 210 | scanptr->comps_in_scan = ncomps; |
211 | if (termchar == ':') { | 211 | if (termchar == ':') { |
212 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') | 212 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') |
213 | goto bogus; | 213 | goto bogus; |
214 | scanptr->Ss = (int) val; | 214 | scanptr->Ss = (int) val; |
215 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') | 215 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') |
216 | goto bogus; | 216 | goto bogus; |
217 | scanptr->Se = (int) val; | 217 | scanptr->Se = (int) val; |
218 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') | 218 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') |
219 | goto bogus; | 219 | goto bogus; |
220 | scanptr->Ah = (int) val; | 220 | scanptr->Ah = (int) val; |
221 | if (! read_scan_integer(fp, &val, &termchar)) | 221 | if (! read_scan_integer(fp, &val, &termchar)) |
222 | goto bogus; | 222 | goto bogus; |
223 | scanptr->Al = (int) val; | 223 | scanptr->Al = (int) val; |
224 | } else { | 224 | } else { |
225 | /* set non-progressive parameters */ | 225 | /* set non-progressive parameters */ |
226 | scanptr->Ss = 0; | 226 | scanptr->Ss = 0; |
227 | scanptr->Se = DCTSIZE2-1; | 227 | scanptr->Se = DCTSIZE2-1; |
228 | scanptr->Ah = 0; | 228 | scanptr->Ah = 0; |
229 | scanptr->Al = 0; | 229 | scanptr->Al = 0; |
230 | } | 230 | } |
231 | if (termchar != ';' && termchar != EOF) { | 231 | if (termchar != ';' && termchar != EOF) { |
232 | bogus: | 232 | bogus: |
233 | fprintf(stderr, "Invalid scan entry format in file %s\n", filename); | 233 | fprintf(stderr, "Invalid scan entry format in file %s\n", filename); |
234 | fclose(fp); | 234 | fclose(fp); |
235 | return FALSE; | 235 | return FALSE; |
236 | } | 236 | } |
237 | scanptr++, scanno++; | 237 | scanptr++, scanno++; |
238 | } | 238 | } |
239 | 239 | ||
240 | if (termchar != EOF) { | 240 | if (termchar != EOF) { |
241 | fprintf(stderr, "Non-numeric data in file %s\n", filename); | 241 | fprintf(stderr, "Non-numeric data in file %s\n", filename); |
242 | fclose(fp); | 242 | fclose(fp); |
243 | return FALSE; | 243 | return FALSE; |
244 | } | 244 | } |
245 | 245 | ||
246 | if (scanno > 0) { | 246 | if (scanno > 0) { |
247 | /* Stash completed scan list in cinfo structure. | 247 | /* Stash completed scan list in cinfo structure. |
248 | * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, | 248 | * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, |
249 | * but if you want to compress multiple images you'd want JPOOL_PERMANENT. | 249 | * but if you want to compress multiple images you'd want JPOOL_PERMANENT. |
250 | */ | 250 | */ |
251 | scanptr = (jpeg_scan_info *) | 251 | scanptr = (jpeg_scan_info *) |
252 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 252 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
253 | scanno * SIZEOF(jpeg_scan_info)); | 253 | scanno * SIZEOF(jpeg_scan_info)); |
254 | MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); | 254 | MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); |
255 | cinfo->scan_info = scanptr; | 255 | cinfo->scan_info = scanptr; |
256 | cinfo->num_scans = scanno; | 256 | cinfo->num_scans = scanno; |
257 | } | 257 | } |
258 | 258 | ||
259 | fclose(fp); | 259 | fclose(fp); |
260 | return TRUE; | 260 | return TRUE; |
261 | } | 261 | } |
262 | 262 | ||
263 | #endif /* C_MULTISCAN_FILES_SUPPORTED */ | 263 | #endif /* C_MULTISCAN_FILES_SUPPORTED */ |
264 | 264 | ||
265 | 265 | ||
266 | GLOBAL(boolean) | 266 | GLOBAL(boolean) |
267 | set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline) | 267 | set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline) |
268 | /* Process a quality-ratings parameter string, of the form | 268 | /* Process a quality-ratings parameter string, of the form |
269 | * N[,N,...] | 269 | * N[,N,...] |
270 | * If there are more q-table slots than parameters, the last value is replicated. | 270 | * If there are more q-table slots than parameters, the last value is replicated. |
271 | */ | 271 | */ |
272 | { | 272 | { |
273 | int val = 75; /* default value */ | 273 | int val = 75; /* default value */ |
274 | int tblno; | 274 | int tblno; |
275 | char ch; | 275 | char ch; |
276 | 276 | ||
277 | for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { | 277 | for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { |
278 | if (*arg) { | 278 | if (*arg) { |
279 | ch = ','; /* if not set by sscanf, will be ',' */ | 279 | ch = ','; /* if not set by sscanf, will be ',' */ |
280 | if (sscanf(arg, "%d%c", &val, &ch) < 1) | 280 | if (sscanf(arg, "%d%c", &val, &ch) < 1) |
281 | return FALSE; | 281 | return FALSE; |
282 | if (ch != ',') /* syntax check */ | 282 | if (ch != ',') /* syntax check */ |
283 | return FALSE; | 283 | return FALSE; |
284 | /* Convert user 0-100 rating to percentage scaling */ | 284 | /* Convert user 0-100 rating to percentage scaling */ |
285 | cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); | 285 | cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); |
286 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ | 286 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ |
287 | ; | 287 | ; |
288 | } else { | 288 | } else { |
289 | /* reached end of parameter, set remaining factors to last value */ | 289 | /* reached end of parameter, set remaining factors to last value */ |
290 | cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); | 290 | cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); |
291 | } | 291 | } |
292 | } | 292 | } |
293 | jpeg_default_qtables(cinfo, force_baseline); | 293 | jpeg_default_qtables(cinfo, force_baseline); |
294 | return TRUE; | 294 | return TRUE; |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
298 | GLOBAL(boolean) | 298 | GLOBAL(boolean) |
299 | set_quant_slots (j_compress_ptr cinfo, char *arg) | 299 | set_quant_slots (j_compress_ptr cinfo, char *arg) |
300 | /* Process a quantization-table-selectors parameter string, of the form | 300 | /* Process a quantization-table-selectors parameter string, of the form |
301 | * N[,N,...] | 301 | * N[,N,...] |
302 | * If there are more components than parameters, the last value is replicated. | 302 | * If there are more components than parameters, the last value is replicated. |
303 | */ | 303 | */ |
304 | { | 304 | { |
305 | int val = 0; /* default table # */ | 305 | int val = 0; /* default table # */ |
306 | int ci; | 306 | int ci; |
307 | char ch; | 307 | char ch; |
308 | 308 | ||
309 | for (ci = 0; ci < MAX_COMPONENTS; ci++) { | 309 | for (ci = 0; ci < MAX_COMPONENTS; ci++) { |
310 | if (*arg) { | 310 | if (*arg) { |
311 | ch = ','; /* if not set by sscanf, will be ',' */ | 311 | ch = ','; /* if not set by sscanf, will be ',' */ |
312 | if (sscanf(arg, "%d%c", &val, &ch) < 1) | 312 | if (sscanf(arg, "%d%c", &val, &ch) < 1) |
313 | return FALSE; | 313 | return FALSE; |
314 | if (ch != ',') /* syntax check */ | 314 | if (ch != ',') /* syntax check */ |
315 | return FALSE; | 315 | return FALSE; |
316 | if (val < 0 || val >= NUM_QUANT_TBLS) { | 316 | if (val < 0 || val >= NUM_QUANT_TBLS) { |
317 | fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", | 317 | fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", |
318 | NUM_QUANT_TBLS-1); | 318 | NUM_QUANT_TBLS-1); |
319 | return FALSE; | 319 | return FALSE; |
320 | } | 320 | } |
321 | cinfo->comp_info[ci].quant_tbl_no = val; | 321 | cinfo->comp_info[ci].quant_tbl_no = val; |
322 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ | 322 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ |
323 | ; | 323 | ; |
324 | } else { | 324 | } else { |
325 | /* reached end of parameter, set remaining components to last table */ | 325 | /* reached end of parameter, set remaining components to last table */ |
326 | cinfo->comp_info[ci].quant_tbl_no = val; | 326 | cinfo->comp_info[ci].quant_tbl_no = val; |
327 | } | 327 | } |
328 | } | 328 | } |
329 | return TRUE; | 329 | return TRUE; |
330 | } | 330 | } |
331 | 331 | ||
332 | 332 | ||
333 | GLOBAL(boolean) | 333 | GLOBAL(boolean) |
334 | set_sample_factors (j_compress_ptr cinfo, char *arg) | 334 | set_sample_factors (j_compress_ptr cinfo, char *arg) |
335 | /* Process a sample-factors parameter string, of the form | 335 | /* Process a sample-factors parameter string, of the form |
336 | * HxV[,HxV,...] | 336 | * HxV[,HxV,...] |
337 | * If there are more components than parameters, "1x1" is assumed for the rest. | 337 | * If there are more components than parameters, "1x1" is assumed for the rest. |
338 | */ | 338 | */ |
339 | { | 339 | { |
340 | int ci, val1, val2; | 340 | int ci, val1, val2; |
341 | char ch1, ch2; | 341 | char ch1, ch2; |
342 | 342 | ||
343 | for (ci = 0; ci < MAX_COMPONENTS; ci++) { | 343 | for (ci = 0; ci < MAX_COMPONENTS; ci++) { |
344 | if (*arg) { | 344 | if (*arg) { |
345 | ch2 = ','; /* if not set by sscanf, will be ',' */ | 345 | ch2 = ','; /* if not set by sscanf, will be ',' */ |
346 | if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) | 346 | if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) |
347 | return FALSE; | 347 | return FALSE; |
348 | if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ | 348 | if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ |
349 | return FALSE; | 349 | return FALSE; |
350 | if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { | 350 | if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { |
351 | fprintf(stderr, "JPEG sampling factors must be 1..4\n"); | 351 | fprintf(stderr, "JPEG sampling factors must be 1..4\n"); |
352 | return FALSE; | 352 | return FALSE; |
353 | } | 353 | } |
354 | cinfo->comp_info[ci].h_samp_factor = val1; | 354 | cinfo->comp_info[ci].h_samp_factor = val1; |
355 | cinfo->comp_info[ci].v_samp_factor = val2; | 355 | cinfo->comp_info[ci].v_samp_factor = val2; |
356 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ | 356 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ |
357 | ; | 357 | ; |
358 | } else { | 358 | } else { |
359 | /* reached end of parameter, set remaining components to 1x1 sampling */ | 359 | /* reached end of parameter, set remaining components to 1x1 sampling */ |
360 | cinfo->comp_info[ci].h_samp_factor = 1; | 360 | cinfo->comp_info[ci].h_samp_factor = 1; |
361 | cinfo->comp_info[ci].v_samp_factor = 1; | 361 | cinfo->comp_info[ci].v_samp_factor = 1; |
362 | } | 362 | } |
363 | } | 363 | } |
364 | return TRUE; | 364 | return TRUE; |
365 | } | 365 | } |