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/djpeg.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/djpeg.c')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/jpeglib/djpeg.c | 1234 |
1 files changed, 617 insertions, 617 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/djpeg.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/djpeg.c index 363c628..bc544dc 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/djpeg.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/djpeg.c | |||
@@ -1,617 +1,617 @@ | |||
1 | /* | 1 | /* |
2 | * djpeg.c | 2 | * djpeg.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991-1997, Thomas G. Lane. | 4 | * Copyright (C) 1991-1997, Thomas G. Lane. |
5 | * Modified 2009 by Guido Vollbeding. | 5 | * Modified 2009 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 decompressor. | 9 | * This file contains a command-line user interface for the JPEG decompressor. |
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 | * djpeg [options] inputfile outputfile | 14 | * djpeg [options] inputfile outputfile |
15 | * djpeg [options] [inputfile] | 15 | * djpeg [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 | * djpeg [options] -outfile outputfile inputfile | 23 | * djpeg [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 | #include <ctype.h> /* to declare isprint() */ | 30 | #include <ctype.h> /* to declare isprint() */ |
31 | 31 | ||
32 | #ifdef USE_CCOMMAND /* command-line reader for Macintosh */ | 32 | #ifdef USE_CCOMMAND /* command-line reader for Macintosh */ |
33 | #ifdef __MWERKS__ | 33 | #ifdef __MWERKS__ |
34 | #include <SIOUX.h> /* Metrowerks needs this */ | 34 | #include <SIOUX.h> /* Metrowerks needs this */ |
35 | #include <console.h> /* ... and this */ | 35 | #include <console.h> /* ... and this */ |
36 | #endif | 36 | #endif |
37 | #ifdef THINK_C | 37 | #ifdef THINK_C |
38 | #include <console.h> /* Think declares it here */ | 38 | #include <console.h> /* Think declares it here */ |
39 | #endif | 39 | #endif |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | 42 | ||
43 | /* Create the add-on message string table. */ | 43 | /* Create the add-on message string table. */ |
44 | 44 | ||
45 | #define JMESSAGE(code,string) string , | 45 | #define JMESSAGE(code,string) string , |
46 | 46 | ||
47 | static const char * const cdjpeg_message_table[] = { | 47 | static const char * const cdjpeg_message_table[] = { |
48 | #include "cderror.h" | 48 | #include "cderror.h" |
49 | NULL | 49 | NULL |
50 | }; | 50 | }; |
51 | 51 | ||
52 | 52 | ||
53 | /* | 53 | /* |
54 | * This list defines the known output image formats | 54 | * This list defines the known output image formats |
55 | * (not all of which need be supported by a given version). | 55 | * (not all of which need be supported by a given version). |
56 | * You can change the default output format by defining DEFAULT_FMT; | 56 | * You can change the default output format by defining DEFAULT_FMT; |
57 | * indeed, you had better do so if you undefine PPM_SUPPORTED. | 57 | * indeed, you had better do so if you undefine PPM_SUPPORTED. |
58 | */ | 58 | */ |
59 | 59 | ||
60 | typedef enum { | 60 | typedef enum { |
61 | FMT_BMP, /* BMP format (Windows flavor) */ | 61 | FMT_BMP, /* BMP format (Windows flavor) */ |
62 | FMT_GIF, /* GIF format */ | 62 | FMT_GIF, /* GIF format */ |
63 | FMT_OS2, /* BMP format (OS/2 flavor) */ | 63 | FMT_OS2, /* BMP format (OS/2 flavor) */ |
64 | FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ | 64 | FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ |
65 | FMT_RLE, /* RLE format */ | 65 | FMT_RLE, /* RLE format */ |
66 | FMT_TARGA, /* Targa format */ | 66 | FMT_TARGA, /* Targa format */ |
67 | FMT_TIFF /* TIFF format */ | 67 | FMT_TIFF /* TIFF format */ |
68 | } IMAGE_FORMATS; | 68 | } IMAGE_FORMATS; |
69 | 69 | ||
70 | #ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ | 70 | #ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ |
71 | #define DEFAULT_FMT FMT_PPM | 71 | #define DEFAULT_FMT FMT_PPM |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | static IMAGE_FORMATS requested_fmt; | 74 | static IMAGE_FORMATS requested_fmt; |
75 | 75 | ||
76 | 76 | ||
77 | /* | 77 | /* |
78 | * Argument-parsing code. | 78 | * Argument-parsing code. |
79 | * The switch parser is designed to be useful with DOS-style command line | 79 | * The switch parser is designed to be useful with DOS-style command line |
80 | * syntax, ie, intermixed switches and file names, where only the switches | 80 | * syntax, ie, intermixed switches and file names, where only the switches |
81 | * to the left of a given file name affect processing of that file. | 81 | * to the left of a given file name affect processing of that file. |
82 | * The main program in this file doesn't actually use this capability... | 82 | * The main program in this file doesn't actually use this capability... |
83 | */ | 83 | */ |
84 | 84 | ||
85 | 85 | ||
86 | static const char * progname; /* program name for error messages */ | 86 | static const char * progname; /* program name for error messages */ |
87 | static char * outfilename; /* for -outfile switch */ | 87 | static char * outfilename; /* for -outfile switch */ |
88 | 88 | ||
89 | 89 | ||
90 | LOCAL(void) | 90 | LOCAL(void) |
91 | usage (void) | 91 | usage (void) |
92 | /* complain about bad command line */ | 92 | /* complain about bad command line */ |
93 | { | 93 | { |
94 | fprintf(stderr, "usage: %s [switches] ", progname); | 94 | fprintf(stderr, "usage: %s [switches] ", progname); |
95 | #ifdef TWO_FILE_COMMANDLINE | 95 | #ifdef TWO_FILE_COMMANDLINE |
96 | fprintf(stderr, "inputfile outputfile\n"); | 96 | fprintf(stderr, "inputfile outputfile\n"); |
97 | #else | 97 | #else |
98 | fprintf(stderr, "[inputfile]\n"); | 98 | fprintf(stderr, "[inputfile]\n"); |
99 | #endif | 99 | #endif |
100 | 100 | ||
101 | fprintf(stderr, "Switches (names may be abbreviated):\n"); | 101 | fprintf(stderr, "Switches (names may be abbreviated):\n"); |
102 | fprintf(stderr, " -colors N Reduce image to no more than N colors\n"); | 102 | fprintf(stderr, " -colors N Reduce image to no more than N colors\n"); |
103 | fprintf(stderr, " -fast Fast, low-quality processing\n"); | 103 | fprintf(stderr, " -fast Fast, low-quality processing\n"); |
104 | fprintf(stderr, " -grayscale Force grayscale output\n"); | 104 | fprintf(stderr, " -grayscale Force grayscale output\n"); |
105 | #ifdef IDCT_SCALING_SUPPORTED | 105 | #ifdef IDCT_SCALING_SUPPORTED |
106 | fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); | 106 | fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); |
107 | #endif | 107 | #endif |
108 | #ifdef BMP_SUPPORTED | 108 | #ifdef BMP_SUPPORTED |
109 | fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", | 109 | fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", |
110 | (DEFAULT_FMT == FMT_BMP ? " (default)" : "")); | 110 | (DEFAULT_FMT == FMT_BMP ? " (default)" : "")); |
111 | #endif | 111 | #endif |
112 | #ifdef GIF_SUPPORTED | 112 | #ifdef GIF_SUPPORTED |
113 | fprintf(stderr, " -gif Select GIF output format%s\n", | 113 | fprintf(stderr, " -gif Select GIF output format%s\n", |
114 | (DEFAULT_FMT == FMT_GIF ? " (default)" : "")); | 114 | (DEFAULT_FMT == FMT_GIF ? " (default)" : "")); |
115 | #endif | 115 | #endif |
116 | #ifdef BMP_SUPPORTED | 116 | #ifdef BMP_SUPPORTED |
117 | fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", | 117 | fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", |
118 | (DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); | 118 | (DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); |
119 | #endif | 119 | #endif |
120 | #ifdef PPM_SUPPORTED | 120 | #ifdef PPM_SUPPORTED |
121 | fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", | 121 | fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", |
122 | (DEFAULT_FMT == FMT_PPM ? " (default)" : "")); | 122 | (DEFAULT_FMT == FMT_PPM ? " (default)" : "")); |
123 | #endif | 123 | #endif |
124 | #ifdef RLE_SUPPORTED | 124 | #ifdef RLE_SUPPORTED |
125 | fprintf(stderr, " -rle Select Utah RLE output format%s\n", | 125 | fprintf(stderr, " -rle Select Utah RLE output format%s\n", |
126 | (DEFAULT_FMT == FMT_RLE ? " (default)" : "")); | 126 | (DEFAULT_FMT == FMT_RLE ? " (default)" : "")); |
127 | #endif | 127 | #endif |
128 | #ifdef TARGA_SUPPORTED | 128 | #ifdef TARGA_SUPPORTED |
129 | fprintf(stderr, " -targa Select Targa output format%s\n", | 129 | fprintf(stderr, " -targa Select Targa output format%s\n", |
130 | (DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); | 130 | (DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); |
131 | #endif | 131 | #endif |
132 | fprintf(stderr, "Switches for advanced users:\n"); | 132 | fprintf(stderr, "Switches for advanced users:\n"); |
133 | #ifdef DCT_ISLOW_SUPPORTED | 133 | #ifdef DCT_ISLOW_SUPPORTED |
134 | fprintf(stderr, " -dct int Use integer DCT method%s\n", | 134 | fprintf(stderr, " -dct int Use integer DCT method%s\n", |
135 | (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); | 135 | (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); |
136 | #endif | 136 | #endif |
137 | #ifdef DCT_IFAST_SUPPORTED | 137 | #ifdef DCT_IFAST_SUPPORTED |
138 | fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", | 138 | fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", |
139 | (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); | 139 | (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); |
140 | #endif | 140 | #endif |
141 | #ifdef DCT_FLOAT_SUPPORTED | 141 | #ifdef DCT_FLOAT_SUPPORTED |
142 | fprintf(stderr, " -dct float Use floating-point DCT method%s\n", | 142 | fprintf(stderr, " -dct float Use floating-point DCT method%s\n", |
143 | (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); | 143 | (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); |
144 | #endif | 144 | #endif |
145 | fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); | 145 | fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); |
146 | fprintf(stderr, " -dither none Don't use dithering in quantization\n"); | 146 | fprintf(stderr, " -dither none Don't use dithering in quantization\n"); |
147 | fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n"); | 147 | fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n"); |
148 | #ifdef QUANT_2PASS_SUPPORTED | 148 | #ifdef QUANT_2PASS_SUPPORTED |
149 | fprintf(stderr, " -map FILE Map to colors used in named image file\n"); | 149 | fprintf(stderr, " -map FILE Map to colors used in named image file\n"); |
150 | #endif | 150 | #endif |
151 | fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n"); | 151 | fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n"); |
152 | #ifdef QUANT_1PASS_SUPPORTED | 152 | #ifdef QUANT_1PASS_SUPPORTED |
153 | fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n"); | 153 | fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n"); |
154 | #endif | 154 | #endif |
155 | fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); | 155 | fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); |
156 | fprintf(stderr, " -outfile name Specify name for output file\n"); | 156 | fprintf(stderr, " -outfile name Specify name for output file\n"); |
157 | fprintf(stderr, " -verbose or -debug Emit debug output\n"); | 157 | fprintf(stderr, " -verbose or -debug Emit debug output\n"); |
158 | exit(EXIT_FAILURE); | 158 | exit(EXIT_FAILURE); |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | LOCAL(int) | 162 | LOCAL(int) |
163 | parse_switches (j_decompress_ptr cinfo, int argc, char **argv, | 163 | parse_switches (j_decompress_ptr cinfo, int argc, char **argv, |
164 | int last_file_arg_seen, boolean for_real) | 164 | int last_file_arg_seen, boolean for_real) |
165 | /* Parse optional switches. | 165 | /* Parse optional switches. |
166 | * Returns argv[] index of first file-name argument (== argc if none). | 166 | * Returns argv[] index of first file-name argument (== argc if none). |
167 | * Any file names with indexes <= last_file_arg_seen are ignored; | 167 | * Any file names with indexes <= last_file_arg_seen are ignored; |
168 | * they have presumably been processed in a previous iteration. | 168 | * they have presumably been processed in a previous iteration. |
169 | * (Pass 0 for last_file_arg_seen on the first or only iteration.) | 169 | * (Pass 0 for last_file_arg_seen on the first or only iteration.) |
170 | * for_real is FALSE on the first (dummy) pass; we may skip any expensive | 170 | * for_real is FALSE on the first (dummy) pass; we may skip any expensive |
171 | * processing. | 171 | * processing. |
172 | */ | 172 | */ |
173 | { | 173 | { |
174 | int argn; | 174 | int argn; |
175 | char * arg; | 175 | char * arg; |
176 | 176 | ||
177 | /* Set up default JPEG parameters. */ | 177 | /* Set up default JPEG parameters. */ |
178 | requested_fmt = DEFAULT_FMT; /* set default output file format */ | 178 | requested_fmt = DEFAULT_FMT; /* set default output file format */ |
179 | outfilename = NULL; | 179 | outfilename = NULL; |
180 | cinfo->err->trace_level = 0; | 180 | cinfo->err->trace_level = 0; |
181 | 181 | ||
182 | /* Scan command line options, adjust parameters */ | 182 | /* Scan command line options, adjust parameters */ |
183 | 183 | ||
184 | for (argn = 1; argn < argc; argn++) { | 184 | for (argn = 1; argn < argc; argn++) { |
185 | arg = argv[argn]; | 185 | arg = argv[argn]; |
186 | if (*arg != '-') { | 186 | if (*arg != '-') { |
187 | /* Not a switch, must be a file name argument */ | 187 | /* Not a switch, must be a file name argument */ |
188 | if (argn <= last_file_arg_seen) { | 188 | if (argn <= last_file_arg_seen) { |
189 | outfilename = NULL; /* -outfile applies to just one input file */ | 189 | outfilename = NULL; /* -outfile applies to just one input file */ |
190 | continue; /* ignore this name if previously processed */ | 190 | continue; /* ignore this name if previously processed */ |
191 | } | 191 | } |
192 | break; /* else done parsing switches */ | 192 | break; /* else done parsing switches */ |
193 | } | 193 | } |
194 | arg++; /* advance past switch marker character */ | 194 | arg++; /* advance past switch marker character */ |
195 | 195 | ||
196 | if (keymatch(arg, "bmp", 1)) { | 196 | if (keymatch(arg, "bmp", 1)) { |
197 | /* BMP output format. */ | 197 | /* BMP output format. */ |
198 | requested_fmt = FMT_BMP; | 198 | requested_fmt = FMT_BMP; |
199 | 199 | ||
200 | } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || | 200 | } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || |
201 | keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { | 201 | keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { |
202 | /* Do color quantization. */ | 202 | /* Do color quantization. */ |
203 | int val; | 203 | int val; |
204 | 204 | ||
205 | if (++argn >= argc) /* advance to next argument */ | 205 | if (++argn >= argc) /* advance to next argument */ |
206 | usage(); | 206 | usage(); |
207 | if (sscanf(argv[argn], "%d", &val) != 1) | 207 | if (sscanf(argv[argn], "%d", &val) != 1) |
208 | usage(); | 208 | usage(); |
209 | cinfo->desired_number_of_colors = val; | 209 | cinfo->desired_number_of_colors = val; |
210 | cinfo->quantize_colors = TRUE; | 210 | cinfo->quantize_colors = TRUE; |
211 | 211 | ||
212 | } else if (keymatch(arg, "dct", 2)) { | 212 | } else if (keymatch(arg, "dct", 2)) { |
213 | /* Select IDCT algorithm. */ | 213 | /* Select IDCT algorithm. */ |
214 | if (++argn >= argc) /* advance to next argument */ | 214 | if (++argn >= argc) /* advance to next argument */ |
215 | usage(); | 215 | usage(); |
216 | if (keymatch(argv[argn], "int", 1)) { | 216 | if (keymatch(argv[argn], "int", 1)) { |
217 | cinfo->dct_method = JDCT_ISLOW; | 217 | cinfo->dct_method = JDCT_ISLOW; |
218 | } else if (keymatch(argv[argn], "fast", 2)) { | 218 | } else if (keymatch(argv[argn], "fast", 2)) { |
219 | cinfo->dct_method = JDCT_IFAST; | 219 | cinfo->dct_method = JDCT_IFAST; |
220 | } else if (keymatch(argv[argn], "float", 2)) { | 220 | } else if (keymatch(argv[argn], "float", 2)) { |
221 | cinfo->dct_method = JDCT_FLOAT; | 221 | cinfo->dct_method = JDCT_FLOAT; |
222 | } else | 222 | } else |
223 | usage(); | 223 | usage(); |
224 | 224 | ||
225 | } else if (keymatch(arg, "dither", 2)) { | 225 | } else if (keymatch(arg, "dither", 2)) { |
226 | /* Select dithering algorithm. */ | 226 | /* Select dithering algorithm. */ |
227 | if (++argn >= argc) /* advance to next argument */ | 227 | if (++argn >= argc) /* advance to next argument */ |
228 | usage(); | 228 | usage(); |
229 | if (keymatch(argv[argn], "fs", 2)) { | 229 | if (keymatch(argv[argn], "fs", 2)) { |
230 | cinfo->dither_mode = JDITHER_FS; | 230 | cinfo->dither_mode = JDITHER_FS; |
231 | } else if (keymatch(argv[argn], "none", 2)) { | 231 | } else if (keymatch(argv[argn], "none", 2)) { |
232 | cinfo->dither_mode = JDITHER_NONE; | 232 | cinfo->dither_mode = JDITHER_NONE; |
233 | } else if (keymatch(argv[argn], "ordered", 2)) { | 233 | } else if (keymatch(argv[argn], "ordered", 2)) { |
234 | cinfo->dither_mode = JDITHER_ORDERED; | 234 | cinfo->dither_mode = JDITHER_ORDERED; |
235 | } else | 235 | } else |
236 | usage(); | 236 | usage(); |
237 | 237 | ||
238 | } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { | 238 | } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { |
239 | /* Enable debug printouts. */ | 239 | /* Enable debug printouts. */ |
240 | /* On first -d, print version identification */ | 240 | /* On first -d, print version identification */ |
241 | static boolean printed_version = FALSE; | 241 | static boolean printed_version = FALSE; |
242 | 242 | ||
243 | if (! printed_version) { | 243 | if (! printed_version) { |
244 | fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n", | 244 | fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n", |
245 | JVERSION, JCOPYRIGHT); | 245 | JVERSION, JCOPYRIGHT); |
246 | printed_version = TRUE; | 246 | printed_version = TRUE; |
247 | } | 247 | } |
248 | cinfo->err->trace_level++; | 248 | cinfo->err->trace_level++; |
249 | 249 | ||
250 | } else if (keymatch(arg, "fast", 1)) { | 250 | } else if (keymatch(arg, "fast", 1)) { |
251 | /* Select recommended processing options for quick-and-dirty output. */ | 251 | /* Select recommended processing options for quick-and-dirty output. */ |
252 | cinfo->two_pass_quantize = FALSE; | 252 | cinfo->two_pass_quantize = FALSE; |
253 | cinfo->dither_mode = JDITHER_ORDERED; | 253 | cinfo->dither_mode = JDITHER_ORDERED; |
254 | if (! cinfo->quantize_colors) /* don't override an earlier -colors */ | 254 | if (! cinfo->quantize_colors) /* don't override an earlier -colors */ |
255 | cinfo->desired_number_of_colors = 216; | 255 | cinfo->desired_number_of_colors = 216; |
256 | cinfo->dct_method = JDCT_FASTEST; | 256 | cinfo->dct_method = JDCT_FASTEST; |
257 | cinfo->do_fancy_upsampling = FALSE; | 257 | cinfo->do_fancy_upsampling = FALSE; |
258 | 258 | ||
259 | } else if (keymatch(arg, "gif", 1)) { | 259 | } else if (keymatch(arg, "gif", 1)) { |
260 | /* GIF output format. */ | 260 | /* GIF output format. */ |
261 | requested_fmt = FMT_GIF; | 261 | requested_fmt = FMT_GIF; |
262 | 262 | ||
263 | } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { | 263 | } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { |
264 | /* Force monochrome output. */ | 264 | /* Force monochrome output. */ |
265 | cinfo->out_color_space = JCS_GRAYSCALE; | 265 | cinfo->out_color_space = JCS_GRAYSCALE; |
266 | 266 | ||
267 | } else if (keymatch(arg, "map", 3)) { | 267 | } else if (keymatch(arg, "map", 3)) { |
268 | /* Quantize to a color map taken from an input file. */ | 268 | /* Quantize to a color map taken from an input file. */ |
269 | if (++argn >= argc) /* advance to next argument */ | 269 | if (++argn >= argc) /* advance to next argument */ |
270 | usage(); | 270 | usage(); |
271 | if (for_real) { /* too expensive to do twice! */ | 271 | if (for_real) { /* too expensive to do twice! */ |
272 | #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ | 272 | #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ |
273 | FILE * mapfile; | 273 | FILE * mapfile; |
274 | 274 | ||
275 | if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { | 275 | if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { |
276 | fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); | 276 | fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); |
277 | exit(EXIT_FAILURE); | 277 | exit(EXIT_FAILURE); |
278 | } | 278 | } |
279 | read_color_map(cinfo, mapfile); | 279 | read_color_map(cinfo, mapfile); |
280 | fclose(mapfile); | 280 | fclose(mapfile); |
281 | cinfo->quantize_colors = TRUE; | 281 | cinfo->quantize_colors = TRUE; |
282 | #else | 282 | #else |
283 | ERREXIT(cinfo, JERR_NOT_COMPILED); | 283 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
284 | #endif | 284 | #endif |
285 | } | 285 | } |
286 | 286 | ||
287 | } else if (keymatch(arg, "maxmemory", 3)) { | 287 | } else if (keymatch(arg, "maxmemory", 3)) { |
288 | /* Maximum memory in Kb (or Mb with 'm'). */ | 288 | /* Maximum memory in Kb (or Mb with 'm'). */ |
289 | long lval; | 289 | long lval; |
290 | char ch = 'x'; | 290 | char ch = 'x'; |
291 | 291 | ||
292 | if (++argn >= argc) /* advance to next argument */ | 292 | if (++argn >= argc) /* advance to next argument */ |
293 | usage(); | 293 | usage(); |
294 | if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) | 294 | if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) |
295 | usage(); | 295 | usage(); |
296 | if (ch == 'm' || ch == 'M') | 296 | if (ch == 'm' || ch == 'M') |
297 | lval *= 1000L; | 297 | lval *= 1000L; |
298 | cinfo->mem->max_memory_to_use = lval * 1000L; | 298 | cinfo->mem->max_memory_to_use = lval * 1000L; |
299 | 299 | ||
300 | } else if (keymatch(arg, "nosmooth", 3)) { | 300 | } else if (keymatch(arg, "nosmooth", 3)) { |
301 | /* Suppress fancy upsampling */ | 301 | /* Suppress fancy upsampling */ |
302 | cinfo->do_fancy_upsampling = FALSE; | 302 | cinfo->do_fancy_upsampling = FALSE; |
303 | 303 | ||
304 | } else if (keymatch(arg, "onepass", 3)) { | 304 | } else if (keymatch(arg, "onepass", 3)) { |
305 | /* Use fast one-pass quantization. */ | 305 | /* Use fast one-pass quantization. */ |
306 | cinfo->two_pass_quantize = FALSE; | 306 | cinfo->two_pass_quantize = FALSE; |
307 | 307 | ||
308 | } else if (keymatch(arg, "os2", 3)) { | 308 | } else if (keymatch(arg, "os2", 3)) { |
309 | /* BMP output format (OS/2 flavor). */ | 309 | /* BMP output format (OS/2 flavor). */ |
310 | requested_fmt = FMT_OS2; | 310 | requested_fmt = FMT_OS2; |
311 | 311 | ||
312 | } else if (keymatch(arg, "outfile", 4)) { | 312 | } else if (keymatch(arg, "outfile", 4)) { |
313 | /* Set output file name. */ | 313 | /* Set output file name. */ |
314 | if (++argn >= argc) /* advance to next argument */ | 314 | if (++argn >= argc) /* advance to next argument */ |
315 | usage(); | 315 | usage(); |
316 | outfilename = argv[argn]; /* save it away for later use */ | 316 | outfilename = argv[argn]; /* save it away for later use */ |
317 | 317 | ||
318 | } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) { | 318 | } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) { |
319 | /* PPM/PGM output format. */ | 319 | /* PPM/PGM output format. */ |
320 | requested_fmt = FMT_PPM; | 320 | requested_fmt = FMT_PPM; |
321 | 321 | ||
322 | } else if (keymatch(arg, "rle", 1)) { | 322 | } else if (keymatch(arg, "rle", 1)) { |
323 | /* RLE output format. */ | 323 | /* RLE output format. */ |
324 | requested_fmt = FMT_RLE; | 324 | requested_fmt = FMT_RLE; |
325 | 325 | ||
326 | } else if (keymatch(arg, "scale", 1)) { | 326 | } else if (keymatch(arg, "scale", 1)) { |
327 | /* Scale the output image by a fraction M/N. */ | 327 | /* Scale the output image by a fraction M/N. */ |
328 | if (++argn >= argc) /* advance to next argument */ | 328 | if (++argn >= argc) /* advance to next argument */ |
329 | usage(); | 329 | usage(); |
330 | if (sscanf(argv[argn], "%d/%d", | 330 | if (sscanf(argv[argn], "%d/%d", |
331 | &cinfo->scale_num, &cinfo->scale_denom) < 1) | 331 | &cinfo->scale_num, &cinfo->scale_denom) < 1) |
332 | usage(); | 332 | usage(); |
333 | 333 | ||
334 | } else if (keymatch(arg, "targa", 1)) { | 334 | } else if (keymatch(arg, "targa", 1)) { |
335 | /* Targa output format. */ | 335 | /* Targa output format. */ |
336 | requested_fmt = FMT_TARGA; | 336 | requested_fmt = FMT_TARGA; |
337 | 337 | ||
338 | } else { | 338 | } else { |
339 | usage(); /* bogus switch */ | 339 | usage(); /* bogus switch */ |
340 | } | 340 | } |
341 | } | 341 | } |
342 | 342 | ||
343 | return argn; /* return index of next arg (file name) */ | 343 | return argn; /* return index of next arg (file name) */ |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | /* | 347 | /* |
348 | * Marker processor for COM and interesting APPn markers. | 348 | * Marker processor for COM and interesting APPn markers. |
349 | * This replaces the library's built-in processor, which just skips the marker. | 349 | * This replaces the library's built-in processor, which just skips the marker. |
350 | * We want to print out the marker as text, to the extent possible. | 350 | * We want to print out the marker as text, to the extent possible. |
351 | * Note this code relies on a non-suspending data source. | 351 | * Note this code relies on a non-suspending data source. |
352 | */ | 352 | */ |
353 | 353 | ||
354 | LOCAL(unsigned int) | 354 | LOCAL(unsigned int) |
355 | jpeg_getc (j_decompress_ptr cinfo) | 355 | jpeg_getc (j_decompress_ptr cinfo) |
356 | /* Read next byte */ | 356 | /* Read next byte */ |
357 | { | 357 | { |
358 | struct jpeg_source_mgr * datasrc = cinfo->src; | 358 | struct jpeg_source_mgr * datasrc = cinfo->src; |
359 | 359 | ||
360 | if (datasrc->bytes_in_buffer == 0) { | 360 | if (datasrc->bytes_in_buffer == 0) { |
361 | if (! (*datasrc->fill_input_buffer) (cinfo)) | 361 | if (! (*datasrc->fill_input_buffer) (cinfo)) |
362 | ERREXIT(cinfo, JERR_CANT_SUSPEND); | 362 | ERREXIT(cinfo, JERR_CANT_SUSPEND); |
363 | } | 363 | } |
364 | datasrc->bytes_in_buffer--; | 364 | datasrc->bytes_in_buffer--; |
365 | return GETJOCTET(*datasrc->next_input_byte++); | 365 | return GETJOCTET(*datasrc->next_input_byte++); |
366 | } | 366 | } |
367 | 367 | ||
368 | 368 | ||
369 | METHODDEF(boolean) | 369 | METHODDEF(boolean) |
370 | print_text_marker (j_decompress_ptr cinfo) | 370 | print_text_marker (j_decompress_ptr cinfo) |
371 | { | 371 | { |
372 | boolean traceit = (cinfo->err->trace_level >= 1); | 372 | boolean traceit = (cinfo->err->trace_level >= 1); |
373 | INT32 length; | 373 | INT32 length; |
374 | unsigned int ch; | 374 | unsigned int ch; |
375 | unsigned int lastch = 0; | 375 | unsigned int lastch = 0; |
376 | 376 | ||
377 | length = jpeg_getc(cinfo) << 8; | 377 | length = jpeg_getc(cinfo) << 8; |
378 | length += jpeg_getc(cinfo); | 378 | length += jpeg_getc(cinfo); |
379 | length -= 2; /* discount the length word itself */ | 379 | length -= 2; /* discount the length word itself */ |
380 | 380 | ||
381 | if (traceit) { | 381 | if (traceit) { |
382 | if (cinfo->unread_marker == JPEG_COM) | 382 | if (cinfo->unread_marker == JPEG_COM) |
383 | fprintf(stderr, "Comment, length %ld:\n", (long) length); | 383 | fprintf(stderr, "Comment, length %ld:\n", (long) length); |
384 | else /* assume it is an APPn otherwise */ | 384 | else /* assume it is an APPn otherwise */ |
385 | fprintf(stderr, "APP%d, length %ld:\n", | 385 | fprintf(stderr, "APP%d, length %ld:\n", |
386 | cinfo->unread_marker - JPEG_APP0, (long) length); | 386 | cinfo->unread_marker - JPEG_APP0, (long) length); |
387 | } | 387 | } |
388 | 388 | ||
389 | while (--length >= 0) { | 389 | while (--length >= 0) { |
390 | ch = jpeg_getc(cinfo); | 390 | ch = jpeg_getc(cinfo); |
391 | if (traceit) { | 391 | if (traceit) { |
392 | /* Emit the character in a readable form. | 392 | /* Emit the character in a readable form. |
393 | * Nonprintables are converted to \nnn form, | 393 | * Nonprintables are converted to \nnn form, |
394 | * while \ is converted to \\. | 394 | * while \ is converted to \\. |
395 | * Newlines in CR, CR/LF, or LF form will be printed as one newline. | 395 | * Newlines in CR, CR/LF, or LF form will be printed as one newline. |
396 | */ | 396 | */ |
397 | if (ch == '\r') { | 397 | if (ch == '\r') { |
398 | fprintf(stderr, "\n"); | 398 | fprintf(stderr, "\n"); |
399 | } else if (ch == '\n') { | 399 | } else if (ch == '\n') { |
400 | if (lastch != '\r') | 400 | if (lastch != '\r') |
401 | fprintf(stderr, "\n"); | 401 | fprintf(stderr, "\n"); |
402 | } else if (ch == '\\') { | 402 | } else if (ch == '\\') { |
403 | fprintf(stderr, "\\\\"); | 403 | fprintf(stderr, "\\\\"); |
404 | } else if (isprint(ch)) { | 404 | } else if (isprint(ch)) { |
405 | putc(ch, stderr); | 405 | putc(ch, stderr); |
406 | } else { | 406 | } else { |
407 | fprintf(stderr, "\\%03o", ch); | 407 | fprintf(stderr, "\\%03o", ch); |
408 | } | 408 | } |
409 | lastch = ch; | 409 | lastch = ch; |
410 | } | 410 | } |
411 | } | 411 | } |
412 | 412 | ||
413 | if (traceit) | 413 | if (traceit) |
414 | fprintf(stderr, "\n"); | 414 | fprintf(stderr, "\n"); |
415 | 415 | ||
416 | return TRUE; | 416 | return TRUE; |
417 | } | 417 | } |
418 | 418 | ||
419 | 419 | ||
420 | /* | 420 | /* |
421 | * The main program. | 421 | * The main program. |
422 | */ | 422 | */ |
423 | 423 | ||
424 | int | 424 | int |
425 | main (int argc, char **argv) | 425 | main (int argc, char **argv) |
426 | { | 426 | { |
427 | struct jpeg_decompress_struct cinfo; | 427 | struct jpeg_decompress_struct cinfo; |
428 | struct jpeg_error_mgr jerr; | 428 | struct jpeg_error_mgr jerr; |
429 | #ifdef PROGRESS_REPORT | 429 | #ifdef PROGRESS_REPORT |
430 | struct cdjpeg_progress_mgr progress; | 430 | struct cdjpeg_progress_mgr progress; |
431 | #endif | 431 | #endif |
432 | int file_index; | 432 | int file_index; |
433 | djpeg_dest_ptr dest_mgr = NULL; | 433 | djpeg_dest_ptr dest_mgr = NULL; |
434 | FILE * input_file; | 434 | FILE * input_file; |
435 | FILE * output_file; | 435 | FILE * output_file; |
436 | JDIMENSION num_scanlines; | 436 | JDIMENSION num_scanlines; |
437 | 437 | ||
438 | /* On Mac, fetch a command line. */ | 438 | /* On Mac, fetch a command line. */ |
439 | #ifdef USE_CCOMMAND | 439 | #ifdef USE_CCOMMAND |
440 | argc = ccommand(&argv); | 440 | argc = ccommand(&argv); |
441 | #endif | 441 | #endif |
442 | 442 | ||
443 | progname = argv[0]; | 443 | progname = argv[0]; |
444 | if (progname == NULL || progname[0] == 0) | 444 | if (progname == NULL || progname[0] == 0) |
445 | progname = "djpeg"; /* in case C library doesn't provide it */ | 445 | progname = "djpeg"; /* in case C library doesn't provide it */ |
446 | 446 | ||
447 | /* Initialize the JPEG decompression object with default error handling. */ | 447 | /* Initialize the JPEG decompression object with default error handling. */ |
448 | cinfo.err = jpeg_std_error(&jerr); | 448 | cinfo.err = jpeg_std_error(&jerr); |
449 | jpeg_create_decompress(&cinfo); | 449 | jpeg_create_decompress(&cinfo); |
450 | /* Add some application-specific error messages (from cderror.h) */ | 450 | /* Add some application-specific error messages (from cderror.h) */ |
451 | jerr.addon_message_table = cdjpeg_message_table; | 451 | jerr.addon_message_table = cdjpeg_message_table; |
452 | jerr.first_addon_message = JMSG_FIRSTADDONCODE; | 452 | jerr.first_addon_message = JMSG_FIRSTADDONCODE; |
453 | jerr.last_addon_message = JMSG_LASTADDONCODE; | 453 | jerr.last_addon_message = JMSG_LASTADDONCODE; |
454 | 454 | ||
455 | /* Insert custom marker processor for COM and APP12. | 455 | /* Insert custom marker processor for COM and APP12. |
456 | * APP12 is used by some digital camera makers for textual info, | 456 | * APP12 is used by some digital camera makers for textual info, |
457 | * so we provide the ability to display it as text. | 457 | * so we provide the ability to display it as text. |
458 | * If you like, additional APPn marker types can be selected for display, | 458 | * If you like, additional APPn marker types can be selected for display, |
459 | * but don't try to override APP0 or APP14 this way (see libjpeg.doc). | 459 | * but don't try to override APP0 or APP14 this way (see libjpeg.doc). |
460 | */ | 460 | */ |
461 | jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker); | 461 | jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker); |
462 | jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker); | 462 | jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker); |
463 | 463 | ||
464 | /* Now safe to enable signal catcher. */ | 464 | /* Now safe to enable signal catcher. */ |
465 | #ifdef NEED_SIGNAL_CATCHER | 465 | #ifdef NEED_SIGNAL_CATCHER |
466 | enable_signal_catcher((j_common_ptr) &cinfo); | 466 | enable_signal_catcher((j_common_ptr) &cinfo); |
467 | #endif | 467 | #endif |
468 | 468 | ||
469 | /* Scan command line to find file names. */ | 469 | /* Scan command line to find file names. */ |
470 | /* It is convenient to use just one switch-parsing routine, but the switch | 470 | /* It is convenient to use just one switch-parsing routine, but the switch |
471 | * values read here are ignored; we will rescan the switches after opening | 471 | * values read here are ignored; we will rescan the switches after opening |
472 | * the input file. | 472 | * the input file. |
473 | * (Exception: tracing level set here controls verbosity for COM markers | 473 | * (Exception: tracing level set here controls verbosity for COM markers |
474 | * found during jpeg_read_header...) | 474 | * found during jpeg_read_header...) |
475 | */ | 475 | */ |
476 | 476 | ||
477 | file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); | 477 | file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); |
478 | 478 | ||
479 | #ifdef TWO_FILE_COMMANDLINE | 479 | #ifdef TWO_FILE_COMMANDLINE |
480 | /* Must have either -outfile switch or explicit output file name */ | 480 | /* Must have either -outfile switch or explicit output file name */ |
481 | if (outfilename == NULL) { | 481 | if (outfilename == NULL) { |
482 | if (file_index != argc-2) { | 482 | if (file_index != argc-2) { |
483 | fprintf(stderr, "%s: must name one input and one output file\n", | 483 | fprintf(stderr, "%s: must name one input and one output file\n", |
484 | progname); | 484 | progname); |
485 | usage(); | 485 | usage(); |
486 | } | 486 | } |
487 | outfilename = argv[file_index+1]; | 487 | outfilename = argv[file_index+1]; |
488 | } else { | 488 | } else { |
489 | if (file_index != argc-1) { | 489 | if (file_index != argc-1) { |
490 | fprintf(stderr, "%s: must name one input and one output file\n", | 490 | fprintf(stderr, "%s: must name one input and one output file\n", |
491 | progname); | 491 | progname); |
492 | usage(); | 492 | usage(); |
493 | } | 493 | } |
494 | } | 494 | } |
495 | #else | 495 | #else |
496 | /* Unix style: expect zero or one file name */ | 496 | /* Unix style: expect zero or one file name */ |
497 | if (file_index < argc-1) { | 497 | if (file_index < argc-1) { |
498 | fprintf(stderr, "%s: only one input file\n", progname); | 498 | fprintf(stderr, "%s: only one input file\n", progname); |
499 | usage(); | 499 | usage(); |
500 | } | 500 | } |
501 | #endif /* TWO_FILE_COMMANDLINE */ | 501 | #endif /* TWO_FILE_COMMANDLINE */ |
502 | 502 | ||
503 | /* Open the input file. */ | 503 | /* Open the input file. */ |
504 | if (file_index < argc) { | 504 | if (file_index < argc) { |
505 | if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { | 505 | if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { |
506 | fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); | 506 | fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); |
507 | exit(EXIT_FAILURE); | 507 | exit(EXIT_FAILURE); |
508 | } | 508 | } |
509 | } else { | 509 | } else { |
510 | /* default input file is stdin */ | 510 | /* default input file is stdin */ |
511 | input_file = read_stdin(); | 511 | input_file = read_stdin(); |
512 | } | 512 | } |
513 | 513 | ||
514 | /* Open the output file. */ | 514 | /* Open the output file. */ |
515 | if (outfilename != NULL) { | 515 | if (outfilename != NULL) { |
516 | if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { | 516 | if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { |
517 | fprintf(stderr, "%s: can't open %s\n", progname, outfilename); | 517 | fprintf(stderr, "%s: can't open %s\n", progname, outfilename); |
518 | exit(EXIT_FAILURE); | 518 | exit(EXIT_FAILURE); |
519 | } | 519 | } |
520 | } else { | 520 | } else { |
521 | /* default output file is stdout */ | 521 | /* default output file is stdout */ |
522 | output_file = write_stdout(); | 522 | output_file = write_stdout(); |
523 | } | 523 | } |
524 | 524 | ||
525 | #ifdef PROGRESS_REPORT | 525 | #ifdef PROGRESS_REPORT |
526 | start_progress_monitor((j_common_ptr) &cinfo, &progress); | 526 | start_progress_monitor((j_common_ptr) &cinfo, &progress); |
527 | #endif | 527 | #endif |
528 | 528 | ||
529 | /* Specify data source for decompression */ | 529 | /* Specify data source for decompression */ |
530 | jpeg_stdio_src(&cinfo, input_file); | 530 | jpeg_stdio_src(&cinfo, input_file); |
531 | 531 | ||
532 | /* Read file header, set default decompression parameters */ | 532 | /* Read file header, set default decompression parameters */ |
533 | (void) jpeg_read_header(&cinfo, TRUE); | 533 | (void) jpeg_read_header(&cinfo, TRUE); |
534 | 534 | ||
535 | /* Adjust default decompression parameters by re-parsing the options */ | 535 | /* Adjust default decompression parameters by re-parsing the options */ |
536 | file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); | 536 | file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); |
537 | 537 | ||
538 | /* Initialize the output module now to let it override any crucial | 538 | /* Initialize the output module now to let it override any crucial |
539 | * option settings (for instance, GIF wants to force color quantization). | 539 | * option settings (for instance, GIF wants to force color quantization). |
540 | */ | 540 | */ |
541 | switch (requested_fmt) { | 541 | switch (requested_fmt) { |
542 | #ifdef BMP_SUPPORTED | 542 | #ifdef BMP_SUPPORTED |
543 | case FMT_BMP: | 543 | case FMT_BMP: |
544 | dest_mgr = jinit_write_bmp(&cinfo, FALSE); | 544 | dest_mgr = jinit_write_bmp(&cinfo, FALSE); |
545 | break; | 545 | break; |
546 | case FMT_OS2: | 546 | case FMT_OS2: |
547 | dest_mgr = jinit_write_bmp(&cinfo, TRUE); | 547 | dest_mgr = jinit_write_bmp(&cinfo, TRUE); |
548 | break; | 548 | break; |
549 | #endif | 549 | #endif |
550 | #ifdef GIF_SUPPORTED | 550 | #ifdef GIF_SUPPORTED |
551 | case FMT_GIF: | 551 | case FMT_GIF: |
552 | dest_mgr = jinit_write_gif(&cinfo); | 552 | dest_mgr = jinit_write_gif(&cinfo); |
553 | break; | 553 | break; |
554 | #endif | 554 | #endif |
555 | #ifdef PPM_SUPPORTED | 555 | #ifdef PPM_SUPPORTED |
556 | case FMT_PPM: | 556 | case FMT_PPM: |
557 | dest_mgr = jinit_write_ppm(&cinfo); | 557 | dest_mgr = jinit_write_ppm(&cinfo); |
558 | break; | 558 | break; |
559 | #endif | 559 | #endif |
560 | #ifdef RLE_SUPPORTED | 560 | #ifdef RLE_SUPPORTED |
561 | case FMT_RLE: | 561 | case FMT_RLE: |
562 | dest_mgr = jinit_write_rle(&cinfo); | 562 | dest_mgr = jinit_write_rle(&cinfo); |
563 | break; | 563 | break; |
564 | #endif | 564 | #endif |
565 | #ifdef TARGA_SUPPORTED | 565 | #ifdef TARGA_SUPPORTED |
566 | case FMT_TARGA: | 566 | case FMT_TARGA: |
567 | dest_mgr = jinit_write_targa(&cinfo); | 567 | dest_mgr = jinit_write_targa(&cinfo); |
568 | break; | 568 | break; |
569 | #endif | 569 | #endif |
570 | default: | 570 | default: |
571 | ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); | 571 | ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); |
572 | break; | 572 | break; |
573 | } | 573 | } |
574 | dest_mgr->output_file = output_file; | 574 | dest_mgr->output_file = output_file; |
575 | 575 | ||
576 | /* Start decompressor */ | 576 | /* Start decompressor */ |
577 | (void) jpeg_start_decompress(&cinfo); | 577 | (void) jpeg_start_decompress(&cinfo); |
578 | 578 | ||
579 | /* Write output file header */ | 579 | /* Write output file header */ |
580 | (*dest_mgr->start_output) (&cinfo, dest_mgr); | 580 | (*dest_mgr->start_output) (&cinfo, dest_mgr); |
581 | 581 | ||
582 | /* Process data */ | 582 | /* Process data */ |
583 | while (cinfo.output_scanline < cinfo.output_height) { | 583 | while (cinfo.output_scanline < cinfo.output_height) { |
584 | num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, | 584 | num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, |
585 | dest_mgr->buffer_height); | 585 | dest_mgr->buffer_height); |
586 | (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); | 586 | (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); |
587 | } | 587 | } |
588 | 588 | ||
589 | #ifdef PROGRESS_REPORT | 589 | #ifdef PROGRESS_REPORT |
590 | /* Hack: count final pass as done in case finish_output does an extra pass. | 590 | /* Hack: count final pass as done in case finish_output does an extra pass. |
591 | * The library won't have updated completed_passes. | 591 | * The library won't have updated completed_passes. |
592 | */ | 592 | */ |
593 | progress.pub.completed_passes = progress.pub.total_passes; | 593 | progress.pub.completed_passes = progress.pub.total_passes; |
594 | #endif | 594 | #endif |
595 | 595 | ||
596 | /* Finish decompression and release memory. | 596 | /* Finish decompression and release memory. |
597 | * I must do it in this order because output module has allocated memory | 597 | * I must do it in this order because output module has allocated memory |
598 | * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory. | 598 | * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory. |
599 | */ | 599 | */ |
600 | (*dest_mgr->finish_output) (&cinfo, dest_mgr); | 600 | (*dest_mgr->finish_output) (&cinfo, dest_mgr); |
601 | (void) jpeg_finish_decompress(&cinfo); | 601 | (void) jpeg_finish_decompress(&cinfo); |
602 | jpeg_destroy_decompress(&cinfo); | 602 | jpeg_destroy_decompress(&cinfo); |
603 | 603 | ||
604 | /* Close files, if we opened them */ | 604 | /* Close files, if we opened them */ |
605 | if (input_file != stdin) | 605 | if (input_file != stdin) |
606 | fclose(input_file); | 606 | fclose(input_file); |
607 | if (output_file != stdout) | 607 | if (output_file != stdout) |
608 | fclose(output_file); | 608 | fclose(output_file); |
609 | 609 | ||
610 | #ifdef PROGRESS_REPORT | 610 | #ifdef PROGRESS_REPORT |
611 | end_progress_monitor((j_common_ptr) &cinfo); | 611 | end_progress_monitor((j_common_ptr) &cinfo); |
612 | #endif | 612 | #endif |
613 | 613 | ||
614 | /* All done. */ | 614 | /* All done. */ |
615 | exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); | 615 | exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); |
616 | return 0; /* suppress no-return-value warnings */ | 616 | return 0; /* suppress no-return-value warnings */ |
617 | } | 617 | } |