/src/xpdf-4.05/xpdf/Function.h
Line | Count | Source (jump to first uncovered line) |
1 | | //======================================================================== |
2 | | // |
3 | | // Function.h |
4 | | // |
5 | | // Copyright 2001-2003 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef FUNCTION_H |
10 | | #define FUNCTION_H |
11 | | |
12 | | #include <aconf.h> |
13 | | |
14 | | #include "gtypes.h" |
15 | | #include "Object.h" |
16 | | |
17 | | class GList; |
18 | | class Dict; |
19 | | class Stream; |
20 | | struct PSCode; |
21 | | |
22 | | //------------------------------------------------------------------------ |
23 | | // Function |
24 | | //------------------------------------------------------------------------ |
25 | | |
26 | 0 | #define funcMaxInputs 32 |
27 | 17.7k | #define funcMaxOutputs 32 |
28 | 0 | #define sampledFuncMaxInputs 16 |
29 | | |
30 | | class Function { |
31 | | public: |
32 | | |
33 | | Function(); |
34 | | |
35 | | virtual ~Function(); |
36 | | |
37 | | // Construct a function, with [expectedInputs] inputs and |
38 | | // [expectedOutputs] outputs. [expectedOutputs] can be -1 to |
39 | | // indicate unknown. Returns NULL if unsuccessful. |
40 | | static Function *parse(Object *funcObj, int expectedInputs, |
41 | | int expectedOutputs, int recursion = 0); |
42 | | |
43 | | // Initialize the entries common to all function types. |
44 | | GBool init(Dict *dict); |
45 | | |
46 | | virtual Function *copy() = 0; |
47 | | |
48 | | // Return the function type: |
49 | | // -1 : identity |
50 | | // 0 : sampled |
51 | | // 2 : exponential |
52 | | // 3 : stitching |
53 | | // 4 : PostScript |
54 | | virtual int getType() = 0; |
55 | | |
56 | | // Return size of input and output tuples. |
57 | 0 | int getInputSize() { return m; } |
58 | 0 | int getOutputSize() { return n; } |
59 | | |
60 | 0 | double getDomainMin(int i) { return domain[i][0]; } |
61 | 0 | double getDomainMax(int i) { return domain[i][1]; } |
62 | 0 | double getRangeMin(int i) { return range[i][0]; } |
63 | 0 | double getRangeMax(int i) { return range[i][1]; } |
64 | 0 | GBool getHasRange() { return hasRange; } |
65 | | |
66 | | // Transform an input tuple into an output tuple. |
67 | | virtual void transform(double *in, double *out) = 0; |
68 | | |
69 | | virtual GBool isOk() = 0; |
70 | | |
71 | | protected: |
72 | | |
73 | | int m, n; // size of input and output tuples |
74 | | double // min and max values for function domain |
75 | | domain[funcMaxInputs][2]; |
76 | | double // min and max values for function range |
77 | | range[funcMaxOutputs][2]; |
78 | | GBool hasRange; // set if range is defined |
79 | | }; |
80 | | |
81 | | //------------------------------------------------------------------------ |
82 | | // IdentityFunction |
83 | | //------------------------------------------------------------------------ |
84 | | |
85 | | class IdentityFunction: public Function { |
86 | | public: |
87 | | |
88 | | IdentityFunction(int nInputs); |
89 | | virtual ~IdentityFunction(); |
90 | 0 | virtual Function *copy() { return new IdentityFunction(m); } |
91 | 0 | virtual int getType() { return -1; } |
92 | | virtual void transform(double *in, double *out); |
93 | 0 | virtual GBool isOk() { return gTrue; } |
94 | | |
95 | | private: |
96 | | }; |
97 | | |
98 | | //------------------------------------------------------------------------ |
99 | | // SampledFunction |
100 | | //------------------------------------------------------------------------ |
101 | | |
102 | | class SampledFunction: public Function { |
103 | | public: |
104 | | |
105 | | SampledFunction(Object *funcObj, Dict *dict); |
106 | | virtual ~SampledFunction(); |
107 | 0 | virtual Function *copy() { return new SampledFunction(this); } |
108 | 0 | virtual int getType() { return 0; } |
109 | | virtual void transform(double *in, double *out); |
110 | 0 | virtual GBool isOk() { return ok; } |
111 | | |
112 | 0 | int getSampleSize(int i) { return sampleSize[i]; } |
113 | 0 | double getEncodeMin(int i) { return encode[i][0]; } |
114 | 0 | double getEncodeMax(int i) { return encode[i][1]; } |
115 | 0 | double getDecodeMin(int i) { return decode[i][0]; } |
116 | 0 | double getDecodeMax(int i) { return decode[i][1]; } |
117 | 0 | double *getSamples() { return samples; } |
118 | | |
119 | | private: |
120 | | |
121 | | SampledFunction(SampledFunction *func); |
122 | | |
123 | | int // number of samples for each domain element |
124 | | sampleSize[funcMaxInputs]; |
125 | | double // min and max values for domain encoder |
126 | | encode[funcMaxInputs][2]; |
127 | | double // min and max values for range decoder |
128 | | decode[funcMaxOutputs][2]; |
129 | | double // input multipliers |
130 | | inputMul[funcMaxInputs]; |
131 | | int *idxOffset; |
132 | | double *samples; // the samples |
133 | | int nSamples; // size of the samples array |
134 | | double *sBuf; // buffer for the transform function |
135 | | double cacheIn[funcMaxInputs]; |
136 | | double cacheOut[funcMaxOutputs]; |
137 | | GBool ok; |
138 | | }; |
139 | | |
140 | | //------------------------------------------------------------------------ |
141 | | // ExponentialFunction |
142 | | //------------------------------------------------------------------------ |
143 | | |
144 | | class ExponentialFunction: public Function { |
145 | | public: |
146 | | |
147 | | ExponentialFunction(Object *funcObj, Dict *dict); |
148 | | virtual ~ExponentialFunction(); |
149 | 0 | virtual Function *copy() { return new ExponentialFunction(this); } |
150 | 0 | virtual int getType() { return 2; } |
151 | | virtual void transform(double *in, double *out); |
152 | 0 | virtual GBool isOk() { return ok; } |
153 | | |
154 | 0 | double *getC0() { return c0; } |
155 | 0 | double *getC1() { return c1; } |
156 | 0 | double getE() { return e; } |
157 | | |
158 | | private: |
159 | | |
160 | | ExponentialFunction(ExponentialFunction *func); |
161 | | |
162 | | double c0[funcMaxOutputs]; |
163 | | double c1[funcMaxOutputs]; |
164 | | double e; |
165 | | GBool ok; |
166 | | }; |
167 | | |
168 | | //------------------------------------------------------------------------ |
169 | | // StitchingFunction |
170 | | //------------------------------------------------------------------------ |
171 | | |
172 | | class StitchingFunction: public Function { |
173 | | public: |
174 | | |
175 | | StitchingFunction(Object *funcObj, Dict *dict, int expectedInputs, |
176 | | int expectedOutputs, int recursion); |
177 | | virtual ~StitchingFunction(); |
178 | 0 | virtual Function *copy() { return new StitchingFunction(this); } |
179 | 0 | virtual int getType() { return 3; } |
180 | | virtual void transform(double *in, double *out); |
181 | 0 | virtual GBool isOk() { return ok; } |
182 | | |
183 | 0 | int getNumFuncs() { return k; } |
184 | 0 | Function *getFunc(int i) { return funcs[i]; } |
185 | 0 | double *getBounds() { return bounds; } |
186 | 0 | double *getEncode() { return encode; } |
187 | 0 | double *getScale() { return scale; } |
188 | | |
189 | | private: |
190 | | |
191 | | StitchingFunction(StitchingFunction *func); |
192 | | |
193 | | int k; |
194 | | Function **funcs; |
195 | | double *bounds; |
196 | | double *encode; |
197 | | double *scale; |
198 | | GBool ok; |
199 | | }; |
200 | | |
201 | | //------------------------------------------------------------------------ |
202 | | // PostScriptFunction |
203 | | //------------------------------------------------------------------------ |
204 | | |
205 | | class PostScriptFunction: public Function { |
206 | | public: |
207 | | |
208 | | PostScriptFunction(Object *funcObj, Dict *dict); |
209 | | virtual ~PostScriptFunction(); |
210 | 0 | virtual Function *copy() { return new PostScriptFunction(this); } |
211 | 0 | virtual int getType() { return 4; } |
212 | | virtual void transform(double *in, double *out); |
213 | 0 | virtual GBool isOk() { return ok; } |
214 | | |
215 | 0 | GString *getCodeString() { return codeString; } |
216 | | |
217 | | private: |
218 | | |
219 | | PostScriptFunction(PostScriptFunction *func); |
220 | | GBool parseCode(GList *tokens, int *tokPtr, int *codePtr); |
221 | | void addCode(int *codePtr, int op); |
222 | | void addCodeI(int *codePtr, int op, int x); |
223 | | void addCodeD(int *codePtr, int op, double x); |
224 | | GString *getToken(Stream *str); |
225 | | int exec(double *stack, int sp0); |
226 | | |
227 | | GString *codeString; |
228 | | PSCode *code; |
229 | | int codeLen; |
230 | | int codeSize; |
231 | | double cacheIn[funcMaxInputs]; |
232 | | double cacheOut[funcMaxOutputs]; |
233 | | GBool ok; |
234 | | }; |
235 | | |
236 | | #endif |