jpegtran: Add option to copy only ICC markers

Closes #533
This commit is contained in:
DRC
2021-07-13 11:52:49 -05:00
parent b201838d8b
commit 4d9f256b01
6 changed files with 31 additions and 10 deletions

View File

@@ -15,6 +15,10 @@ undefined C compiler behavior led to crashes ("SIGBUS: illegal alignment") on
Android systems when running AArch32/Thumb builds of libjpeg-turbo built with
recent versions of Clang.
4. Added a command-line argument (`-copy icc`) to jpegtran that causes it to
copy only the ICC profile markers from the source file and discard any other
metadata.
2.1.0
=====

View File

@@ -1,4 +1,4 @@
.TH JPEGTRAN 1 "26 October 2020"
.TH JPEGTRAN 1 "13 July 2021"
.SH NAME
jpegtran \- lossless transformation of JPEG files
.SH SYNOPSIS
@@ -247,6 +247,10 @@ comments and other metadata in the source file.
Copy only comment markers. This setting copies comments from the source file
but discards any other metadata.
.TP
.B \-copy icc
Copy only ICC profile markers. This setting copies the ICC profile from the
source file but discards any other metadata.
.TP
.B \-copy all
Copy all extra markers. This setting preserves miscellaneous markers
found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
@@ -261,7 +265,7 @@ Additional switches recognized by jpegtran are:
.BI \-icc " file"
Embed ICC color management profile contained in the specified file. Note that
this will cause \fBjpegtran\fR to ignore any APP2 markers in the input file,
even if \fB-copy all\fR is specified.
even if \fB-copy all\fR or \fB-copy icc\fR is specified.
.TP
.BI \-maxmemory " N"
Set limit for amount of memory to use in processing large images. Value is

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-2019, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2010, 2014, 2017, 2019-2020, D. R. Commander.
* Copyright (C) 2010, 2014, 2017, 2019-2021, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -64,6 +64,7 @@ usage(void)
fprintf(stderr, "Switches (names may be abbreviated):\n");
fprintf(stderr, " -copy none Copy no extra markers from source file\n");
fprintf(stderr, " -copy comments Copy only comment markers (default)\n");
fprintf(stderr, " -copy icc Copy only ICC profile markers\n");
fprintf(stderr, " -copy all Copy all extra markers\n");
#ifdef ENTROPY_OPT_SUPPORTED
fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
@@ -196,6 +197,8 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
copyoption = JCOPYOPT_NONE;
} else if (keymatch(argv[argn], "comments", 1)) {
copyoption = JCOPYOPT_COMMENTS;
} else if (keymatch(argv[argn], "icc", 1)) {
copyoption = JCOPYOPT_ICC;
} else if (keymatch(argv[argn], "all", 1)) {
copyoption = JCOPYOPT_ALL;
} else
@@ -570,6 +573,8 @@ main(int argc, char **argv)
fclose(icc_file);
if (copyoption == JCOPYOPT_ALL)
copyoption = JCOPYOPT_ALL_EXCEPT_ICC;
if (copyoption == JCOPYOPT_ICC)
copyoption = JCOPYOPT_NONE;
}
if (report) {

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1997-2019, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2010, 2017, D. R. Commander.
* Copyright (C) 2010, 2017, 2021, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -2310,7 +2310,7 @@ jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option)
int m;
/* Save comments except under NONE option */
if (option != JCOPYOPT_NONE) {
if (option != JCOPYOPT_NONE && option != JCOPYOPT_ICC) {
jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
}
/* Save all types of APPn markers iff ALL option */
@@ -2321,6 +2321,10 @@ jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option)
jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
}
}
/* Save only APP2 markers if ICC option selected */
if (option == JCOPYOPT_ICC) {
jpeg_save_markers(srcinfo, JPEG_APP0 + 2, 0xFFFF);
}
#endif /* SAVE_MARKERS_SUPPORTED */
}

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1997-2019, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2017, D. R. Commander.
* Copyright (C) 2017, 2021, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -213,10 +213,11 @@ EXTERN(boolean) jtransform_perfect_transform(JDIMENSION image_width,
*/
typedef enum {
JCOPYOPT_NONE, /* copy no optional markers */
JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
JCOPYOPT_ALL, /* copy all optional markers */
JCOPYOPT_ALL_EXCEPT_ICC /* copy all optional markers except APP2 */
JCOPYOPT_NONE, /* copy no optional markers */
JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
JCOPYOPT_ALL, /* copy all optional markers */
JCOPYOPT_ALL_EXCEPT_ICC, /* copy all optional markers except APP2 */
JCOPYOPT_ICC /* copy only ICC profile (APP2) markers */
} JCOPY_OPTION;
#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */

View File

@@ -601,6 +601,9 @@ markers, such as comment blocks:
-copy comments Copy only comment markers. This setting copies
comments from the source file but discards any other
metadata.
-copy icc Copy only ICC profile markers. This setting copies the
ICC profile from the source file but discards any other
metadata.
-copy all Copy all extra markers. This setting preserves
miscellaneous markers found in the source file, such
as JFIF thumbnails, Exif data, and Photoshop settings.