Update libjpeg-turbo to 2.0.0
Bug: 78329453
Update to upstream at https://github.com/libjpeg-turbo/libjpeg-turbo/tree/2.0.0
This includes a fix for a bug that could result in an infinite loop.
ChangeLog.md contains detailed changes about the upstream library. Changes
I made are below:
- Remove files that are no longer in upstream, and include all current
files from upstream.
- Update various references to the version.
Android.bp:
- Update to build new files/files in new locations.
- Run bpfmt
README.android:
- Remove cherry-pick references, as they are no longer needed.
- Remove modification in jsimdext.inc, which no longer appears to be
necessary.
README.version:
- Use the github URL, as it is now the official upstream build
- Replace msarett as OWNER, as he no longer works on this project
- Update the version
Change-Id: Ie6cfee5a8f820f28656bbb305f500e75e7ce7915
diff --git a/jpegtran.c b/jpegtran.c
index 6f8fd5b..058e844 100644
--- a/jpegtran.c
+++ b/jpegtran.c
@@ -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 @@
#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");
@@ -97,7 +99,7 @@
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 @@
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 @@
/* Set up default JPEG parameters. */
simple_progressive = FALSE;
+ icc_filename = NULL;
outfilename = NULL;
copyoption = JCOPYOPT_DEFAULT;
transformoption.transform = JXFORM_NONE;
@@ -190,7 +193,7 @@
#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 @@
/* 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 @@
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 @@
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 @@
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 @@
#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 @@
*/
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 @@
* 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 @@
#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 @@
}
#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 @@
/* 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 @@
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 @@
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 @@
/* 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 @@
/* 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 @@
/* 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 @@
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 */
}