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

Unified Diff: cjpeg.c

Issue 1934113002: Update libjpeg_turbo to 1.4.90 from https://github.com/libjpeg-turbo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cjpeg.c
diff --git a/cjpeg.c b/cjpeg.c
index 0c23fe7e371f1832a6691b5b75a39a5b77053a14..713224ff41cf6dd0f49105386de9adbfc59978b3 100644
--- a/cjpeg.c
+++ b/cjpeg.c
@@ -5,16 +5,17 @@
* Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2011 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2013, D. R. Commander.
- * For conditions of distribution and use, see the accompanying README file.
+ * Copyright (C) 2010, 2013-2014, D. R. Commander.
+ * For conditions of distribution and use, see the accompanying README.ijg
+ * file.
*
* This file contains a command-line user interface for the JPEG compressor.
* It should work on any system with Unix- or MS-DOS-style command lines.
*
* Two different command line styles are permitted, depending on the
* compile-time switch TWO_FILE_COMMANDLINE:
- * cjpeg [options] inputfile outputfile
- * cjpeg [options] [inputfile]
+ * cjpeg [options] inputfile outputfile
+ * cjpeg [options] [inputfile]
* In the second style, output is always to standard output, which you'd
* normally redirect to a file or pipe to some other program. Input is
* either from a named file or from standard input (typically redirected).
@@ -22,28 +23,28 @@
* don't support pipes. Also, you MUST use the first style if your system
* doesn't do binary I/O to stdin/stdout.
* To simplify script writing, the "-outfile" switch is provided. The syntax
- * cjpeg [options] -outfile outputfile inputfile
+ * cjpeg [options] -outfile outputfile inputfile
* works regardless of which command line style is used.
*/
-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
-#include "jversion.h" /* for version message */
-#include "config.h"
+#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
+#include "jversion.h" /* for version message */
+#include "jconfigint.h"
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
+#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
+#include <console.h> /* ... and this */
#endif
#ifdef THINK_C
-#include <console.h> /* Think declares it here */
+#include <console.h> /* Think declares it here */
#endif
#endif
/* Create the add-on message string table. */
-#define JMESSAGE(code,string) string ,
+#define JMESSAGE(code,string) string ,
static const char * const cdjpeg_message_table[] = {
#include "cderror.h"
@@ -77,11 +78,11 @@ static const char * const cdjpeg_message_table[] = {
* seldom-used ID field), so we provide a switch to force Targa input mode.
*/
-static boolean is_targa; /* records user -targa switch */
+static boolean is_targa; /* records user -targa switch */
LOCAL(cjpeg_source_ptr)
-select_file_type (j_compress_ptr cinfo, FILE * infile)
+select_file_type (j_compress_ptr cinfo, FILE *infile)
{
int c;
@@ -124,7 +125,7 @@ select_file_type (j_compress_ptr cinfo, FILE * infile)
break;
}
- return NULL; /* suppress compiler warnings */
+ return NULL; /* suppress compiler warnings */
}
@@ -137,9 +138,9 @@ select_file_type (j_compress_ptr cinfo, FILE * infile)
*/
-static const char * progname; /* program name for error messages */
-static char * outfilename; /* for -outfile switch */
-boolean memdst; /* for -memdst switch */
+static const char *progname; /* program name for error messages */
+static char *outfilename; /* for -outfile switch */
+boolean memdst; /* for -memdst switch */
LOCAL(void)
@@ -154,7 +155,8 @@ usage (void)
#endif
fprintf(stderr, "Switches (names may be abbreviated):\n");
- fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n");
+ fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is most useful range,\n");
+ fprintf(stderr, " default is 75)\n");
fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
fprintf(stderr, " -rgb Create RGB JPEG file\n");
#ifdef ENTROPY_OPT_SUPPORTED
@@ -172,15 +174,15 @@ usage (void)
#endif
#ifdef DCT_ISLOW_SUPPORTED
fprintf(stderr, " -dct int Use integer DCT method%s\n",
- (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
+ (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
#endif
#ifdef DCT_IFAST_SUPPORTED
fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
- (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
+ (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
#endif
#ifdef DCT_FLOAT_SUPPORTED
fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
- (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
+ (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
#endif
fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
#ifdef INPUT_SMOOTHING_SUPPORTED
@@ -192,6 +194,7 @@ usage (void)
fprintf(stderr, " -memdst Compress to memory instead of file (useful for benchmarking)\n");
#endif
fprintf(stderr, " -verbose or -debug Emit debug output\n");
+ fprintf(stderr, " -version Print version information and exit\n");
fprintf(stderr, "Switches for wizards:\n");
fprintf(stderr, " -baseline Force baseline quantization tables\n");
fprintf(stderr, " -qtables file Use quantization tables given in file\n");
@@ -206,7 +209,7 @@ usage (void)
LOCAL(int)
parse_switches (j_compress_ptr cinfo, int argc, char **argv,
- int last_file_arg_seen, boolean for_real)
+ int last_file_arg_seen, boolean for_real)
/* Parse optional switches.
* Returns argv[] index of first file-name argument (== argc if none).
* Any file names with indexes <= last_file_arg_seen are ignored;
@@ -217,18 +220,18 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
*/
{
int argn;
- char * arg;
+ char *arg;
boolean force_baseline;
boolean simple_progressive;
- char * qualityarg = NULL; /* saves -quality parm if any */
- char * qtablefile = NULL; /* saves -qtables filename if any */
- char * qslotsarg = NULL; /* saves -qslots parm if any */
- char * samplearg = NULL; /* saves -sample parm if any */
- char * scansarg = NULL; /* saves -scans parm if any */
+ char *qualityarg = NULL; /* saves -quality parm if any */
+ char *qtablefile = NULL; /* saves -qtables filename if any */
+ char *qslotsarg = NULL; /* saves -qslots parm if any */
+ char *samplearg = NULL; /* saves -sample parm if any */
+ char *scansarg = NULL; /* saves -scans parm if any */
/* Set up default JPEG parameters. */
- force_baseline = FALSE; /* by default, allow 16-bit quantizers */
+ force_baseline = FALSE; /* by default, allow 16-bit quantizers */
simple_progressive = FALSE;
is_targa = FALSE;
outfilename = NULL;
@@ -242,12 +245,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
if (*arg != '-') {
/* Not a switch, must be a file name argument */
if (argn <= last_file_arg_seen) {
- outfilename = NULL; /* -outfile applies to just one input file */
- continue; /* ignore this name if previously processed */
+ outfilename = NULL; /* -outfile applies to just one input file */
+ continue; /* ignore this name if previously processed */
}
- break; /* else done parsing switches */
+ break; /* else done parsing switches */
}
- arg++; /* advance past switch marker character */
+ arg++; /* advance past switch marker character */
if (keymatch(arg, "arithmetic", 1)) {
/* Use arithmetic coding. */
@@ -255,7 +258,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->arith_code = TRUE;
#else
fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
- progname);
+ progname);
exit(EXIT_FAILURE);
#endif
@@ -265,16 +268,16 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "dct", 2)) {
/* Select DCT algorithm. */
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
if (keymatch(argv[argn], "int", 1)) {
- cinfo->dct_method = JDCT_ISLOW;
+ cinfo->dct_method = JDCT_ISLOW;
} else if (keymatch(argv[argn], "fast", 2)) {
- cinfo->dct_method = JDCT_IFAST;
+ cinfo->dct_method = JDCT_IFAST;
} else if (keymatch(argv[argn], "float", 2)) {
- cinfo->dct_method = JDCT_FLOAT;
+ cinfo->dct_method = JDCT_FLOAT;
} else
- usage();
+ usage();
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
/* Enable debug printouts. */
@@ -282,15 +285,20 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
static boolean printed_version = FALSE;
if (! printed_version) {
- fprintf(stderr, "%s version %s (build %s)\n",
- PACKAGE_NAME, VERSION, BUILD);
- fprintf(stderr, "%s\n\n", JCOPYRIGHT);
- fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
- JVERSION);
- printed_version = TRUE;
+ fprintf(stderr, "%s version %s (build %s)\n",
+ PACKAGE_NAME, VERSION, BUILD);
+ fprintf(stderr, "%s\n\n", JCOPYRIGHT);
+ fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
+ JVERSION);
+ printed_version = TRUE;
}
cinfo->err->trace_level++;
+ } else if (keymatch(arg, "version", 4)) {
+ fprintf(stderr, "%s version %s (build %s)\n",
+ PACKAGE_NAME, VERSION, BUILD);
+ exit(EXIT_SUCCESS);
+
} else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
/* Force a monochrome JPEG file to be generated. */
jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
@@ -304,12 +312,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval;
char ch = 'x';
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
+ usage();
if (ch == 'm' || ch == 'M')
- lval *= 1000L;
+ lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L;
} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
@@ -318,15 +326,15 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->optimize_coding = TRUE;
#else
fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n",
- progname);
+ progname);
exit(EXIT_FAILURE);
#endif
} else if (keymatch(arg, "outfile", 4)) {
/* Set output file name. */
- if (++argn >= argc) /* advance to next argument */
- usage();
- outfilename = argv[argn]; /* save it away for later use */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "progressive", 1)) {
/* Select simple progressive mode. */
@@ -335,7 +343,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* We must postpone execution until num_components is known. */
#else
fprintf(stderr, "%s: sorry, progressive output was not compiled in\n",
- progname);
+ progname);
exit(EXIT_FAILURE);
#endif
@@ -351,14 +359,14 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "quality", 1)) {
/* Quality ratings (quantization table scaling factors). */
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
qualityarg = argv[argn];
} else if (keymatch(arg, "qslots", 2)) {
/* Quantization table slot numbers. */
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
qslotsarg = argv[argn];
/* Must delay setting qslots until after we have processed any
* colorspace-determining switches, since jpeg_set_colorspace sets
@@ -367,8 +375,8 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "qtables", 2)) {
/* Quantization tables fetched from file. */
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
qtablefile = argv[argn];
/* We postpone actually reading the file in case -quality comes later. */
@@ -377,24 +385,24 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval;
char ch = 'x';
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
- usage();
+ usage();
if (lval < 0 || lval > 65535L)
- usage();
+ usage();
if (ch == 'b' || ch == 'B') {
- cinfo->restart_interval = (unsigned int) lval;
- cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
+ cinfo->restart_interval = (unsigned int) lval;
+ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
} else {
- cinfo->restart_in_rows = (int) lval;
- /* restart_interval will be computed during startup */
+ cinfo->restart_in_rows = (int) lval;
+ /* restart_interval will be computed during startup */
}
} else if (keymatch(arg, "sample", 2)) {
/* Set sampling factors. */
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
samplearg = argv[argn];
/* Must delay setting sample factors until after we have processed any
* colorspace-determining switches, since jpeg_set_colorspace sets
@@ -404,13 +412,13 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "scans", 4)) {
/* Set scan script. */
#ifdef C_MULTISCAN_FILES_SUPPORTED
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
scansarg = argv[argn];
/* We must postpone reading the file in case -progressive appears. */
#else
fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n",
- progname);
+ progname);
exit(EXIT_FAILURE);
#endif
@@ -418,12 +426,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set input smoothing factor. */
int val;
- if (++argn >= argc) /* advance to next argument */
- usage();
+ if (++argn >= argc) /* advance to next argument */
+ usage();
if (sscanf(argv[argn], "%d", &val) != 1)
- usage();
+ usage();
if (val < 0 || val > 100)
- usage();
+ usage();
cinfo->smoothing_factor = val;
} else if (keymatch(arg, "targa", 1)) {
@@ -431,7 +439,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
is_targa = TRUE;
} else {
- usage(); /* bogus switch */
+ usage(); /* bogus switch */
}
}
@@ -441,35 +449,35 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set quantization tables for selected quality. */
/* Some or all may be overridden if -qtables is present. */
- if (qualityarg != NULL) /* process -quality if it was present */
+ if (qualityarg != NULL) /* process -quality if it was present */
if (! set_quality_ratings(cinfo, qualityarg, force_baseline))
- usage();
+ usage();
- if (qtablefile != NULL) /* process -qtables if it was present */
+ if (qtablefile != NULL) /* process -qtables if it was present */
if (! read_quant_tables(cinfo, qtablefile, force_baseline))
- usage();
+ usage();
- if (qslotsarg != NULL) /* process -qslots if it was present */
+ if (qslotsarg != NULL) /* process -qslots if it was present */
if (! set_quant_slots(cinfo, qslotsarg))
- usage();
+ usage();
- if (samplearg != NULL) /* process -sample if it was present */
+ if (samplearg != NULL) /* process -sample if it was present */
if (! set_sample_factors(cinfo, samplearg))
- usage();
+ usage();
#ifdef C_PROGRESSIVE_SUPPORTED
- if (simple_progressive) /* process -progressive; -scans can override */
+ if (simple_progressive) /* process -progressive; -scans can override */
jpeg_simple_progression(cinfo);
#endif
#ifdef C_MULTISCAN_FILES_SUPPORTED
- if (scansarg != NULL) /* process -scans if it was present */
+ if (scansarg != NULL) /* process -scans if it was present */
if (! read_scan_script(cinfo, scansarg))
- usage();
+ usage();
#endif
}
- return argn; /* return index of next arg (file name) */
+ return argn; /* return index of next arg (file name) */
}
@@ -487,8 +495,8 @@ main (int argc, char **argv)
#endif
int file_index;
cjpeg_source_ptr src_mgr;
- FILE * input_file;
- FILE * output_file = NULL;
+ FILE *input_file;
+ FILE *output_file = NULL;
unsigned char *outbuffer = NULL;
unsigned long outsize = 0;
JDIMENSION num_scanlines;
@@ -500,7 +508,7 @@ main (int argc, char **argv)
progname = argv[0];
if (progname == NULL || progname[0] == 0)
- progname = "cjpeg"; /* in case C library doesn't provide it */
+ progname = "cjpeg"; /* in case C library doesn't provide it */
/* Initialize the JPEG compression object with default error handling. */
cinfo.err = jpeg_std_error(&jerr);
@@ -510,11 +518,6 @@ main (int argc, char **argv)
jerr.first_addon_message = JMSG_FIRSTADDONCODE;
jerr.last_addon_message = JMSG_LASTADDONCODE;
- /* Now safe to enable signal catcher. */
-#ifdef NEED_SIGNAL_CATCHER
- enable_signal_catcher((j_common_ptr) &cinfo);
-#endif
-
/* Initialize JPEG parameters.
* Much of this may be overridden later.
* In particular, we don't yet know the input file's color space,
@@ -637,5 +640,5 @@ main (int argc, char **argv)
/* All done. */
exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
- return 0; /* suppress no-return-value warnings */
+ return 0; /* suppress no-return-value warnings */
}

Powered by Google App Engine
This is Rietveld 408576698