summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-06-16 16:18:47 -0700
committerTom Sepez <tsepez@chromium.org>2015-06-16 16:18:47 -0700
commitea44bd064a86679a47a7265020f997d6e3b88336 (patch)
treee74d7540d03da8250bcb2fbae087d0c9ddb94cef
parent5fef754bc09e971f1bf1ba79da98c0a7ee1e1c8d (diff)
downloadpdfium-ea44bd064a86679a47a7265020f997d6e3b88336.tar.xz
Add constructor for CPDF_ColorSpace.
Prevents sub-classes from tweaking parent class instance vars. Also "fix" https://code.google.com/p/pdfium/issues/detail?id=170, assuming 0 is a good value. BUG=pdfium:170 R=thestig@chromium.org Review URL: https://codereview.chromium.org/1185903002.
-rw-r--r--core/include/fpdfapi/fpdf_page.h1
-rw-r--r--core/include/fpdfapi/fpdf_resource.h12
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp341
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp7
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h71
5 files changed, 229 insertions, 203 deletions
diff --git a/core/include/fpdfapi/fpdf_page.h b/core/include/fpdfapi/fpdf_page.h
index e766504ee1..7aed626fae 100644
--- a/core/include/fpdfapi/fpdf_page.h
+++ b/core/include/fpdfapi/fpdf_page.h
@@ -21,7 +21,6 @@ class CPDF_StreamFilter;
class CPDF_AllStates;
class CPDF_ContentParser;
class CPDF_StreamContentParser;
-class CPDF_ResourceNaming;
#define PDFTRANS_GROUP 0x0100
#define PDFTRANS_ISOLATED 0x0200
#define PDFTRANS_KNOCKOUT 0x0400
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 19ba818180..a73b2cd1a2 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -637,11 +637,17 @@ public:
}
virtual void EnableStdConversion(FX_BOOL bEnabled);
- CPDF_Document* m_pDocument;
-protected:
- CPDF_ColorSpace();
+ CPDF_Document* const m_pDocument;
+protected:
+ CPDF_ColorSpace(CPDF_Document* pDoc, int family, int nComponents)
+ : m_pDocument(pDoc),
+ m_Family(family),
+ m_nComponents(nComponents),
+ m_pArray(nullptr),
+ m_dwStdConversion(0) {
+ }
virtual ~CPDF_ColorSpace() {}
virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
index 8ee966fcfb..bcb6f4cb58 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
@@ -9,6 +9,9 @@
#include "../../../include/fxcodec/fx_codec.h"
#include "pageint.h"
#include <limits.h>
+
+namespace {
+
void sRGB_to_AdobeCMYK(FX_FLOAT R, FX_FLOAT G, FX_FLOAT B, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k)
{
c = 1.0f - R;
@@ -22,17 +25,21 @@ void sRGB_to_AdobeCMYK(FX_FLOAT R, FX_FLOAT G, FX_FLOAT B, FX_FLOAT& c, FX_FLOAT
k = y;
}
}
-CPDF_DeviceCS::CPDF_DeviceCS(int family)
-{
- m_Family = family;
- if (m_Family == PDFCS_DEVICERGB) {
- m_nComponents = 3;
- } else if (m_Family == PDFCS_DEVICEGRAY) {
- m_nComponents = 1;
- } else {
- m_nComponents = 4;
- }
+
+int ComponentsForFamily(int family) {
+ if (family == PDFCS_DEVICERGB)
+ return 3;
+ if (family == PDFCS_DEVICEGRAY)
+ return 1;
+ return 4;
}
+
+} // namespace
+
+CPDF_DeviceCS::CPDF_DeviceCS(CPDF_Document* pDoc, int family)
+ : CPDF_ColorSpace(pDoc, family, ComponentsForFamily(family)) {
+}
+
FX_BOOL CPDF_DeviceCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const
{
if (m_Family == PDFCS_DEVICERGB) {
@@ -264,20 +271,21 @@ static void XYZ_to_sRGB_WhitePoint(FX_FLOAT X, FX_FLOAT Y, FX_FLOAT Z, FX_FLOAT&
class CPDF_CalGray : public CPDF_ColorSpace
{
public:
- CPDF_CalGray();
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- virtual void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask = FALSE) const;
- FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const;
- FX_FLOAT m_WhitePoint[3];
- FX_FLOAT m_BlackPoint[3];
- FX_FLOAT m_Gamma;
+ explicit CPDF_CalGray(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_CALGRAY, 1) {
+ }
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const override;
+ FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const override;
+ void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width,
+ int image_height, FX_BOOL bTransMask = FALSE) const override;
+
+private:
+ FX_FLOAT m_WhitePoint[3];
+ FX_FLOAT m_BlackPoint[3];
+ FX_FLOAT m_Gamma;
};
-CPDF_CalGray::CPDF_CalGray()
-{
- m_Family = PDFCS_CALGRAY;
- m_nComponents = 1;
-}
+
FX_BOOL CPDF_CalGray::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
CPDF_Dictionary* pDict = pArray->GetDict(1);
@@ -321,22 +329,22 @@ void CPDF_CalGray::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf,
class CPDF_CalRGB : public CPDF_ColorSpace
{
public:
- CPDF_CalRGB();
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- virtual void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask = FALSE) const;
- FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const;
- FX_FLOAT m_WhitePoint[3];
- FX_FLOAT m_BlackPoint[3];
- FX_FLOAT m_Gamma[3];
- FX_FLOAT m_Matrix[9];
- FX_BOOL m_bGamma, m_bMatrix;
+ explicit CPDF_CalRGB(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_CALRGB, 3) {
+ }
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const override;
+ FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const override;
+ void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width,
+ int image_height, FX_BOOL bTransMask = FALSE) const override;
+
+ FX_FLOAT m_WhitePoint[3];
+ FX_FLOAT m_BlackPoint[3];
+ FX_FLOAT m_Gamma[3];
+ FX_FLOAT m_Matrix[9];
+ FX_BOOL m_bGamma;
+ FX_BOOL m_bMatrix;
};
-CPDF_CalRGB::CPDF_CalRGB()
-{
- m_Family = PDFCS_CALRGB;
- m_nComponents = 3;
-}
FX_BOOL CPDF_CalRGB::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
CPDF_Dictionary* pDict = pArray->GetDict(1);
@@ -421,19 +429,19 @@ void CPDF_CalRGB::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf,
class CPDF_LabCS : public CPDF_ColorSpace
{
public:
- CPDF_LabCS()
- {
- m_Family = PDFCS_LAB;
- m_nComponents = 3;
- }
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- virtual void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const;
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const;
- virtual void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask = FALSE) const;
- FX_FLOAT m_WhitePoint[3];
- FX_FLOAT m_BlackPoint[3];
- FX_FLOAT m_Ranges[4];
+ explicit CPDF_LabCS(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_LAB, 3) {
+ }
+ void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const override;
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const override;
+ FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const override;
+ void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width,
+ int image_height, FX_BOOL bTransMask = FALSE) const;
+
+ FX_FLOAT m_WhitePoint[3];
+ FX_FLOAT m_BlackPoint[3];
+ FX_FLOAT m_Ranges[4];
};
FX_BOOL CPDF_LabCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
@@ -543,34 +551,32 @@ CPDF_IccProfile::~CPDF_IccProfile()
class CPDF_ICCBasedCS : public CPDF_ColorSpace
{
public:
- CPDF_ICCBasedCS();
- virtual ~CPDF_ICCBasedCS();
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- void GetDefaultValue(int i, FX_FLOAT& min, FX_FLOAT& max) const
- {
- min = m_pRanges[i * 2];
- max = m_pRanges[i * 2 + 1];
- }
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- FX_BOOL v_GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const;
- FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const;
- virtual void EnableStdConversion(FX_BOOL bEnabled);
- virtual void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask = FALSE) const;
- FX_FLOAT* m_pRanges;
- CPDF_IccProfile* m_pProfile;
- CPDF_ColorSpace* m_pAlterCS;
- uint8_t* m_pCache;
- FX_BOOL m_bOwn;
+ explicit CPDF_ICCBasedCS(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_ICCBASED, 0),
+ m_pAlterCS(nullptr),
+ m_pProfile(nullptr),
+ m_pCache(nullptr),
+ m_pRanges(nullptr),
+ m_bOwn(FALSE) {
+ }
+ ~CPDF_ICCBasedCS() override;
+
+ void GetDefaultValue(int i, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const override;
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const override;
+ FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const override;
+ FX_BOOL v_GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const override;
+ void EnableStdConversion(FX_BOOL bEnabled) override;
+ void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width,
+ int image_height, FX_BOOL bTransMask = FALSE) const override;
+
+ CPDF_ColorSpace* m_pAlterCS;
+ CPDF_IccProfile* m_pProfile;
+ uint8_t* m_pCache;
+ FX_FLOAT* m_pRanges;
+ FX_BOOL m_bOwn;
};
-CPDF_ICCBasedCS::CPDF_ICCBasedCS()
-{
- m_pAlterCS = NULL;
- m_pProfile = NULL;
- m_Family = PDFCS_ICCBASED;
- m_pCache = NULL;
- m_pRanges = NULL;
- m_bOwn = FALSE;
-}
+
CPDF_ICCBasedCS::~CPDF_ICCBasedCS()
{
if (m_pCache) {
@@ -586,6 +592,14 @@ CPDF_ICCBasedCS::~CPDF_ICCBasedCS()
m_pDocument->GetPageData()->ReleaseIccProfile(m_pProfile);
}
}
+
+void CPDF_ICCBasedCS::GetDefaultValue(int i, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const
+{
+ min = m_pRanges[i * 2];
+ max = m_pRanges[i * 2 + 1];
+ value = min;
+}
+
FX_BOOL CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
CPDF_Stream* pStream = pArray->GetStream(1);
@@ -749,35 +763,27 @@ void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcB
class CPDF_IndexedCS : public CPDF_ColorSpace
{
public:
- CPDF_IndexedCS();
- virtual ~CPDF_IndexedCS();
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- void GetDefaultValue(int iComponent, FX_FLOAT& min, FX_FLOAT& max) const
- {
- min = 0;
- max = (FX_FLOAT)m_MaxIndex;
+ explicit CPDF_IndexedCS(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_INDEXED, 1),
+ m_pBaseCS(nullptr),
+ m_pCountedBaseCS(nullptr),
+ m_pCompMinMax(nullptr) {
}
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- virtual CPDF_ColorSpace* GetBaseCS() const
- {
- return m_pBaseCS;
- }
- virtual void EnableStdConversion(FX_BOOL bEnabled);
- CPDF_ColorSpace* m_pBaseCS;
- CPDF_CountedColorSpace* m_pCountedBaseCS;
- int m_nBaseComponents;
- int m_MaxIndex;
- CFX_ByteString m_Table;
- FX_FLOAT* m_pCompMinMax;
+ ~CPDF_IndexedCS() override;
+
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const override;
+ CPDF_ColorSpace* GetBaseCS() const override;
+ void EnableStdConversion(FX_BOOL bEnabled) override;
+
+ CPDF_ColorSpace* m_pBaseCS;
+ CPDF_CountedColorSpace* m_pCountedBaseCS;
+ int m_nBaseComponents;
+ int m_MaxIndex;
+ CFX_ByteString m_Table;
+ FX_FLOAT* m_pCompMinMax;
};
-CPDF_IndexedCS::CPDF_IndexedCS()
-{
- m_pBaseCS = NULL;
- m_pCountedBaseCS = NULL;
- m_Family = PDFCS_INDEXED;
- m_nComponents = 1;
- m_pCompMinMax = NULL;
-}
CPDF_IndexedCS::~CPDF_IndexedCS()
{
if (m_pCompMinMax) {
@@ -824,6 +830,13 @@ FX_BOOL CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
}
return TRUE;
}
+void CPDF_IndexedCS::GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const
+{
+ value = 0.0;
+ min = 0.0;
+ max = (FX_FLOAT)m_MaxIndex;
+}
+
FX_BOOL CPDF_IndexedCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const
{
int index = (int32_t)(*pBuf);
@@ -846,6 +859,10 @@ FX_BOOL CPDF_IndexedCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOA
m_pBaseCS->GetRGB(comps, R, G, B);
return TRUE;
}
+CPDF_ColorSpace*CPDF_IndexedCS::GetBaseCS() const
+{
+ return m_pBaseCS;
+}
void CPDF_IndexedCS::EnableStdConversion(FX_BOOL bEnabled)
{
CPDF_ColorSpace::EnableStdConversion(bEnabled);
@@ -860,13 +877,6 @@ typedef struct _PatternValue {
int m_nComps;
FX_FLOAT m_Comps[MAX_PATTERN_COLORCOMPS];
} PatternValue;
-CPDF_PatternCS::CPDF_PatternCS()
-{
- m_Family = PDFCS_PATTERN;
- m_pBaseCS = NULL;
- m_nComponents = 1;
- m_pCountedBaseCS = NULL;
-}
CPDF_PatternCS::~CPDF_PatternCS()
{
CPDF_ColorSpace* pCS = m_pCountedBaseCS ? m_pCountedBaseCS->get() : NULL;
@@ -908,31 +918,28 @@ FX_BOOL CPDF_PatternCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOA
R = G = B = 0.75f;
return FALSE;
}
+CPDF_ColorSpace* CPDF_PatternCS::GetBaseCS() const
+{
+ return m_pBaseCS;
+}
class CPDF_SeparationCS : public CPDF_ColorSpace
{
public:
- CPDF_SeparationCS();
- virtual ~CPDF_SeparationCS();
- virtual void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const
- {
- value = 1.0f;
- min = 0;
- max = 1.0f;
- }
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- virtual void EnableStdConversion(FX_BOOL bEnabled);
- CPDF_ColorSpace* m_pAltCS;
- CPDF_Function* m_pFunc;
- enum {None, All, Colorant} m_Type;
+ CPDF_SeparationCS(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_SEPARATION, 1),
+ m_pAltCS(nullptr),
+ m_pFunc(nullptr) {
+ }
+ ~CPDF_SeparationCS() override;
+ void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const override;
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const override;
+ void EnableStdConversion(FX_BOOL bEnabled) override;
+
+ CPDF_ColorSpace* m_pAltCS;
+ CPDF_Function* m_pFunc;
+ enum { None, All, Colorant } m_Type;
};
-CPDF_SeparationCS::CPDF_SeparationCS()
-{
- m_Family = PDFCS_SEPARATION;
- m_pAltCS = NULL;
- m_pFunc = NULL;
- m_nComponents = 1;
-}
CPDF_SeparationCS::~CPDF_SeparationCS()
{
if (m_pAltCS) {
@@ -942,6 +949,12 @@ CPDF_SeparationCS::~CPDF_SeparationCS()
delete m_pFunc;
}
}
+void CPDF_SeparationCS::GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const
+{
+ value = 1.0f;
+ min = 0;
+ max = 1.0f;
+}
FX_BOOL CPDF_SeparationCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
CFX_ByteString name = pArray->GetString(1);
@@ -1006,26 +1019,20 @@ void CPDF_SeparationCS::EnableStdConversion(FX_BOOL bEnabled)
class CPDF_DeviceNCS : public CPDF_ColorSpace
{
public:
- CPDF_DeviceNCS();
- virtual ~CPDF_DeviceNCS();
- virtual void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const
- {
- value = 1.0f;
- min = 0;
- max = 1.0f;
- }
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- virtual void EnableStdConversion(FX_BOOL bEnabled);
- CPDF_ColorSpace* m_pAltCS;
- CPDF_Function* m_pFunc;
+ CPDF_DeviceNCS(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_DEVICEN, 0),
+ m_pAltCS(nullptr),
+ m_pFunc(nullptr) {
+ }
+ ~CPDF_DeviceNCS() override;
+ void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const override;
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const override;
+ void EnableStdConversion(FX_BOOL bEnabled) override;
+
+ CPDF_ColorSpace* m_pAltCS;
+ CPDF_Function* m_pFunc;
};
-CPDF_DeviceNCS::CPDF_DeviceNCS()
-{
- m_Family = PDFCS_DEVICEN;
- m_pAltCS = NULL;
- m_pFunc = NULL;
-}
CPDF_DeviceNCS::~CPDF_DeviceNCS()
{
if (m_pFunc) {
@@ -1035,6 +1042,12 @@ CPDF_DeviceNCS::~CPDF_DeviceNCS()
m_pAltCS->ReleaseCS();
}
}
+void CPDF_DeviceNCS::GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const
+{
+ value = 1.0f;
+ min = 0;
+ max = 1.0f;
+}
FX_BOOL CPDF_DeviceNCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
CPDF_Object* pObj = pArray->GetElementValue(1);
@@ -1145,25 +1158,24 @@ CPDF_ColorSpace* CPDF_ColorSpace::Load(CPDF_Document* pDoc, CPDF_Object* pObj)
CPDF_ColorSpace* pCS = NULL;
FX_DWORD id = familyname.GetID();
if (id == FXBSTR_ID('C', 'a', 'l', 'G')) {
- pCS = new CPDF_CalGray();
+ pCS = new CPDF_CalGray(pDoc);
} else if (id == FXBSTR_ID('C', 'a', 'l', 'R')) {
- pCS = new CPDF_CalRGB();
+ pCS = new CPDF_CalRGB(pDoc);
} else if (id == FXBSTR_ID('L', 'a', 'b', 0)) {
- pCS = new CPDF_LabCS();
+ pCS = new CPDF_LabCS(pDoc);
} else if (id == FXBSTR_ID('I', 'C', 'C', 'B')) {
- pCS = new CPDF_ICCBasedCS();
+ pCS = new CPDF_ICCBasedCS(pDoc);
} else if (id == FXBSTR_ID('I', 'n', 'd', 'e') || id == FXBSTR_ID('I', 0, 0, 0)) {
- pCS = new CPDF_IndexedCS();
+ pCS = new CPDF_IndexedCS(pDoc);
} else if (id == FXBSTR_ID('S', 'e', 'p', 'a')) {
- pCS = new CPDF_SeparationCS();
+ pCS = new CPDF_SeparationCS(pDoc);
} else if (id == FXBSTR_ID('D', 'e', 'v', 'i')) {
- pCS = new CPDF_DeviceNCS();
+ pCS = new CPDF_DeviceNCS(pDoc);
} else if (id == FXBSTR_ID('P', 'a', 't', 't')) {
- pCS = new CPDF_PatternCS();
+ pCS = new CPDF_PatternCS(pDoc);
} else {
return NULL;
}
- pCS->m_pDocument = pDoc;
pCS->m_pArray = pArray;
if (!pCS->v_Load(pDoc, pArray)) {
pCS->ReleaseCS();
@@ -1171,13 +1183,6 @@ CPDF_ColorSpace* CPDF_ColorSpace::Load(CPDF_Document* pDoc, CPDF_Object* pObj)
}
return pCS;
}
-CPDF_ColorSpace::CPDF_ColorSpace()
-{
- m_Family = 0;
- m_pArray = NULL;
- m_dwStdConversion = 0;
- m_pDocument = NULL;
-}
void CPDF_ColorSpace::ReleaseCS()
{
if (this == GetStockCS(PDFCS_DEVICERGB)) {
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index 13d870d7e5..05233a12a4 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -14,9 +14,10 @@ class CPDF_PageModule : public IPDF_PageModule
{
public:
CPDF_PageModule()
- : m_StockGrayCS(PDFCS_DEVICEGRAY),
- m_StockRGBCS(PDFCS_DEVICERGB),
- m_StockCMYKCS(PDFCS_DEVICECMYK) {}
+ : m_StockGrayCS(nullptr, PDFCS_DEVICEGRAY),
+ m_StockRGBCS(nullptr, PDFCS_DEVICERGB),
+ m_StockCMYKCS(nullptr, PDFCS_DEVICECMYK),
+ m_StockPatternCS(nullptr) {}
private:
~CPDF_PageModule() override {}
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index e9141cd6b2..95e16cb8cf 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -411,42 +411,57 @@ public:
private:
int32_t m_nSrcComponents;
};
+
class CPDF_DeviceCS : public CPDF_ColorSpace
{
public:
- CPDF_DeviceCS(int family);
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const;
- FX_BOOL v_GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const;
- FX_BOOL v_SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const;
- virtual void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask = FALSE) const;
+ CPDF_DeviceCS(CPDF_Document* pDoc, int family);
+
+ FX_BOOL GetRGB(FX_FLOAT* pBuf,
+ FX_FLOAT& R,
+ FX_FLOAT& G,
+ FX_FLOAT& B) const override;
+ FX_BOOL SetRGB(FX_FLOAT* pBuf,
+ FX_FLOAT R,
+ FX_FLOAT G,
+ FX_FLOAT B) const override;
+ FX_BOOL v_GetCMYK(FX_FLOAT* pBuf,
+ FX_FLOAT& c,
+ FX_FLOAT& m,
+ FX_FLOAT& y,
+ FX_FLOAT& k) const override;
+ FX_BOOL v_SetCMYK(FX_FLOAT* pBuf,
+ FX_FLOAT c,
+ FX_FLOAT m,
+ FX_FLOAT y,
+ FX_FLOAT k) const override;
+ void TranslateImageLine(uint8_t* pDestBuf,
+ const uint8_t* pSrcBuf,
+ int pixels,
+ int image_width,
+ int image_height,
+ FX_BOOL bTransMask = FALSE) const override;
};
+
class CPDF_PatternCS : public CPDF_ColorSpace
{
public:
- CPDF_PatternCS();
- ~CPDF_PatternCS();
- virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray);
- virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
- virtual CPDF_ColorSpace* GetBaseCS() const
- {
- return m_pBaseCS;
+ explicit CPDF_PatternCS(CPDF_Document* pDoc)
+ : CPDF_ColorSpace(pDoc, PDFCS_PATTERN, 1),
+ m_pBaseCS(nullptr),
+ m_pCountedBaseCS(nullptr) {
}
- CPDF_ColorSpace* m_pBaseCS;
- CPDF_CountedColorSpace* m_pCountedBaseCS;
-};
-#define MAX_PAGE_OBJECTS_UNIFY_NAMING 4096
-class CPDF_ResourceNaming
-{
-public:
- struct _NamingState {
- CFX_ByteString m_Prefix;
- int m_nIndex;
- };
- ~CPDF_ResourceNaming();
- CFX_ByteString GetName(const CPDF_Dictionary* pResList, const FX_CHAR* szType);
-protected:
- CFX_MapByteStringToPtr m_NamingCache;
+ ~CPDF_PatternCS() override;
+ FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override;
+ FX_BOOL GetRGB(FX_FLOAT* pBuf,
+ FX_FLOAT& R,
+ FX_FLOAT& G,
+ FX_FLOAT& B) const override;
+ CPDF_ColorSpace* GetBaseCS() const override;
+
+private:
+ CPDF_ColorSpace* m_pBaseCS;
+ CPDF_CountedColorSpace* m_pCountedBaseCS;
};
#endif // CORE_SRC_FPDFAPI_FPDF_PAGE_PAGEINT_H_