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

Side by Side Diff: cjpeg.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 | « cjpeg.1 ('k') | coderules.txt » ('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 * cjpeg.c 2 * cjpeg.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-1998, Thomas G. Lane. 5 * Copyright (C) 1991-1998, Thomas G. Lane.
6 * Modified 2003-2011 by Guido Vollbeding. 6 * Modified 2003-2011 by Guido Vollbeding.
7 * libjpeg-turbo Modifications: 7 * libjpeg-turbo Modifications:
8 * Copyright (C) 2010, 2013, D. R. Commander. 8 * Copyright (C) 2010, 2013-2014, 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 a command-line user interface for the JPEG compressor. 12 * This file contains a command-line user interface for the JPEG compressor.
12 * It should work on any system with Unix- or MS-DOS-style command lines. 13 * It should work on any system with Unix- or MS-DOS-style command lines.
13 * 14 *
14 * Two different command line styles are permitted, depending on the 15 * Two different command line styles are permitted, depending on the
15 * compile-time switch TWO_FILE_COMMANDLINE: 16 * compile-time switch TWO_FILE_COMMANDLINE:
16 *» cjpeg [options] inputfile outputfile 17 * cjpeg [options] inputfile outputfile
17 *» cjpeg [options] [inputfile] 18 * cjpeg [options] [inputfile]
18 * In the second style, output is always to standard output, which you'd 19 * In the second style, output is always to standard output, which you'd
19 * normally redirect to a file or pipe to some other program. Input is 20 * normally redirect to a file or pipe to some other program. Input is
20 * either from a named file or from standard input (typically redirected). 21 * either from a named file or from standard input (typically redirected).
21 * The second style is convenient on Unix but is unhelpful on systems that 22 * The second style is convenient on Unix but is unhelpful on systems that
22 * don't support pipes. Also, you MUST use the first style if your system 23 * don't support pipes. Also, you MUST use the first style if your system
23 * doesn't do binary I/O to stdin/stdout. 24 * doesn't do binary I/O to stdin/stdout.
24 * To simplify script writing, the "-outfile" switch is provided. The syntax 25 * To simplify script writing, the "-outfile" switch is provided. The syntax
25 *» cjpeg [options] -outfile outputfile inputfile 26 * cjpeg [options] -outfile outputfile inputfile
26 * works regardless of which command line style is used. 27 * works regardless of which command line style is used.
27 */ 28 */
28 29
29 #include "cdjpeg.h"» » /* Common decls for cjpeg/djpeg applications */ 30 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
30 #include "jversion.h"» » /* for version message */ 31 #include "jversion.h" /* for version message */
31 #include "config.h" 32 #include "jconfigint.h"
32 33
33 #ifdef USE_CCOMMAND» » /* command-line reader for Macintosh */ 34 #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
34 #ifdef __MWERKS__ 35 #ifdef __MWERKS__
35 #include <SIOUX.h> /* Metrowerks needs this */ 36 #include <SIOUX.h> /* Metrowerks needs this */
36 #include <console.h>» » /* ... and this */ 37 #include <console.h> /* ... and this */
37 #endif 38 #endif
38 #ifdef THINK_C 39 #ifdef THINK_C
39 #include <console.h>» » /* Think declares it here */ 40 #include <console.h> /* Think declares it here */
40 #endif 41 #endif
41 #endif 42 #endif
42 43
43 44
44 /* Create the add-on message string table. */ 45 /* Create the add-on message string table. */
45 46
46 #define JMESSAGE(code,string)» string , 47 #define JMESSAGE(code,string) string ,
47 48
48 static const char * const cdjpeg_message_table[] = { 49 static const char * const cdjpeg_message_table[] = {
49 #include "cderror.h" 50 #include "cderror.h"
50 NULL 51 NULL
51 }; 52 };
52 53
53 54
54 /* 55 /*
55 * This routine determines what format the input file is, 56 * This routine determines what format the input file is,
56 * and selects the appropriate input-reading module. 57 * and selects the appropriate input-reading module.
(...skipping 13 matching lines...) Expand all
70 * 71 *
71 * The most portable solution for file types that can't be identified by their 72 * The most portable solution for file types that can't be identified by their
72 * first byte is to make the user tell us what they are. This is also the 73 * first byte is to make the user tell us what they are. This is also the
73 * only approach for "raw" file types that contain only arbitrary values. 74 * only approach for "raw" file types that contain only arbitrary values.
74 * We presently apply this method for Targa files. Most of the time Targa 75 * We presently apply this method for Targa files. Most of the time Targa
75 * files start with 0x00, so we recognize that case. Potentially, however, 76 * files start with 0x00, so we recognize that case. Potentially, however,
76 * a Targa file could start with any byte value (byte 0 is the length of the 77 * a Targa file could start with any byte value (byte 0 is the length of the
77 * seldom-used ID field), so we provide a switch to force Targa input mode. 78 * seldom-used ID field), so we provide a switch to force Targa input mode.
78 */ 79 */
79 80
80 static boolean is_targa;» /* records user -targa switch */ 81 static boolean is_targa; /* records user -targa switch */
81 82
82 83
83 LOCAL(cjpeg_source_ptr) 84 LOCAL(cjpeg_source_ptr)
84 select_file_type (j_compress_ptr cinfo, FILE * infile) 85 select_file_type (j_compress_ptr cinfo, FILE *infile)
85 { 86 {
86 int c; 87 int c;
87 88
88 if (is_targa) { 89 if (is_targa) {
89 #ifdef TARGA_SUPPORTED 90 #ifdef TARGA_SUPPORTED
90 return jinit_read_targa(cinfo); 91 return jinit_read_targa(cinfo);
91 #else 92 #else
92 ERREXIT(cinfo, JERR_TGA_NOTCOMP); 93 ERREXIT(cinfo, JERR_TGA_NOTCOMP);
93 #endif 94 #endif
94 } 95 }
(...skipping 22 matching lines...) Expand all
117 #endif 118 #endif
118 #ifdef TARGA_SUPPORTED 119 #ifdef TARGA_SUPPORTED
119 case 0x00: 120 case 0x00:
120 return jinit_read_targa(cinfo); 121 return jinit_read_targa(cinfo);
121 #endif 122 #endif
122 default: 123 default:
123 ERREXIT(cinfo, JERR_UNKNOWN_FORMAT); 124 ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
124 break; 125 break;
125 } 126 }
126 127
127 return NULL;» » » /* suppress compiler warnings */ 128 return NULL; /* suppress compiler warnings */
128 } 129 }
129 130
130 131
131 /* 132 /*
132 * Argument-parsing code. 133 * Argument-parsing code.
133 * The switch parser is designed to be useful with DOS-style command line 134 * The switch parser is designed to be useful with DOS-style command line
134 * syntax, ie, intermixed switches and file names, where only the switches 135 * syntax, ie, intermixed switches and file names, where only the switches
135 * to the left of a given file name affect processing of that file. 136 * to the left of a given file name affect processing of that file.
136 * The main program in this file doesn't actually use this capability... 137 * The main program in this file doesn't actually use this capability...
137 */ 138 */
138 139
139 140
140 static const char * progname;» /* program name for error messages */ 141 static const char *progname; /* program name for error messages */
141 static char * outfilename;» /* for -outfile switch */ 142 static char *outfilename; /* for -outfile switch */
142 boolean memdst; /* for -memdst switch */ 143 boolean memdst; /* for -memdst switch */
143 144
144 145
145 LOCAL(void) 146 LOCAL(void)
146 usage (void) 147 usage (void)
147 /* complain about bad command line */ 148 /* complain about bad command line */
148 { 149 {
149 fprintf(stderr, "usage: %s [switches] ", progname); 150 fprintf(stderr, "usage: %s [switches] ", progname);
150 #ifdef TWO_FILE_COMMANDLINE 151 #ifdef TWO_FILE_COMMANDLINE
151 fprintf(stderr, "inputfile outputfile\n"); 152 fprintf(stderr, "inputfile outputfile\n");
152 #else 153 #else
153 fprintf(stderr, "[inputfile]\n"); 154 fprintf(stderr, "[inputfile]\n");
154 #endif 155 #endif
155 156
156 fprintf(stderr, "Switches (names may be abbreviated):\n"); 157 fprintf(stderr, "Switches (names may be abbreviated):\n");
157 fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is use ful range)\n"); 158 fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is mos t useful range,\n");
159 fprintf(stderr, " default is 75)\n");
158 fprintf(stderr, " -grayscale Create monochrome JPEG file\n"); 160 fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
159 fprintf(stderr, " -rgb Create RGB JPEG file\n"); 161 fprintf(stderr, " -rgb Create RGB JPEG file\n");
160 #ifdef ENTROPY_OPT_SUPPORTED 162 #ifdef ENTROPY_OPT_SUPPORTED
161 fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but sl ow compression)\n"); 163 fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but sl ow compression)\n");
162 #endif 164 #endif
163 #ifdef C_PROGRESSIVE_SUPPORTED 165 #ifdef C_PROGRESSIVE_SUPPORTED
164 fprintf(stderr, " -progressive Create progressive JPEG file\n"); 166 fprintf(stderr, " -progressive Create progressive JPEG file\n");
165 #endif 167 #endif
166 #ifdef TARGA_SUPPORTED 168 #ifdef TARGA_SUPPORTED
167 fprintf(stderr, " -targa Input file is Targa format (usually not need ed)\n"); 169 fprintf(stderr, " -targa Input file is Targa format (usually not need ed)\n");
168 #endif 170 #endif
169 fprintf(stderr, "Switches for advanced users:\n"); 171 fprintf(stderr, "Switches for advanced users:\n");
170 #ifdef C_ARITH_CODING_SUPPORTED 172 #ifdef C_ARITH_CODING_SUPPORTED
171 fprintf(stderr, " -arithmetic Use arithmetic coding\n"); 173 fprintf(stderr, " -arithmetic Use arithmetic coding\n");
172 #endif 174 #endif
173 #ifdef DCT_ISLOW_SUPPORTED 175 #ifdef DCT_ISLOW_SUPPORTED
174 fprintf(stderr, " -dct int Use integer DCT method%s\n", 176 fprintf(stderr, " -dct int Use integer DCT method%s\n",
175 » (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); 177 (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
176 #endif 178 #endif
177 #ifdef DCT_IFAST_SUPPORTED 179 #ifdef DCT_IFAST_SUPPORTED
178 fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", 180 fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
179 » (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); 181 (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
180 #endif 182 #endif
181 #ifdef DCT_FLOAT_SUPPORTED 183 #ifdef DCT_FLOAT_SUPPORTED
182 fprintf(stderr, " -dct float Use floating-point DCT method%s\n", 184 fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
183 » (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); 185 (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
184 #endif 186 #endif
185 fprintf(stderr, " -restart N Set restart interval in rows, or in blocks w ith B\n"); 187 fprintf(stderr, " -restart N Set restart interval in rows, or in blocks w ith B\n");
186 #ifdef INPUT_SMOOTHING_SUPPORTED 188 #ifdef INPUT_SMOOTHING_SUPPORTED
187 fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength) \n"); 189 fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength) \n");
188 #endif 190 #endif
189 fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); 191 fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
190 fprintf(stderr, " -outfile name Specify name for output file\n"); 192 fprintf(stderr, " -outfile name Specify name for output file\n");
191 #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) 193 #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
192 fprintf(stderr, " -memdst Compress to memory instead of file (useful f or benchmarking)\n"); 194 fprintf(stderr, " -memdst Compress to memory instead of file (useful f or benchmarking)\n");
193 #endif 195 #endif
194 fprintf(stderr, " -verbose or -debug Emit debug output\n"); 196 fprintf(stderr, " -verbose or -debug Emit debug output\n");
197 fprintf(stderr, " -version Print version information and exit\n");
195 fprintf(stderr, "Switches for wizards:\n"); 198 fprintf(stderr, "Switches for wizards:\n");
196 fprintf(stderr, " -baseline Force baseline quantization tables\n"); 199 fprintf(stderr, " -baseline Force baseline quantization tables\n");
197 fprintf(stderr, " -qtables file Use quantization tables given in file\n"); 200 fprintf(stderr, " -qtables file Use quantization tables given in file\n");
198 fprintf(stderr, " -qslots N[,...] Set component quantization tables\n"); 201 fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
199 fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n"); 202 fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
200 #ifdef C_MULTISCAN_FILES_SUPPORTED 203 #ifdef C_MULTISCAN_FILES_SUPPORTED
201 fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); 204 fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
202 #endif 205 #endif
203 exit(EXIT_FAILURE); 206 exit(EXIT_FAILURE);
204 } 207 }
205 208
206 209
207 LOCAL(int) 210 LOCAL(int)
208 parse_switches (j_compress_ptr cinfo, int argc, char **argv, 211 parse_switches (j_compress_ptr cinfo, int argc, char **argv,
209 » » int last_file_arg_seen, boolean for_real) 212 int last_file_arg_seen, boolean for_real)
210 /* Parse optional switches. 213 /* Parse optional switches.
211 * Returns argv[] index of first file-name argument (== argc if none). 214 * Returns argv[] index of first file-name argument (== argc if none).
212 * Any file names with indexes <= last_file_arg_seen are ignored; 215 * Any file names with indexes <= last_file_arg_seen are ignored;
213 * they have presumably been processed in a previous iteration. 216 * they have presumably been processed in a previous iteration.
214 * (Pass 0 for last_file_arg_seen on the first or only iteration.) 217 * (Pass 0 for last_file_arg_seen on the first or only iteration.)
215 * for_real is FALSE on the first (dummy) pass; we may skip any expensive 218 * for_real is FALSE on the first (dummy) pass; we may skip any expensive
216 * processing. 219 * processing.
217 */ 220 */
218 { 221 {
219 int argn; 222 int argn;
220 char * arg; 223 char *arg;
221 boolean force_baseline; 224 boolean force_baseline;
222 boolean simple_progressive; 225 boolean simple_progressive;
223 char * qualityarg = NULL;» /* saves -quality parm if any */ 226 char *qualityarg = NULL; /* saves -quality parm if any */
224 char * qtablefile = NULL;» /* saves -qtables filename if any */ 227 char *qtablefile = NULL; /* saves -qtables filename if any */
225 char * qslotsarg = NULL;» /* saves -qslots parm if any */ 228 char *qslotsarg = NULL; /* saves -qslots parm if any */
226 char * samplearg = NULL;» /* saves -sample parm if any */ 229 char *samplearg = NULL; /* saves -sample parm if any */
227 char * scansarg = NULL;» /* saves -scans parm if any */ 230 char *scansarg = NULL; /* saves -scans parm if any */
228 231
229 /* Set up default JPEG parameters. */ 232 /* Set up default JPEG parameters. */
230 233
231 force_baseline = FALSE;» /* by default, allow 16-bit quantizers */ 234 force_baseline = FALSE; /* by default, allow 16-bit quantizers */
232 simple_progressive = FALSE; 235 simple_progressive = FALSE;
233 is_targa = FALSE; 236 is_targa = FALSE;
234 outfilename = NULL; 237 outfilename = NULL;
235 memdst = FALSE; 238 memdst = FALSE;
236 cinfo->err->trace_level = 0; 239 cinfo->err->trace_level = 0;
237 240
238 /* Scan command line options, adjust parameters */ 241 /* Scan command line options, adjust parameters */
239 242
240 for (argn = 1; argn < argc; argn++) { 243 for (argn = 1; argn < argc; argn++) {
241 arg = argv[argn]; 244 arg = argv[argn];
242 if (*arg != '-') { 245 if (*arg != '-') {
243 /* Not a switch, must be a file name argument */ 246 /* Not a switch, must be a file name argument */
244 if (argn <= last_file_arg_seen) { 247 if (argn <= last_file_arg_seen) {
245 » outfilename = NULL;» /* -outfile applies to just one input file */ 248 outfilename = NULL; /* -outfile applies to just one input file */
246 » continue;» » /* ignore this name if previously processed */ 249 continue; /* ignore this name if previously processed */
247 } 250 }
248 break;» » » /* else done parsing switches */ 251 break; /* else done parsing switches */
249 } 252 }
250 arg++;» » » /* advance past switch marker character */ 253 arg++; /* advance past switch marker character */
251 254
252 if (keymatch(arg, "arithmetic", 1)) { 255 if (keymatch(arg, "arithmetic", 1)) {
253 /* Use arithmetic coding. */ 256 /* Use arithmetic coding. */
254 #ifdef C_ARITH_CODING_SUPPORTED 257 #ifdef C_ARITH_CODING_SUPPORTED
255 cinfo->arith_code = TRUE; 258 cinfo->arith_code = TRUE;
256 #else 259 #else
257 fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", 260 fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
258 » progname); 261 progname);
259 exit(EXIT_FAILURE); 262 exit(EXIT_FAILURE);
260 #endif 263 #endif
261 264
262 } else if (keymatch(arg, "baseline", 1)) { 265 } else if (keymatch(arg, "baseline", 1)) {
263 /* Force baseline-compatible output (8-bit quantizer values). */ 266 /* Force baseline-compatible output (8-bit quantizer values). */
264 force_baseline = TRUE; 267 force_baseline = TRUE;
265 268
266 } else if (keymatch(arg, "dct", 2)) { 269 } else if (keymatch(arg, "dct", 2)) {
267 /* Select DCT algorithm. */ 270 /* Select DCT algorithm. */
268 if (++argn >= argc)» /* advance to next argument */ 271 if (++argn >= argc) /* advance to next argument */
269 » usage(); 272 usage();
270 if (keymatch(argv[argn], "int", 1)) { 273 if (keymatch(argv[argn], "int", 1)) {
271 » cinfo->dct_method = JDCT_ISLOW; 274 cinfo->dct_method = JDCT_ISLOW;
272 } else if (keymatch(argv[argn], "fast", 2)) { 275 } else if (keymatch(argv[argn], "fast", 2)) {
273 » cinfo->dct_method = JDCT_IFAST; 276 cinfo->dct_method = JDCT_IFAST;
274 } else if (keymatch(argv[argn], "float", 2)) { 277 } else if (keymatch(argv[argn], "float", 2)) {
275 » cinfo->dct_method = JDCT_FLOAT; 278 cinfo->dct_method = JDCT_FLOAT;
276 } else 279 } else
277 » usage(); 280 usage();
278 281
279 } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { 282 } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
280 /* Enable debug printouts. */ 283 /* Enable debug printouts. */
281 /* On first -d, print version identification */ 284 /* On first -d, print version identification */
282 static boolean printed_version = FALSE; 285 static boolean printed_version = FALSE;
283 286
284 if (! printed_version) { 287 if (! printed_version) {
285 » fprintf(stderr, "%s version %s (build %s)\n", 288 fprintf(stderr, "%s version %s (build %s)\n",
286 » » PACKAGE_NAME, VERSION, BUILD); 289 PACKAGE_NAME, VERSION, BUILD);
287 » fprintf(stderr, "%s\n\n", JCOPYRIGHT); 290 fprintf(stderr, "%s\n\n", JCOPYRIGHT);
288 » fprintf(stderr, "Emulating The Independent JPEG Group's software, versio n %s\n\n", 291 fprintf(stderr, "Emulating The Independent JPEG Group's software, versio n %s\n\n",
289 » » JVERSION); 292 JVERSION);
290 » printed_version = TRUE; 293 printed_version = TRUE;
291 } 294 }
292 cinfo->err->trace_level++; 295 cinfo->err->trace_level++;
293 296
297 } else if (keymatch(arg, "version", 4)) {
298 fprintf(stderr, "%s version %s (build %s)\n",
299 PACKAGE_NAME, VERSION, BUILD);
300 exit(EXIT_SUCCESS);
301
294 } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { 302 } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
295 /* Force a monochrome JPEG file to be generated. */ 303 /* Force a monochrome JPEG file to be generated. */
296 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); 304 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
297 305
298 } else if (keymatch(arg, "rgb", 3)) { 306 } else if (keymatch(arg, "rgb", 3)) {
299 /* Force an RGB JPEG file to be generated. */ 307 /* Force an RGB JPEG file to be generated. */
300 jpeg_set_colorspace(cinfo, JCS_RGB); 308 jpeg_set_colorspace(cinfo, JCS_RGB);
301 309
302 } else if (keymatch(arg, "maxmemory", 3)) { 310 } else if (keymatch(arg, "maxmemory", 3)) {
303 /* Maximum memory in Kb (or Mb with 'm'). */ 311 /* Maximum memory in Kb (or Mb with 'm'). */
304 long lval; 312 long lval;
305 char ch = 'x'; 313 char ch = 'x';
306 314
307 if (++argn >= argc)» /* advance to next argument */ 315 if (++argn >= argc) /* advance to next argument */
308 » usage(); 316 usage();
309 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) 317 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
310 » usage(); 318 usage();
311 if (ch == 'm' || ch == 'M') 319 if (ch == 'm' || ch == 'M')
312 » lval *= 1000L; 320 lval *= 1000L;
313 cinfo->mem->max_memory_to_use = lval * 1000L; 321 cinfo->mem->max_memory_to_use = lval * 1000L;
314 322
315 } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { 323 } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
316 /* Enable entropy parm optimization. */ 324 /* Enable entropy parm optimization. */
317 #ifdef ENTROPY_OPT_SUPPORTED 325 #ifdef ENTROPY_OPT_SUPPORTED
318 cinfo->optimize_coding = TRUE; 326 cinfo->optimize_coding = TRUE;
319 #else 327 #else
320 fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n", 328 fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n",
321 » progname); 329 progname);
322 exit(EXIT_FAILURE); 330 exit(EXIT_FAILURE);
323 #endif 331 #endif
324 332
325 } else if (keymatch(arg, "outfile", 4)) { 333 } else if (keymatch(arg, "outfile", 4)) {
326 /* Set output file name. */ 334 /* Set output file name. */
327 if (++argn >= argc)» /* advance to next argument */ 335 if (++argn >= argc) /* advance to next argument */
328 » usage(); 336 usage();
329 outfilename = argv[argn];»/* save it away for later use */ 337 outfilename = argv[argn]; /* save it away for later use */
330 338
331 } else if (keymatch(arg, "progressive", 1)) { 339 } else if (keymatch(arg, "progressive", 1)) {
332 /* Select simple progressive mode. */ 340 /* Select simple progressive mode. */
333 #ifdef C_PROGRESSIVE_SUPPORTED 341 #ifdef C_PROGRESSIVE_SUPPORTED
334 simple_progressive = TRUE; 342 simple_progressive = TRUE;
335 /* We must postpone execution until num_components is known. */ 343 /* We must postpone execution until num_components is known. */
336 #else 344 #else
337 fprintf(stderr, "%s: sorry, progressive output was not compiled in\n", 345 fprintf(stderr, "%s: sorry, progressive output was not compiled in\n",
338 » progname); 346 progname);
339 exit(EXIT_FAILURE); 347 exit(EXIT_FAILURE);
340 #endif 348 #endif
341 349
342 } else if (keymatch(arg, "memdst", 2)) { 350 } else if (keymatch(arg, "memdst", 2)) {
343 /* Use in-memory destination manager */ 351 /* Use in-memory destination manager */
344 #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) 352 #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
345 memdst = TRUE; 353 memdst = TRUE;
346 #else 354 #else
347 fprintf(stderr, "%s: sorry, in-memory destination manager was not compiled in\n", 355 fprintf(stderr, "%s: sorry, in-memory destination manager was not compiled in\n",
348 progname); 356 progname);
349 exit(EXIT_FAILURE); 357 exit(EXIT_FAILURE);
350 #endif 358 #endif
351 359
352 } else if (keymatch(arg, "quality", 1)) { 360 } else if (keymatch(arg, "quality", 1)) {
353 /* Quality ratings (quantization table scaling factors). */ 361 /* Quality ratings (quantization table scaling factors). */
354 if (++argn >= argc)» /* advance to next argument */ 362 if (++argn >= argc) /* advance to next argument */
355 » usage(); 363 usage();
356 qualityarg = argv[argn]; 364 qualityarg = argv[argn];
357 365
358 } else if (keymatch(arg, "qslots", 2)) { 366 } else if (keymatch(arg, "qslots", 2)) {
359 /* Quantization table slot numbers. */ 367 /* Quantization table slot numbers. */
360 if (++argn >= argc)» /* advance to next argument */ 368 if (++argn >= argc) /* advance to next argument */
361 » usage(); 369 usage();
362 qslotsarg = argv[argn]; 370 qslotsarg = argv[argn];
363 /* Must delay setting qslots until after we have processed any 371 /* Must delay setting qslots until after we have processed any
364 * colorspace-determining switches, since jpeg_set_colorspace sets 372 * colorspace-determining switches, since jpeg_set_colorspace sets
365 * default quant table numbers. 373 * default quant table numbers.
366 */ 374 */
367 375
368 } else if (keymatch(arg, "qtables", 2)) { 376 } else if (keymatch(arg, "qtables", 2)) {
369 /* Quantization tables fetched from file. */ 377 /* Quantization tables fetched from file. */
370 if (++argn >= argc)» /* advance to next argument */ 378 if (++argn >= argc) /* advance to next argument */
371 » usage(); 379 usage();
372 qtablefile = argv[argn]; 380 qtablefile = argv[argn];
373 /* We postpone actually reading the file in case -quality comes later. */ 381 /* We postpone actually reading the file in case -quality comes later. */
374 382
375 } else if (keymatch(arg, "restart", 1)) { 383 } else if (keymatch(arg, "restart", 1)) {
376 /* Restart interval in MCU rows (or in MCUs with 'b'). */ 384 /* Restart interval in MCU rows (or in MCUs with 'b'). */
377 long lval; 385 long lval;
378 char ch = 'x'; 386 char ch = 'x';
379 387
380 if (++argn >= argc)» /* advance to next argument */ 388 if (++argn >= argc) /* advance to next argument */
381 » usage(); 389 usage();
382 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) 390 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
383 » usage(); 391 usage();
384 if (lval < 0 || lval > 65535L) 392 if (lval < 0 || lval > 65535L)
385 » usage(); 393 usage();
386 if (ch == 'b' || ch == 'B') { 394 if (ch == 'b' || ch == 'B') {
387 » cinfo->restart_interval = (unsigned int) lval; 395 cinfo->restart_interval = (unsigned int) lval;
388 » cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ 396 cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
389 } else { 397 } else {
390 » cinfo->restart_in_rows = (int) lval; 398 cinfo->restart_in_rows = (int) lval;
391 » /* restart_interval will be computed during startup */ 399 /* restart_interval will be computed during startup */
392 } 400 }
393 401
394 } else if (keymatch(arg, "sample", 2)) { 402 } else if (keymatch(arg, "sample", 2)) {
395 /* Set sampling factors. */ 403 /* Set sampling factors. */
396 if (++argn >= argc)» /* advance to next argument */ 404 if (++argn >= argc) /* advance to next argument */
397 » usage(); 405 usage();
398 samplearg = argv[argn]; 406 samplearg = argv[argn];
399 /* Must delay setting sample factors until after we have processed any 407 /* Must delay setting sample factors until after we have processed any
400 * colorspace-determining switches, since jpeg_set_colorspace sets 408 * colorspace-determining switches, since jpeg_set_colorspace sets
401 * default sampling factors. 409 * default sampling factors.
402 */ 410 */
403 411
404 } else if (keymatch(arg, "scans", 4)) { 412 } else if (keymatch(arg, "scans", 4)) {
405 /* Set scan script. */ 413 /* Set scan script. */
406 #ifdef C_MULTISCAN_FILES_SUPPORTED 414 #ifdef C_MULTISCAN_FILES_SUPPORTED
407 if (++argn >= argc)» /* advance to next argument */ 415 if (++argn >= argc) /* advance to next argument */
408 » usage(); 416 usage();
409 scansarg = argv[argn]; 417 scansarg = argv[argn];
410 /* We must postpone reading the file in case -progressive appears. */ 418 /* We must postpone reading the file in case -progressive appears. */
411 #else 419 #else
412 fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n", 420 fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n",
413 » progname); 421 progname);
414 exit(EXIT_FAILURE); 422 exit(EXIT_FAILURE);
415 #endif 423 #endif
416 424
417 } else if (keymatch(arg, "smooth", 2)) { 425 } else if (keymatch(arg, "smooth", 2)) {
418 /* Set input smoothing factor. */ 426 /* Set input smoothing factor. */
419 int val; 427 int val;
420 428
421 if (++argn >= argc)» /* advance to next argument */ 429 if (++argn >= argc) /* advance to next argument */
422 » usage(); 430 usage();
423 if (sscanf(argv[argn], "%d", &val) != 1) 431 if (sscanf(argv[argn], "%d", &val) != 1)
424 » usage(); 432 usage();
425 if (val < 0 || val > 100) 433 if (val < 0 || val > 100)
426 » usage(); 434 usage();
427 cinfo->smoothing_factor = val; 435 cinfo->smoothing_factor = val;
428 436
429 } else if (keymatch(arg, "targa", 1)) { 437 } else if (keymatch(arg, "targa", 1)) {
430 /* Input file is Targa format. */ 438 /* Input file is Targa format. */
431 is_targa = TRUE; 439 is_targa = TRUE;
432 440
433 } else { 441 } else {
434 usage();» » » /* bogus switch */ 442 usage(); /* bogus switch */
435 } 443 }
436 } 444 }
437 445
438 /* Post-switch-scanning cleanup */ 446 /* Post-switch-scanning cleanup */
439 447
440 if (for_real) { 448 if (for_real) {
441 449
442 /* Set quantization tables for selected quality. */ 450 /* Set quantization tables for selected quality. */
443 /* Some or all may be overridden if -qtables is present. */ 451 /* Some or all may be overridden if -qtables is present. */
444 if (qualityarg != NULL)» /* process -quality if it was present */ 452 if (qualityarg != NULL) /* process -quality if it was present */
445 if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) 453 if (! set_quality_ratings(cinfo, qualityarg, force_baseline))
446 » usage(); 454 usage();
447 455
448 if (qtablefile != NULL)» /* process -qtables if it was present */ 456 if (qtablefile != NULL) /* process -qtables if it was present */
449 if (! read_quant_tables(cinfo, qtablefile, force_baseline)) 457 if (! read_quant_tables(cinfo, qtablefile, force_baseline))
450 » usage(); 458 usage();
451 459
452 if (qslotsarg != NULL)» /* process -qslots if it was present */ 460 if (qslotsarg != NULL) /* process -qslots if it was present */
453 if (! set_quant_slots(cinfo, qslotsarg)) 461 if (! set_quant_slots(cinfo, qslotsarg))
454 » usage(); 462 usage();
455 463
456 if (samplearg != NULL)» /* process -sample if it was present */ 464 if (samplearg != NULL) /* process -sample if it was present */
457 if (! set_sample_factors(cinfo, samplearg)) 465 if (! set_sample_factors(cinfo, samplearg))
458 » usage(); 466 usage();
459 467
460 #ifdef C_PROGRESSIVE_SUPPORTED 468 #ifdef C_PROGRESSIVE_SUPPORTED
461 if (simple_progressive)» /* process -progressive; -scans can override */ 469 if (simple_progressive) /* process -progressive; -scans can override */
462 jpeg_simple_progression(cinfo); 470 jpeg_simple_progression(cinfo);
463 #endif 471 #endif
464 472
465 #ifdef C_MULTISCAN_FILES_SUPPORTED 473 #ifdef C_MULTISCAN_FILES_SUPPORTED
466 if (scansarg != NULL)» /* process -scans if it was present */ 474 if (scansarg != NULL) /* process -scans if it was present */
467 if (! read_scan_script(cinfo, scansarg)) 475 if (! read_scan_script(cinfo, scansarg))
468 » usage(); 476 usage();
469 #endif 477 #endif
470 } 478 }
471 479
472 return argn;» » » /* return index of next arg (file name) */ 480 return argn; /* return index of next arg (file name) */
473 } 481 }
474 482
475 483
476 /* 484 /*
477 * The main program. 485 * The main program.
478 */ 486 */
479 487
480 int 488 int
481 main (int argc, char **argv) 489 main (int argc, char **argv)
482 { 490 {
483 struct jpeg_compress_struct cinfo; 491 struct jpeg_compress_struct cinfo;
484 struct jpeg_error_mgr jerr; 492 struct jpeg_error_mgr jerr;
485 #ifdef PROGRESS_REPORT 493 #ifdef PROGRESS_REPORT
486 struct cdjpeg_progress_mgr progress; 494 struct cdjpeg_progress_mgr progress;
487 #endif 495 #endif
488 int file_index; 496 int file_index;
489 cjpeg_source_ptr src_mgr; 497 cjpeg_source_ptr src_mgr;
490 FILE * input_file; 498 FILE *input_file;
491 FILE * output_file = NULL; 499 FILE *output_file = NULL;
492 unsigned char *outbuffer = NULL; 500 unsigned char *outbuffer = NULL;
493 unsigned long outsize = 0; 501 unsigned long outsize = 0;
494 JDIMENSION num_scanlines; 502 JDIMENSION num_scanlines;
495 503
496 /* On Mac, fetch a command line. */ 504 /* On Mac, fetch a command line. */
497 #ifdef USE_CCOMMAND 505 #ifdef USE_CCOMMAND
498 argc = ccommand(&argv); 506 argc = ccommand(&argv);
499 #endif 507 #endif
500 508
501 progname = argv[0]; 509 progname = argv[0];
502 if (progname == NULL || progname[0] == 0) 510 if (progname == NULL || progname[0] == 0)
503 progname = "cjpeg";»» /* in case C library doesn't provide it */ 511 progname = "cjpeg"; /* in case C library doesn't provide it */
504 512
505 /* Initialize the JPEG compression object with default error handling. */ 513 /* Initialize the JPEG compression object with default error handling. */
506 cinfo.err = jpeg_std_error(&jerr); 514 cinfo.err = jpeg_std_error(&jerr);
507 jpeg_create_compress(&cinfo); 515 jpeg_create_compress(&cinfo);
508 /* Add some application-specific error messages (from cderror.h) */ 516 /* Add some application-specific error messages (from cderror.h) */
509 jerr.addon_message_table = cdjpeg_message_table; 517 jerr.addon_message_table = cdjpeg_message_table;
510 jerr.first_addon_message = JMSG_FIRSTADDONCODE; 518 jerr.first_addon_message = JMSG_FIRSTADDONCODE;
511 jerr.last_addon_message = JMSG_LASTADDONCODE; 519 jerr.last_addon_message = JMSG_LASTADDONCODE;
512 520
513 /* Now safe to enable signal catcher. */
514 #ifdef NEED_SIGNAL_CATCHER
515 enable_signal_catcher((j_common_ptr) &cinfo);
516 #endif
517
518 /* Initialize JPEG parameters. 521 /* Initialize JPEG parameters.
519 * Much of this may be overridden later. 522 * Much of this may be overridden later.
520 * In particular, we don't yet know the input file's color space, 523 * In particular, we don't yet know the input file's color space,
521 * but we need to provide some value for jpeg_set_defaults() to work. 524 * but we need to provide some value for jpeg_set_defaults() to work.
522 */ 525 */
523 526
524 cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ 527 cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
525 jpeg_set_defaults(&cinfo); 528 jpeg_set_defaults(&cinfo);
526 529
527 /* Scan command line to find file names. 530 /* Scan command line to find file names.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 #endif 633 #endif
631 634
632 if (memdst) { 635 if (memdst) {
633 fprintf(stderr, "Compressed size: %lu bytes\n", outsize); 636 fprintf(stderr, "Compressed size: %lu bytes\n", outsize);
634 if (outbuffer != NULL) 637 if (outbuffer != NULL)
635 free(outbuffer); 638 free(outbuffer);
636 } 639 }
637 640
638 /* All done. */ 641 /* All done. */
639 exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); 642 exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
640 return 0;» » » /* suppress no-return-value warnings */ 643 return 0; /* suppress no-return-value warnings */
641 } 644 }
OLDNEW
« no previous file with comments | « cjpeg.1 ('k') | coderules.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698