Commit f33522ac46a16963565076b996eca2ca6409843e

Authored by Jay Berkenbilt
1 parent 5548b3bb

Restore CompressConfig until qpdf 12

Removing it was ABI-breaking. I must have done it forgetting Pl_DCT.hh
was in the public API.
include/qpdf/Pl_DCT.hh
@@ -52,6 +52,16 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline @@ -52,6 +52,16 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline
52 QPDF_DLL 52 QPDF_DLL
53 static void setThrowOnCorruptData(bool treat_as_error); 53 static void setThrowOnCorruptData(bool treat_as_error);
54 54
  55 + class QPDF_DLL_CLASS CompressConfig
  56 + {
  57 + public:
  58 + QPDF_DLL
  59 + CompressConfig() = default;
  60 + QPDF_DLL
  61 + virtual ~CompressConfig() = default;
  62 + virtual void apply(jpeg_compress_struct*) = 0;
  63 + };
  64 +
55 // Constructor for compressing image data 65 // Constructor for compressing image data
56 QPDF_DLL 66 QPDF_DLL
57 Pl_DCT( 67 Pl_DCT(
@@ -60,7 +70,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline @@ -60,7 +70,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline
60 JDIMENSION image_width, 70 JDIMENSION image_width,
61 JDIMENSION image_height, 71 JDIMENSION image_height,
62 int components, 72 int components,
63 - J_COLOR_SPACE color_space); 73 + J_COLOR_SPACE color_space,
  74 + CompressConfig* config_callback = nullptr);
64 75
65 QPDF_DLL 76 QPDF_DLL
66 ~Pl_DCT() override; 77 ~Pl_DCT() override;
@@ -93,7 +104,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline @@ -93,7 +104,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline
93 JDIMENSION image_width, 104 JDIMENSION image_width,
94 JDIMENSION image_height, 105 JDIMENSION image_height,
95 int components, 106 int components,
96 - J_COLOR_SPACE color_space); 107 + J_COLOR_SPACE color_space,
  108 + CompressConfig* config_callback);
97 // For decompression 109 // For decompression
98 Members(); 110 Members();
99 111
@@ -105,6 +117,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline @@ -105,6 +117,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline
105 JDIMENSION image_height{0}; 117 JDIMENSION image_height{0};
106 int components{1}; 118 int components{1};
107 J_COLOR_SPACE color_space{JCS_GRAYSCALE}; 119 J_COLOR_SPACE color_space{JCS_GRAYSCALE};
  120 +
  121 + CompressConfig* config_callback{nullptr};
108 }; 122 };
109 123
110 std::shared_ptr<Members> m; 124 std::shared_ptr<Members> m;
libqpdf/Pl_DCT.cc
@@ -64,13 +64,18 @@ Pl_DCT::Members::Members() : @@ -64,13 +64,18 @@ Pl_DCT::Members::Members() :
64 } 64 }
65 65
66 Pl_DCT::Members::Members( 66 Pl_DCT::Members::Members(
67 - JDIMENSION image_width, JDIMENSION image_height, int components, J_COLOR_SPACE color_space) : 67 + JDIMENSION image_width,
  68 + JDIMENSION image_height,
  69 + int components,
  70 + J_COLOR_SPACE color_space,
  71 + CompressConfig* config_callback) :
68 action(a_compress), 72 action(a_compress),
69 buf("DCT uncompressed image"), 73 buf("DCT uncompressed image"),
70 image_width(image_width), 74 image_width(image_width),
71 image_height(image_height), 75 image_height(image_height),
72 components(components), 76 components(components),
73 - color_space(color_space) 77 + color_space(color_space),
  78 + config_callback(config_callback)
74 { 79 {
75 } 80 }
76 81
@@ -107,9 +112,10 @@ Pl_DCT::Pl_DCT( @@ -107,9 +112,10 @@ Pl_DCT::Pl_DCT(
107 JDIMENSION image_width, 112 JDIMENSION image_width,
108 JDIMENSION image_height, 113 JDIMENSION image_height,
109 int components, 114 int components,
110 - J_COLOR_SPACE color_space) : 115 + J_COLOR_SPACE color_space,
  116 + CompressConfig* compress_callback) :
111 Pipeline(identifier, next), 117 Pipeline(identifier, next),
112 - m(new Members(image_width, image_height, components, color_space)) 118 + m(new Members(image_width, image_height, components, color_space, compress_callback))
113 { 119 {
114 } 120 }
115 121
@@ -310,6 +316,9 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) @@ -310,6 +316,9 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b)
310 cinfo->input_components = m->components; 316 cinfo->input_components = m->components;
311 cinfo->in_color_space = m->color_space; 317 cinfo->in_color_space = m->color_space;
312 jpeg_set_defaults(cinfo); 318 jpeg_set_defaults(cinfo);
  319 + if (m->config_callback) {
  320 + m->config_callback->apply(cinfo);
  321 + }
313 322
314 jpeg_start_compress(cinfo, TRUE); 323 jpeg_start_compress(cinfo, TRUE);
315 324