Add fault tolerance features to djpeg and jpegtran

- Enable progress reporting at run time using a new -report argument
  (cjpeg now supports that argument as well)
- Limit the allowable number of scans using a new -maxscans argument
- Treat warnings as fatal using a new -strict argument

This mainly demonstrates how to work around the two issues with the
JPEG standard described here:
https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf
since those and similar issues continue to be erroneously reported as
libjpeg-turbo bugs.
This commit is contained in:
DRC
2019-12-18 15:12:33 -06:00
parent 54288598bb
commit e98b061282
9 changed files with 205 additions and 54 deletions

22
cjpeg.c
View File

@@ -5,7 +5,7 @@
* Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2011 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2010, 2013-2014, 2017, D. R. Commander.
* Copyright (C) 2010, 2013-2014, 2017, 2019, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -147,6 +147,7 @@ static const char *progname; /* program name for error messages */
static char *icc_filename; /* for -icc switch */
static char *outfilename; /* for -outfile switch */
boolean memdst; /* for -memdst switch */
boolean report; /* for -report switch */
LOCAL(void)
@@ -200,6 +201,7 @@ usage(void)
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
fprintf(stderr, " -memdst Compress to memory instead of file (useful for benchmarking)\n");
#endif
fprintf(stderr, " -report Report compression progress\n");
fprintf(stderr, " -verbose or -debug Emit debug output\n");
fprintf(stderr, " -version Print version information and exit\n");
fprintf(stderr, "Switches for wizards:\n");
@@ -244,6 +246,7 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
icc_filename = NULL;
outfilename = NULL;
memdst = FALSE;
report = FALSE;
cinfo->err->trace_level = 0;
/* Scan command line options, adjust parameters */
@@ -395,6 +398,9 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
qtablefile = argv[argn];
/* We postpone actually reading the file in case -quality comes later. */
} else if (keymatch(arg, "report", 3)) {
report = TRUE;
} else if (keymatch(arg, "restart", 1)) {
/* Restart interval in MCU rows (or in MCUs with 'b'). */
long lval;
@@ -505,9 +511,7 @@ main(int argc, char **argv)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
#ifdef PROGRESS_REPORT
struct cdjpeg_progress_mgr progress;
#endif
int file_index;
cjpeg_source_ptr src_mgr;
FILE *input_file;
@@ -628,9 +632,10 @@ main(int argc, char **argv)
fclose(icc_file);
}
#ifdef PROGRESS_REPORT
start_progress_monitor((j_common_ptr)&cinfo, &progress);
#endif
if (report) {
start_progress_monitor((j_common_ptr)&cinfo, &progress);
progress.report = report;
}
/* Figure out the input file format, and set up to read it. */
src_mgr = select_file_type(&cinfo, input_file);
@@ -676,9 +681,8 @@ main(int argc, char **argv)
if (output_file != stdout && output_file != NULL)
fclose(output_file);
#ifdef PROGRESS_REPORT
end_progress_monitor((j_common_ptr)&cinfo);
#endif
if (report)
end_progress_monitor((j_common_ptr)&cinfo);
if (memdst) {
fprintf(stderr, "Compressed size: %lu bytes\n", outsize);