beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / Function.h
blob90e2a768ad09bef87f7bab13da436a872032eb8a
1 //========================================================================
2 //
3 // Function.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2009, 2010 Albert Astals Cid <aacid@kde.org>
17 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
18 // Copyright (C) 2011 Andrea Canciani <ranma42@gmail.com>
19 // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
20 // Copyright (C) 2012 Adam Reichold <adamreichold@myopera.com>
22 // To see a description of the changes please see the Changelog file that
23 // came with your tarball or type make ChangeLog if you are building from git
25 //========================================================================
27 #ifndef FUNCTION_H
28 #define FUNCTION_H
30 #ifdef USE_GCC_PRAGMAS
31 #pragma interface
32 #endif
34 #include "goo/gtypes.h"
35 #include "Object.h"
36 #include <set>
38 class Dict;
39 class Stream;
40 struct PSObject;
41 class PSStack;
42 class PopplerCache;
44 //------------------------------------------------------------------------
45 // Function
46 //------------------------------------------------------------------------
48 #define funcMaxInputs 32
49 #define funcMaxOutputs 32
50 #define sampledFuncMaxInputs 16
52 class Function {
53 public:
55 Function();
57 virtual ~Function();
59 // Construct a function. Returns NULL if unsuccessful.
60 static Function *parse(Object *funcObj);
62 // Initialize the entries common to all function types.
63 GBool init(Dict *dict);
65 virtual Function *copy() = 0;
67 // Return the function type:
68 // -1 : identity
69 // 0 : sampled
70 // 2 : exponential
71 // 3 : stitching
72 // 4 : PostScript
73 virtual int getType() = 0;
75 // Return size of input and output tuples.
76 int getInputSize() { return m; }
77 int getOutputSize() { return n; }
79 double getDomainMin(int i) { return domain[i][0]; }
80 double getDomainMax(int i) { return domain[i][1]; }
81 double getRangeMin(int i) { return range[i][0]; }
82 double getRangeMax(int i) { return range[i][1]; }
83 GBool getHasRange() { return hasRange; }
84 virtual GBool hasDifferentResultSet(Function *func) { return gFalse; }
86 // Transform an input tuple into an output tuple.
87 virtual void transform(double *in, double *out) = 0;
89 virtual GBool isOk() = 0;
91 protected:
92 static Function *parse(Object *funcObj, std::set<int> *usedParents);
94 Function(const Function *func);
96 int m, n; // size of input and output tuples
97 double // min and max values for function domain
98 domain[funcMaxInputs][2];
99 double // min and max values for function range
100 range[funcMaxOutputs][2];
101 GBool hasRange; // set if range is defined
104 //------------------------------------------------------------------------
105 // IdentityFunction
106 //------------------------------------------------------------------------
108 class IdentityFunction: public Function {
109 public:
111 IdentityFunction();
112 virtual ~IdentityFunction();
113 virtual Function *copy() { return new IdentityFunction(); }
114 virtual int getType() { return -1; }
115 virtual void transform(double *in, double *out);
116 virtual GBool isOk() { return gTrue; }
118 private:
121 //------------------------------------------------------------------------
122 // SampledFunction
123 //------------------------------------------------------------------------
125 class SampledFunction: public Function {
126 public:
128 SampledFunction(Object *funcObj, Dict *dict);
129 virtual ~SampledFunction();
130 virtual Function *copy() { return new SampledFunction(this); }
131 virtual int getType() { return 0; }
132 virtual void transform(double *in, double *out);
133 virtual GBool isOk() { return ok; }
134 virtual GBool hasDifferentResultSet(Function *func);
136 int getSampleSize(int i) { return sampleSize[i]; }
137 double getEncodeMin(int i) { return encode[i][0]; }
138 double getEncodeMax(int i) { return encode[i][1]; }
139 double getDecodeMin(int i) { return decode[i][0]; }
140 double getDecodeMax(int i) { return decode[i][1]; }
141 double *getSamples() { return samples; }
142 int getSampleNumber() { return nSamples; }
144 private:
146 SampledFunction(const SampledFunction *func);
148 int // number of samples for each domain element
149 sampleSize[funcMaxInputs];
150 double // min and max values for domain encoder
151 encode[funcMaxInputs][2];
152 double // min and max values for range decoder
153 decode[funcMaxOutputs][2];
154 double // input multipliers
155 inputMul[funcMaxInputs];
156 int *idxOffset;
157 double *samples; // the samples
158 int nSamples; // size of the samples array
159 double *sBuf; // buffer for the transform function
160 double cacheIn[funcMaxInputs];
161 double cacheOut[funcMaxOutputs];
162 GBool ok;
165 //------------------------------------------------------------------------
166 // ExponentialFunction
167 //------------------------------------------------------------------------
169 class ExponentialFunction: public Function {
170 public:
172 ExponentialFunction(Object *funcObj, Dict *dict);
173 virtual ~ExponentialFunction();
174 virtual Function *copy() { return new ExponentialFunction(this); }
175 virtual int getType() { return 2; }
176 virtual void transform(double *in, double *out);
177 virtual GBool isOk() { return ok; }
179 double *getC0() { return c0; }
180 double *getC1() { return c1; }
181 double getE() { return e; }
183 private:
185 ExponentialFunction(const ExponentialFunction *func);
187 double c0[funcMaxOutputs];
188 double c1[funcMaxOutputs];
189 double e;
190 bool isLinear;
191 GBool ok;
194 //------------------------------------------------------------------------
195 // StitchingFunction
196 //------------------------------------------------------------------------
198 class StitchingFunction: public Function {
199 public:
201 StitchingFunction(Object *funcObj, Dict *dict, std::set<int> *usedParents);
202 virtual ~StitchingFunction();
203 virtual Function *copy() { return new StitchingFunction(this); }
204 virtual int getType() { return 3; }
205 virtual void transform(double *in, double *out);
206 virtual GBool isOk() { return ok; }
208 int getNumFuncs() { return k; }
209 Function *getFunc(int i) { return funcs[i]; }
210 double *getBounds() { return bounds; }
211 double *getEncode() { return encode; }
212 double *getScale() { return scale; }
214 private:
216 StitchingFunction(const StitchingFunction *func);
218 int k;
219 Function **funcs;
220 double *bounds;
221 double *encode;
222 double *scale;
223 GBool ok;
226 //------------------------------------------------------------------------
227 // PostScriptFunction
228 //------------------------------------------------------------------------
230 class PostScriptFunction: public Function {
231 public:
233 PostScriptFunction(Object *funcObj, Dict *dict);
234 virtual ~PostScriptFunction();
235 virtual Function *copy() { return new PostScriptFunction(this); }
236 virtual int getType() { return 4; }
237 virtual void transform(double *in, double *out);
238 virtual GBool isOk() { return ok; }
240 GooString *getCodeString() { return codeString; }
242 private:
244 PostScriptFunction(const PostScriptFunction *func);
245 GBool parseCode(Stream *str, int *codePtr);
246 GooString *getToken(Stream *str);
247 void resizeCode(int newSize);
248 void exec(PSStack *stack, int codePtr);
250 GooString *codeString;
251 PSObject *code;
252 int codeSize;
253 double cacheIn[funcMaxInputs];
254 double cacheOut[funcMaxOutputs];
255 GBool ok;
258 #endif