1 //========================================================================
5 // Copyright 2001-2002 Glyph & Cog, LLC
7 //========================================================================
24 //------------------------------------------------------------------------
26 //------------------------------------------------------------------------
28 #define funcMaxInputs 8
29 #define funcMaxOutputs 8
38 // Construct a function. Returns NULL if unsuccessful.
39 static Function *parse(Object *funcObj);
41 // Initialize the entries common to all function types.
42 GBool init(Dict *dict);
44 virtual Function *copy() = 0;
46 // Return size of input and output tuples.
47 int getInputSize() { return m; }
48 int getOutputSize() { return n; }
50 // Transform an input tuple into an output tuple.
51 virtual void transform(double *in, double *out) = 0;
53 virtual GBool isOk() = 0;
57 int m, n; // size of input and output tuples
58 double // min and max values for function domain
59 domain[funcMaxInputs][2];
60 double // min and max values for function range
61 range[funcMaxOutputs][2];
62 GBool hasRange; // set if range is defined
65 //------------------------------------------------------------------------
67 //------------------------------------------------------------------------
69 class IdentityFunction: public Function {
73 virtual ~IdentityFunction();
74 virtual Function *copy() { return new IdentityFunction(); }
75 virtual void transform(double *in, double *out);
76 virtual GBool isOk() { return gTrue; }
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
85 class SampledFunction: public Function {
88 SampledFunction(Object *funcObj, Dict *dict);
89 virtual ~SampledFunction();
90 virtual Function *copy() { return new SampledFunction(this); }
91 virtual void transform(double *in, double *out);
92 virtual GBool isOk() { return ok; }
96 SampledFunction(SampledFunction *func);
98 int // number of samples for each domain element
99 sampleSize[funcMaxInputs];
100 double // min and max values for domain encoder
101 encode[funcMaxInputs][2];
102 double // min and max values for range decoder
103 decode[funcMaxOutputs][2];
104 double *samples; // the samples
108 //------------------------------------------------------------------------
109 // ExponentialFunction
110 //------------------------------------------------------------------------
112 class ExponentialFunction: public Function {
115 ExponentialFunction(Object *funcObj, Dict *dict);
116 virtual ~ExponentialFunction();
117 virtual Function *copy() { return new ExponentialFunction(this); }
118 virtual void transform(double *in, double *out);
119 virtual GBool isOk() { return ok; }
123 ExponentialFunction(ExponentialFunction *func);
125 double c0[funcMaxOutputs];
126 double c1[funcMaxOutputs];
131 //------------------------------------------------------------------------
133 //------------------------------------------------------------------------
135 class StitchingFunction: public Function {
138 StitchingFunction(Object *funcObj, Dict *dict);
139 virtual ~StitchingFunction();
140 virtual Function *copy() { return new StitchingFunction(this); }
141 virtual void transform(double *in, double *out);
142 virtual GBool isOk() { return ok; }
146 StitchingFunction(StitchingFunction *func);
155 //------------------------------------------------------------------------
156 // PostScriptFunction
157 //------------------------------------------------------------------------
159 class PostScriptFunction: public Function {
162 PostScriptFunction(Object *funcObj, Dict *dict);
163 virtual ~PostScriptFunction();
164 virtual Function *copy() { return new PostScriptFunction(this); }
165 virtual void transform(double *in, double *out);
166 virtual GBool isOk() { return ok; }
170 PostScriptFunction(PostScriptFunction *func);
171 GBool parseCode(Stream *str, int *codePtr);
172 GString *getToken(Stream *str);
173 void resizeCode(int newSize);
174 void exec(PSStack *stack, int codePtr);