PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfFunctionDefinition.h
1// SPDX-FileCopyrightText: 2022 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_FUNCTION_DEFINITION_H
5#define PDF_FUNCTION_DEFINITION_H
6
7#include "PdfEncodingCommon.h"
8#include "PdfObject.h"
9
10namespace PoDoFo
11{
12 class PdfIndirectObjectList;
13 class PdfFunction;
14
15 enum class PdfFunctionType : uint8_t
16 {
17 Unknown = 0,
18 Sampled = 1,
19 Exponential = 2,
20 Stitching = 3,
21 PostScriptCalculator = 4
22 };
23
24 class PODOFO_API PdfFunctionDefinition
25 {
26 friend class PdfFunction;
27 friend class PdfSampledFunctionDefinition;
28 friend class PdfExponentialFunctionDefinition;
29 friend class PdfStitchingFunctionDefinition;
30 friend class PdfPostScriptCalculatorFunctionDefinition;
31 public:
32 virtual ~PdfFunctionDefinition();
33 private:
34 PdfFunctionDefinition(PdfFunctionType type, std::vector<double>&& domain, std::vector<double>&& range);
35 public:
36 unsigned GetInputCount() const;
37 virtual unsigned GetOutputCount() const;
38 const std::vector<double>& GetDomain() const { return m_Domain; }
39 const std::vector<double>& GetRange() const { return m_Range; }
40 PdfFunctionType GetType() const { return m_Type; }
41 protected:
42 PdfFunctionDefinition(const PdfFunctionDefinition&) = default;
43 virtual void fillExportDictionary(PdfDictionary& dict) const = 0;
44 private:
45 const PdfFunctionDefinition& operator=(const PdfFunctionDefinition&) = delete;
46 void FillExportDictionary(PdfDictionary& dict) const;
47 private:
48 std::vector<double> m_Domain;
49 std::vector<double> m_Range;
50 PdfFunctionType m_Type;
51 };
52
54 using PdfFunctionDefinitionPtr = std::shared_ptr<const PdfFunctionDefinition>;
55
56 class PODOFO_API PdfFunctionListInitializer final
57 {
58 friend class PdfStitchingFunctionDefinition;
59 friend class PdfShadingDefinition;
60
61 public:
62 PdfFunctionListInitializer();
63
64 PdfFunctionListInitializer(const PdfFunction& func);
65
66 PdfFunctionListInitializer(cspan<std::reference_wrapper<const PdfFunction>> funcs);
67
68 template <typename... Args>
69 PdfFunctionListInitializer(const PdfFunction& func, const Args& ...more);
70
71 private:
72 PdfFunctionListInitializer(size_t reserveSize);
73
74 void pushBack(const PdfFunction& func);
75
76 PdfFunctionListInitializer(const PdfFunctionListInitializer&) = delete;
77 PdfFunctionListInitializer& operator=(const PdfFunctionListInitializer&) = delete;
78
79 private:
80 std::vector<PdfFunctionDefinitionPtr> Take(PdfVariant& expVar);
81
82 private:
83 std::vector<PdfFunctionDefinitionPtr> m_Definitions;
84 PdfVariant m_ExpVar;
85 };
86
87 enum class PdfSampledFunctionOrder : uint8_t
88 {
89 Linear = 1,
90 Cubic = 3,
91 };
92
93 class PODOFO_API PdfSampledFunctionDefinition final : public PdfFunctionDefinition
94 {
95 public:
96 PdfSampledFunctionDefinition(std::vector<unsigned> size, unsigned char bitsPerSample, std::vector<unsigned> samples,
97 std::vector<double> domain, std::vector<double> range,
98 PdfSampledFunctionOrder order = PdfSampledFunctionOrder::Linear,
99 std::vector<double> encode = { }, std::vector<double> decode = { });
100
101 PdfSampledFunctionDefinition(const PdfSampledFunctionDefinition&) = default;
102 public:
103 unsigned GetSampleCount() const;
104 unsigned char GetBitsPerSample() const { return m_BitsPerSample; }
105 PdfSampledFunctionOrder GetOrder() const { return m_Order; }
106 const std::vector<unsigned>& GetSize() const { return m_Size; }
107 const std::vector<unsigned>& GetSamples() const { return m_Samples; }
108 const std::vector<double>& GetEncode() const { return m_Encode; }
109 const std::vector<double>& GetDecode() const { return m_Decode; }
110 protected:
111 void fillExportDictionary(PdfDictionary& dict) const override;
112 private:
113 unsigned char m_BitsPerSample;
114 PdfSampledFunctionOrder m_Order;
115 std::vector<unsigned> m_Size;
116 std::vector<unsigned> m_Samples;
117 std::vector<double> m_Encode;
118 std::vector<double> m_Decode;
119 };
120
121 class PODOFO_API PdfExponentialFunctionDefinition final : public PdfFunctionDefinition
122 {
123 public:
126 PdfExponentialFunctionDefinition(double interpolationExponent, std::vector<double> domain,
127 std::vector<double> c0 = { },
128 std::vector<double> c1 = { },
129 std::vector<double> range = { });
130
131 PdfExponentialFunctionDefinition(const PdfExponentialFunctionDefinition&) = default;
132 public:
133 unsigned GetOutputCount() const override;
134 double GetInterpolationExponent() const { return m_InterpolationExponent; }
135 const std::vector<double>& GetC0() const { return m_C0; }
136 const std::vector<double>& GetC1() const { return m_C1; }
137 protected:
138 void fillExportDictionary(PdfDictionary& dict) const override;
139 private:
140 double m_InterpolationExponent;
141 std::vector<double> m_C0;
142 std::vector<double> m_C1;
143 };
144
145 class PODOFO_API PdfStitchingFunctionDefinition final : public PdfFunctionDefinition
146 {
147 public:
148 PdfStitchingFunctionDefinition(PdfFunctionListInitializer&& functions,
149 std::vector<double> bounds, std::vector<double> encode,
150 std::vector<double> domain, std::vector<double> range = { });
151
153 PdfStitchingFunctionDefinition(std::vector<PdfFunctionDefinitionPtr>&& functions,
154 std::vector<double>&& bounds, std::vector<double>&& encode,
155 std::vector<double>&& domain, std::vector<double>&& range);
156
157 PdfStitchingFunctionDefinition(const PdfStitchingFunctionDefinition&) = default;
158
159 public:
160 const std::vector<std::shared_ptr<const PdfFunctionDefinition>>& GetFunctions() const { return m_Functions; }
161 const std::vector<double>& GetBounds() const { return m_Bounds; }
162 const std::vector<double>& GetEncode() const { return m_Encode; }
163 protected:
164 void fillExportDictionary(PdfDictionary& dict) const override;
165 private:
166 std::vector<std::shared_ptr<const PdfFunctionDefinition>> m_Functions;
167 PdfVariant m_functionsExpVar;
168 std::vector<double> m_Bounds;
169 std::vector<double> m_Encode;
170 };
171
172 class PODOFO_API PdfPostScriptCalculatorFunctionDefinition final : public PdfFunctionDefinition
173 {
174 public:
175 PdfPostScriptCalculatorFunctionDefinition(std::vector<double> domain, std::vector<double> range);
176
177 PdfPostScriptCalculatorFunctionDefinition(const PdfPostScriptCalculatorFunctionDefinition&) = default;
178 protected:
179 void fillExportDictionary(PdfDictionary& dict) const override;
180 };
181
182 template<typename ...Args>
183 PdfFunctionListInitializer::PdfFunctionListInitializer(const PdfFunction& func, const Args& ...more)
184 : PdfFunctionListInitializer(1 + sizeof...(more))
185 {
186 pushBack(func);
187 (pushBack(more), ...);
188 }
189}
190
191#endif // PDF_FUNCTION_DEFINITION_H
A variant data type which supports all data types supported by the PDF standard.
Definition PdfVariant.h:29
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
tcb::span< const T, Extent > cspan
Constant span.
Definition span.h:18
std::shared_ptr< const PdfFunctionDefinition > PdfFunctionDefinitionPtr
Convenience alias for a constant PdfFunction shared ptr.
Definition PdfFunctionDefinition.h:54