2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

In QPDFWriter::writeLinearized remember whether streams are filtered

This commit is contained in:
m-holger 2024-08-02 20:52:42 +01:00
parent 634d924986
commit 99f3a7b5a3

View File

@ -2544,14 +2544,20 @@ QPDFWriter::writeLinearized()
{
// Optimize file and enqueue objects in order
auto skip_stream_parameters = [this](QPDFObjectHandle& stream) {
bool compress_stream;
bool is_metadata;
if (willFilterStream(stream, compress_stream, is_metadata, nullptr)) {
return 2;
} else {
return 1;
std::map<int, int> stream_cache;
auto skip_stream_parameters = [this, &stream_cache](QPDFObjectHandle& stream) {
auto& result = stream_cache[stream.getObjectID()];
if (result == 0) {
bool compress_stream;
bool is_metadata;
if (willFilterStream(stream, compress_stream, is_metadata, nullptr)) {
result = 2;
} else {
result = 1;
}
}
return result;
};
QPDF::Writer::optimize(m->pdf, m->obj, skip_stream_parameters);