Home | History | Annotate | Download | only in page
      1 // Copyright 2014 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_PAGEINT_H_
      8 #define CORE_FPDFAPI_PAGE_PAGEINT_H_
      9 
     10 #include <memory>
     11 #include <vector>
     12 
     13 #include "core/fpdfapi/page/cpdf_colorspace.h"
     14 #include "core/fpdfapi/page/cpdf_countedobject.h"
     15 
     16 class CPDF_ExpIntFunc;
     17 class CPDF_Pattern;
     18 class CPDF_SampledFunc;
     19 class CPDF_StitchFunc;
     20 class CPDF_StreamAcc;
     21 
     22 class CPDF_Function {
     23  public:
     24   enum class Type {
     25     kTypeInvalid = -1,
     26     kType0Sampled = 0,
     27     kType2ExpotentialInterpolation = 2,
     28     kType3Stitching = 3,
     29     kType4PostScript = 4,
     30   };
     31 
     32   static std::unique_ptr<CPDF_Function> Load(CPDF_Object* pFuncObj);
     33   static Type IntegerToFunctionType(int iType);
     34 
     35   virtual ~CPDF_Function();
     36   bool Call(FX_FLOAT* inputs,
     37             uint32_t ninputs,
     38             FX_FLOAT* results,
     39             int& nresults) const;
     40   uint32_t CountInputs() const { return m_nInputs; }
     41   uint32_t CountOutputs() const { return m_nOutputs; }
     42   FX_FLOAT GetDomain(int i) const { return m_pDomains[i]; }
     43   FX_FLOAT GetRange(int i) const { return m_pRanges[i]; }
     44 
     45   const CPDF_SampledFunc* ToSampledFunc() const;
     46   const CPDF_ExpIntFunc* ToExpIntFunc() const;
     47   const CPDF_StitchFunc* ToStitchFunc() const;
     48 
     49  protected:
     50   explicit CPDF_Function(Type type);
     51 
     52   bool Init(CPDF_Object* pObj);
     53   virtual bool v_Init(CPDF_Object* pObj) = 0;
     54   virtual bool v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const = 0;
     55 
     56   uint32_t m_nInputs;
     57   uint32_t m_nOutputs;
     58   FX_FLOAT* m_pDomains;
     59   FX_FLOAT* m_pRanges;
     60   const Type m_Type;
     61 };
     62 
     63 class CPDF_ExpIntFunc : public CPDF_Function {
     64  public:
     65   CPDF_ExpIntFunc();
     66   ~CPDF_ExpIntFunc() override;
     67 
     68   // CPDF_Function
     69   bool v_Init(CPDF_Object* pObj) override;
     70   bool v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
     71 
     72   uint32_t m_nOrigOutputs;
     73   FX_FLOAT m_Exponent;
     74   FX_FLOAT* m_pBeginValues;
     75   FX_FLOAT* m_pEndValues;
     76 };
     77 
     78 class CPDF_SampledFunc : public CPDF_Function {
     79  public:
     80   struct SampleEncodeInfo {
     81     FX_FLOAT encode_max;
     82     FX_FLOAT encode_min;
     83     uint32_t sizes;
     84   };
     85 
     86   struct SampleDecodeInfo {
     87     FX_FLOAT decode_max;
     88     FX_FLOAT decode_min;
     89   };
     90 
     91   CPDF_SampledFunc();
     92   ~CPDF_SampledFunc() override;
     93 
     94   // CPDF_Function
     95   bool v_Init(CPDF_Object* pObj) override;
     96   bool v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
     97 
     98   const std::vector<SampleEncodeInfo>& GetEncodeInfo() const {
     99     return m_EncodeInfo;
    100   }
    101   uint32_t GetBitsPerSample() const { return m_nBitsPerSample; }
    102   const CPDF_StreamAcc* GetSampleStream() const {
    103     return m_pSampleStream.get();
    104   }
    105 
    106  private:
    107   std::vector<SampleEncodeInfo> m_EncodeInfo;
    108   std::vector<SampleDecodeInfo> m_DecodeInfo;
    109   uint32_t m_nBitsPerSample;
    110   uint32_t m_SampleMax;
    111   std::unique_ptr<CPDF_StreamAcc> m_pSampleStream;
    112 };
    113 
    114 class CPDF_StitchFunc : public CPDF_Function {
    115  public:
    116   CPDF_StitchFunc();
    117   ~CPDF_StitchFunc() override;
    118 
    119   // CPDF_Function
    120   bool v_Init(CPDF_Object* pObj) override;
    121   bool v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
    122 
    123   const std::vector<std::unique_ptr<CPDF_Function>>& GetSubFunctions() const {
    124     return m_pSubFunctions;
    125   }
    126   FX_FLOAT GetBound(size_t i) const { return m_pBounds[i]; }
    127 
    128  private:
    129   std::vector<std::unique_ptr<CPDF_Function>> m_pSubFunctions;
    130   FX_FLOAT* m_pBounds;
    131   FX_FLOAT* m_pEncode;
    132 
    133   static const uint32_t kRequiredNumInputs = 1;
    134 };
    135 
    136 class CPDF_IccProfile {
    137  public:
    138   CPDF_IccProfile(const uint8_t* pData, uint32_t dwSize);
    139   ~CPDF_IccProfile();
    140   uint32_t GetComponents() const { return m_nSrcComponents; }
    141   bool m_bsRGB;
    142   void* m_pTransform;
    143 
    144  private:
    145   uint32_t m_nSrcComponents;
    146 };
    147 
    148 class CPDF_DeviceCS : public CPDF_ColorSpace {
    149  public:
    150   CPDF_DeviceCS(CPDF_Document* pDoc, int family);
    151 
    152   bool GetRGB(FX_FLOAT* pBuf,
    153               FX_FLOAT& R,
    154               FX_FLOAT& G,
    155               FX_FLOAT& B) const override;
    156   bool SetRGB(FX_FLOAT* pBuf,
    157               FX_FLOAT R,
    158               FX_FLOAT G,
    159               FX_FLOAT B) const override;
    160   bool v_GetCMYK(FX_FLOAT* pBuf,
    161                  FX_FLOAT& c,
    162                  FX_FLOAT& m,
    163                  FX_FLOAT& y,
    164                  FX_FLOAT& k) const override;
    165   bool v_SetCMYK(FX_FLOAT* pBuf,
    166                  FX_FLOAT c,
    167                  FX_FLOAT m,
    168                  FX_FLOAT y,
    169                  FX_FLOAT k) const override;
    170   void TranslateImageLine(uint8_t* pDestBuf,
    171                           const uint8_t* pSrcBuf,
    172                           int pixels,
    173                           int image_width,
    174                           int image_height,
    175                           bool bTransMask = false) const override;
    176 };
    177 
    178 class CPDF_PatternCS : public CPDF_ColorSpace {
    179  public:
    180   explicit CPDF_PatternCS(CPDF_Document* pDoc);
    181   ~CPDF_PatternCS() override;
    182   bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
    183   bool GetRGB(FX_FLOAT* pBuf,
    184               FX_FLOAT& R,
    185               FX_FLOAT& G,
    186               FX_FLOAT& B) const override;
    187   CPDF_ColorSpace* GetBaseCS() const override;
    188 
    189  private:
    190   CPDF_ColorSpace* m_pBaseCS;
    191   CPDF_CountedColorSpace* m_pCountedBaseCS;
    192 };
    193 
    194 #define MAX_PATTERN_COLORCOMPS 16
    195 struct PatternValue {
    196   CPDF_Pattern* m_pPattern;
    197   CPDF_CountedPattern* m_pCountedPattern;
    198   int m_nComps;
    199   FX_FLOAT m_Comps[MAX_PATTERN_COLORCOMPS];
    200 };
    201 
    202 CFX_ByteStringC PDF_FindKeyAbbreviationForTesting(const CFX_ByteStringC& abbr);
    203 CFX_ByteStringC PDF_FindValueAbbreviationForTesting(
    204     const CFX_ByteStringC& abbr);
    205 
    206 #endif  // CORE_FPDFAPI_PAGE_PAGEINT_H_
    207