Commit bbc2f8ffae939eab598f583514fb132d23c11705
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.
Showing
6 changed files
with
32 additions
and
1 deletions
ChangeLog
| 1 | 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 | 7 | * Add "encrypt" key to the json output. This contains largely the |
| 4 | 8 | same information as given by --show-encryption but in a |
| 5 | 9 | consistent, parseable format. | ... | ... |
libqpdf/QPDFPageObjectHelper.cc
| ... | ... | @@ -141,6 +141,22 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) |
| 141 | 141 | } |
| 142 | 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 | 160 | name.clear(); |
| 145 | 161 | } |
| 146 | 162 | if (! name.empty()) | ... | ... |
qpdf/qpdf.testcov
qpdf/qtest/qpdf.test
| ... | ... | @@ -809,7 +809,7 @@ $td->runtest("check pass1 file", |
| 809 | 809 | show_ntests(); |
| 810 | 810 | # ---------- |
| 811 | 811 | $td->notify("--- Inline Images ---"); |
| 812 | -$n_tests += 8; | |
| 812 | +$n_tests += 10; | |
| 813 | 813 | |
| 814 | 814 | # The file large-inline-image.pdf is a hand-crafted file with several |
| 815 | 815 | # inline images of various sizes including one that is two megabytes, |
| ... | ... | @@ -853,6 +853,16 @@ $td->runtest("externalize damaged image", |
| 853 | 853 | $td->runtest("check output", |
| 854 | 854 | {$td->FILE => "a.pdf"}, |
| 855 | 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 | 867 | my @eii_tests = ( |
| 858 | 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