mirror of
https://github.com/qpdf/qpdf.git
synced 2024-05-30 00:40:52 +00:00
Improve --optimize-images to find images nested within XObjects
This commit is contained in:
parent
b27be3ed27
commit
8de2497a8f
|
@ -2349,31 +2349,30 @@ QPDFJob::handleTransformations(QPDF& pdf)
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (auto& ph: dh.getAllPages()) {
|
for (auto& ph: dh.getAllPages()) {
|
||||||
++pageno;
|
++pageno;
|
||||||
QPDFObjectHandle page = ph.getObjectHandle();
|
ph.forEachImage(
|
||||||
for (auto& iter2: ph.getImages()) {
|
true,
|
||||||
std::string name = iter2.first;
|
[this, pageno, &pdf](
|
||||||
QPDFObjectHandle& image = iter2.second;
|
QPDFObjectHandle& obj,
|
||||||
ImageOptimizer* io = new ImageOptimizer(
|
QPDFObjectHandle& xobj_dict,
|
||||||
*this,
|
std::string const& key) {
|
||||||
m->oi_min_width,
|
auto io = std::make_unique<ImageOptimizer>(
|
||||||
m->oi_min_height,
|
*this,
|
||||||
m->oi_min_area,
|
m->oi_min_width,
|
||||||
image);
|
m->oi_min_height,
|
||||||
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> sdp(io);
|
m->oi_min_area,
|
||||||
if (io->evaluate(
|
obj);
|
||||||
"image " + name + " on page " +
|
if (io->evaluate(
|
||||||
std::to_string(pageno))) {
|
"image " + key + " on page " +
|
||||||
QPDFObjectHandle new_image = pdf.newStream();
|
std::to_string(pageno))) {
|
||||||
new_image.replaceDict(image.getDict().shallowCopy());
|
QPDFObjectHandle new_image = pdf.newStream();
|
||||||
new_image.replaceStreamData(
|
new_image.replaceDict(obj.getDict().shallowCopy());
|
||||||
sdp,
|
new_image.replaceStreamData(
|
||||||
QPDFObjectHandle::newName("/DCTDecode"),
|
std::move(io),
|
||||||
QPDFObjectHandle::newNull());
|
QPDFObjectHandle::newName("/DCTDecode"),
|
||||||
ph.getAttribute("/Resources", true)
|
QPDFObjectHandle::newNull());
|
||||||
.getKey("/XObject")
|
xobj_dict.replaceKey(key, new_image);
|
||||||
.replaceKey(name, new_image);
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m->generate_appearances) {
|
if (m->generate_appearances) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user