| OLD | NEW |
| 1 /* | 1 /* |
| 2 * jpegtran.c | 2 * jpegtran.c |
| 3 * | 3 * |
| 4 * This file was part of the Independent JPEG Group's software: | 4 * This file was part of the Independent JPEG Group's software: |
| 5 * Copyright (C) 1995-2010, Thomas G. Lane, Guido Vollbeding. | 5 * Copyright (C) 1995-2010, Thomas G. Lane, Guido Vollbeding. |
| 6 * libjpeg-turbo Modifications: | 6 * libjpeg-turbo Modifications: |
| 7 * Copyright (C) 2010, D. R. Commander. | 7 * Copyright (C) 2010, 2014, D. R. Commander. |
| 8 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README.ijg |
| 9 * file. |
| 9 * | 10 * |
| 10 * This file contains a command-line user interface for JPEG transcoding. | 11 * This file contains a command-line user interface for JPEG transcoding. |
| 11 * It is very similar to cjpeg.c, and partly to djpeg.c, but provides | 12 * It is very similar to cjpeg.c, and partly to djpeg.c, but provides |
| 12 * lossless transcoding between different JPEG file formats. It also | 13 * lossless transcoding between different JPEG file formats. It also |
| 13 * provides some lossless and sort-of-lossless transformations of JPEG data. | 14 * provides some lossless and sort-of-lossless transformations of JPEG data. |
| 14 */ | 15 */ |
| 15 | 16 |
| 16 #include "cdjpeg.h"» » /* Common decls for cjpeg/djpeg applications */ | 17 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
| 17 #include "transupp.h"» » /* Support routines for jpegtran */ | 18 #include "transupp.h" /* Support routines for jpegtran */ |
| 18 #include "jversion.h"» » /* for version message */ | 19 #include "jversion.h" /* for version message */ |
| 19 #include "config.h" | 20 #include "jconfigint.h" |
| 20 | 21 |
| 21 #ifdef USE_CCOMMAND» » /* command-line reader for Macintosh */ | 22 #ifdef USE_CCOMMAND /* command-line reader for Macintosh */ |
| 22 #ifdef __MWERKS__ | 23 #ifdef __MWERKS__ |
| 23 #include <SIOUX.h> /* Metrowerks needs this */ | 24 #include <SIOUX.h> /* Metrowerks needs this */ |
| 24 #include <console.h>» » /* ... and this */ | 25 #include <console.h> /* ... and this */ |
| 25 #endif | 26 #endif |
| 26 #ifdef THINK_C | 27 #ifdef THINK_C |
| 27 #include <console.h>» » /* Think declares it here */ | 28 #include <console.h> /* Think declares it here */ |
| 28 #endif | 29 #endif |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 | 32 |
| 32 /* | 33 /* |
| 33 * Argument-parsing code. | 34 * Argument-parsing code. |
| 34 * The switch parser is designed to be useful with DOS-style command line | 35 * The switch parser is designed to be useful with DOS-style command line |
| 35 * syntax, ie, intermixed switches and file names, where only the switches | 36 * syntax, ie, intermixed switches and file names, where only the switches |
| 36 * to the left of a given file name affect processing of that file. | 37 * to the left of a given file name affect processing of that file. |
| 37 * The main program in this file doesn't actually use this capability... | 38 * The main program in this file doesn't actually use this capability... |
| 38 */ | 39 */ |
| 39 | 40 |
| 40 | 41 |
| 41 static const char * progname;» /* program name for error messages */ | 42 static const char *progname; /* program name for error messages */ |
| 42 static char * outfilename;» /* for -outfile switch */ | 43 static char *outfilename; /* for -outfile switch */ |
| 43 static JCOPY_OPTION copyoption;»/* -copy switch */ | 44 static JCOPY_OPTION copyoption; /* -copy switch */ |
| 44 static jpeg_transform_info transformoption; /* image transformation options */ | 45 static jpeg_transform_info transformoption; /* image transformation options */ |
| 45 | 46 |
| 46 | 47 |
| 47 LOCAL(void) | 48 LOCAL(void) |
| 48 usage (void) | 49 usage (void) |
| 49 /* complain about bad command line */ | 50 /* complain about bad command line */ |
| 50 { | 51 { |
| 51 fprintf(stderr, "usage: %s [switches] ", progname); | 52 fprintf(stderr, "usage: %s [switches] ", progname); |
| 52 #ifdef TWO_FILE_COMMANDLINE | 53 #ifdef TWO_FILE_COMMANDLINE |
| 53 fprintf(stderr, "inputfile outputfile\n"); | 54 fprintf(stderr, "inputfile outputfile\n"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 79 fprintf(stderr, " -trim Drop non-transformable edge blocks\n"); | 80 fprintf(stderr, " -trim Drop non-transformable edge blocks\n"); |
| 80 #endif | 81 #endif |
| 81 fprintf(stderr, "Switches for advanced users:\n"); | 82 fprintf(stderr, "Switches for advanced users:\n"); |
| 82 #ifdef C_ARITH_CODING_SUPPORTED | 83 #ifdef C_ARITH_CODING_SUPPORTED |
| 83 fprintf(stderr, " -arithmetic Use arithmetic coding\n"); | 84 fprintf(stderr, " -arithmetic Use arithmetic coding\n"); |
| 84 #endif | 85 #endif |
| 85 fprintf(stderr, " -restart N Set restart interval in rows, or in blocks w
ith B\n"); | 86 fprintf(stderr, " -restart N Set restart interval in rows, or in blocks w
ith B\n"); |
| 86 fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); | 87 fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); |
| 87 fprintf(stderr, " -outfile name Specify name for output file\n"); | 88 fprintf(stderr, " -outfile name Specify name for output file\n"); |
| 88 fprintf(stderr, " -verbose or -debug Emit debug output\n"); | 89 fprintf(stderr, " -verbose or -debug Emit debug output\n"); |
| 90 fprintf(stderr, " -version Print version information and exit\n"); |
| 89 fprintf(stderr, "Switches for wizards:\n"); | 91 fprintf(stderr, "Switches for wizards:\n"); |
| 90 #ifdef C_MULTISCAN_FILES_SUPPORTED | 92 #ifdef C_MULTISCAN_FILES_SUPPORTED |
| 91 fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); | 93 fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); |
| 92 #endif | 94 #endif |
| 93 exit(EXIT_FAILURE); | 95 exit(EXIT_FAILURE); |
| 94 } | 96 } |
| 95 | 97 |
| 96 | 98 |
| 97 LOCAL(void) | 99 LOCAL(void) |
| 98 select_transform (JXFORM_CODE transform) | 100 select_transform (JXFORM_CODE transform) |
| 99 /* Silly little routine to detect multiple transform options, | 101 /* Silly little routine to detect multiple transform options, |
| 100 * which we can't handle. | 102 * which we can't handle. |
| 101 */ | 103 */ |
| 102 { | 104 { |
| 103 #if TRANSFORMS_SUPPORTED | 105 #if TRANSFORMS_SUPPORTED |
| 104 if (transformoption.transform == JXFORM_NONE || | 106 if (transformoption.transform == JXFORM_NONE || |
| 105 transformoption.transform == transform) { | 107 transformoption.transform == transform) { |
| 106 transformoption.transform = transform; | 108 transformoption.transform = transform; |
| 107 } else { | 109 } else { |
| 108 fprintf(stderr, "%s: can only do one image transformation at a time\n", | 110 fprintf(stderr, "%s: can only do one image transformation at a time\n", |
| 109 » progname); | 111 progname); |
| 110 usage(); | 112 usage(); |
| 111 } | 113 } |
| 112 #else | 114 #else |
| 113 fprintf(stderr, "%s: sorry, image transformation was not compiled\n", | 115 fprintf(stderr, "%s: sorry, image transformation was not compiled\n", |
| 114 » progname); | 116 progname); |
| 115 exit(EXIT_FAILURE); | 117 exit(EXIT_FAILURE); |
| 116 #endif | 118 #endif |
| 117 } | 119 } |
| 118 | 120 |
| 119 | 121 |
| 120 LOCAL(int) | 122 LOCAL(int) |
| 121 parse_switches (j_compress_ptr cinfo, int argc, char **argv, | 123 parse_switches (j_compress_ptr cinfo, int argc, char **argv, |
| 122 » » int last_file_arg_seen, boolean for_real) | 124 int last_file_arg_seen, boolean for_real) |
| 123 /* Parse optional switches. | 125 /* Parse optional switches. |
| 124 * Returns argv[] index of first file-name argument (== argc if none). | 126 * Returns argv[] index of first file-name argument (== argc if none). |
| 125 * Any file names with indexes <= last_file_arg_seen are ignored; | 127 * Any file names with indexes <= last_file_arg_seen are ignored; |
| 126 * they have presumably been processed in a previous iteration. | 128 * they have presumably been processed in a previous iteration. |
| 127 * (Pass 0 for last_file_arg_seen on the first or only iteration.) | 129 * (Pass 0 for last_file_arg_seen on the first or only iteration.) |
| 128 * for_real is FALSE on the first (dummy) pass; we may skip any expensive | 130 * for_real is FALSE on the first (dummy) pass; we may skip any expensive |
| 129 * processing. | 131 * processing. |
| 130 */ | 132 */ |
| 131 { | 133 { |
| 132 int argn; | 134 int argn; |
| 133 char * arg; | 135 char *arg; |
| 134 boolean simple_progressive; | 136 boolean simple_progressive; |
| 135 char * scansarg = NULL;» /* saves -scans parm if any */ | 137 char *scansarg = NULL; /* saves -scans parm if any */ |
| 136 | 138 |
| 137 /* Set up default JPEG parameters. */ | 139 /* Set up default JPEG parameters. */ |
| 138 simple_progressive = FALSE; | 140 simple_progressive = FALSE; |
| 139 outfilename = NULL; | 141 outfilename = NULL; |
| 140 copyoption = JCOPYOPT_DEFAULT; | 142 copyoption = JCOPYOPT_DEFAULT; |
| 141 transformoption.transform = JXFORM_NONE; | 143 transformoption.transform = JXFORM_NONE; |
| 142 transformoption.perfect = FALSE; | 144 transformoption.perfect = FALSE; |
| 143 transformoption.trim = FALSE; | 145 transformoption.trim = FALSE; |
| 144 transformoption.force_grayscale = FALSE; | 146 transformoption.force_grayscale = FALSE; |
| 145 transformoption.crop = FALSE; | 147 transformoption.crop = FALSE; |
| 146 transformoption.slow_hflip = FALSE; | 148 transformoption.slow_hflip = FALSE; |
| 147 cinfo->err->trace_level = 0; | 149 cinfo->err->trace_level = 0; |
| 148 | 150 |
| 149 /* Scan command line options, adjust parameters */ | 151 /* Scan command line options, adjust parameters */ |
| 150 | 152 |
| 151 for (argn = 1; argn < argc; argn++) { | 153 for (argn = 1; argn < argc; argn++) { |
| 152 arg = argv[argn]; | 154 arg = argv[argn]; |
| 153 if (*arg != '-') { | 155 if (*arg != '-') { |
| 154 /* Not a switch, must be a file name argument */ | 156 /* Not a switch, must be a file name argument */ |
| 155 if (argn <= last_file_arg_seen) { | 157 if (argn <= last_file_arg_seen) { |
| 156 » outfilename = NULL;» /* -outfile applies to just one input file */ | 158 outfilename = NULL; /* -outfile applies to just one input file */ |
| 157 » continue;» » /* ignore this name if previously processed */ | 159 continue; /* ignore this name if previously processed */ |
| 158 } | 160 } |
| 159 break;» » » /* else done parsing switches */ | 161 break; /* else done parsing switches */ |
| 160 } | 162 } |
| 161 arg++;» » » /* advance past switch marker character */ | 163 arg++; /* advance past switch marker character */ |
| 162 | 164 |
| 163 if (keymatch(arg, "arithmetic", 1)) { | 165 if (keymatch(arg, "arithmetic", 1)) { |
| 164 /* Use arithmetic coding. */ | 166 /* Use arithmetic coding. */ |
| 165 #ifdef C_ARITH_CODING_SUPPORTED | 167 #ifdef C_ARITH_CODING_SUPPORTED |
| 166 cinfo->arith_code = TRUE; | 168 cinfo->arith_code = TRUE; |
| 167 #else | 169 #else |
| 168 fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", | 170 fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", |
| 169 » progname); | 171 progname); |
| 170 exit(EXIT_FAILURE); | 172 exit(EXIT_FAILURE); |
| 171 #endif | 173 #endif |
| 172 | 174 |
| 173 } else if (keymatch(arg, "copy", 2)) { | 175 } else if (keymatch(arg, "copy", 2)) { |
| 174 /* Select which extra markers to copy. */ | 176 /* Select which extra markers to copy. */ |
| 175 if (++argn >= argc)» /* advance to next argument */ | 177 if (++argn >= argc) /* advance to next argument */ |
| 176 » usage(); | 178 usage(); |
| 177 if (keymatch(argv[argn], "none", 1)) { | 179 if (keymatch(argv[argn], "none", 1)) { |
| 178 » copyoption = JCOPYOPT_NONE; | 180 copyoption = JCOPYOPT_NONE; |
| 179 } else if (keymatch(argv[argn], "comments", 1)) { | 181 } else if (keymatch(argv[argn], "comments", 1)) { |
| 180 » copyoption = JCOPYOPT_COMMENTS; | 182 copyoption = JCOPYOPT_COMMENTS; |
| 181 } else if (keymatch(argv[argn], "all", 1)) { | 183 } else if (keymatch(argv[argn], "all", 1)) { |
| 182 » copyoption = JCOPYOPT_ALL; | 184 copyoption = JCOPYOPT_ALL; |
| 183 } else | 185 } else |
| 184 » usage(); | 186 usage(); |
| 185 | 187 |
| 186 } else if (keymatch(arg, "crop", 2)) { | 188 } else if (keymatch(arg, "crop", 2)) { |
| 187 /* Perform lossless cropping. */ | 189 /* Perform lossless cropping. */ |
| 188 #if TRANSFORMS_SUPPORTED | 190 #if TRANSFORMS_SUPPORTED |
| 189 if (++argn >= argc)» /* advance to next argument */ | 191 if (++argn >= argc) /* advance to next argument */ |
| 190 » usage(); | 192 usage(); |
| 191 if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) { | 193 if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) { |
| 192 » fprintf(stderr, "%s: bogus -crop argument '%s'\n", | 194 fprintf(stderr, "%s: bogus -crop argument '%s'\n", |
| 193 » » progname, argv[argn]); | 195 progname, argv[argn]); |
| 194 » exit(EXIT_FAILURE); | 196 exit(EXIT_FAILURE); |
| 195 } | 197 } |
| 196 #else | 198 #else |
| 197 select_transform(JXFORM_NONE);» /* force an error */ | 199 select_transform(JXFORM_NONE); /* force an error */ |
| 198 #endif | 200 #endif |
| 199 | 201 |
| 200 } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { | 202 } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { |
| 201 /* Enable debug printouts. */ | 203 /* Enable debug printouts. */ |
| 202 /* On first -d, print version identification */ | 204 /* On first -d, print version identification */ |
| 203 static boolean printed_version = FALSE; | 205 static boolean printed_version = FALSE; |
| 204 | 206 |
| 205 if (! printed_version) { | 207 if (! printed_version) { |
| 206 » fprintf(stderr, "%s version %s (build %s)\n", | 208 fprintf(stderr, "%s version %s (build %s)\n", |
| 207 » » PACKAGE_NAME, VERSION, BUILD); | 209 PACKAGE_NAME, VERSION, BUILD); |
| 208 » fprintf(stderr, "%s\n\n", JCOPYRIGHT); | 210 fprintf(stderr, "%s\n\n", JCOPYRIGHT); |
| 209 » fprintf(stderr, "Emulating The Independent JPEG Group's software, versio
n %s\n\n", | 211 fprintf(stderr, "Emulating The Independent JPEG Group's software, versio
n %s\n\n", |
| 210 » » JVERSION); | 212 JVERSION); |
| 211 » printed_version = TRUE; | 213 printed_version = TRUE; |
| 212 } | 214 } |
| 213 cinfo->err->trace_level++; | 215 cinfo->err->trace_level++; |
| 214 | 216 |
| 217 } else if (keymatch(arg, "version", 4)) { |
| 218 fprintf(stderr, "%s version %s (build %s)\n", |
| 219 PACKAGE_NAME, VERSION, BUILD); |
| 220 exit(EXIT_SUCCESS); |
| 221 |
| 215 } else if (keymatch(arg, "flip", 1)) { | 222 } else if (keymatch(arg, "flip", 1)) { |
| 216 /* Mirror left-right or top-bottom. */ | 223 /* Mirror left-right or top-bottom. */ |
| 217 if (++argn >= argc)» /* advance to next argument */ | 224 if (++argn >= argc) /* advance to next argument */ |
| 218 » usage(); | 225 usage(); |
| 219 if (keymatch(argv[argn], "horizontal", 1)) | 226 if (keymatch(argv[argn], "horizontal", 1)) |
| 220 » select_transform(JXFORM_FLIP_H); | 227 select_transform(JXFORM_FLIP_H); |
| 221 else if (keymatch(argv[argn], "vertical", 1)) | 228 else if (keymatch(argv[argn], "vertical", 1)) |
| 222 » select_transform(JXFORM_FLIP_V); | 229 select_transform(JXFORM_FLIP_V); |
| 223 else | 230 else |
| 224 » usage(); | 231 usage(); |
| 225 | 232 |
| 226 } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) { | 233 } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) { |
| 227 /* Force to grayscale. */ | 234 /* Force to grayscale. */ |
| 228 #if TRANSFORMS_SUPPORTED | 235 #if TRANSFORMS_SUPPORTED |
| 229 transformoption.force_grayscale = TRUE; | 236 transformoption.force_grayscale = TRUE; |
| 230 #else | 237 #else |
| 231 select_transform(JXFORM_NONE);» /* force an error */ | 238 select_transform(JXFORM_NONE); /* force an error */ |
| 232 #endif | 239 #endif |
| 233 | 240 |
| 234 } else if (keymatch(arg, "maxmemory", 3)) { | 241 } else if (keymatch(arg, "maxmemory", 3)) { |
| 235 /* Maximum memory in Kb (or Mb with 'm'). */ | 242 /* Maximum memory in Kb (or Mb with 'm'). */ |
| 236 long lval; | 243 long lval; |
| 237 char ch = 'x'; | 244 char ch = 'x'; |
| 238 | 245 |
| 239 if (++argn >= argc)» /* advance to next argument */ | 246 if (++argn >= argc) /* advance to next argument */ |
| 240 » usage(); | 247 usage(); |
| 241 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) | 248 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) |
| 242 » usage(); | 249 usage(); |
| 243 if (ch == 'm' || ch == 'M') | 250 if (ch == 'm' || ch == 'M') |
| 244 » lval *= 1000L; | 251 lval *= 1000L; |
| 245 cinfo->mem->max_memory_to_use = lval * 1000L; | 252 cinfo->mem->max_memory_to_use = lval * 1000L; |
| 246 | 253 |
| 247 } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { | 254 } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { |
| 248 /* Enable entropy parm optimization. */ | 255 /* Enable entropy parm optimization. */ |
| 249 #ifdef ENTROPY_OPT_SUPPORTED | 256 #ifdef ENTROPY_OPT_SUPPORTED |
| 250 cinfo->optimize_coding = TRUE; | 257 cinfo->optimize_coding = TRUE; |
| 251 #else | 258 #else |
| 252 fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", | 259 fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", |
| 253 » progname); | 260 progname); |
| 254 exit(EXIT_FAILURE); | 261 exit(EXIT_FAILURE); |
| 255 #endif | 262 #endif |
| 256 | 263 |
| 257 } else if (keymatch(arg, "outfile", 4)) { | 264 } else if (keymatch(arg, "outfile", 4)) { |
| 258 /* Set output file name. */ | 265 /* Set output file name. */ |
| 259 if (++argn >= argc)» /* advance to next argument */ | 266 if (++argn >= argc) /* advance to next argument */ |
| 260 » usage(); | 267 usage(); |
| 261 outfilename = argv[argn];»/* save it away for later use */ | 268 outfilename = argv[argn]; /* save it away for later use */ |
| 262 | 269 |
| 263 } else if (keymatch(arg, "perfect", 2)) { | 270 } else if (keymatch(arg, "perfect", 2)) { |
| 264 /* Fail if there is any partial edge MCUs that the transform can't | 271 /* Fail if there is any partial edge MCUs that the transform can't |
| 265 * handle. */ | 272 * handle. */ |
| 266 transformoption.perfect = TRUE; | 273 transformoption.perfect = TRUE; |
| 267 | 274 |
| 268 } else if (keymatch(arg, "progressive", 2)) { | 275 } else if (keymatch(arg, "progressive", 2)) { |
| 269 /* Select simple progressive mode. */ | 276 /* Select simple progressive mode. */ |
| 270 #ifdef C_PROGRESSIVE_SUPPORTED | 277 #ifdef C_PROGRESSIVE_SUPPORTED |
| 271 simple_progressive = TRUE; | 278 simple_progressive = TRUE; |
| 272 /* We must postpone execution until num_components is known. */ | 279 /* We must postpone execution until num_components is known. */ |
| 273 #else | 280 #else |
| 274 fprintf(stderr, "%s: sorry, progressive output was not compiled\n", | 281 fprintf(stderr, "%s: sorry, progressive output was not compiled\n", |
| 275 » progname); | 282 progname); |
| 276 exit(EXIT_FAILURE); | 283 exit(EXIT_FAILURE); |
| 277 #endif | 284 #endif |
| 278 | 285 |
| 279 } else if (keymatch(arg, "restart", 1)) { | 286 } else if (keymatch(arg, "restart", 1)) { |
| 280 /* Restart interval in MCU rows (or in MCUs with 'b'). */ | 287 /* Restart interval in MCU rows (or in MCUs with 'b'). */ |
| 281 long lval; | 288 long lval; |
| 282 char ch = 'x'; | 289 char ch = 'x'; |
| 283 | 290 |
| 284 if (++argn >= argc)» /* advance to next argument */ | 291 if (++argn >= argc) /* advance to next argument */ |
| 285 » usage(); | 292 usage(); |
| 286 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) | 293 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) |
| 287 » usage(); | 294 usage(); |
| 288 if (lval < 0 || lval > 65535L) | 295 if (lval < 0 || lval > 65535L) |
| 289 » usage(); | 296 usage(); |
| 290 if (ch == 'b' || ch == 'B') { | 297 if (ch == 'b' || ch == 'B') { |
| 291 » cinfo->restart_interval = (unsigned int) lval; | 298 cinfo->restart_interval = (unsigned int) lval; |
| 292 » cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ | 299 cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ |
| 293 } else { | 300 } else { |
| 294 » cinfo->restart_in_rows = (int) lval; | 301 cinfo->restart_in_rows = (int) lval; |
| 295 » /* restart_interval will be computed during startup */ | 302 /* restart_interval will be computed during startup */ |
| 296 } | 303 } |
| 297 | 304 |
| 298 } else if (keymatch(arg, "rotate", 2)) { | 305 } else if (keymatch(arg, "rotate", 2)) { |
| 299 /* Rotate 90, 180, or 270 degrees (measured clockwise). */ | 306 /* Rotate 90, 180, or 270 degrees (measured clockwise). */ |
| 300 if (++argn >= argc)» /* advance to next argument */ | 307 if (++argn >= argc) /* advance to next argument */ |
| 301 » usage(); | 308 usage(); |
| 302 if (keymatch(argv[argn], "90", 2)) | 309 if (keymatch(argv[argn], "90", 2)) |
| 303 » select_transform(JXFORM_ROT_90); | 310 select_transform(JXFORM_ROT_90); |
| 304 else if (keymatch(argv[argn], "180", 3)) | 311 else if (keymatch(argv[argn], "180", 3)) |
| 305 » select_transform(JXFORM_ROT_180); | 312 select_transform(JXFORM_ROT_180); |
| 306 else if (keymatch(argv[argn], "270", 3)) | 313 else if (keymatch(argv[argn], "270", 3)) |
| 307 » select_transform(JXFORM_ROT_270); | 314 select_transform(JXFORM_ROT_270); |
| 308 else | 315 else |
| 309 » usage(); | 316 usage(); |
| 310 | 317 |
| 311 } else if (keymatch(arg, "scans", 1)) { | 318 } else if (keymatch(arg, "scans", 1)) { |
| 312 /* Set scan script. */ | 319 /* Set scan script. */ |
| 313 #ifdef C_MULTISCAN_FILES_SUPPORTED | 320 #ifdef C_MULTISCAN_FILES_SUPPORTED |
| 314 if (++argn >= argc)» /* advance to next argument */ | 321 if (++argn >= argc) /* advance to next argument */ |
| 315 » usage(); | 322 usage(); |
| 316 scansarg = argv[argn]; | 323 scansarg = argv[argn]; |
| 317 /* We must postpone reading the file in case -progressive appears. */ | 324 /* We must postpone reading the file in case -progressive appears. */ |
| 318 #else | 325 #else |
| 319 fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", | 326 fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", |
| 320 » progname); | 327 progname); |
| 321 exit(EXIT_FAILURE); | 328 exit(EXIT_FAILURE); |
| 322 #endif | 329 #endif |
| 323 | 330 |
| 324 } else if (keymatch(arg, "transpose", 1)) { | 331 } else if (keymatch(arg, "transpose", 1)) { |
| 325 /* Transpose (across UL-to-LR axis). */ | 332 /* Transpose (across UL-to-LR axis). */ |
| 326 select_transform(JXFORM_TRANSPOSE); | 333 select_transform(JXFORM_TRANSPOSE); |
| 327 | 334 |
| 328 } else if (keymatch(arg, "transverse", 6)) { | 335 } else if (keymatch(arg, "transverse", 6)) { |
| 329 /* Transverse transpose (across UR-to-LL axis). */ | 336 /* Transverse transpose (across UR-to-LL axis). */ |
| 330 select_transform(JXFORM_TRANSVERSE); | 337 select_transform(JXFORM_TRANSVERSE); |
| 331 | 338 |
| 332 } else if (keymatch(arg, "trim", 3)) { | 339 } else if (keymatch(arg, "trim", 3)) { |
| 333 /* Trim off any partial edge MCUs that the transform can't handle. */ | 340 /* Trim off any partial edge MCUs that the transform can't handle. */ |
| 334 transformoption.trim = TRUE; | 341 transformoption.trim = TRUE; |
| 335 | 342 |
| 336 } else { | 343 } else { |
| 337 usage();» » » /* bogus switch */ | 344 usage(); /* bogus switch */ |
| 338 } | 345 } |
| 339 } | 346 } |
| 340 | 347 |
| 341 /* Post-switch-scanning cleanup */ | 348 /* Post-switch-scanning cleanup */ |
| 342 | 349 |
| 343 if (for_real) { | 350 if (for_real) { |
| 344 | 351 |
| 345 #ifdef C_PROGRESSIVE_SUPPORTED | 352 #ifdef C_PROGRESSIVE_SUPPORTED |
| 346 if (simple_progressive)» /* process -progressive; -scans can override */ | 353 if (simple_progressive) /* process -progressive; -scans can override */ |
| 347 jpeg_simple_progression(cinfo); | 354 jpeg_simple_progression(cinfo); |
| 348 #endif | 355 #endif |
| 349 | 356 |
| 350 #ifdef C_MULTISCAN_FILES_SUPPORTED | 357 #ifdef C_MULTISCAN_FILES_SUPPORTED |
| 351 if (scansarg != NULL)» /* process -scans if it was present */ | 358 if (scansarg != NULL) /* process -scans if it was present */ |
| 352 if (! read_scan_script(cinfo, scansarg)) | 359 if (! read_scan_script(cinfo, scansarg)) |
| 353 » usage(); | 360 usage(); |
| 354 #endif | 361 #endif |
| 355 } | 362 } |
| 356 | 363 |
| 357 return argn;» » » /* return index of next arg (file name) */ | 364 return argn; /* return index of next arg (file name) */ |
| 358 } | 365 } |
| 359 | 366 |
| 360 | 367 |
| 361 /* | 368 /* |
| 362 * The main program. | 369 * The main program. |
| 363 */ | 370 */ |
| 364 | 371 |
| 365 int | 372 int |
| 366 main (int argc, char **argv) | 373 main (int argc, char **argv) |
| 367 { | 374 { |
| 368 struct jpeg_decompress_struct srcinfo; | 375 struct jpeg_decompress_struct srcinfo; |
| 369 struct jpeg_compress_struct dstinfo; | 376 struct jpeg_compress_struct dstinfo; |
| 370 struct jpeg_error_mgr jsrcerr, jdsterr; | 377 struct jpeg_error_mgr jsrcerr, jdsterr; |
| 371 #ifdef PROGRESS_REPORT | 378 #ifdef PROGRESS_REPORT |
| 372 struct cdjpeg_progress_mgr progress; | 379 struct cdjpeg_progress_mgr progress; |
| 373 #endif | 380 #endif |
| 374 jvirt_barray_ptr * src_coef_arrays; | 381 jvirt_barray_ptr *src_coef_arrays; |
| 375 jvirt_barray_ptr * dst_coef_arrays; | 382 jvirt_barray_ptr *dst_coef_arrays; |
| 376 int file_index; | 383 int file_index; |
| 377 /* We assume all-in-memory processing and can therefore use only a | 384 /* We assume all-in-memory processing and can therefore use only a |
| 378 * single file pointer for sequential input and output operation. | 385 * single file pointer for sequential input and output operation. |
| 379 */ | 386 */ |
| 380 FILE * fp; | 387 FILE *fp; |
| 381 | 388 |
| 382 /* On Mac, fetch a command line. */ | 389 /* On Mac, fetch a command line. */ |
| 383 #ifdef USE_CCOMMAND | 390 #ifdef USE_CCOMMAND |
| 384 argc = ccommand(&argv); | 391 argc = ccommand(&argv); |
| 385 #endif | 392 #endif |
| 386 | 393 |
| 387 progname = argv[0]; | 394 progname = argv[0]; |
| 388 if (progname == NULL || progname[0] == 0) | 395 if (progname == NULL || progname[0] == 0) |
| 389 progname = "jpegtran";» /* in case C library doesn't provide it */ | 396 progname = "jpegtran"; /* in case C library doesn't provide it */ |
| 390 | 397 |
| 391 /* Initialize the JPEG decompression object with default error handling. */ | 398 /* Initialize the JPEG decompression object with default error handling. */ |
| 392 srcinfo.err = jpeg_std_error(&jsrcerr); | 399 srcinfo.err = jpeg_std_error(&jsrcerr); |
| 393 jpeg_create_decompress(&srcinfo); | 400 jpeg_create_decompress(&srcinfo); |
| 394 /* Initialize the JPEG compression object with default error handling. */ | 401 /* Initialize the JPEG compression object with default error handling. */ |
| 395 dstinfo.err = jpeg_std_error(&jdsterr); | 402 dstinfo.err = jpeg_std_error(&jdsterr); |
| 396 jpeg_create_compress(&dstinfo); | 403 jpeg_create_compress(&dstinfo); |
| 397 | 404 |
| 398 /* Now safe to enable signal catcher. | |
| 399 * Note: we assume only the decompression object will have virtual arrays. | |
| 400 */ | |
| 401 #ifdef NEED_SIGNAL_CATCHER | |
| 402 enable_signal_catcher((j_common_ptr) &srcinfo); | |
| 403 #endif | |
| 404 | |
| 405 /* Scan command line to find file names. | 405 /* Scan command line to find file names. |
| 406 * It is convenient to use just one switch-parsing routine, but the switch | 406 * It is convenient to use just one switch-parsing routine, but the switch |
| 407 * values read here are mostly ignored; we will rescan the switches after | 407 * values read here are mostly ignored; we will rescan the switches after |
| 408 * opening the input file. Also note that most of the switches affect the | 408 * opening the input file. Also note that most of the switches affect the |
| 409 * destination JPEG object, so we parse into that and then copy over what | 409 * destination JPEG object, so we parse into that and then copy over what |
| 410 * needs to affects the source too. | 410 * needs to affects the source too. |
| 411 */ | 411 */ |
| 412 | 412 |
| 413 file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE); | 413 file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE); |
| 414 jsrcerr.trace_level = jdsterr.trace_level; | 414 jsrcerr.trace_level = jdsterr.trace_level; |
| 415 srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use; | 415 srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use; |
| 416 | 416 |
| 417 #ifdef TWO_FILE_COMMANDLINE | 417 #ifdef TWO_FILE_COMMANDLINE |
| 418 /* Must have either -outfile switch or explicit output file name */ | 418 /* Must have either -outfile switch or explicit output file name */ |
| 419 if (outfilename == NULL) { | 419 if (outfilename == NULL) { |
| 420 if (file_index != argc-2) { | 420 if (file_index != argc-2) { |
| 421 fprintf(stderr, "%s: must name one input and one output file\n", | 421 fprintf(stderr, "%s: must name one input and one output file\n", |
| 422 » progname); | 422 progname); |
| 423 usage(); | 423 usage(); |
| 424 } | 424 } |
| 425 outfilename = argv[file_index+1]; | 425 outfilename = argv[file_index+1]; |
| 426 } else { | 426 } else { |
| 427 if (file_index != argc-1) { | 427 if (file_index != argc-1) { |
| 428 fprintf(stderr, "%s: must name one input and one output file\n", | 428 fprintf(stderr, "%s: must name one input and one output file\n", |
| 429 » progname); | 429 progname); |
| 430 usage(); | 430 usage(); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 #else | 433 #else |
| 434 /* Unix style: expect zero or one file name */ | 434 /* Unix style: expect zero or one file name */ |
| 435 if (file_index < argc-1) { | 435 if (file_index < argc-1) { |
| 436 fprintf(stderr, "%s: only one input file\n", progname); | 436 fprintf(stderr, "%s: only one input file\n", progname); |
| 437 usage(); | 437 usage(); |
| 438 } | 438 } |
| 439 #endif /* TWO_FILE_COMMANDLINE */ | 439 #endif /* TWO_FILE_COMMANDLINE */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 src_coef_arrays = jpeg_read_coefficients(&srcinfo); | 478 src_coef_arrays = jpeg_read_coefficients(&srcinfo); |
| 479 | 479 |
| 480 /* Initialize destination compression parameters from source values */ | 480 /* Initialize destination compression parameters from source values */ |
| 481 jpeg_copy_critical_parameters(&srcinfo, &dstinfo); | 481 jpeg_copy_critical_parameters(&srcinfo, &dstinfo); |
| 482 | 482 |
| 483 /* Adjust destination parameters if required by transform options; | 483 /* Adjust destination parameters if required by transform options; |
| 484 * also find out which set of coefficient arrays will hold the output. | 484 * also find out which set of coefficient arrays will hold the output. |
| 485 */ | 485 */ |
| 486 #if TRANSFORMS_SUPPORTED | 486 #if TRANSFORMS_SUPPORTED |
| 487 dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo, | 487 dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo, |
| 488 » » » » » » src_coef_arrays, | 488 src_coef_arrays, |
| 489 » » » » » » &transformoption); | 489 &transformoption); |
| 490 #else | 490 #else |
| 491 dst_coef_arrays = src_coef_arrays; | 491 dst_coef_arrays = src_coef_arrays; |
| 492 #endif | 492 #endif |
| 493 | 493 |
| 494 /* Close input file, if we opened it. | 494 /* Close input file, if we opened it. |
| 495 * Note: we assume that jpeg_read_coefficients consumed all input | 495 * Note: we assume that jpeg_read_coefficients consumed all input |
| 496 * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will | 496 * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will |
| 497 * only consume more while (! cinfo->inputctl->eoi_reached). | 497 * only consume more while (! cinfo->inputctl->eoi_reached). |
| 498 * We cannot call jpeg_finish_decompress here since we still need the | 498 * We cannot call jpeg_finish_decompress here since we still need the |
| 499 * virtual arrays allocated from the source object for processing. | 499 * virtual arrays allocated from the source object for processing. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 520 | 520 |
| 521 /* Start compressor (note no image data is actually written here) */ | 521 /* Start compressor (note no image data is actually written here) */ |
| 522 jpeg_write_coefficients(&dstinfo, dst_coef_arrays); | 522 jpeg_write_coefficients(&dstinfo, dst_coef_arrays); |
| 523 | 523 |
| 524 /* Copy to the output file any extra markers that we want to preserve */ | 524 /* Copy to the output file any extra markers that we want to preserve */ |
| 525 jcopy_markers_execute(&srcinfo, &dstinfo, copyoption); | 525 jcopy_markers_execute(&srcinfo, &dstinfo, copyoption); |
| 526 | 526 |
| 527 /* Execute image transformation, if any */ | 527 /* Execute image transformation, if any */ |
| 528 #if TRANSFORMS_SUPPORTED | 528 #if TRANSFORMS_SUPPORTED |
| 529 jtransform_execute_transformation(&srcinfo, &dstinfo, | 529 jtransform_execute_transformation(&srcinfo, &dstinfo, |
| 530 » » » » src_coef_arrays, | 530 src_coef_arrays, |
| 531 » » » » &transformoption); | 531 &transformoption); |
| 532 #endif | 532 #endif |
| 533 | 533 |
| 534 /* Finish compression and release memory */ | 534 /* Finish compression and release memory */ |
| 535 jpeg_finish_compress(&dstinfo); | 535 jpeg_finish_compress(&dstinfo); |
| 536 jpeg_destroy_compress(&dstinfo); | 536 jpeg_destroy_compress(&dstinfo); |
| 537 (void) jpeg_finish_decompress(&srcinfo); | 537 (void) jpeg_finish_decompress(&srcinfo); |
| 538 jpeg_destroy_decompress(&srcinfo); | 538 jpeg_destroy_decompress(&srcinfo); |
| 539 | 539 |
| 540 /* Close output file, if we opened it */ | 540 /* Close output file, if we opened it */ |
| 541 if (fp != stdout) | 541 if (fp != stdout) |
| 542 fclose(fp); | 542 fclose(fp); |
| 543 | 543 |
| 544 #ifdef PROGRESS_REPORT | 544 #ifdef PROGRESS_REPORT |
| 545 end_progress_monitor((j_common_ptr) &dstinfo); | 545 end_progress_monitor((j_common_ptr) &dstinfo); |
| 546 #endif | 546 #endif |
| 547 | 547 |
| 548 /* All done. */ | 548 /* All done. */ |
| 549 exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); | 549 exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); |
| 550 return 0;» » » /* suppress no-return-value warnings */ | 550 return 0; /* suppress no-return-value warnings */ |
| 551 } | 551 } |
| OLD | NEW |