]>
git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/Function.h
1 //========================================================================
5 // Copyright 2001-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
26 //------------------------------------------------------------------------
28 //------------------------------------------------------------------------
30 #define funcMaxInputs 8
31 #define funcMaxOutputs 32
40 // Construct a function. Returns NULL if unsuccessful.
41 static Function
*parse(Object
*funcObj
);
43 // Initialize the entries common to all function types.
44 GBool
init(Dict
*dict
);
46 virtual Function
*copy() = 0;
48 // Return the function type:
54 virtual int getType() = 0;
56 // Return size of input and output tuples.
57 int getInputSize() { return m
; }
58 int getOutputSize() { return n
; }
60 double getDomainMin(int i
) { return domain
[i
][0]; }
61 double getDomainMax(int i
) { return domain
[i
][1]; }
62 double getRangeMin(int i
) { return range
[i
][0]; }
63 double getRangeMax(int i
) { return range
[i
][1]; }
64 GBool
getHasRange() { return hasRange
; }
66 // Transform an input tuple into an output tuple.
67 virtual void transform(double *in
, double *out
) = 0;
69 virtual GBool
isOk() = 0;
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
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
85 class IdentityFunction
: public Function
{
89 virtual ~IdentityFunction();
90 virtual Function
*copy() { return new IdentityFunction(); }
91 virtual int getType() { return -1; }
92 virtual void transform(double *in
, double *out
);
93 virtual GBool
isOk() { return gTrue
; }
98 //------------------------------------------------------------------------
100 //------------------------------------------------------------------------
102 class SampledFunction
: public Function
{
105 SampledFunction(Object
*funcObj
, Dict
*dict
);
106 virtual ~SampledFunction();
107 virtual Function
*copy() { return new SampledFunction(this); }
108 virtual int getType() { return 0; }
109 virtual void transform(double *in
, double *out
);
110 virtual GBool
isOk() { return ok
; }
112 int getSampleSize(int i
) { return sampleSize
[i
]; }
113 double getEncodeMin(int i
) { return encode
[i
][0]; }
114 double getEncodeMax(int i
) { return encode
[i
][1]; }
115 double getDecodeMin(int i
) { return decode
[i
][0]; }
116 double getDecodeMax(int i
) { return decode
[i
][1]; }
117 double *getSamples() { return samples
; }
121 SampledFunction(SampledFunction
*func
);
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 idxMul
[funcMaxInputs
]; // sample array index multipliers
132 double *samples
; // the samples
133 int nSamples
; // size of the samples array
137 //------------------------------------------------------------------------
138 // ExponentialFunction
139 //------------------------------------------------------------------------
141 class ExponentialFunction
: public Function
{
144 ExponentialFunction(Object
*funcObj
, Dict
*dict
);
145 virtual ~ExponentialFunction();
146 virtual Function
*copy() { return new ExponentialFunction(this); }
147 virtual int getType() { return 2; }
148 virtual void transform(double *in
, double *out
);
149 virtual GBool
isOk() { return ok
; }
151 double *getC0() { return c0
; }
152 double *getC1() { return c1
; }
153 double getE() { return e
; }
157 ExponentialFunction(ExponentialFunction
*func
);
159 double c0
[funcMaxOutputs
];
160 double c1
[funcMaxOutputs
];
165 //------------------------------------------------------------------------
167 //------------------------------------------------------------------------
169 class StitchingFunction
: public Function
{
172 StitchingFunction(Object
*funcObj
, Dict
*dict
);
173 virtual ~StitchingFunction();
174 virtual Function
*copy() { return new StitchingFunction(this); }
175 virtual int getType() { return 3; }
176 virtual void transform(double *in
, double *out
);
177 virtual GBool
isOk() { return ok
; }
179 int getNumFuncs() { return k
; }
180 Function
*getFunc(int i
) { return funcs
[i
]; }
181 double *getBounds() { return bounds
; }
182 double *getEncode() { return encode
; }
186 StitchingFunction(StitchingFunction
*func
);
195 //------------------------------------------------------------------------
196 // PostScriptFunction
197 //------------------------------------------------------------------------
199 class PostScriptFunction
: public Function
{
202 PostScriptFunction(Object
*funcObj
, Dict
*dict
);
203 virtual ~PostScriptFunction();
204 virtual Function
*copy() { return new PostScriptFunction(this); }
205 virtual int getType() { return 4; }
206 virtual void transform(double *in
, double *out
);
207 virtual GBool
isOk() { return ok
; }
209 GString
*getCodeString() { return codeString
; }
213 PostScriptFunction(PostScriptFunction
*func
);
214 GBool
parseCode(Stream
*str
, int *codePtr
);
215 GString
*getToken(Stream
*str
);
216 void resizeCode(int newSize
);
217 void exec(PSStack
*stack
, int codePtr
);