jpegtran: Add option to copy only ICC markers
Closes #533
diff --git a/ChangeLog.md b/ChangeLog.md
index ca5208b..22bfa00 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -15,6 +15,10 @@
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
=====
diff --git a/jpegtran.1 b/jpegtran.1
index da7a266..5b1ded2 100644
--- a/jpegtran.1
+++ b/jpegtran.1
@@ -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 @@
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 @@
.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
diff --git a/jpegtran.c b/jpegtran.c
index 244996d..7dd2723 100644
--- a/jpegtran.c
+++ b/jpegtran.c
@@ -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 @@
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 @@
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 @@
fclose(icc_file);
if (copyoption == JCOPYOPT_ALL)
copyoption = JCOPYOPT_ALL_EXCEPT_ICC;
+ if (copyoption == JCOPYOPT_ICC)
+ copyoption = JCOPYOPT_NONE;
}
if (report) {
diff --git a/transupp.c b/transupp.c
index 6e86077..ce30ab7 100644
--- a/transupp.c
+++ b/transupp.c
@@ -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 @@
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 @@
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 */
}
diff --git a/transupp.h b/transupp.h
index ea6be1f..cea1f40 100644
--- a/transupp.h
+++ b/transupp.h
@@ -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 @@
*/
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 */
diff --git a/usage.txt b/usage.txt
index f7fa3c0..b60a593 100644
--- a/usage.txt
+++ b/usage.txt
@@ -601,6 +601,9 @@
-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.