Function.h
1//========================================================================
2//
3// Function.h
4//
5// Copyright 2001-2002 Glyph & Cog, LLC
6//
7//========================================================================
8
9#ifndef FUNCTION_H
10#define FUNCTION_H
11
12#include <aconf.h>
13
14#ifdef USE_GCC_PRAGMAS
15#pragma interface
16#endif
17
18#include "gtypes.h"
19#include "Object.h"
20
21class Dict;
22class Stream;
23struct PSObject;
24class PSStack;
25
26//------------------------------------------------------------------------
27// Function
28//------------------------------------------------------------------------
29
30#define funcMaxInputs 8
31#define funcMaxOutputs 8
32
33class Function {
34public:
35
36 Function();
37
38 virtual ~Function();
39
40 // Construct a function. Returns NULL if unsuccessful.
41 static Function *parse(Object *funcObj);
42
43 // Initialize the entries common to all function types.
44 GBool init(Dict *dict);
45
46 virtual Function *copy() const = 0;
47
48 // Return size of input and output tuples.
49 int getInputSize() const { return m; }
50 int getOutputSize() const { return n; }
51
52 // Transform an input tuple into an output tuple.
53 virtual void transform(const double *in, double *out) const = 0;
54
55 virtual GBool isOk() const = 0;
56
57protected:
58
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
65};
66
67//------------------------------------------------------------------------
68// IdentityFunction
69//------------------------------------------------------------------------
70
71class IdentityFunction: public Function {
72public:
73
74 IdentityFunction();
75 virtual ~IdentityFunction();
76 virtual Function *copy() const { return new IdentityFunction(); }
77 virtual void transform(const double *in, double *out) const;
78 virtual GBool isOk() const { return gTrue; }
79
80private:
81};
82
83//------------------------------------------------------------------------
84// SampledFunction
85//------------------------------------------------------------------------
86
87class SampledFunction: public Function {
88public:
89
90 SampledFunction(Object *funcObj, Dict *dict);
91 virtual ~SampledFunction();
92 virtual Function *copy() const { return new SampledFunction(this); }
93 virtual void transform(const double *in, double *out) const;
94 virtual GBool isOk() const { return ok; }
95
96private:
97
98 SampledFunction(const SampledFunction *func);
99
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;
108};
109
110//------------------------------------------------------------------------
111// ExponentialFunction
112//------------------------------------------------------------------------
113
114class ExponentialFunction: public Function {
115public:
116
117 ExponentialFunction(Object *funcObj, Dict *dict);
118 virtual ~ExponentialFunction();
119 virtual Function *copy() const { return new ExponentialFunction(this); }
120 virtual void transform(const double *in, double *out) const;
121 virtual GBool isOk() const { return ok; }
122
123private:
124
125 ExponentialFunction(const ExponentialFunction *func);
126
127 double c0[funcMaxOutputs];
128 double c1[funcMaxOutputs];
129 double e;
130 GBool ok;
131};
132
133//------------------------------------------------------------------------
134// StitchingFunction
135//------------------------------------------------------------------------
136
137class StitchingFunction: public Function {
138public:
139
140 StitchingFunction(Object *funcObj, Dict *dict);
141 virtual ~StitchingFunction();
142 virtual Function *copy() const { return new StitchingFunction(this); }
143 virtual void transform(const double *in, double *out) const;
144 virtual GBool isOk() const { return ok; }
145
146private:
147
148 StitchingFunction(const StitchingFunction *func);
149
150 int k;
151 Function **funcs;
152 double *bounds;
153 double *encode;
154 GBool ok;
155};
156
157//------------------------------------------------------------------------
158// PostScriptFunction
159//------------------------------------------------------------------------
160
161class PostScriptFunction: public Function {
162public:
163
164 PostScriptFunction(Object *funcObj, Dict *dict);
165 virtual ~PostScriptFunction();
166 virtual Function *copy() const { return new PostScriptFunction(this); }
167 virtual void transform(const double *in, double *out) const;
168 virtual GBool isOk() const { return ok; }
169
170private:
171
172 PostScriptFunction(const 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) const;
177
178 PSObject *code;
179 int codeSize;
180 GBool ok;
181};
182
183#endif