Commit bbc2f8ffae939eab598f583514fb132d23c11705

Authored by Jay Berkenbilt
1 parent 12777a04

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
1 2020-01-26 Jay Berkenbilt <ejb@ql.org> 1 2020-01-26 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Bug fix: when externalizing inline images, a colorspace value
  4 + that was a lookup key in the page's /Resource -> /ColorSpace
  5 + dictionary was not properly handled. Fixes #392.
  6 +
3 * Add "encrypt" key to the json output. This contains largely the 7 * Add "encrypt" key to the json output. This contains largely the
4 same information as given by --show-encryption but in a 8 same information as given by --show-encryption but in a
5 consistent, parseable format. 9 consistent, parseable format.
libqpdf/QPDFPageObjectHelper.cc
@@ -141,6 +141,22 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) @@ -141,6 +141,22 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict)
141 } 141 }
142 else 142 else
143 { 143 {
  144 + // This is a key in the page's /Resources ->
  145 + // /ColorSpace dictionary. We need to look it up
  146 + // and use its value as the color space for the
  147 + // image.
  148 + QPDFObjectHandle colorspace =
  149 + resources.getKey("/ColorSpace");
  150 + if (colorspace.isDictionary() && colorspace.hasKey(name))
  151 + {
  152 + QTC::TC("qpdf", "QPDFPageObjectHelper colorspace lookup");
  153 + value = colorspace.getKey(name);
  154 + }
  155 + else
  156 + {
  157 + resources.warnIfPossible(
  158 + "unable to resolve colorspace " + name);
  159 + }
144 name.clear(); 160 name.clear();
145 } 161 }
146 if (! name.empty()) 162 if (! name.empty())
qpdf/qpdf.testcov
@@ -447,3 +447,4 @@ QPDF_encryption same password 1 @@ -447,3 +447,4 @@ QPDF_encryption same password 1
447 QPDFWriter stream in ostream 0 447 QPDFWriter stream in ostream 0
448 QPDFObjectHandle duplicate dict key 0 448 QPDFObjectHandle duplicate dict key 0
449 QPDFWriter no encryption sig contents 0 449 QPDFWriter no encryption sig contents 0
  450 +QPDFPageObjectHelper colorspace lookup 0
qpdf/qtest/qpdf.test
@@ -809,7 +809,7 @@ $td-&gt;runtest(&quot;check pass1 file&quot;, @@ -809,7 +809,7 @@ $td-&gt;runtest(&quot;check pass1 file&quot;,
809 show_ntests(); 809 show_ntests();
810 # ---------- 810 # ----------
811 $td->notify("--- Inline Images ---"); 811 $td->notify("--- Inline Images ---");
812 -$n_tests += 8; 812 +$n_tests += 10;
813 813
814 # The file large-inline-image.pdf is a hand-crafted file with several 814 # The file large-inline-image.pdf is a hand-crafted file with several
815 # inline images of various sizes including one that is two megabytes, 815 # inline images of various sizes including one that is two megabytes,
@@ -853,6 +853,16 @@ $td-&gt;runtest(&quot;externalize damaged image&quot;, @@ -853,6 +853,16 @@ $td-&gt;runtest(&quot;externalize damaged image&quot;,
853 $td->runtest("check output", 853 $td->runtest("check output",
854 {$td->FILE => "a.pdf"}, 854 {$td->FILE => "a.pdf"},
855 {$td->FILE => "damaged-inline-image-out.pdf"}); 855 {$td->FILE => "damaged-inline-image-out.pdf"});
  856 +$td->runtest("named colorspace",
  857 + {$td->COMMAND =>
  858 + "qpdf --static-id --externalize-inline-images" .
  859 + " --ii-min-bytes=0 inline-image-colorspace-lookup.pdf a.pdf"},
  860 + {$td->STRING => "", $td->EXIT_STATUS => 0},
  861 + $td->NORMALIZE_NEWLINES);
  862 +$td->runtest("check output",
  863 + {$td->FILE => "a.pdf"},
  864 + {$td->FILE => "inline-image-colorspace-lookup-out.pdf"});
  865 +
856 866
857 my @eii_tests = ( 867 my @eii_tests = (
858 ['inline-images', 80], 868 ['inline-images', 80],
qpdf/qtest/qpdf/inline-image-colorspace-lookup-out.pdf 0 → 100644
No preview for this file type
qpdf/qtest/qpdf/inline-image-colorspace-lookup.pdf 0 → 100644
No preview for this file type