aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-01-31 22:07:33 +0100
committerJay Berkenbilt <ejb@ql.org>2019-02-01 03:29:28 +0100
commit0a470d2daf8ec8a1ba0abfea053af4b4d0955ff6 (patch)
treee2ce315e1904cc593ab5f6b411043b5559d7df18 /qpdf
parenteb49e07c0afc1b30b53d3ae2849c824c9407f00d (diff)
downloadqpdf-0a470d2daf8ec8a1ba0abfea053af4b4d0955ff6.tar.zst
Don't optimize non-8-bit images
Also add test cases for additional coverage on image optimization.
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qpdf.cc13
-rw-r--r--qpdf/qpdf.testcov2
-rw-r--r--qpdf/qtest/qpdf.test2
-rw-r--r--qpdf/qtest/qpdf/optimize-images-unsupported-json.out49
-rw-r--r--qpdf/qtest/qpdf/optimize-images-unsupported.out3
-rw-r--r--qpdf/qtest/qpdf/unsupported-optimization.pdfbin0 -> 1621 bytes
6 files changed, 69 insertions, 0 deletions
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 12672e21..6db07432 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -3816,6 +3816,18 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next)
}
return result;
}
+ QPDFObjectHandle components_obj = dict.getKey("/BitsPerComponent");
+ if (! (components_obj.isInteger() && (components_obj.getIntValue() == 8)))
+ {
+ QTC::TC("qpdf", "qpdf image optimize bits per component");
+ if (o.verbose && (! description.empty()))
+ {
+ std::cout << whoami << ": " << description
+ << ": not optimizing because image has other than"
+ << " 8 bits per component" << std::endl;
+ }
+ return result;
+ }
// Files have been seen in the wild whose width and height are
// floating point, which is goofy, but we can deal with it.
JDIMENSION w = static_cast<JDIMENSION>(
@@ -3844,6 +3856,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next)
}
else
{
+ QTC::TC("qpdf", "qpdf image optimize colorspace");
if (o.verbose && (! description.empty()))
{
std::cout << whoami << ": " << description
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index b7d2b704..b62dc663 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -437,3 +437,5 @@ QPDFTokenizer inline image at EOF the old way 0
QPDFTokenizer found EI after more than one try 0
QPDFPageObjectHelper externalize inline image 0
QPDFPageObjectHelper keep inline image 0
+qpdf image optimize colorspace 0
+qpdf image optimize bits per component 0
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 4862f02f..762c3fc5 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -2088,6 +2088,8 @@ my @image_opt = (
'--oi-min-width=0 --oi-min-height=0 --oi-min-area=0 --ii-min-bytes=0'],
['large-inline-image', 'inline-images-keep-some', ''],
['large-inline-image', 'inline-images-keep-all', '--keep-inline-images'],
+ ['unsupported-optimization', 'unsupported',
+ '--oi-min-width=0 --oi-min-height=0 --oi-min-area=0'],
);
$n_tests += 2 * scalar(@image_opt);
diff --git a/qpdf/qtest/qpdf/optimize-images-unsupported-json.out b/qpdf/qtest/qpdf/optimize-images-unsupported-json.out
new file mode 100644
index 00000000..78026973
--- /dev/null
+++ b/qpdf/qtest/qpdf/optimize-images-unsupported-json.out
@@ -0,0 +1,49 @@
+{
+ "pages": [
+ {
+ "contents": [
+ "4 0 R"
+ ],
+ "images": [
+ {
+ "bitspercomponent": 1,
+ "colorspace": "/DeviceGray",
+ "decodeparms": [
+ null
+ ],
+ "filter": [
+ "/FlateDecode"
+ ],
+ "filterable": true,
+ "height": 200,
+ "name": "/Im1",
+ "object": "6 0 R",
+ "width": 100
+ },
+ {
+ "bitspercomponent": 8,
+ "colorspace": "/XeviceGray",
+ "decodeparms": [
+ null
+ ],
+ "filter": [
+ "/FlateDecode"
+ ],
+ "filterable": true,
+ "height": 200,
+ "name": "/Im2",
+ "object": "7 0 R",
+ "width": 200
+ }
+ ],
+ "label": null,
+ "object": "3 0 R",
+ "outlines": [],
+ "pageposfrom1": 1
+ }
+ ],
+ "parameters": {
+ "decodelevel": "generalized"
+ },
+ "version": 1
+}
diff --git a/qpdf/qtest/qpdf/optimize-images-unsupported.out b/qpdf/qtest/qpdf/optimize-images-unsupported.out
new file mode 100644
index 00000000..2b281039
--- /dev/null
+++ b/qpdf/qtest/qpdf/optimize-images-unsupported.out
@@ -0,0 +1,3 @@
+qpdf: image /Im1 on page 1: not optimizing because image has other than 8 bits per component
+qpdf: image /Im2 on page 1: not optimizing because qpdf can't optimize images with this colorspace
+qpdf: wrote file a.pdf
diff --git a/qpdf/qtest/qpdf/unsupported-optimization.pdf b/qpdf/qtest/qpdf/unsupported-optimization.pdf
new file mode 100644
index 00000000..51816b34
--- /dev/null
+++ b/qpdf/qtest/qpdf/unsupported-optimization.pdf
Binary files differ