1 // Copyright 2017 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFAPI_PAGE_CPDF_FUNCTION_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_FUNCTION_H_ 9 10 #include <memory> 11 #include <set> 12 #include <vector> 13 14 class CPDF_ExpIntFunc; 15 class CPDF_Object; 16 class CPDF_SampledFunc; 17 class CPDF_StitchFunc; 18 19 class CPDF_Function { 20 public: 21 enum class Type { 22 kTypeInvalid = -1, 23 kType0Sampled = 0, 24 kType2ExpotentialInterpolation = 2, 25 kType3Stitching = 3, 26 kType4PostScript = 4, 27 }; 28 29 static std::unique_ptr<CPDF_Function> Load(const CPDF_Object* pFuncObj); 30 static Type IntegerToFunctionType(int iType); 31 32 virtual ~CPDF_Function(); 33 34 bool Call(const float* inputs, 35 uint32_t ninputs, 36 float* results, 37 int* nresults) const; CountInputs()38 uint32_t CountInputs() const { return m_nInputs; } CountOutputs()39 uint32_t CountOutputs() const { return m_nOutputs; } GetDomain(int i)40 float GetDomain(int i) const { return m_Domains[i]; } GetRange(int i)41 float GetRange(int i) const { return m_Ranges[i]; } 42 float Interpolate(float x, 43 float xmin, 44 float xmax, 45 float ymin, 46 float ymax) const; 47 48 const CPDF_SampledFunc* ToSampledFunc() const; 49 const CPDF_ExpIntFunc* ToExpIntFunc() const; 50 const CPDF_StitchFunc* ToStitchFunc() const; 51 52 protected: 53 explicit CPDF_Function(Type type); 54 55 static std::unique_ptr<CPDF_Function> Load( 56 const CPDF_Object* pFuncObj, 57 std::set<const CPDF_Object*>* pVisited); 58 bool Init(const CPDF_Object* pObj, std::set<const CPDF_Object*>* pVisited); 59 virtual bool v_Init(const CPDF_Object* pObj, 60 std::set<const CPDF_Object*>* pVisited) = 0; 61 virtual bool v_Call(const float* inputs, float* results) const = 0; 62 63 const Type m_Type; 64 uint32_t m_nInputs; 65 uint32_t m_nOutputs; 66 std::vector<float> m_Domains; 67 std::vector<float> m_Ranges; 68 }; 69 70 #endif // CORE_FPDFAPI_PAGE_CPDF_FUNCTION_H_ 71