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