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/cjpeg.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 'libraries/irrlicht-1.8/source/Irrlicht/jpeglib/cjpeg.c')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/jpeglib/cjpeg.c | 1286 |
1 files changed, 643 insertions, 643 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/cjpeg.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/cjpeg.c index a999eee..9a9a09a 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/cjpeg.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/cjpeg.c | |||
@@ -1,643 +1,643 @@ | |||
1 | /* | 1 | /* |
2 | * cjpeg.c | 2 | * cjpeg.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991-1998, Thomas G. Lane. | 4 | * Copyright (C) 1991-1998, Thomas G. Lane. |
5 | * Modified 2003-2011 by Guido Vollbeding. | 5 | * Modified 2003-2011 by Guido Vollbeding. |
6 | * This file is part of the Independent JPEG Group's software. | 6 | * This file is part of the Independent JPEG Group's software. |
7 | * For conditions of distribution and use, see the accompanying README file. | 7 | * For conditions of distribution and use, see the accompanying README file. |
8 | * | 8 | * |
9 | * This file contains a command-line user interface for the JPEG compressor. | 9 | * This file contains a command-line user interface for the JPEG compressor. |
10 | * It should work on any system with Unix- or MS-DOS-style command lines. | 10 | * It should work on any system with Unix- or MS-DOS-style command lines. |
11 | * | 11 | * |
12 | * Two different command line styles are permitted, depending on the | 12 | * Two different command line styles are permitted, depending on the |
13 | * compile-time switch TWO_FILE_COMMANDLINE: | 13 | * compile-time switch TWO_FILE_COMMANDLINE: |
14 | * cjpeg [options] inputfile outputfile | 14 | * cjpeg [options] inputfile outputfile |
15 | * cjpeg [options] [inputfile] | 15 | * cjpeg [options] [inputfile] |
16 | * In the second style, output is always to standard output, which you'd | 16 | * In the second style, output is always to standard output, which you'd |
17 | * normally redirect to a file or pipe to some other program. Input is | 17 | * normally redirect to a file or pipe to some other program. Input is |
18 | * either from a named file or from standard input (typically redirected). | 18 | * either from a named file or from standard input (typically redirected). |
19 | * The second style is convenient on Unix but is unhelpful on systems that | 19 | * The second style is convenient on Unix but is unhelpful on systems that |
20 | * don't support pipes. Also, you MUST use the first style if your system | 20 | * don't support pipes. Also, you MUST use the first style if your system |
21 | * doesn't do binary I/O to stdin/stdout. | 21 | * doesn't do binary I/O to stdin/stdout. |
22 | * To simplify script writing, the "-outfile" switch is provided. The syntax | 22 | * To simplify script writing, the "-outfile" switch is provided. The syntax |
23 | * cjpeg [options] -outfile outputfile inputfile | 23 | * cjpeg [options] -outfile outputfile inputfile |
24 | * works regardless of which command line style is used. | 24 | * works regardless of which command line style is used. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ | 27 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
28 | #include "jversion.h" /* for version message */ | 28 | #include "jversion.h" /* for version message */ |
29 | 29 | ||
30 | #ifdef USE_CCOMMAND /* command-line reader for Macintosh */ | 30 | #ifdef USE_CCOMMAND /* command-line reader for Macintosh */ |
31 | #ifdef __MWERKS__ | 31 | #ifdef __MWERKS__ |
32 | #include <SIOUX.h> /* Metrowerks needs this */ | 32 | #include <SIOUX.h> /* Metrowerks needs this */ |
33 | #include <console.h> /* ... and this */ | 33 | #include <console.h> /* ... and this */ |
34 | #endif | 34 | #endif |
35 | #ifdef THINK_C | 35 | #ifdef THINK_C |
36 | #include <console.h> /* Think declares it here */ | 36 | #include <console.h> /* Think declares it here */ |
37 | #endif | 37 | #endif |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | 40 | ||
41 | /* Create the add-on message string table. */ | 41 | /* Create the add-on message string table. */ |
42 | 42 | ||
43 | #define JMESSAGE(code,string) string , | 43 | #define JMESSAGE(code,string) string , |
44 | 44 | ||
45 | static const char * const cdjpeg_message_table[] = { | 45 | static const char * const cdjpeg_message_table[] = { |
46 | #include "cderror.h" | 46 | #include "cderror.h" |
47 | NULL | 47 | NULL |
48 | }; | 48 | }; |
49 | 49 | ||
50 | 50 | ||
51 | /* | 51 | /* |
52 | * This routine determines what format the input file is, | 52 | * This routine determines what format the input file is, |
53 | * and selects the appropriate input-reading module. | 53 | * and selects the appropriate input-reading module. |
54 | * | 54 | * |
55 | * To determine which family of input formats the file belongs to, | 55 | * To determine which family of input formats the file belongs to, |
56 | * we may look only at the first byte of the file, since C does not | 56 | * we may look only at the first byte of the file, since C does not |
57 | * guarantee that more than one character can be pushed back with ungetc. | 57 | * guarantee that more than one character can be pushed back with ungetc. |
58 | * Looking at additional bytes would require one of these approaches: | 58 | * Looking at additional bytes would require one of these approaches: |
59 | * 1) assume we can fseek() the input file (fails for piped input); | 59 | * 1) assume we can fseek() the input file (fails for piped input); |
60 | * 2) assume we can push back more than one character (works in | 60 | * 2) assume we can push back more than one character (works in |
61 | * some C implementations, but unportable); | 61 | * some C implementations, but unportable); |
62 | * 3) provide our own buffering (breaks input readers that want to use | 62 | * 3) provide our own buffering (breaks input readers that want to use |
63 | * stdio directly, such as the RLE library); | 63 | * stdio directly, such as the RLE library); |
64 | * or 4) don't put back the data, and modify the input_init methods to assume | 64 | * or 4) don't put back the data, and modify the input_init methods to assume |
65 | * they start reading after the start of file (also breaks RLE library). | 65 | * they start reading after the start of file (also breaks RLE library). |
66 | * #1 is attractive for MS-DOS but is untenable on Unix. | 66 | * #1 is attractive for MS-DOS but is untenable on Unix. |
67 | * | 67 | * |
68 | * The most portable solution for file types that can't be identified by their | 68 | * The most portable solution for file types that can't be identified by their |
69 | * first byte is to make the user tell us what they are. This is also the | 69 | * first byte is to make the user tell us what they are. This is also the |
70 | * only approach for "raw" file types that contain only arbitrary values. | 70 | * only approach for "raw" file types that contain only arbitrary values. |
71 | * We presently apply this method for Targa files. Most of the time Targa | 71 | * We presently apply this method for Targa files. Most of the time Targa |
72 | * files start with 0x00, so we recognize that case. Potentially, however, | 72 | * files start with 0x00, so we recognize that case. Potentially, however, |
73 | * a Targa file could start with any byte value (byte 0 is the length of the | 73 | * a Targa file could start with any byte value (byte 0 is the length of the |
74 | * seldom-used ID field), so we provide a switch to force Targa input mode. | 74 | * seldom-used ID field), so we provide a switch to force Targa input mode. |
75 | */ | 75 | */ |
76 | 76 | ||
77 | static boolean is_targa; /* records user -targa switch */ | 77 | static boolean is_targa; /* records user -targa switch */ |
78 | 78 | ||
79 | 79 | ||
80 | LOCAL(cjpeg_source_ptr) | 80 | LOCAL(cjpeg_source_ptr) |
81 | select_file_type (j_compress_ptr cinfo, FILE * infile) | 81 | select_file_type (j_compress_ptr cinfo, FILE * infile) |
82 | { | 82 | { |
83 | int c; | 83 | int c; |
84 | 84 | ||
85 | if (is_targa) { | 85 | if (is_targa) { |
86 | #ifdef TARGA_SUPPORTED | 86 | #ifdef TARGA_SUPPORTED |
87 | return jinit_read_targa(cinfo); | 87 | return jinit_read_targa(cinfo); |
88 | #else | 88 | #else |
89 | ERREXIT(cinfo, JERR_TGA_NOTCOMP); | 89 | ERREXIT(cinfo, JERR_TGA_NOTCOMP); |
90 | #endif | 90 | #endif |
91 | } | 91 | } |
92 | 92 | ||
93 | if ((c = getc(infile)) == EOF) | 93 | if ((c = getc(infile)) == EOF) |
94 | ERREXIT(cinfo, JERR_INPUT_EMPTY); | 94 | ERREXIT(cinfo, JERR_INPUT_EMPTY); |
95 | if (ungetc(c, infile) == EOF) | 95 | if (ungetc(c, infile) == EOF) |
96 | ERREXIT(cinfo, JERR_UNGETC_FAILED); | 96 | ERREXIT(cinfo, JERR_UNGETC_FAILED); |
97 | 97 | ||
98 | switch (c) { | 98 | switch (c) { |
99 | #ifdef BMP_SUPPORTED | 99 | #ifdef BMP_SUPPORTED |
100 | case 'B': | 100 | case 'B': |
101 | return jinit_read_bmp(cinfo); | 101 | return jinit_read_bmp(cinfo); |
102 | #endif | 102 | #endif |
103 | #ifdef GIF_SUPPORTED | 103 | #ifdef GIF_SUPPORTED |
104 | case 'G': | 104 | case 'G': |
105 | return jinit_read_gif(cinfo); | 105 | return jinit_read_gif(cinfo); |
106 | #endif | 106 | #endif |
107 | #ifdef PPM_SUPPORTED | 107 | #ifdef PPM_SUPPORTED |
108 | case 'P': | 108 | case 'P': |
109 | return jinit_read_ppm(cinfo); | 109 | return jinit_read_ppm(cinfo); |
110 | #endif | 110 | #endif |
111 | #ifdef RLE_SUPPORTED | 111 | #ifdef RLE_SUPPORTED |
112 | case 'R': | 112 | case 'R': |
113 | return jinit_read_rle(cinfo); | 113 | return jinit_read_rle(cinfo); |
114 | #endif | 114 | #endif |
115 | #ifdef TARGA_SUPPORTED | 115 | #ifdef TARGA_SUPPORTED |
116 | case 0x00: | 116 | case 0x00: |
117 | return jinit_read_targa(cinfo); | 117 | return jinit_read_targa(cinfo); |
118 | #endif | 118 | #endif |
119 | default: | 119 | default: |
120 | ERREXIT(cinfo, JERR_UNKNOWN_FORMAT); | 120 | ERREXIT(cinfo, JERR_UNKNOWN_FORMAT); |
121 | break; | 121 | break; |
122 | } | 122 | } |
123 | 123 | ||
124 | return NULL; /* suppress compiler warnings */ | 124 | return NULL; /* suppress compiler warnings */ |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | /* | 128 | /* |
129 | * Argument-parsing code. | 129 | * Argument-parsing code. |
130 | * The switch parser is designed to be useful with DOS-style command line | 130 | * The switch parser is designed to be useful with DOS-style command line |
131 | * syntax, ie, intermixed switches and file names, where only the switches | 131 | * syntax, ie, intermixed switches and file names, where only the switches |
132 | * to the left of a given file name affect processing of that file. | 132 | * to the left of a given file name affect processing of that file. |
133 | * The main program in this file doesn't actually use this capability... | 133 | * The main program in this file doesn't actually use this capability... |
134 | */ | 134 | */ |
135 | 135 | ||
136 | 136 | ||
137 | static const char * progname; /* program name for error messages */ | 137 | static const char * progname; /* program name for error messages */ |
138 | static char * outfilename; /* for -outfile switch */ | 138 | static char * outfilename; /* for -outfile switch */ |
139 | 139 | ||
140 | 140 | ||
141 | LOCAL(void) | 141 | LOCAL(void) |
142 | usage (void) | 142 | usage (void) |
143 | /* complain about bad command line */ | 143 | /* complain about bad command line */ |
144 | { | 144 | { |
145 | fprintf(stderr, "usage: %s [switches] ", progname); | 145 | fprintf(stderr, "usage: %s [switches] ", progname); |
146 | #ifdef TWO_FILE_COMMANDLINE | 146 | #ifdef TWO_FILE_COMMANDLINE |
147 | fprintf(stderr, "inputfile outputfile\n"); | 147 | fprintf(stderr, "inputfile outputfile\n"); |
148 | #else | 148 | #else |
149 | fprintf(stderr, "[inputfile]\n"); | 149 | fprintf(stderr, "[inputfile]\n"); |
150 | #endif | 150 | #endif |
151 | 151 | ||
152 | fprintf(stderr, "Switches (names may be abbreviated):\n"); | 152 | fprintf(stderr, "Switches (names may be abbreviated):\n"); |
153 | fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n"); | 153 | fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n"); |
154 | fprintf(stderr, " -grayscale Create monochrome JPEG file\n"); | 154 | fprintf(stderr, " -grayscale Create monochrome JPEG file\n"); |
155 | fprintf(stderr, " -rgb Create RGB JPEG file\n"); | 155 | fprintf(stderr, " -rgb Create RGB JPEG file\n"); |
156 | #ifdef ENTROPY_OPT_SUPPORTED | 156 | #ifdef ENTROPY_OPT_SUPPORTED |
157 | fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); | 157 | fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); |
158 | #endif | 158 | #endif |
159 | #ifdef C_PROGRESSIVE_SUPPORTED | 159 | #ifdef C_PROGRESSIVE_SUPPORTED |
160 | fprintf(stderr, " -progressive Create progressive JPEG file\n"); | 160 | fprintf(stderr, " -progressive Create progressive JPEG file\n"); |
161 | #endif | 161 | #endif |
162 | #ifdef DCT_SCALING_SUPPORTED | 162 | #ifdef DCT_SCALING_SUPPORTED |
163 | fprintf(stderr, " -scale M/N Scale image by fraction M/N, eg, 1/2\n"); | 163 | fprintf(stderr, " -scale M/N Scale image by fraction M/N, eg, 1/2\n"); |
164 | #endif | 164 | #endif |
165 | #ifdef TARGA_SUPPORTED | 165 | #ifdef TARGA_SUPPORTED |
166 | fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n"); | 166 | fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n"); |
167 | #endif | 167 | #endif |
168 | fprintf(stderr, "Switches for advanced users:\n"); | 168 | fprintf(stderr, "Switches for advanced users:\n"); |
169 | #ifdef C_ARITH_CODING_SUPPORTED | 169 | #ifdef C_ARITH_CODING_SUPPORTED |
170 | fprintf(stderr, " -arithmetic Use arithmetic coding\n"); | 170 | fprintf(stderr, " -arithmetic Use arithmetic coding\n"); |
171 | #endif | 171 | #endif |
172 | #ifdef DCT_SCALING_SUPPORTED | 172 | #ifdef DCT_SCALING_SUPPORTED |
173 | fprintf(stderr, " -block N DCT block size (1..16; default is 8)\n"); | 173 | fprintf(stderr, " -block N DCT block size (1..16; default is 8)\n"); |
174 | #endif | 174 | #endif |
175 | #ifdef DCT_ISLOW_SUPPORTED | 175 | #ifdef DCT_ISLOW_SUPPORTED |
176 | fprintf(stderr, " -dct int Use integer DCT method%s\n", | 176 | fprintf(stderr, " -dct int Use integer DCT method%s\n", |
177 | (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); | 177 | (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); |
178 | #endif | 178 | #endif |
179 | #ifdef DCT_IFAST_SUPPORTED | 179 | #ifdef DCT_IFAST_SUPPORTED |
180 | 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", |
181 | (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); | 181 | (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); |
182 | #endif | 182 | #endif |
183 | #ifdef DCT_FLOAT_SUPPORTED | 183 | #ifdef DCT_FLOAT_SUPPORTED |
184 | fprintf(stderr, " -dct float Use floating-point DCT method%s\n", | 184 | fprintf(stderr, " -dct float Use floating-point DCT method%s\n", |
185 | (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); | 185 | (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); |
186 | #endif | 186 | #endif |
187 | fprintf(stderr, " -nosmooth Don't use high-quality downsampling\n"); | 187 | fprintf(stderr, " -nosmooth Don't use high-quality downsampling\n"); |
188 | fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); | 188 | fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); |
189 | #ifdef INPUT_SMOOTHING_SUPPORTED | 189 | #ifdef INPUT_SMOOTHING_SUPPORTED |
190 | fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n"); | 190 | fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n"); |
191 | #endif | 191 | #endif |
192 | fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); | 192 | fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); |
193 | fprintf(stderr, " -outfile name Specify name for output file\n"); | 193 | fprintf(stderr, " -outfile name Specify name for output file\n"); |
194 | fprintf(stderr, " -verbose or -debug Emit debug output\n"); | 194 | fprintf(stderr, " -verbose or -debug Emit debug output\n"); |
195 | fprintf(stderr, "Switches for wizards:\n"); | 195 | fprintf(stderr, "Switches for wizards:\n"); |
196 | fprintf(stderr, " -baseline Force baseline quantization tables\n"); | 196 | fprintf(stderr, " -baseline Force baseline quantization tables\n"); |
197 | fprintf(stderr, " -qtables file Use quantization tables given in file\n"); | 197 | fprintf(stderr, " -qtables file Use quantization tables given in file\n"); |
198 | fprintf(stderr, " -qslots N[,...] Set component quantization tables\n"); | 198 | fprintf(stderr, " -qslots N[,...] Set component quantization tables\n"); |
199 | fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n"); | 199 | fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n"); |
200 | #ifdef C_MULTISCAN_FILES_SUPPORTED | 200 | #ifdef C_MULTISCAN_FILES_SUPPORTED |
201 | fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); | 201 | fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); |
202 | #endif | 202 | #endif |
203 | exit(EXIT_FAILURE); | 203 | exit(EXIT_FAILURE); |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | LOCAL(int) | 207 | LOCAL(int) |
208 | parse_switches (j_compress_ptr cinfo, int argc, char **argv, | 208 | parse_switches (j_compress_ptr cinfo, int argc, char **argv, |
209 | int last_file_arg_seen, boolean for_real) | 209 | int last_file_arg_seen, boolean for_real) |
210 | /* Parse optional switches. | 210 | /* Parse optional switches. |
211 | * Returns argv[] index of first file-name argument (== argc if none). | 211 | * Returns argv[] index of first file-name argument (== argc if none). |
212 | * Any file names with indexes <= last_file_arg_seen are ignored; | 212 | * Any file names with indexes <= last_file_arg_seen are ignored; |
213 | * they have presumably been processed in a previous iteration. | 213 | * they have presumably been processed in a previous iteration. |
214 | * (Pass 0 for last_file_arg_seen on the first or only iteration.) | 214 | * (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 | 215 | * for_real is FALSE on the first (dummy) pass; we may skip any expensive |
216 | * processing. | 216 | * processing. |
217 | */ | 217 | */ |
218 | { | 218 | { |
219 | int argn; | 219 | int argn; |
220 | char * arg; | 220 | char * arg; |
221 | boolean force_baseline; | 221 | boolean force_baseline; |
222 | boolean simple_progressive; | 222 | boolean simple_progressive; |
223 | char * qualityarg = NULL; /* saves -quality parm if any */ | 223 | char * qualityarg = NULL; /* saves -quality parm if any */ |
224 | char * qtablefile = NULL; /* saves -qtables filename if any */ | 224 | char * qtablefile = NULL; /* saves -qtables filename if any */ |
225 | char * qslotsarg = NULL; /* saves -qslots parm if any */ | 225 | char * qslotsarg = NULL; /* saves -qslots parm if any */ |
226 | char * samplearg = NULL; /* saves -sample parm if any */ | 226 | char * samplearg = NULL; /* saves -sample parm if any */ |
227 | char * scansarg = NULL; /* saves -scans parm if any */ | 227 | char * scansarg = NULL; /* saves -scans parm if any */ |
228 | 228 | ||
229 | /* Set up default JPEG parameters. */ | 229 | /* Set up default JPEG parameters. */ |
230 | 230 | ||
231 | force_baseline = FALSE; /* by default, allow 16-bit quantizers */ | 231 | force_baseline = FALSE; /* by default, allow 16-bit quantizers */ |
232 | simple_progressive = FALSE; | 232 | simple_progressive = FALSE; |
233 | is_targa = FALSE; | 233 | is_targa = FALSE; |
234 | outfilename = NULL; | 234 | outfilename = NULL; |
235 | cinfo->err->trace_level = 0; | 235 | cinfo->err->trace_level = 0; |
236 | 236 | ||
237 | /* Scan command line options, adjust parameters */ | 237 | /* Scan command line options, adjust parameters */ |
238 | 238 | ||
239 | for (argn = 1; argn < argc; argn++) { | 239 | for (argn = 1; argn < argc; argn++) { |
240 | arg = argv[argn]; | 240 | arg = argv[argn]; |
241 | if (*arg != '-') { | 241 | if (*arg != '-') { |
242 | /* Not a switch, must be a file name argument */ | 242 | /* Not a switch, must be a file name argument */ |
243 | if (argn <= last_file_arg_seen) { | 243 | if (argn <= last_file_arg_seen) { |
244 | outfilename = NULL; /* -outfile applies to just one input file */ | 244 | outfilename = NULL; /* -outfile applies to just one input file */ |
245 | continue; /* ignore this name if previously processed */ | 245 | continue; /* ignore this name if previously processed */ |
246 | } | 246 | } |
247 | break; /* else done parsing switches */ | 247 | break; /* else done parsing switches */ |
248 | } | 248 | } |
249 | arg++; /* advance past switch marker character */ | 249 | arg++; /* advance past switch marker character */ |
250 | 250 | ||
251 | if (keymatch(arg, "arithmetic", 1)) { | 251 | if (keymatch(arg, "arithmetic", 1)) { |
252 | /* Use arithmetic coding. */ | 252 | /* Use arithmetic coding. */ |
253 | #ifdef C_ARITH_CODING_SUPPORTED | 253 | #ifdef C_ARITH_CODING_SUPPORTED |
254 | cinfo->arith_code = TRUE; | 254 | cinfo->arith_code = TRUE; |
255 | #else | 255 | #else |
256 | fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", | 256 | fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", |
257 | progname); | 257 | progname); |
258 | exit(EXIT_FAILURE); | 258 | exit(EXIT_FAILURE); |
259 | #endif | 259 | #endif |
260 | 260 | ||
261 | } else if (keymatch(arg, "baseline", 2)) { | 261 | } else if (keymatch(arg, "baseline", 2)) { |
262 | /* Force baseline-compatible output (8-bit quantizer values). */ | 262 | /* Force baseline-compatible output (8-bit quantizer values). */ |
263 | force_baseline = TRUE; | 263 | force_baseline = TRUE; |
264 | 264 | ||
265 | } else if (keymatch(arg, "block", 2)) { | 265 | } else if (keymatch(arg, "block", 2)) { |
266 | /* Set DCT block size. */ | 266 | /* Set DCT block size. */ |
267 | #if defined DCT_SCALING_SUPPORTED && JPEG_LIB_VERSION_MAJOR >= 8 && \ | 267 | #if defined DCT_SCALING_SUPPORTED && JPEG_LIB_VERSION_MAJOR >= 8 && \ |
268 | (JPEG_LIB_VERSION_MAJOR > 8 || JPEG_LIB_VERSION_MINOR >= 3) | 268 | (JPEG_LIB_VERSION_MAJOR > 8 || JPEG_LIB_VERSION_MINOR >= 3) |
269 | int val; | 269 | int val; |
270 | 270 | ||
271 | if (++argn >= argc) /* advance to next argument */ | 271 | if (++argn >= argc) /* advance to next argument */ |
272 | usage(); | 272 | usage(); |
273 | if (sscanf(argv[argn], "%d", &val) != 1) | 273 | if (sscanf(argv[argn], "%d", &val) != 1) |
274 | usage(); | 274 | usage(); |
275 | if (val < 1 || val > 16) | 275 | if (val < 1 || val > 16) |
276 | usage(); | 276 | usage(); |
277 | cinfo->block_size = val; | 277 | cinfo->block_size = val; |
278 | #else | 278 | #else |
279 | fprintf(stderr, "%s: sorry, block size setting not supported\n", | 279 | fprintf(stderr, "%s: sorry, block size setting not supported\n", |
280 | progname); | 280 | progname); |
281 | exit(EXIT_FAILURE); | 281 | exit(EXIT_FAILURE); |
282 | #endif | 282 | #endif |
283 | 283 | ||
284 | } else if (keymatch(arg, "dct", 2)) { | 284 | } else if (keymatch(arg, "dct", 2)) { |
285 | /* Select DCT algorithm. */ | 285 | /* Select DCT algorithm. */ |
286 | if (++argn >= argc) /* advance to next argument */ | 286 | if (++argn >= argc) /* advance to next argument */ |
287 | usage(); | 287 | usage(); |
288 | if (keymatch(argv[argn], "int", 1)) { | 288 | if (keymatch(argv[argn], "int", 1)) { |
289 | cinfo->dct_method = JDCT_ISLOW; | 289 | cinfo->dct_method = JDCT_ISLOW; |
290 | } else if (keymatch(argv[argn], "fast", 2)) { | 290 | } else if (keymatch(argv[argn], "fast", 2)) { |
291 | cinfo->dct_method = JDCT_IFAST; | 291 | cinfo->dct_method = JDCT_IFAST; |
292 | } else if (keymatch(argv[argn], "float", 2)) { | 292 | } else if (keymatch(argv[argn], "float", 2)) { |
293 | cinfo->dct_method = JDCT_FLOAT; | 293 | cinfo->dct_method = JDCT_FLOAT; |
294 | } else | 294 | } else |
295 | usage(); | 295 | usage(); |
296 | 296 | ||
297 | } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { | 297 | } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { |
298 | /* Enable debug printouts. */ | 298 | /* Enable debug printouts. */ |
299 | /* On first -d, print version identification */ | 299 | /* On first -d, print version identification */ |
300 | static boolean printed_version = FALSE; | 300 | static boolean printed_version = FALSE; |
301 | 301 | ||
302 | if (! printed_version) { | 302 | if (! printed_version) { |
303 | fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n", | 303 | fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n", |
304 | JVERSION, JCOPYRIGHT); | 304 | JVERSION, JCOPYRIGHT); |
305 | printed_version = TRUE; | 305 | printed_version = TRUE; |
306 | } | 306 | } |
307 | cinfo->err->trace_level++; | 307 | cinfo->err->trace_level++; |
308 | 308 | ||
309 | } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { | 309 | } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { |
310 | /* Force a monochrome JPEG file to be generated. */ | 310 | /* Force a monochrome JPEG file to be generated. */ |
311 | jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); | 311 | jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); |
312 | 312 | ||
313 | } else if (keymatch(arg, "rgb", 3)) { | 313 | } else if (keymatch(arg, "rgb", 3)) { |
314 | /* Force an RGB JPEG file to be generated. */ | 314 | /* Force an RGB JPEG file to be generated. */ |
315 | jpeg_set_colorspace(cinfo, JCS_RGB); | 315 | jpeg_set_colorspace(cinfo, JCS_RGB); |
316 | 316 | ||
317 | } else if (keymatch(arg, "maxmemory", 3)) { | 317 | } else if (keymatch(arg, "maxmemory", 3)) { |
318 | /* Maximum memory in Kb (or Mb with 'm'). */ | 318 | /* Maximum memory in Kb (or Mb with 'm'). */ |
319 | long lval; | 319 | long lval; |
320 | char ch = 'x'; | 320 | char ch = 'x'; |
321 | 321 | ||
322 | if (++argn >= argc) /* advance to next argument */ | 322 | if (++argn >= argc) /* advance to next argument */ |
323 | usage(); | 323 | usage(); |
324 | if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) | 324 | if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) |
325 | usage(); | 325 | usage(); |
326 | if (ch == 'm' || ch == 'M') | 326 | if (ch == 'm' || ch == 'M') |
327 | lval *= 1000L; | 327 | lval *= 1000L; |
328 | cinfo->mem->max_memory_to_use = lval * 1000L; | 328 | cinfo->mem->max_memory_to_use = lval * 1000L; |
329 | 329 | ||
330 | } else if (keymatch(arg, "nosmooth", 3)) { | 330 | } else if (keymatch(arg, "nosmooth", 3)) { |
331 | /* Suppress fancy downsampling */ | 331 | /* Suppress fancy downsampling */ |
332 | cinfo->do_fancy_downsampling = FALSE; | 332 | cinfo->do_fancy_downsampling = FALSE; |
333 | 333 | ||
334 | } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { | 334 | } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { |
335 | /* Enable entropy parm optimization. */ | 335 | /* Enable entropy parm optimization. */ |
336 | #ifdef ENTROPY_OPT_SUPPORTED | 336 | #ifdef ENTROPY_OPT_SUPPORTED |
337 | cinfo->optimize_coding = TRUE; | 337 | cinfo->optimize_coding = TRUE; |
338 | #else | 338 | #else |
339 | fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", | 339 | fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", |
340 | progname); | 340 | progname); |
341 | exit(EXIT_FAILURE); | 341 | exit(EXIT_FAILURE); |
342 | #endif | 342 | #endif |
343 | 343 | ||
344 | } else if (keymatch(arg, "outfile", 4)) { | 344 | } else if (keymatch(arg, "outfile", 4)) { |
345 | /* Set output file name. */ | 345 | /* Set output file name. */ |
346 | if (++argn >= argc) /* advance to next argument */ | 346 | if (++argn >= argc) /* advance to next argument */ |
347 | usage(); | 347 | usage(); |
348 | outfilename = argv[argn]; /* save it away for later use */ | 348 | outfilename = argv[argn]; /* save it away for later use */ |
349 | 349 | ||
350 | } else if (keymatch(arg, "progressive", 1)) { | 350 | } else if (keymatch(arg, "progressive", 1)) { |
351 | /* Select simple progressive mode. */ | 351 | /* Select simple progressive mode. */ |
352 | #ifdef C_PROGRESSIVE_SUPPORTED | 352 | #ifdef C_PROGRESSIVE_SUPPORTED |
353 | simple_progressive = TRUE; | 353 | simple_progressive = TRUE; |
354 | /* We must postpone execution until num_components is known. */ | 354 | /* We must postpone execution until num_components is known. */ |
355 | #else | 355 | #else |
356 | fprintf(stderr, "%s: sorry, progressive output was not compiled\n", | 356 | fprintf(stderr, "%s: sorry, progressive output was not compiled\n", |
357 | progname); | 357 | progname); |
358 | exit(EXIT_FAILURE); | 358 | exit(EXIT_FAILURE); |
359 | #endif | 359 | #endif |
360 | 360 | ||
361 | } else if (keymatch(arg, "quality", 1)) { | 361 | } else if (keymatch(arg, "quality", 1)) { |
362 | /* Quality ratings (quantization table scaling factors). */ | 362 | /* Quality ratings (quantization table scaling factors). */ |
363 | if (++argn >= argc) /* advance to next argument */ | 363 | if (++argn >= argc) /* advance to next argument */ |
364 | usage(); | 364 | usage(); |
365 | qualityarg = argv[argn]; | 365 | qualityarg = argv[argn]; |
366 | 366 | ||
367 | } else if (keymatch(arg, "qslots", 2)) { | 367 | } else if (keymatch(arg, "qslots", 2)) { |
368 | /* Quantization table slot numbers. */ | 368 | /* Quantization table slot numbers. */ |
369 | if (++argn >= argc) /* advance to next argument */ | 369 | if (++argn >= argc) /* advance to next argument */ |
370 | usage(); | 370 | usage(); |
371 | qslotsarg = argv[argn]; | 371 | qslotsarg = argv[argn]; |
372 | /* Must delay setting qslots until after we have processed any | 372 | /* Must delay setting qslots until after we have processed any |
373 | * colorspace-determining switches, since jpeg_set_colorspace sets | 373 | * colorspace-determining switches, since jpeg_set_colorspace sets |
374 | * default quant table numbers. | 374 | * default quant table numbers. |
375 | */ | 375 | */ |
376 | 376 | ||
377 | } else if (keymatch(arg, "qtables", 2)) { | 377 | } else if (keymatch(arg, "qtables", 2)) { |
378 | /* Quantization tables fetched from file. */ | 378 | /* Quantization tables fetched from file. */ |
379 | if (++argn >= argc) /* advance to next argument */ | 379 | if (++argn >= argc) /* advance to next argument */ |
380 | usage(); | 380 | usage(); |
381 | qtablefile = argv[argn]; | 381 | qtablefile = argv[argn]; |
382 | /* We postpone actually reading the file in case -quality comes later. */ | 382 | /* We postpone actually reading the file in case -quality comes later. */ |
383 | 383 | ||
384 | } else if (keymatch(arg, "restart", 1)) { | 384 | } else if (keymatch(arg, "restart", 1)) { |
385 | /* Restart interval in MCU rows (or in MCUs with 'b'). */ | 385 | /* Restart interval in MCU rows (or in MCUs with 'b'). */ |
386 | long lval; | 386 | long lval; |
387 | char ch = 'x'; | 387 | char ch = 'x'; |
388 | 388 | ||
389 | if (++argn >= argc) /* advance to next argument */ | 389 | if (++argn >= argc) /* advance to next argument */ |
390 | usage(); | 390 | usage(); |
391 | if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) | 391 | if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) |
392 | usage(); | 392 | usage(); |
393 | if (lval < 0 || lval > 65535L) | 393 | if (lval < 0 || lval > 65535L) |
394 | usage(); | 394 | usage(); |
395 | if (ch == 'b' || ch == 'B') { | 395 | if (ch == 'b' || ch == 'B') { |
396 | cinfo->restart_interval = (unsigned int) lval; | 396 | cinfo->restart_interval = (unsigned int) lval; |
397 | cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ | 397 | cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ |
398 | } else { | 398 | } else { |
399 | cinfo->restart_in_rows = (int) lval; | 399 | cinfo->restart_in_rows = (int) lval; |
400 | /* restart_interval will be computed during startup */ | 400 | /* restart_interval will be computed during startup */ |
401 | } | 401 | } |
402 | 402 | ||
403 | } else if (keymatch(arg, "sample", 2)) { | 403 | } else if (keymatch(arg, "sample", 2)) { |
404 | /* Set sampling factors. */ | 404 | /* Set sampling factors. */ |
405 | if (++argn >= argc) /* advance to next argument */ | 405 | if (++argn >= argc) /* advance to next argument */ |
406 | usage(); | 406 | usage(); |
407 | samplearg = argv[argn]; | 407 | samplearg = argv[argn]; |
408 | /* Must delay setting sample factors until after we have processed any | 408 | /* Must delay setting sample factors until after we have processed any |
409 | * colorspace-determining switches, since jpeg_set_colorspace sets | 409 | * colorspace-determining switches, since jpeg_set_colorspace sets |
410 | * default sampling factors. | 410 | * default sampling factors. |
411 | */ | 411 | */ |
412 | 412 | ||
413 | } else if (keymatch(arg, "scale", 4)) { | 413 | } else if (keymatch(arg, "scale", 4)) { |
414 | /* Scale the image by a fraction M/N. */ | 414 | /* Scale the image by a fraction M/N. */ |
415 | if (++argn >= argc) /* advance to next argument */ | 415 | if (++argn >= argc) /* advance to next argument */ |
416 | usage(); | 416 | usage(); |
417 | if (sscanf(argv[argn], "%d/%d", | 417 | if (sscanf(argv[argn], "%d/%d", |
418 | &cinfo->scale_num, &cinfo->scale_denom) != 2) | 418 | &cinfo->scale_num, &cinfo->scale_denom) != 2) |
419 | usage(); | 419 | usage(); |
420 | 420 | ||
421 | } else if (keymatch(arg, "scans", 4)) { | 421 | } else if (keymatch(arg, "scans", 4)) { |
422 | /* Set scan script. */ | 422 | /* Set scan script. */ |
423 | #ifdef C_MULTISCAN_FILES_SUPPORTED | 423 | #ifdef C_MULTISCAN_FILES_SUPPORTED |
424 | if (++argn >= argc) /* advance to next argument */ | 424 | if (++argn >= argc) /* advance to next argument */ |
425 | usage(); | 425 | usage(); |
426 | scansarg = argv[argn]; | 426 | scansarg = argv[argn]; |
427 | /* We must postpone reading the file in case -progressive appears. */ | 427 | /* We must postpone reading the file in case -progressive appears. */ |
428 | #else | 428 | #else |
429 | fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", | 429 | fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", |
430 | progname); | 430 | progname); |
431 | exit(EXIT_FAILURE); | 431 | exit(EXIT_FAILURE); |
432 | #endif | 432 | #endif |
433 | 433 | ||
434 | } else if (keymatch(arg, "smooth", 2)) { | 434 | } else if (keymatch(arg, "smooth", 2)) { |
435 | /* Set input smoothing factor. */ | 435 | /* Set input smoothing factor. */ |
436 | int val; | 436 | int val; |
437 | 437 | ||
438 | if (++argn >= argc) /* advance to next argument */ | 438 | if (++argn >= argc) /* advance to next argument */ |
439 | usage(); | 439 | usage(); |
440 | if (sscanf(argv[argn], "%d", &val) != 1) | 440 | if (sscanf(argv[argn], "%d", &val) != 1) |
441 | usage(); | 441 | usage(); |
442 | if (val < 0 || val > 100) | 442 | if (val < 0 || val > 100) |
443 | usage(); | 443 | usage(); |
444 | cinfo->smoothing_factor = val; | 444 | cinfo->smoothing_factor = val; |
445 | 445 | ||
446 | } else if (keymatch(arg, "targa", 1)) { | 446 | } else if (keymatch(arg, "targa", 1)) { |
447 | /* Input file is Targa format. */ | 447 | /* Input file is Targa format. */ |
448 | is_targa = TRUE; | 448 | is_targa = TRUE; |
449 | 449 | ||
450 | } else { | 450 | } else { |
451 | usage(); /* bogus switch */ | 451 | usage(); /* bogus switch */ |
452 | } | 452 | } |
453 | } | 453 | } |
454 | 454 | ||
455 | /* Post-switch-scanning cleanup */ | 455 | /* Post-switch-scanning cleanup */ |
456 | 456 | ||
457 | if (for_real) { | 457 | if (for_real) { |
458 | 458 | ||
459 | /* Set quantization tables for selected quality. */ | 459 | /* Set quantization tables for selected quality. */ |
460 | /* Some or all may be overridden if -qtables is present. */ | 460 | /* Some or all may be overridden if -qtables is present. */ |
461 | if (qualityarg != NULL) /* process -quality if it was present */ | 461 | if (qualityarg != NULL) /* process -quality if it was present */ |
462 | if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) | 462 | if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) |
463 | usage(); | 463 | usage(); |
464 | 464 | ||
465 | if (qtablefile != NULL) /* process -qtables if it was present */ | 465 | if (qtablefile != NULL) /* process -qtables if it was present */ |
466 | if (! read_quant_tables(cinfo, qtablefile, force_baseline)) | 466 | if (! read_quant_tables(cinfo, qtablefile, force_baseline)) |
467 | usage(); | 467 | usage(); |
468 | 468 | ||
469 | if (qslotsarg != NULL) /* process -qslots if it was present */ | 469 | if (qslotsarg != NULL) /* process -qslots if it was present */ |
470 | if (! set_quant_slots(cinfo, qslotsarg)) | 470 | if (! set_quant_slots(cinfo, qslotsarg)) |
471 | usage(); | 471 | usage(); |
472 | 472 | ||
473 | if (samplearg != NULL) /* process -sample if it was present */ | 473 | if (samplearg != NULL) /* process -sample if it was present */ |
474 | if (! set_sample_factors(cinfo, samplearg)) | 474 | if (! set_sample_factors(cinfo, samplearg)) |
475 | usage(); | 475 | usage(); |
476 | 476 | ||
477 | #ifdef C_PROGRESSIVE_SUPPORTED | 477 | #ifdef C_PROGRESSIVE_SUPPORTED |
478 | if (simple_progressive) /* process -progressive; -scans can override */ | 478 | if (simple_progressive) /* process -progressive; -scans can override */ |
479 | jpeg_simple_progression(cinfo); | 479 | jpeg_simple_progression(cinfo); |
480 | #endif | 480 | #endif |
481 | 481 | ||
482 | #ifdef C_MULTISCAN_FILES_SUPPORTED | 482 | #ifdef C_MULTISCAN_FILES_SUPPORTED |
483 | if (scansarg != NULL) /* process -scans if it was present */ | 483 | if (scansarg != NULL) /* process -scans if it was present */ |
484 | if (! read_scan_script(cinfo, scansarg)) | 484 | if (! read_scan_script(cinfo, scansarg)) |
485 | usage(); | 485 | usage(); |
486 | #endif | 486 | #endif |
487 | } | 487 | } |
488 | 488 | ||
489 | return argn; /* return index of next arg (file name) */ | 489 | return argn; /* return index of next arg (file name) */ |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | /* | 493 | /* |
494 | * The main program. | 494 | * The main program. |
495 | */ | 495 | */ |
496 | 496 | ||
497 | int | 497 | int |
498 | main (int argc, char **argv) | 498 | main (int argc, char **argv) |
499 | { | 499 | { |
500 | struct jpeg_compress_struct cinfo; | 500 | struct jpeg_compress_struct cinfo; |
501 | struct jpeg_error_mgr jerr; | 501 | struct jpeg_error_mgr jerr; |
502 | #ifdef PROGRESS_REPORT | 502 | #ifdef PROGRESS_REPORT |
503 | struct cdjpeg_progress_mgr progress; | 503 | struct cdjpeg_progress_mgr progress; |
504 | #endif | 504 | #endif |
505 | int file_index; | 505 | int file_index; |
506 | cjpeg_source_ptr src_mgr; | 506 | cjpeg_source_ptr src_mgr; |
507 | FILE * input_file; | 507 | FILE * input_file; |
508 | FILE * output_file; | 508 | FILE * output_file; |
509 | JDIMENSION num_scanlines; | 509 | JDIMENSION num_scanlines; |
510 | 510 | ||
511 | /* On Mac, fetch a command line. */ | 511 | /* On Mac, fetch a command line. */ |
512 | #ifdef USE_CCOMMAND | 512 | #ifdef USE_CCOMMAND |
513 | argc = ccommand(&argv); | 513 | argc = ccommand(&argv); |
514 | #endif | 514 | #endif |
515 | 515 | ||
516 | progname = argv[0]; | 516 | progname = argv[0]; |
517 | if (progname == NULL || progname[0] == 0) | 517 | if (progname == NULL || progname[0] == 0) |
518 | progname = "cjpeg"; /* in case C library doesn't provide it */ | 518 | progname = "cjpeg"; /* in case C library doesn't provide it */ |
519 | 519 | ||
520 | /* Initialize the JPEG compression object with default error handling. */ | 520 | /* Initialize the JPEG compression object with default error handling. */ |
521 | cinfo.err = jpeg_std_error(&jerr); | 521 | cinfo.err = jpeg_std_error(&jerr); |
522 | jpeg_create_compress(&cinfo); | 522 | jpeg_create_compress(&cinfo); |
523 | /* Add some application-specific error messages (from cderror.h) */ | 523 | /* Add some application-specific error messages (from cderror.h) */ |
524 | jerr.addon_message_table = cdjpeg_message_table; | 524 | jerr.addon_message_table = cdjpeg_message_table; |
525 | jerr.first_addon_message = JMSG_FIRSTADDONCODE; | 525 | jerr.first_addon_message = JMSG_FIRSTADDONCODE; |
526 | jerr.last_addon_message = JMSG_LASTADDONCODE; | 526 | jerr.last_addon_message = JMSG_LASTADDONCODE; |
527 | 527 | ||
528 | /* Now safe to enable signal catcher. */ | 528 | /* Now safe to enable signal catcher. */ |
529 | #ifdef NEED_SIGNAL_CATCHER | 529 | #ifdef NEED_SIGNAL_CATCHER |
530 | enable_signal_catcher((j_common_ptr) &cinfo); | 530 | enable_signal_catcher((j_common_ptr) &cinfo); |
531 | #endif | 531 | #endif |
532 | 532 | ||
533 | /* Initialize JPEG parameters. | 533 | /* Initialize JPEG parameters. |
534 | * Much of this may be overridden later. | 534 | * Much of this may be overridden later. |
535 | * In particular, we don't yet know the input file's color space, | 535 | * In particular, we don't yet know the input file's color space, |
536 | * but we need to provide some value for jpeg_set_defaults() to work. | 536 | * but we need to provide some value for jpeg_set_defaults() to work. |
537 | */ | 537 | */ |
538 | 538 | ||
539 | cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ | 539 | cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ |
540 | jpeg_set_defaults(&cinfo); | 540 | jpeg_set_defaults(&cinfo); |
541 | 541 | ||
542 | /* Scan command line to find file names. | 542 | /* Scan command line to find file names. |
543 | * It is convenient to use just one switch-parsing routine, but the switch | 543 | * It is convenient to use just one switch-parsing routine, but the switch |
544 | * values read here are ignored; we will rescan the switches after opening | 544 | * values read here are ignored; we will rescan the switches after opening |
545 | * the input file. | 545 | * the input file. |
546 | */ | 546 | */ |
547 | 547 | ||
548 | file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); | 548 | file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); |
549 | 549 | ||
550 | #ifdef TWO_FILE_COMMANDLINE | 550 | #ifdef TWO_FILE_COMMANDLINE |
551 | /* Must have either -outfile switch or explicit output file name */ | 551 | /* Must have either -outfile switch or explicit output file name */ |
552 | if (outfilename == NULL) { | 552 | if (outfilename == NULL) { |
553 | if (file_index != argc-2) { | 553 | if (file_index != argc-2) { |
554 | fprintf(stderr, "%s: must name one input and one output file\n", | 554 | fprintf(stderr, "%s: must name one input and one output file\n", |
555 | progname); | 555 | progname); |
556 | usage(); | 556 | usage(); |
557 | } | 557 | } |
558 | outfilename = argv[file_index+1]; | 558 | outfilename = argv[file_index+1]; |
559 | } else { | 559 | } else { |
560 | if (file_index != argc-1) { | 560 | if (file_index != argc-1) { |
561 | fprintf(stderr, "%s: must name one input and one output file\n", | 561 | fprintf(stderr, "%s: must name one input and one output file\n", |
562 | progname); | 562 | progname); |
563 | usage(); | 563 | usage(); |
564 | } | 564 | } |
565 | } | 565 | } |
566 | #else | 566 | #else |
567 | /* Unix style: expect zero or one file name */ | 567 | /* Unix style: expect zero or one file name */ |
568 | if (file_index < argc-1) { | 568 | if (file_index < argc-1) { |
569 | fprintf(stderr, "%s: only one input file\n", progname); | 569 | fprintf(stderr, "%s: only one input file\n", progname); |
570 | usage(); | 570 | usage(); |
571 | } | 571 | } |
572 | #endif /* TWO_FILE_COMMANDLINE */ | 572 | #endif /* TWO_FILE_COMMANDLINE */ |
573 | 573 | ||
574 | /* Open the input file. */ | 574 | /* Open the input file. */ |
575 | if (file_index < argc) { | 575 | if (file_index < argc) { |
576 | if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { | 576 | if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { |
577 | fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); | 577 | fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); |
578 | exit(EXIT_FAILURE); | 578 | exit(EXIT_FAILURE); |
579 | } | 579 | } |
580 | } else { | 580 | } else { |
581 | /* default input file is stdin */ | 581 | /* default input file is stdin */ |
582 | input_file = read_stdin(); | 582 | input_file = read_stdin(); |
583 | } | 583 | } |
584 | 584 | ||
585 | /* Open the output file. */ | 585 | /* Open the output file. */ |
586 | if (outfilename != NULL) { | 586 | if (outfilename != NULL) { |
587 | if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { | 587 | if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { |
588 | fprintf(stderr, "%s: can't open %s\n", progname, outfilename); | 588 | fprintf(stderr, "%s: can't open %s\n", progname, outfilename); |
589 | exit(EXIT_FAILURE); | 589 | exit(EXIT_FAILURE); |
590 | } | 590 | } |
591 | } else { | 591 | } else { |
592 | /* default output file is stdout */ | 592 | /* default output file is stdout */ |
593 | output_file = write_stdout(); | 593 | output_file = write_stdout(); |
594 | } | 594 | } |
595 | 595 | ||
596 | #ifdef PROGRESS_REPORT | 596 | #ifdef PROGRESS_REPORT |
597 | start_progress_monitor((j_common_ptr) &cinfo, &progress); | 597 | start_progress_monitor((j_common_ptr) &cinfo, &progress); |
598 | #endif | 598 | #endif |
599 | 599 | ||
600 | /* Figure out the input file format, and set up to read it. */ | 600 | /* Figure out the input file format, and set up to read it. */ |
601 | src_mgr = select_file_type(&cinfo, input_file); | 601 | src_mgr = select_file_type(&cinfo, input_file); |
602 | src_mgr->input_file = input_file; | 602 | src_mgr->input_file = input_file; |
603 | 603 | ||
604 | /* Read the input file header to obtain file size & colorspace. */ | 604 | /* Read the input file header to obtain file size & colorspace. */ |
605 | (*src_mgr->start_input) (&cinfo, src_mgr); | 605 | (*src_mgr->start_input) (&cinfo, src_mgr); |
606 | 606 | ||
607 | /* Now that we know input colorspace, fix colorspace-dependent defaults */ | 607 | /* Now that we know input colorspace, fix colorspace-dependent defaults */ |
608 | jpeg_default_colorspace(&cinfo); | 608 | jpeg_default_colorspace(&cinfo); |
609 | 609 | ||
610 | /* Adjust default compression parameters by re-parsing the options */ | 610 | /* Adjust default compression parameters by re-parsing the options */ |
611 | file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); | 611 | file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); |
612 | 612 | ||
613 | /* Specify data destination for compression */ | 613 | /* Specify data destination for compression */ |
614 | jpeg_stdio_dest(&cinfo, output_file); | 614 | jpeg_stdio_dest(&cinfo, output_file); |
615 | 615 | ||
616 | /* Start compressor */ | 616 | /* Start compressor */ |
617 | jpeg_start_compress(&cinfo, TRUE); | 617 | jpeg_start_compress(&cinfo, TRUE); |
618 | 618 | ||
619 | /* Process data */ | 619 | /* Process data */ |
620 | while (cinfo.next_scanline < cinfo.image_height) { | 620 | while (cinfo.next_scanline < cinfo.image_height) { |
621 | num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); | 621 | num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); |
622 | (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); | 622 | (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); |
623 | } | 623 | } |
624 | 624 | ||
625 | /* Finish compression and release memory */ | 625 | /* Finish compression and release memory */ |
626 | (*src_mgr->finish_input) (&cinfo, src_mgr); | 626 | (*src_mgr->finish_input) (&cinfo, src_mgr); |
627 | jpeg_finish_compress(&cinfo); | 627 | jpeg_finish_compress(&cinfo); |
628 | jpeg_destroy_compress(&cinfo); | 628 | jpeg_destroy_compress(&cinfo); |
629 | 629 | ||
630 | /* Close files, if we opened them */ | 630 | /* Close files, if we opened them */ |
631 | if (input_file != stdin) | 631 | if (input_file != stdin) |
632 | fclose(input_file); | 632 | fclose(input_file); |
633 | if (output_file != stdout) | 633 | if (output_file != stdout) |
634 | fclose(output_file); | 634 | fclose(output_file); |
635 | 635 | ||
636 | #ifdef PROGRESS_REPORT | 636 | #ifdef PROGRESS_REPORT |
637 | end_progress_monitor((j_common_ptr) &cinfo); | 637 | end_progress_monitor((j_common_ptr) &cinfo); |
638 | #endif | 638 | #endif |
639 | 639 | ||
640 | /* All done. */ | 640 | /* All done. */ |
641 | exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); | 641 | exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); |
642 | return 0; /* suppress no-return-value warnings */ | 642 | return 0; /* suppress no-return-value warnings */ |
643 | } | 643 | } |