upgrade to xpdf 3.00.
[swftools.git] / pdf2swf / xpdf / Function.h
blob0ceb03515c352493f275de75afd010e6a2c7fea1
1 //========================================================================
2 //
3 // Function.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef FUNCTION_H
10 #define FUNCTION_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include "gtypes.h"
19 #include "Object.h"
21 class Dict;
22 class Stream;
23 struct PSObject;
24 class PSStack;
26 //------------------------------------------------------------------------
27 // Function
28 //------------------------------------------------------------------------
30 #define funcMaxInputs 8
31 #define funcMaxOutputs 32
33 class Function {
34 public:
36 Function();
38 virtual ~Function();
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;
57 protected:
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 //------------------------------------------------------------------------
68 // IdentityFunction
69 //------------------------------------------------------------------------
71 class IdentityFunction: public Function {
72 public:
74 IdentityFunction();
75 virtual ~IdentityFunction();
76 virtual Function *copy() { return new IdentityFunction(); }
77 virtual void transform(double *in, double *out);
78 virtual GBool isOk() { return gTrue; }
80 private:
83 //------------------------------------------------------------------------
84 // SampledFunction
85 //------------------------------------------------------------------------
87 class SampledFunction: public Function {
88 public:
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; }
96 private:
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
107 GBool ok;
110 //------------------------------------------------------------------------
111 // ExponentialFunction
112 //------------------------------------------------------------------------
114 class ExponentialFunction: public Function {
115 public:
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; }
123 private:
125 ExponentialFunction(ExponentialFunction *func);
127 double c0[funcMaxOutputs];
128 double c1[funcMaxOutputs];
129 double e;
130 GBool ok;
133 //------------------------------------------------------------------------
134 // StitchingFunction
135 //------------------------------------------------------------------------
137 class StitchingFunction: public Function {
138 public:
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; }
146 private:
148 StitchingFunction(StitchingFunction *func);
150 int k;
151 Function **funcs;
152 double *bounds;
153 double *encode;
154 GBool ok;
157 //------------------------------------------------------------------------
158 // PostScriptFunction
159 //------------------------------------------------------------------------
161 class PostScriptFunction: public Function {
162 public:
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; }
170 private:
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);
178 PSObject *code;
179 int codeSize;
180 GBool ok;
183 #endif