diff --git a/ChangeLog b/ChangeLog index 68aff3f..3874975 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 d588c32..01f1d66 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 82ac968..db3de95 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 bfc2017..f9bab01 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 0000000..5fa0ed6 --- /dev/null +++ b/qpdf/qtest/qpdf/inline-image-colorspace-lookup-out.pdf 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 0000000..3058473 --- /dev/null +++ b/qpdf/qtest/qpdf/inline-image-colorspace-lookup.pdf