1 //========================================================================
5 // Copyright 2001-2003 Glyph & Cog, LLC
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 //========================================================================
30 #ifdef USE_GCC_PRAGMAS
34 #include "goo/gtypes.h"
44 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
48 #define funcMaxInputs 32
49 #define funcMaxOutputs 32
50 #define sampledFuncMaxInputs 16
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:
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;
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 //------------------------------------------------------------------------
106 //------------------------------------------------------------------------
108 class IdentityFunction
: public Function
{
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
; }
121 //------------------------------------------------------------------------
123 //------------------------------------------------------------------------
125 class SampledFunction
: public Function
{
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
; }
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
];
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
];
165 //------------------------------------------------------------------------
166 // ExponentialFunction
167 //------------------------------------------------------------------------
169 class ExponentialFunction
: public Function
{
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
; }
185 ExponentialFunction(const ExponentialFunction
*func
);
187 double c0
[funcMaxOutputs
];
188 double c1
[funcMaxOutputs
];
194 //------------------------------------------------------------------------
196 //------------------------------------------------------------------------
198 class StitchingFunction
: public Function
{
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
; }
216 StitchingFunction(const StitchingFunction
*func
);
226 //------------------------------------------------------------------------
227 // PostScriptFunction
228 //------------------------------------------------------------------------
230 class PostScriptFunction
: public Function
{
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
; }
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
;
253 double cacheIn
[funcMaxInputs
];
254 double cacheOut
[funcMaxOutputs
];