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 52 QPDF_DLL
53 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 65 // Constructor for compressing image data
56 66 QPDF_DLL
57 67 Pl_DCT(
... ... @@ -60,7 +70,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline
60 70 JDIMENSION image_width,
61 71 JDIMENSION image_height,
62 72 int components,
63   - J_COLOR_SPACE color_space);
  73 + J_COLOR_SPACE color_space,
  74 + CompressConfig* config_callback = nullptr);
64 75  
65 76 QPDF_DLL
66 77 ~Pl_DCT() override;
... ... @@ -93,7 +104,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline
93 104 JDIMENSION image_width,
94 105 JDIMENSION image_height,
95 106 int components,
96   - J_COLOR_SPACE color_space);
  107 + J_COLOR_SPACE color_space,
  108 + CompressConfig* config_callback);
97 109 // For decompression
98 110 Members();
99 111  
... ... @@ -105,6 +117,8 @@ class QPDF_DLL_CLASS Pl_DCT: public Pipeline
105 117 JDIMENSION image_height{0};
106 118 int components{1};
107 119 J_COLOR_SPACE color_space{JCS_GRAYSCALE};
  120 +
  121 + CompressConfig* config_callback{nullptr};
108 122 };
109 123  
110 124 std::shared_ptr<Members> m;
... ...
libqpdf/Pl_DCT.cc
... ... @@ -64,13 +64,18 @@ Pl_DCT::Members::Members() :
64 64 }
65 65  
66 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 72 action(a_compress),
69 73 buf("DCT uncompressed image"),
70 74 image_width(image_width),
71 75 image_height(image_height),
72 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 112 JDIMENSION image_width,
108 113 JDIMENSION image_height,
109 114 int components,
110   - J_COLOR_SPACE color_space) :
  115 + J_COLOR_SPACE color_space,
  116 + CompressConfig* compress_callback) :
111 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 316 cinfo->input_components = m->components;
311 317 cinfo->in_color_space = m->color_space;
312 318 jpeg_set_defaults(cinfo);
  319 + if (m->config_callback) {
  320 + m->config_callback->apply(cinfo);
  321 + }
313 322  
314 323 jpeg_start_compress(cinfo, TRUE);
315 324  
... ...