diff options
author | Chris Blume <cblume@chromium.org> | 2019-03-01 01:09:50 -0800 |
---|---|---|
committer | Chris Blume <cblume@chromium.org> | 2019-03-01 01:09:50 -0800 |
commit | cca8c4dec783a048da6933c86028556622d7c355 (patch) | |
tree | 8a7ff526cd8cbe3bf1bfaa4ec1c29fe3268ed51b /jpegtran.c | |
parent | 61a2bbaa9aec89cb2c882d87ace6aba9aee49bb9 (diff) |
Update libjpeg-turbo to v2.0.1
In order to apply some performance updates from ARM, we need to update
libjpeg-turbo. These performance updates have yielded a 50% speedup on
some devices.
This CL updates our copy of libjpeg-turbo to v2.0.1 and re-applies our
local patches. This patch also deletes some extra files which were not
being used locally.
Update our local patch that was applied to fix http://crbug.com/398235
(https://codereview.appspot.com/229430043/). The original patch
incorrectly removed "& 0xFF" which limited an array index to within
that array's bounds (effectively reverting
https://github.com/libjpeg-turbo/libjpeg-turbo/commit/fa1d18385d904d530b4aec83ab7757a33397de6e).
Restore the mask, making the array access safe and fixing a graphical
glitch which would otherwise be introduced by this change.
Bug:922430
Change-Id: I3860fdb424deecf7a17818ed09a640e632e71f8d
Diffstat (limited to 'jpegtran.c')
-rw-r--r-- | jpegtran.c | 104 |
1 files changed, 77 insertions, 27 deletions
@@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1995-2010, Thomas G. Lane, Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2014, D. R. Commander. + * Copyright (C) 2010, 2014, 2017, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -40,13 +40,14 @@ static const char *progname; /* program name for error messages */ +static char *icc_filename; /* for -icc switch */ static char *outfilename; /* for -outfile switch */ static JCOPY_OPTION copyoption; /* -copy switch */ static jpeg_transform_info transformoption; /* image transformation options */ LOCAL(void) -usage (void) +usage(void) /* complain about bad command line */ { fprintf(stderr, "usage: %s [switches] ", progname); @@ -83,6 +84,7 @@ usage (void) #ifdef C_ARITH_CODING_SUPPORTED fprintf(stderr, " -arithmetic Use arithmetic coding\n"); #endif + fprintf(stderr, " -icc FILE Embed ICC profile contained in FILE\n"); fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); fprintf(stderr, " -outfile name Specify name for output file\n"); @@ -90,14 +92,14 @@ usage (void) fprintf(stderr, " -version Print version information and exit\n"); fprintf(stderr, "Switches for wizards:\n"); #ifdef C_MULTISCAN_FILES_SUPPORTED - fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); + fprintf(stderr, " -scans FILE Create multi-scan JPEG per script FILE\n"); #endif exit(EXIT_FAILURE); } LOCAL(void) -select_transform (JXFORM_CODE transform) +select_transform(JXFORM_CODE transform) /* Silly little routine to detect multiple transform options, * which we can't handle. */ @@ -120,8 +122,8 @@ select_transform (JXFORM_CODE transform) LOCAL(int) -parse_switches (j_compress_ptr cinfo, int argc, char **argv, - int last_file_arg_seen, boolean for_real) +parse_switches(j_compress_ptr cinfo, int argc, char **argv, + 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; @@ -138,6 +140,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, /* Set up default JPEG parameters. */ simple_progressive = FALSE; + icc_filename = NULL; outfilename = NULL; copyoption = JCOPYOPT_DEFAULT; transformoption.transform = JXFORM_NONE; @@ -190,7 +193,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, #if TRANSFORMS_SUPPORTED if (++argn >= argc) /* advance to next argument */ usage(); - if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) { + if (!jtransform_parse_crop_spec(&transformoption, argv[argn])) { fprintf(stderr, "%s: bogus -crop argument '%s'\n", progname, argv[argn]); exit(EXIT_FAILURE); @@ -204,7 +207,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, /* On first -d, print version identification */ static boolean printed_version = FALSE; - if (! printed_version) { + if (!printed_version) { fprintf(stderr, "%s version %s (build %s)\n", PACKAGE_NAME, VERSION, BUILD); fprintf(stderr, "%s\n\n", JCOPYRIGHT); @@ -230,7 +233,8 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, else usage(); - } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) { + } else if (keymatch(arg, "grayscale", 1) || + keymatch(arg, "greyscale", 1)) { /* Force to grayscale. */ #if TRANSFORMS_SUPPORTED transformoption.force_grayscale = TRUE; @@ -238,6 +242,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, select_transform(JXFORM_NONE); /* force an error */ #endif + } else if (keymatch(arg, "icc", 1)) { + /* Set ICC filename. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + icc_filename = argv[argn]; + } else if (keymatch(arg, "maxmemory", 3)) { /* Maximum memory in Kb (or Mb with 'm'). */ long lval; @@ -295,10 +305,10 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, if (lval < 0 || lval > 65535L) usage(); if (ch == 'b' || ch == 'B') { - cinfo->restart_interval = (unsigned int) lval; + cinfo->restart_interval = (unsigned int)lval; cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ } else { - cinfo->restart_in_rows = (int) lval; + cinfo->restart_in_rows = (int)lval; /* restart_interval will be computed during startup */ } @@ -356,7 +366,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, #ifdef C_MULTISCAN_FILES_SUPPORTED if (scansarg != NULL) /* process -scans if it was present */ - if (! read_scan_script(cinfo, scansarg)) + if (!read_scan_script(cinfo, scansarg)) usage(); #endif } @@ -370,7 +380,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, */ int -main (int argc, char **argv) +main(int argc, char **argv) { struct jpeg_decompress_struct srcinfo; struct jpeg_compress_struct dstinfo; @@ -385,6 +395,9 @@ main (int argc, char **argv) * single file pointer for sequential input and output operation. */ FILE *fp; + FILE *icc_file; + JOCTET *icc_profile = NULL; + long icc_len = 0; /* On Mac, fetch a command line. */ #ifdef USE_CCOMMAND @@ -417,14 +430,14 @@ main (int argc, char **argv) #ifdef TWO_FILE_COMMANDLINE /* Must have either -outfile switch or explicit output file name */ if (outfilename == NULL) { - if (file_index != argc-2) { + if (file_index != argc - 2) { fprintf(stderr, "%s: must name one input and one output file\n", progname); usage(); } - outfilename = argv[file_index+1]; + outfilename = argv[file_index + 1]; } else { - if (file_index != argc-1) { + if (file_index != argc - 1) { fprintf(stderr, "%s: must name one input and one output file\n", progname); usage(); @@ -432,7 +445,7 @@ main (int argc, char **argv) } #else /* Unix style: expect zero or one file name */ - if (file_index < argc-1) { + if (file_index < argc - 1) { fprintf(stderr, "%s: only one input file\n", progname); usage(); } @@ -441,7 +454,8 @@ main (int argc, char **argv) /* Open the input file. */ if (file_index < argc) { if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s for reading\n", progname, argv[file_index]); + fprintf(stderr, "%s: can't open %s for reading\n", progname, + argv[file_index]); exit(EXIT_FAILURE); } } else { @@ -449,8 +463,37 @@ main (int argc, char **argv) fp = read_stdin(); } + if (icc_filename != NULL) { + if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, icc_filename); + exit(EXIT_FAILURE); + } + if (fseek(icc_file, 0, SEEK_END) < 0 || + (icc_len = ftell(icc_file)) < 1 || + fseek(icc_file, 0, SEEK_SET) < 0) { + fprintf(stderr, "%s: can't determine size of %s\n", progname, + icc_filename); + exit(EXIT_FAILURE); + } + if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) { + fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname); + fclose(icc_file); + exit(EXIT_FAILURE); + } + if (fread(icc_profile, icc_len, 1, icc_file) < 1) { + fprintf(stderr, "%s: can't read ICC profile from %s\n", progname, + icc_filename); + free(icc_profile); + fclose(icc_file); + exit(EXIT_FAILURE); + } + fclose(icc_file); + if (copyoption == JCOPYOPT_ALL) + copyoption = JCOPYOPT_ALL_EXCEPT_ICC; + } + #ifdef PROGRESS_REPORT - start_progress_monitor((j_common_ptr) &dstinfo, &progress); + start_progress_monitor((j_common_ptr)&dstinfo, &progress); #endif /* Specify data source for decompression */ @@ -460,7 +503,7 @@ main (int argc, char **argv) jcopy_markers_setup(&srcinfo, copyoption); /* Read file header */ - (void) jpeg_read_header(&srcinfo, TRUE); + (void)jpeg_read_header(&srcinfo, TRUE); /* Any space needed by a transform option must be requested before * jpeg_read_coefficients so that memory allocation will be done right. @@ -494,7 +537,7 @@ main (int argc, char **argv) /* Close input file, if we opened it. * Note: we assume that jpeg_read_coefficients consumed all input * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will - * only consume more while (! cinfo->inputctl->eoi_reached). + * only consume more while (!cinfo->inputctl->eoi_reached). * We cannot call jpeg_finish_decompress here since we still need the * virtual arrays allocated from the source object for processing. */ @@ -504,7 +547,8 @@ main (int argc, char **argv) /* Open the output file. */ if (outfilename != NULL) { if ((fp = fopen(outfilename, WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s for writing\n", progname, outfilename); + fprintf(stderr, "%s: can't open %s for writing\n", progname, + outfilename); exit(EXIT_FAILURE); } } else { @@ -524,17 +568,19 @@ main (int argc, char **argv) /* Copy to the output file any extra markers that we want to preserve */ jcopy_markers_execute(&srcinfo, &dstinfo, copyoption); + if (icc_profile != NULL) + jpeg_write_icc_profile(&dstinfo, icc_profile, (unsigned int)icc_len); + /* Execute image transformation, if any */ #if TRANSFORMS_SUPPORTED - jtransform_execute_transformation(&srcinfo, &dstinfo, - src_coef_arrays, + jtransform_execute_transformation(&srcinfo, &dstinfo, src_coef_arrays, &transformoption); #endif /* Finish compression and release memory */ jpeg_finish_compress(&dstinfo); jpeg_destroy_compress(&dstinfo); - (void) jpeg_finish_decompress(&srcinfo); + (void)jpeg_finish_decompress(&srcinfo); jpeg_destroy_decompress(&srcinfo); /* Close output file, if we opened it */ @@ -542,10 +588,14 @@ main (int argc, char **argv) fclose(fp); #ifdef PROGRESS_REPORT - end_progress_monitor((j_common_ptr) &dstinfo); + end_progress_monitor((j_common_ptr)&dstinfo); #endif + if (icc_profile != NULL) + free(icc_profile); + /* All done. */ - exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); + exit(jsrcerr.num_warnings + jdsterr.num_warnings ? + EXIT_WARNING : EXIT_SUCCESS); return 0; /* suppress no-return-value warnings */ } |