From bbc2f8ffae939eab598f583514fb132d23c11705 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 26 Jan 2020 15:07:18 -0500 Subject: Bug fix: handle ColorSpace lookup for inline images (fixes #392) If the value of /CS in the inline image dictionary was is key in the page's /Resource -> /ColorSpace dictionary, properly resolve it by referencing the proper colorspace, and not just the name, in the external image dictionary. --- ChangeLog | 4 ++++ libqpdf/QPDFPageObjectHelper.cc | 16 ++++++++++++++++ qpdf/qpdf.testcov | 1 + qpdf/qtest/qpdf.test | 12 +++++++++++- qpdf/qtest/qpdf/inline-image-colorspace-lookup-out.pdf | Bin 0 -> 1348 bytes qpdf/qtest/qpdf/inline-image-colorspace-lookup.pdf | Bin 0 -> 1176 bytes 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 qpdf/qtest/qpdf/inline-image-colorspace-lookup-out.pdf create mode 100644 qpdf/qtest/qpdf/inline-image-colorspace-lookup.pdf diff --git a/ChangeLog b/ChangeLog index 68aff3fe..38749752 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-01-26 Jay Berkenbilt + * Bug fix: when externalizing inline images, a colorspace value + that was a lookup key in the page's /Resource -> /ColorSpace + dictionary was not properly handled. Fixes #392. + * Add "encrypt" key to the json output. This contains largely the same information as given by --show-encryption but in a consistent, parseable format. diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index d588c322..01f1d662 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -141,6 +141,22 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) } else { + // This is a key in the page's /Resources -> + // /ColorSpace dictionary. We need to look it up + // and use its value as the color space for the + // image. + QPDFObjectHandle colorspace = + resources.getKey("/ColorSpace"); + if (colorspace.isDictionary() && colorspace.hasKey(name)) + { + QTC::TC("qpdf", "QPDFPageObjectHelper colorspace lookup"); + value = colorspace.getKey(name); + } + else + { + resources.warnIfPossible( + "unable to resolve colorspace " + name); + } name.clear(); } if (! name.empty()) diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 82ac9684..db3de950 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -447,3 +447,4 @@ QPDF_encryption same password 1 QPDFWriter stream in ostream 0 QPDFObjectHandle duplicate dict key 0 QPDFWriter no encryption sig contents 0 +QPDFPageObjectHelper colorspace lookup 0 diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index bfc20178..f9bab01f 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -809,7 +809,7 @@ $td->runtest("check pass1 file", show_ntests(); # ---------- $td->notify("--- Inline Images ---"); -$n_tests += 8; +$n_tests += 10; # The file large-inline-image.pdf is a hand-crafted file with several # inline images of various sizes including one that is two megabytes, @@ -853,6 +853,16 @@ $td->runtest("externalize damaged image", $td->runtest("check output", {$td->FILE => "a.pdf"}, {$td->FILE => "damaged-inline-image-out.pdf"}); +$td->runtest("named colorspace", + {$td->COMMAND => + "qpdf --static-id --externalize-inline-images" . + " --ii-min-bytes=0 inline-image-colorspace-lookup.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "inline-image-colorspace-lookup-out.pdf"}); + my @eii_tests = ( ['inline-images', 80], diff --git a/qpdf/qtest/qpdf/inline-image-colorspace-lookup-out.pdf b/qpdf/qtest/qpdf/inline-image-colorspace-lookup-out.pdf new file mode 100644 index 00000000..5fa0ed6c Binary files /dev/null and b/qpdf/qtest/qpdf/inline-image-colorspace-lookup-out.pdf differ diff --git a/qpdf/qtest/qpdf/inline-image-colorspace-lookup.pdf b/qpdf/qtest/qpdf/inline-image-colorspace-lookup.pdf new file mode 100644 index 00000000..30584737 Binary files /dev/null and b/qpdf/qtest/qpdf/inline-image-colorspace-lookup.pdf differ -- cgit v1.2.3-54-g00ecf