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 size of input and output tuples.
49 int getInputSize() { return m
; }
50 int getOutputSize() { return n
; }
52 // Transform an input tuple into an output tuple.
53 virtual void transform(double *in
, double *out
) = 0;
55 virtual GBool
isOk() = 0;
59 int m
, n
; // size of input and output tuples
60 double // min and max values for function domain
61 domain
[funcMaxInputs
][2];
62 double // min and max values for function range
63 range
[funcMaxOutputs
][2];
64 GBool hasRange
; // set if range is defined
67 //------------------------------------------------------------------------
69 //------------------------------------------------------------------------
71 class IdentityFunction
: public Function
{
75 virtual ~IdentityFunction();
76 virtual Function
*copy() { return new IdentityFunction(); }
77 virtual void transform(double *in
, double *out
);
78 virtual GBool
isOk() { return gTrue
; }
83 //------------------------------------------------------------------------
85 //------------------------------------------------------------------------
87 class SampledFunction
: public Function
{
90 SampledFunction(Object
*funcObj
, Dict
*dict
);
91 virtual ~SampledFunction();
92 virtual Function
*copy() { return new SampledFunction(this); }
93 virtual void transform(double *in
, double *out
);
94 virtual GBool
isOk() { return ok
; }
98 SampledFunction(SampledFunction
*func
);
100 int // number of samples for each domain element
101 sampleSize
[funcMaxInputs
];
102 double // min and max values for domain encoder
103 encode
[funcMaxInputs
][2];
104 double // min and max values for range decoder
105 decode
[funcMaxOutputs
][2];
106 double *samples
; // the samples
110 //------------------------------------------------------------------------
111 // ExponentialFunction
112 //------------------------------------------------------------------------
114 class ExponentialFunction
: public Function
{
117 ExponentialFunction(Object
*funcObj
, Dict
*dict
);
118 virtual ~ExponentialFunction();
119 virtual Function
*copy() { return new ExponentialFunction(this); }
120 virtual void transform(double *in
, double *out
);
121 virtual GBool
isOk() { return ok
; }
125 ExponentialFunction(ExponentialFunction
*func
);
127 double c0
[funcMaxOutputs
];
128 double c1
[funcMaxOutputs
];
133 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
137 class StitchingFunction
: public Function
{
140 StitchingFunction(Object
*funcObj
, Dict
*dict
);
141 virtual ~StitchingFunction();
142 virtual Function
*copy() { return new StitchingFunction(this); }
143 virtual void transform(double *in
, double *out
);
144 virtual GBool
isOk() { return ok
; }
148 StitchingFunction(StitchingFunction
*func
);
157 //------------------------------------------------------------------------
158 // PostScriptFunction
159 //------------------------------------------------------------------------
161 class PostScriptFunction
: public Function
{
164 PostScriptFunction(Object
*funcObj
, Dict
*dict
);
165 virtual ~PostScriptFunction();
166 virtual Function
*copy() { return new PostScriptFunction(this); }
167 virtual void transform(double *in
, double *out
);
168 virtual GBool
isOk() { return ok
; }
172 PostScriptFunction(PostScriptFunction
*func
);
173 GBool
parseCode(Stream
*str
, int *codePtr
);
174 GString
*getToken(Stream
*str
);
175 void resizeCode(int newSize
);
176 void exec(PSStack
*stack
, int codePtr
);