1 // Copyright 2017 The PDFium Authors 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 #include "core/fxcrt/retain_ptr.h" 15 #include "third_party/abseil-cpp/absl/types/optional.h" 16 #include "third_party/base/span.h" 17 18 class CPDF_ExpIntFunc; 19 class CPDF_Object; 20 class CPDF_SampledFunc; 21 class CPDF_StitchFunc; 22 23 class CPDF_Function { 24 public: 25 // Valid values are from ISO 32000-1:2008 spec, table 38. DO NOT CHANGE. 26 enum class Type { 27 kTypeInvalid = -1, 28 kType0Sampled = 0, 29 kType2ExponentialInterpolation = 2, 30 kType3Stitching = 3, 31 kType4PostScript = 4, 32 }; 33 34 static std::unique_ptr<CPDF_Function> Load( 35 RetainPtr<const CPDF_Object> pFuncObj); 36 37 virtual ~CPDF_Function(); 38 39 absl::optional<uint32_t> Call(pdfium::span<const float> inputs, 40 pdfium::span<float> results) const; CountInputs()41 uint32_t CountInputs() const { return m_nInputs; } CountOutputs()42 uint32_t CountOutputs() const { return m_nOutputs; } GetDomain(int i)43 float GetDomain(int i) const { return m_Domains[i]; } GetRange(int i)44 float GetRange(int i) const { return m_Ranges[i]; } 45 float Interpolate(float x, 46 float xmin, 47 float xmax, 48 float ymin, 49 float ymax) const; 50 51 #if defined(_SKIA_SUPPORT_) 52 const CPDF_SampledFunc* ToSampledFunc() const; 53 const CPDF_ExpIntFunc* ToExpIntFunc() const; 54 const CPDF_StitchFunc* ToStitchFunc() const; 55 #endif // defined(_SKIA_SUPPORT_) 56 57 protected: 58 explicit CPDF_Function(Type type); 59 60 using VisitedSet = std::set<RetainPtr<const CPDF_Object>>; 61 static std::unique_ptr<CPDF_Function> Load( 62 RetainPtr<const CPDF_Object> pFuncObj, 63 VisitedSet* pVisited); 64 bool Init(const CPDF_Object* pObj, VisitedSet* pVisited); 65 virtual bool v_Init(const CPDF_Object* pObj, VisitedSet* pVisited) = 0; 66 virtual bool v_Call(pdfium::span<const float> inputs, 67 pdfium::span<float> results) const = 0; 68 69 const Type m_Type; 70 uint32_t m_nInputs = 0; 71 uint32_t m_nOutputs = 0; 72 std::vector<float> m_Domains; 73 std::vector<float> m_Ranges; 74 }; 75 76 #endif // CORE_FPDFAPI_PAGE_CPDF_FUNCTION_H_ 77