Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:46

0001 //========================================================================
0002 //
0003 // Function.h
0004 //
0005 // Copyright 2001-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2009, 2010, 2018, 2019, 2021 Albert Astals Cid <aacid@kde.org>
0017 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
0018 // Copyright (C) 2011 Andrea Canciani <ranma42@gmail.com>
0019 // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
0020 // Copyright (C) 2012 Adam Reichold <adamreichold@myopera.com>
0021 //
0022 // To see a description of the changes please see the Changelog file that
0023 // came with your tarball or type make ChangeLog if you are building from git
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 // Function
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     // Construct a function.  Returns NULL if unsuccessful.
0057     static Function *parse(Object *funcObj);
0058 
0059     // Initialize the entries common to all function types.
0060     bool init(Dict *dict);
0061 
0062     virtual Function *copy() const = 0;
0063 
0064     // Return the function type:
0065     //   -1 : identity
0066     //    0 : sampled
0067     //    2 : exponential
0068     //    3 : stitching
0069     //    4 : PostScript
0070     virtual int getType() const = 0;
0071 
0072     // Return size of input and output tuples.
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     // Transform an input tuple into an output tuple.
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; // size of input and output tuples
0094     double // min and max values for function domain
0095             domain[funcMaxInputs][2];
0096     double // min and max values for function range
0097             range[funcMaxOutputs][2];
0098     bool hasRange; // set if range is defined
0099 };
0100 
0101 //------------------------------------------------------------------------
0102 // IdentityFunction
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 // SampledFunction
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 // number of samples for each domain element
0145             sampleSize[funcMaxInputs];
0146     double // min and max values for domain encoder
0147             encode[funcMaxInputs][2];
0148     double // min and max values for range decoder
0149             decode[funcMaxOutputs][2];
0150     double // input multipliers
0151             inputMul[funcMaxInputs];
0152     int *idxOffset;
0153     double *samples; // the samples
0154     int nSamples; // size of the samples array
0155     double *sBuf; // buffer for the transform function
0156     mutable double cacheIn[funcMaxInputs];
0157     mutable double cacheOut[funcMaxOutputs];
0158     bool ok;
0159 };
0160 
0161 //------------------------------------------------------------------------
0162 // ExponentialFunction
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 // StitchingFunction
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 // PostScriptFunction
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