00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef FUNCTION_H
00010 #define FUNCTION_H
00011
00012 #ifdef __GNUC__
00013 #pragma interface
00014 #endif
00015
00016 #include "gtypes.h"
00017 #include "Object.h"
00018
00019 class Dict;
00020 class Stream;
00021 struct PSObject;
00022 class PSStack;
00023
00024
00025
00026
00027
00028 #define funcMaxInputs 8
00029 #define funcMaxOutputs 8
00030
00031 class Function {
00032 public:
00033
00034 Function();
00035
00036 virtual ~Function();
00037
00038
00039 static Function *parse(Object *funcObj);
00040
00041
00042 GBool init(Dict *dict);
00043
00044 virtual Function *copy() = 0;
00045
00046
00047 int getInputSize() { return m; }
00048 int getOutputSize() { return n; }
00049
00050
00051 virtual void transform(fouble *in, fouble *out) = 0;
00052
00053 virtual GBool isOk() = 0;
00054
00055 protected:
00056
00057 int m, n;
00058 fouble
00059 domain[funcMaxInputs][2];
00060 fouble
00061 range[funcMaxOutputs][2];
00062 GBool hasRange;
00063 };
00064
00065
00066
00067
00068
00069 class IdentityFunction: public Function {
00070 public:
00071
00072 IdentityFunction();
00073 virtual ~IdentityFunction();
00074 virtual Function *copy() { return new IdentityFunction(); }
00075 virtual void transform(fouble *in, fouble *out);
00076 virtual GBool isOk() { return gTrue; }
00077
00078 private:
00079 };
00080
00081
00082
00083
00084
00085 class SampledFunction: public Function {
00086 public:
00087
00088 SampledFunction(Object *funcObj, Dict *dict);
00089 virtual ~SampledFunction();
00090 virtual Function *copy() { return new SampledFunction(this); }
00091 virtual void transform(fouble *in, fouble *out);
00092 virtual GBool isOk() { return ok; }
00093
00094 private:
00095
00096 SampledFunction(SampledFunction *func);
00097
00098 int
00099 sampleSize[funcMaxInputs];
00100 fouble
00101 encode[funcMaxInputs][2];
00102 fouble
00103 decode[funcMaxOutputs][2];
00104 fouble *samples;
00105 GBool ok;
00106 };
00107
00108
00109
00110
00111
00112 class ExponentialFunction: public Function {
00113 public:
00114
00115 ExponentialFunction(Object *funcObj, Dict *dict);
00116 virtual ~ExponentialFunction();
00117 virtual Function *copy() { return new ExponentialFunction(this); }
00118 virtual void transform(fouble *in, fouble *out);
00119 virtual GBool isOk() { return ok; }
00120
00121 private:
00122
00123 ExponentialFunction(ExponentialFunction *func);
00124
00125 fouble c0[funcMaxOutputs];
00126 fouble c1[funcMaxOutputs];
00127 fouble e;
00128 GBool ok;
00129 };
00130
00131
00132
00133
00134
00135 class StitchingFunction: public Function {
00136 public:
00137
00138 StitchingFunction(Object *funcObj, Dict *dict);
00139 virtual ~StitchingFunction();
00140 virtual Function *copy() { return new StitchingFunction(this); }
00141 virtual void transform(fouble *in, fouble *out);
00142 virtual GBool isOk() { return ok; }
00143
00144 private:
00145
00146 StitchingFunction(StitchingFunction *func);
00147
00148 int k;
00149 Function **funcs;
00150 fouble *bounds;
00151 fouble *encode;
00152 GBool ok;
00153 };
00154
00155
00156
00157
00158
00159 class PostScriptFunction: public Function {
00160 public:
00161
00162 PostScriptFunction(Object *funcObj, Dict *dict);
00163 virtual ~PostScriptFunction();
00164 virtual Function *copy() { return new PostScriptFunction(this); }
00165 virtual void transform(fouble *in, fouble *out);
00166 virtual GBool isOk() { return ok; }
00167
00168 private:
00169
00170 PostScriptFunction(PostScriptFunction *func);
00171 GBool parseCode(Stream *str, int *codePtr);
00172 GString *getToken(Stream *str);
00173 void resizeCode(int newSize);
00174 void exec(PSStack *stack, int codePtr);
00175
00176 PSObject *code;
00177 int codeSize;
00178 GBool ok;
00179 };
00180
00181 #endif