From f33522ac46a16963565076b996eca2ca6409843e Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 8 Feb 2025 11:45:13 -0500 Subject: [PATCH] Restore CompressConfig until qpdf 12 --- include/qpdf/Pl_DCT.hh | 18 ++++++++++++++++-- libqpdf/Pl_DCT.cc | 17 +++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/qpdf/Pl_DCT.hh b/include/qpdf/Pl_DCT.hh index 1f63f93..1af9d36 100644 --- a/include/qpdf/Pl_DCT.hh +++ b/include/qpdf/Pl_DCT.hh @@ -52,6 +52,16 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline QPDF_DLL static void setThrowOnCorruptData(bool treat_as_error); + class QPDF_DLL_CLASS CompressConfig + { + public: + QPDF_DLL + CompressConfig() = default; + QPDF_DLL + virtual ~CompressConfig() = default; + virtual void apply(jpeg_compress_struct*) = 0; + }; + // Constructor for compressing image data QPDF_DLL Pl_DCT( @@ -60,7 +70,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline JDIMENSION image_width, JDIMENSION image_height, int components, - J_COLOR_SPACE color_space); + J_COLOR_SPACE color_space, + CompressConfig* config_callback = nullptr); QPDF_DLL ~Pl_DCT() override; @@ -93,7 +104,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline JDIMENSION image_width, JDIMENSION image_height, int components, - J_COLOR_SPACE color_space); + J_COLOR_SPACE color_space, + CompressConfig* config_callback); // For decompression Members(); @@ -105,6 +117,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline JDIMENSION image_height{0}; int components{1}; J_COLOR_SPACE color_space{JCS_GRAYSCALE}; + + CompressConfig* config_callback{nullptr}; }; std::shared_ptr m; diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc index f7b37a2..047cacb 100644 --- a/libqpdf/Pl_DCT.cc +++ b/libqpdf/Pl_DCT.cc @@ -64,13 +64,18 @@ Pl_DCT::Members::Members() : } Pl_DCT::Members::Members( - JDIMENSION image_width, JDIMENSION image_height, int components, J_COLOR_SPACE color_space) : + JDIMENSION image_width, + JDIMENSION image_height, + int components, + J_COLOR_SPACE color_space, + CompressConfig* config_callback) : action(a_compress), buf("DCT uncompressed image"), image_width(image_width), image_height(image_height), components(components), - color_space(color_space) + color_space(color_space), + config_callback(config_callback) { } @@ -107,9 +112,10 @@ Pl_DCT::Pl_DCT( JDIMENSION image_width, JDIMENSION image_height, int components, - J_COLOR_SPACE color_space) : + J_COLOR_SPACE color_space, + CompressConfig* compress_callback) : Pipeline(identifier, next), - m(new Members(image_width, image_height, components, color_space)) + m(new Members(image_width, image_height, components, color_space, compress_callback)) { } @@ -310,6 +316,9 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) cinfo->input_components = m->components; cinfo->in_color_space = m->color_space; jpeg_set_defaults(cinfo); + if (m->config_callback) { + m->config_callback->apply(cinfo); + } jpeg_start_compress(cinfo, TRUE); -- libgit2 0.21.4