• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 class CPDF_ExpIntFunc;
13 class CPDF_Object;
14 class CPDF_SampledFunc;
15 class CPDF_StitchFunc;
16 
17 class CPDF_Function {
18  public:
19   enum class Type {
20     kTypeInvalid = -1,
21     kType0Sampled = 0,
22     kType2ExpotentialInterpolation = 2,
23     kType3Stitching = 3,
24     kType4PostScript = 4,
25   };
26 
27   static std::unique_ptr<CPDF_Function> Load(CPDF_Object* pFuncObj);
28   static Type IntegerToFunctionType(int iType);
29 
30   virtual ~CPDF_Function();
31 
32   bool Call(float* inputs,
33             uint32_t ninputs,
34             float* results,
35             int* nresults) const;
CountInputs()36   uint32_t CountInputs() const { return m_nInputs; }
CountOutputs()37   uint32_t CountOutputs() const { return m_nOutputs; }
GetDomain(int i)38   float GetDomain(int i) const { return m_pDomains[i]; }
GetRange(int i)39   float GetRange(int i) const { return m_pRanges[i]; }
40   float Interpolate(float x,
41                     float xmin,
42                     float xmax,
43                     float ymin,
44                     float ymax) const;
45 
46   const CPDF_SampledFunc* ToSampledFunc() const;
47   const CPDF_ExpIntFunc* ToExpIntFunc() const;
48   const CPDF_StitchFunc* ToStitchFunc() const;
49 
50  protected:
51   explicit CPDF_Function(Type type);
52 
53   bool Init(CPDF_Object* pObj);
54   virtual bool v_Init(CPDF_Object* pObj) = 0;
55   virtual bool v_Call(float* inputs, float* results) const = 0;
56 
57   uint32_t m_nInputs;
58   uint32_t m_nOutputs;
59   float* m_pDomains;
60   float* m_pRanges;
61   const Type m_Type;
62 };
63 
64 #endif  // CORE_FPDFAPI_PAGE_CPDF_FUNCTION_H_
65