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.
This commit is contained in:
Jay Berkenbilt 2020-01-26 15:07:18 -05:00
parent 12777a04ca
commit bbc2f8ffae
6 changed files with 32 additions and 1 deletions

View File

@ -1,5 +1,9 @@
2020-01-26 Jay Berkenbilt <ejb@ql.org>
* 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.

View File

@ -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())

View File

@ -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

View File

@ -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],

Binary file not shown.

Binary file not shown.