/src/qpdf/include/qpdf/Pl_DCT.hh
Line | Count | Source |
1 | | // Copyright (c) 2005-2021 Jay Berkenbilt |
2 | | // Copyright (c) 2022-2025 Jay Berkenbilt and Manfred Holger |
3 | | // |
4 | | // This file is part of qpdf. |
5 | | // |
6 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
7 | | // in compliance with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
12 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
13 | | // or implied. See the License for the specific language governing permissions and limitations under |
14 | | // the License. |
15 | | // |
16 | | // Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic |
17 | | // License. At your option, you may continue to consider qpdf to be licensed under those terms. |
18 | | // Please see the manual for additional information. |
19 | | |
20 | | #ifndef PL_DCT_HH |
21 | | #define PL_DCT_HH |
22 | | |
23 | | #include <qpdf/Pipeline.hh> |
24 | | |
25 | | #include <cstddef> |
26 | | #include <functional> |
27 | | |
28 | | // jpeglib.h must be included after cstddef or else it messes up the definition of size_t. |
29 | | #include <jpeglib.h> |
30 | | |
31 | | class QPDF_DLL_CLASS Pl_DCT: public Pipeline |
32 | | { |
33 | | public: |
34 | | // Constructor for decompressing image data |
35 | | QPDF_DLL |
36 | | Pl_DCT(char const* identifier, Pipeline* next); |
37 | | |
38 | | // Limit the memory used by jpeglib when decompressing data. |
39 | | // NB This is a static option affecting all Pl_DCT instances. |
40 | | QPDF_DLL |
41 | | static void setMemoryLimit(long limit); |
42 | | |
43 | | // Limit the number of scans used by jpeglib when decompressing progressive jpegs. |
44 | | // NB This is a static option affecting all Pl_DCT instances. |
45 | | QPDF_DLL |
46 | | static void setScanLimit(int limit); |
47 | | |
48 | | // Treat corrupt data as a runtime error rather than attempting to decompress regardless. This |
49 | | // is the qpdf default behaviour. To attempt to decompress corrupt data set 'treat_as_error' to |
50 | | // false. |
51 | | // NB This is a static option affecting all Pl_DCT instances. |
52 | | QPDF_DLL |
53 | | static void setThrowOnCorruptData(bool treat_as_error); |
54 | | |
55 | | class QPDF_DLL_CLASS CompressConfig |
56 | | { |
57 | | public: |
58 | | QPDF_DLL |
59 | 0 | CompressConfig() = default; |
60 | | QPDF_DLL |
61 | 0 | virtual ~CompressConfig() = default; |
62 | | virtual void apply(jpeg_compress_struct*) = 0; |
63 | | }; |
64 | | |
65 | | QPDF_DLL |
66 | | static std::unique_ptr<CompressConfig> |
67 | | make_compress_config(std::function<void(jpeg_compress_struct*)>); |
68 | | |
69 | | // Constructor for compressing image data |
70 | | QPDF_DLL |
71 | | Pl_DCT( |
72 | | char const* identifier, |
73 | | Pipeline* next, |
74 | | JDIMENSION image_width, |
75 | | JDIMENSION image_height, |
76 | | int components, |
77 | | J_COLOR_SPACE color_space, |
78 | | CompressConfig* config_callback = nullptr); |
79 | | |
80 | | QPDF_DLL |
81 | | ~Pl_DCT() override; |
82 | | |
83 | | QPDF_DLL |
84 | | void write(unsigned char const* data, size_t len) override; |
85 | | QPDF_DLL |
86 | | void finish() override; |
87 | | |
88 | | private: |
89 | | QPDF_DLL_PRIVATE |
90 | | void compress(void* cinfo); |
91 | | QPDF_DLL_PRIVATE |
92 | | void decompress(void* cinfo); |
93 | | |
94 | | enum action_e { a_compress, a_decompress }; |
95 | | |
96 | | class Members; |
97 | | |
98 | | std::unique_ptr<Members> m; |
99 | | }; |
100 | | |
101 | | #endif // PL_DCT_HH |