summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/libjpeg_turbo/djpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/libjpeg_turbo/djpeg.c')
-rw-r--r--chromium/third_party/libjpeg_turbo/djpeg.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/chromium/third_party/libjpeg_turbo/djpeg.c b/chromium/third_party/libjpeg_turbo/djpeg.c
index 2438856ef66..589c5805cb5 100644
--- a/chromium/third_party/libjpeg_turbo/djpeg.c
+++ b/chromium/third_party/libjpeg_turbo/djpeg.c
@@ -1,9 +1,10 @@
/*
* djpeg.c
*
+ * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
- * Copyright (C) 2010-2011, D. R. Commander.
- * This file is part of the Independent JPEG Group's software.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2010-2011, 2013, D. R. Commander.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains a command-line user interface for the JPEG decompressor.
@@ -86,6 +87,8 @@ static IMAGE_FORMATS requested_fmt;
static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */
+boolean memsrc; /* for -memsrc switch */
+#define INPUT_BUF_SIZE 4096
LOCAL(void)
@@ -156,6 +159,10 @@ usage (void)
#endif
fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
fprintf(stderr, " -outfile name Specify name for output file\n");
+#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
+ fprintf(stderr, " -memsrc Load input file into memory before decompressing\n");
+#endif
+
fprintf(stderr, " -verbose or -debug Emit debug output\n");
exit(EXIT_FAILURE);
}
@@ -179,6 +186,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
/* Set up default JPEG parameters. */
requested_fmt = DEFAULT_FMT; /* set default output file format */
outfilename = NULL;
+ memsrc = FALSE;
cinfo->err->trace_level = 0;
/* Scan command line options, adjust parameters */
@@ -246,7 +254,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
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 libjpeg, version %s\n\n",
+ fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION);
printed_version = TRUE;
}
@@ -324,6 +332,16 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
usage();
outfilename = argv[argn]; /* save it away for later use */
+ } else if (keymatch(arg, "memsrc", 2)) {
+ /* Use in-memory source manager */
+#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
+ memsrc = TRUE;
+#else
+ fprintf(stderr, "%s: sorry, in-memory source manager was not compiled in\n",
+ progname);
+ exit(EXIT_FAILURE);
+#endif
+
} else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
/* PPM/PGM output format. */
requested_fmt = FMT_PPM;
@@ -442,6 +460,8 @@ main (int argc, char **argv)
djpeg_dest_ptr dest_mgr = NULL;
FILE * input_file;
FILE * output_file;
+ unsigned char *inbuffer = NULL;
+ unsigned long insize = 0;
JDIMENSION num_scanlines;
/* On Mac, fetch a command line. */
@@ -536,7 +556,30 @@ main (int argc, char **argv)
#endif
/* Specify data source for decompression */
- jpeg_stdio_src(&cinfo, input_file);
+#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
+ if (memsrc) {
+ size_t nbytes;
+ do {
+ inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE);
+ if (inbuffer == NULL) {
+ fprintf(stderr, "%s: memory allocation failure\n", progname);
+ exit(EXIT_FAILURE);
+ }
+ nbytes = JFREAD(input_file, &inbuffer[insize], INPUT_BUF_SIZE);
+ if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) {
+ if (file_index < argc)
+ fprintf(stderr, "%s: can't read from %s\n", progname,
+ argv[file_index]);
+ else
+ fprintf(stderr, "%s: can't read from stdin\n", progname);
+ }
+ insize += (unsigned long)nbytes;
+ } while (nbytes == INPUT_BUF_SIZE);
+ fprintf(stderr, "Compressed size: %lu bytes\n", insize);
+ jpeg_mem_src(&cinfo, inbuffer, insize);
+ } else
+#endif
+ jpeg_stdio_src(&cinfo, input_file);
/* Read file header, set default decompression parameters */
(void) jpeg_read_header(&cinfo, TRUE);
@@ -620,6 +663,9 @@ main (int argc, char **argv)
end_progress_monitor((j_common_ptr) &cinfo);
#endif
+ if (memsrc && inbuffer != NULL)
+ free(inbuffer);
+
/* All done. */
exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */