summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Knechtges <philipp-dev@knechtges.com>2020-05-30 19:18:53 +0200
committerPhilipp Knechtges <philipp-dev@knechtges.com>2020-06-03 19:29:22 +0200
commit6bf89c78447692ed781918b7cb3fadb21aa0cf89 (patch)
tree77c652d373efa6cfffb36fec1bfa0a20ba136267
parenta628cbb6da948bb3e508f120a4deb76257b96dd3 (diff)
pdftoppm: add option to set display profile
-rw-r--r--utils/CMakeLists.txt3
-rw-r--r--utils/pdftoppm.14
-rw-r--r--utils/pdftoppm.cc55
3 files changed, 62 insertions, 0 deletions
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index 80f54245..c3df0c3f 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -14,6 +14,9 @@ if (ENABLE_SPLASH)
)
add_executable(pdftoppm ${pdftoppm_SOURCES})
target_link_libraries(pdftoppm ${common_libs})
+ if(LCMS2_FOUND)
+ target_link_libraries(pdftoppm ${LCMS2_LIBRARIES})
+ endif()
install(TARGETS pdftoppm DESTINATION bin)
install(FILES pdftoppm.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
endif ()
diff --git a/utils/pdftoppm.1 b/utils/pdftoppm.1
index 472f6f21..22f0bd29 100644
--- a/utils/pdftoppm.1
+++ b/utils/pdftoppm.1
@@ -92,6 +92,10 @@ Generate a monochrome PBM file (instead of a color PPM file).
.B \-gray
Generate a grayscale PGM file (instead of a color PPM file).
.TP
+.BI \-displayprofile " displayprofilefile"
+If poppler is compiled with colour management support, this option sets the display profile
+to the ICC profile stored in displayprofilefile.
+.TP
.B \-png
Generates a PNG file instead a PPM file.
.TP
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index a079e680..2652f799 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -72,6 +72,10 @@
#include <deque>
#endif // UTILS_USE_PTHREADS
+#ifdef USE_CMS
+#include <lcms2.h>
+#endif
+
static int firstPage = 1;
static int lastPage = 0;
static bool printOnlyOdd = false;
@@ -93,6 +97,10 @@ static bool hideAnnotations = false;
static bool useCropBox = false;
static bool mono = false;
static bool gray = false;
+#ifdef USE_CMS
+static GooString displayprofilename;
+static GfxLCMSProfilePtr displayprofile;
+#endif
static char sep[2] = "-";
static bool forceNum = false;
static bool png = false;
@@ -168,6 +176,10 @@ static const ArgDesc argDesc[] = {
"generate a monochrome PBM file"},
{"-gray", argFlag, &gray, 0,
"generate a grayscale PGM file"},
+#ifdef USE_CMS
+ {"-displayprofile", argGooString, &displayprofilename, 0,
+ "ICC color profile to use as the display profile"},
+#endif
{"-sep", argString, sep, sizeof(sep),
"single character separator between name and page number, default - "},
{"-forcenum", argFlag, &forceNum, 0,
@@ -388,6 +400,9 @@ static void processPageJobs() {
splashOut->setFontAntialias(fontAntialias);
splashOut->setVectorAntialias(vectorAntialias);
splashOut->setEnableFreeType(enableFreeType);
+#ifdef USE_CMS
+ splashOut->setDisplayProfile(displayprofile);
+#endif
splashOut->startDoc(pageJob.doc);
savePageSlice(pageJob.doc, splashOut, pageJob.pg, x, y, w, h, pageJob.pg_w, pageJob.pg_h, pageJob.ppmFile);
@@ -415,6 +430,9 @@ int main(int argc, char *argv[]) {
int exitCode;
int pg, pg_num_len;
double pg_w, pg_h;
+#ifdef USE_CMS
+ cmsColorSpaceSignature displayprofilecolorspace;
+#endif
Win32Console win32Console(&argc, &argv);
exitCode = 99;
@@ -557,6 +575,40 @@ int main(int argc, char *argv[]) {
paperColor[1] = 255;
paperColor[2] = 255;
}
+
+#ifdef USE_CMS
+ if (!displayprofilename.toStr().empty()) {
+ displayprofile = make_GfxLCMSProfilePtr(cmsOpenProfileFromFile(displayprofilename.c_str(),"r"));
+ if (!displayprofile) {
+ fprintf(stderr, "Could not open the ICC profile \"%s\".\n", displayprofilename.c_str());
+ goto err1;
+ }
+ if(!cmsIsIntentSupported(displayprofile.get(), INTENT_RELATIVE_COLORIMETRIC, LCMS_USED_AS_OUTPUT) &&
+ !cmsIsIntentSupported(displayprofile.get(), INTENT_ABSOLUTE_COLORIMETRIC, LCMS_USED_AS_OUTPUT) &&
+ !cmsIsIntentSupported(displayprofile.get(), INTENT_SATURATION, LCMS_USED_AS_OUTPUT) &&
+ !cmsIsIntentSupported(displayprofile.get(), INTENT_PERCEPTUAL, LCMS_USED_AS_OUTPUT)) {
+ fprintf(stderr, "ICC profile \"%s\" is not an output profile.\n", displayprofilename.c_str());
+ goto err1;
+ }
+ displayprofilecolorspace = cmsGetColorSpace(displayprofile.get());
+ if (jpegcmyk || overprint) {
+ if (displayprofilecolorspace != cmsSigCmykData) {
+ fprintf(stderr, "Warning: Supplied ICC profile \"%s\" is not a CMYK profile.\n",
+ displayprofilename.c_str());
+ }
+ } else if (mono || gray) {
+ if (displayprofilecolorspace != cmsSigGrayData) {
+ fprintf(stderr, "Warning: Supplied ICC profile \"%s\" is not a monochrome profile.\n",
+ displayprofilename.c_str());
+ }
+ } else {
+ if (displayprofilecolorspace != cmsSigRgbData) {
+ fprintf(stderr, "Warning: Supplied ICC profile \"%s\" is not a RGB profile.\n",
+ displayprofilename.c_str());
+ }
+ }
+ }
+#endif
#ifndef UTILS_USE_PTHREADS
@@ -571,6 +623,9 @@ int main(int argc, char *argv[]) {
splashOut->setFontAntialias(fontAntialias);
splashOut->setVectorAntialias(vectorAntialias);
splashOut->setEnableFreeType(enableFreeType);
+#ifdef USE_CMS
+ splashOut->setDisplayProfile(displayprofile);
+#endif
splashOut->startDoc(doc);
#endif // UTILS_USE_PTHREADS