File indexing completed on 2025-12-10 10:23:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef FUNCTION_H
0028 #define FUNCTION_H
0029
0030 #include "Object.h"
0031 #include <set>
0032
0033 class Dict;
0034 class Stream;
0035 struct PSObject;
0036 class PSStack;
0037
0038
0039
0040
0041
0042 #define funcMaxInputs 32
0043 #define funcMaxOutputs 32
0044 #define sampledFuncMaxInputs 16
0045
0046 class POPPLER_PRIVATE_EXPORT Function
0047 {
0048 public:
0049 Function();
0050
0051 virtual ~Function();
0052
0053 Function(const Function &) = delete;
0054 Function &operator=(const Function &other) = delete;
0055
0056
0057 static Function *parse(Object *funcObj);
0058
0059
0060 bool init(Dict *dict);
0061
0062 virtual Function *copy() const = 0;
0063
0064
0065
0066
0067
0068
0069
0070 virtual int getType() const = 0;
0071
0072
0073 int getInputSize() const { return m; }
0074 int getOutputSize() const { return n; }
0075
0076 double getDomainMin(int i) const { return domain[i][0]; }
0077 double getDomainMax(int i) const { return domain[i][1]; }
0078 double getRangeMin(int i) const { return range[i][0]; }
0079 double getRangeMax(int i) const { return range[i][1]; }
0080 bool getHasRange() const { return hasRange; }
0081 virtual bool hasDifferentResultSet(const Function *func) const { return false; }
0082
0083
0084 virtual void transform(const double *in, double *out) const = 0;
0085
0086 virtual bool isOk() const = 0;
0087
0088 protected:
0089 static Function *parse(Object *funcObj, std::set<int> *usedParents);
0090
0091 explicit Function(const Function *func);
0092
0093 int m, n;
0094 double
0095 domain[funcMaxInputs][2];
0096 double
0097 range[funcMaxOutputs][2];
0098 bool hasRange;
0099 };
0100
0101
0102
0103
0104
0105 class IdentityFunction : public Function
0106 {
0107 public:
0108 IdentityFunction();
0109 ~IdentityFunction() override;
0110 Function *copy() const override { return new IdentityFunction(); }
0111 int getType() const override { return -1; }
0112 void transform(const double *in, double *out) const override;
0113 bool isOk() const override { return true; }
0114
0115 private:
0116 };
0117
0118
0119
0120
0121
0122 class SampledFunction : public Function
0123 {
0124 public:
0125 SampledFunction(Object *funcObj, Dict *dict);
0126 ~SampledFunction() override;
0127 Function *copy() const override { return new SampledFunction(this); }
0128 int getType() const override { return 0; }
0129 void transform(const double *in, double *out) const override;
0130 bool isOk() const override { return ok; }
0131 bool hasDifferentResultSet(const Function *func) const override;
0132
0133 int getSampleSize(int i) const { return sampleSize[i]; }
0134 double getEncodeMin(int i) const { return encode[i][0]; }
0135 double getEncodeMax(int i) const { return encode[i][1]; }
0136 double getDecodeMin(int i) const { return decode[i][0]; }
0137 double getDecodeMax(int i) const { return decode[i][1]; }
0138 const double *getSamples() const { return samples; }
0139 int getSampleNumber() const { return nSamples; }
0140
0141 private:
0142 explicit SampledFunction(const SampledFunction *func);
0143
0144 int
0145 sampleSize[funcMaxInputs];
0146 double
0147 encode[funcMaxInputs][2];
0148 double
0149 decode[funcMaxOutputs][2];
0150 double
0151 inputMul[funcMaxInputs];
0152 int *idxOffset;
0153 double *samples;
0154 int nSamples;
0155 double *sBuf;
0156 mutable double cacheIn[funcMaxInputs];
0157 mutable double cacheOut[funcMaxOutputs];
0158 bool ok;
0159 };
0160
0161
0162
0163
0164
0165 class ExponentialFunction : public Function
0166 {
0167 public:
0168 ExponentialFunction(Object *funcObj, Dict *dict);
0169 ~ExponentialFunction() override;
0170 Function *copy() const override { return new ExponentialFunction(this); }
0171 int getType() const override { return 2; }
0172 void transform(const double *in, double *out) const override;
0173 bool isOk() const override { return ok; }
0174
0175 const double *getC0() const { return c0; }
0176 const double *getC1() const { return c1; }
0177 double getE() const { return e; }
0178
0179 private:
0180 explicit ExponentialFunction(const ExponentialFunction *func);
0181
0182 double c0[funcMaxOutputs];
0183 double c1[funcMaxOutputs];
0184 double e;
0185 bool isLinear;
0186 bool ok;
0187 };
0188
0189
0190
0191
0192
0193 class StitchingFunction : public Function
0194 {
0195 public:
0196 StitchingFunction(Object *funcObj, Dict *dict, std::set<int> *usedParents);
0197 ~StitchingFunction() override;
0198 Function *copy() const override { return new StitchingFunction(this); }
0199 int getType() const override { return 3; }
0200 void transform(const double *in, double *out) const override;
0201 bool isOk() const override { return ok; }
0202
0203 int getNumFuncs() const { return k; }
0204 const Function *getFunc(int i) const { return funcs[i]; }
0205 const double *getBounds() const { return bounds; }
0206 const double *getEncode() const { return encode; }
0207 const double *getScale() const { return scale; }
0208
0209 private:
0210 explicit StitchingFunction(const StitchingFunction *func);
0211
0212 int k;
0213 Function **funcs;
0214 double *bounds;
0215 double *encode;
0216 double *scale;
0217 bool ok;
0218 };
0219
0220
0221
0222
0223
0224 class PostScriptFunction : public Function
0225 {
0226 public:
0227 PostScriptFunction(Object *funcObj, Dict *dict);
0228 ~PostScriptFunction() override;
0229 Function *copy() const override { return new PostScriptFunction(this); }
0230 int getType() const override { return 4; }
0231 void transform(const double *in, double *out) const override;
0232 bool isOk() const override { return ok; }
0233
0234 const GooString *getCodeString() const { return codeString; }
0235
0236 private:
0237 explicit PostScriptFunction(const PostScriptFunction *func);
0238 bool parseCode(Stream *str, int *codePtr);
0239 GooString getToken(Stream *str);
0240 void resizeCode(int newSize);
0241 void exec(PSStack *stack, int codePtr) const;
0242
0243 GooString *codeString;
0244 PSObject *code;
0245 int codeSize;
0246 mutable double cacheIn[funcMaxInputs];
0247 mutable double cacheOut[funcMaxOutputs];
0248 bool ok;
0249 };
0250
0251 #endif