Home | History | Annotate | Download | only in page
      1 // Copyright 2016 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_COLORSPACE_H_
      8 #define CORE_FPDFAPI_PAGE_CPDF_COLORSPACE_H_
      9 
     10 #include <memory>
     11 
     12 #include "core/fxcrt/fx_string.h"
     13 #include "core/fxcrt/fx_system.h"
     14 
     15 #define PDFCS_DEVICEGRAY 1
     16 #define PDFCS_DEVICERGB 2
     17 #define PDFCS_DEVICECMYK 3
     18 #define PDFCS_CALGRAY 4
     19 #define PDFCS_CALRGB 5
     20 #define PDFCS_LAB 6
     21 #define PDFCS_ICCBASED 7
     22 #define PDFCS_SEPARATION 8
     23 #define PDFCS_DEVICEN 9
     24 #define PDFCS_INDEXED 10
     25 #define PDFCS_PATTERN 11
     26 
     27 class CPDF_Array;
     28 class CPDF_Document;
     29 class CPDF_Object;
     30 
     31 class CPDF_ColorSpace {
     32  public:
     33   static CPDF_ColorSpace* GetStockCS(int Family);
     34   static CPDF_ColorSpace* ColorspaceFromName(const CFX_ByteString& name);
     35   static std::unique_ptr<CPDF_ColorSpace> Load(CPDF_Document* pDoc,
     36                                                CPDF_Object* pCSObj);
     37 
     38   void Release();
     39 
     40   int GetBufSize() const;
     41   FX_FLOAT* CreateBuf();
     42   void GetDefaultColor(FX_FLOAT* buf) const;
     43   uint32_t CountComponents() const;
     44   int GetFamily() const { return m_Family; }
     45   virtual void GetDefaultValue(int iComponent,
     46                                FX_FLOAT& value,
     47                                FX_FLOAT& min,
     48                                FX_FLOAT& max) const;
     49 
     50   bool sRGB() const;
     51   virtual bool GetRGB(FX_FLOAT* pBuf,
     52                       FX_FLOAT& R,
     53                       FX_FLOAT& G,
     54                       FX_FLOAT& B) const = 0;
     55   virtual bool SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const;
     56 
     57   bool GetCMYK(FX_FLOAT* pBuf,
     58                FX_FLOAT& c,
     59                FX_FLOAT& m,
     60                FX_FLOAT& y,
     61                FX_FLOAT& k) const;
     62   bool SetCMYK(FX_FLOAT* pBuf,
     63                FX_FLOAT c,
     64                FX_FLOAT m,
     65                FX_FLOAT y,
     66                FX_FLOAT k) const;
     67 
     68   virtual void TranslateImageLine(uint8_t* dest_buf,
     69                                   const uint8_t* src_buf,
     70                                   int pixels,
     71                                   int image_width,
     72                                   int image_height,
     73                                   bool bTransMask = false) const;
     74 
     75   CPDF_Array*& GetArray() { return m_pArray; }
     76   virtual CPDF_ColorSpace* GetBaseCS() const;
     77 
     78   virtual void EnableStdConversion(bool bEnabled);
     79 
     80   CPDF_Document* const m_pDocument;
     81 
     82  protected:
     83   CPDF_ColorSpace(CPDF_Document* pDoc, int family, uint32_t nComponents);
     84   virtual ~CPDF_ColorSpace();
     85 
     86   virtual bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
     87   virtual bool v_GetCMYK(FX_FLOAT* pBuf,
     88                          FX_FLOAT& c,
     89                          FX_FLOAT& m,
     90                          FX_FLOAT& y,
     91                          FX_FLOAT& k) const;
     92   virtual bool v_SetCMYK(FX_FLOAT* pBuf,
     93                          FX_FLOAT c,
     94                          FX_FLOAT m,
     95                          FX_FLOAT y,
     96                          FX_FLOAT k) const;
     97 
     98   int m_Family;
     99   uint32_t m_nComponents;
    100   CPDF_Array* m_pArray;
    101   uint32_t m_dwStdConversion;
    102 };
    103 
    104 namespace std {
    105 
    106 // Make std::unique_ptr<CPDF_ColorSpace> call Release() rather than
    107 // simply deleting the object.
    108 template <>
    109 struct default_delete<CPDF_ColorSpace> {
    110   void operator()(CPDF_ColorSpace* pColorSpace) const {
    111     if (pColorSpace)
    112       pColorSpace->Release();
    113   }
    114 };
    115 
    116 }  // namespace std
    117 
    118 #endif  // CORE_FPDFAPI_PAGE_CPDF_COLORSPACE_H_
    119