diff options
author | Lei Zhang <thestig@chromium.org> | 2018-04-16 18:32:47 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-16 18:32:47 +0000 |
commit | 4aa00d537a7e328c4ce23887fd93b87986e93589 (patch) | |
tree | 5d038a0ba3bc248129e2ce2de10cd2e53e7cdc7c /core | |
parent | 0edfab886bc5a50fc7c11564b2b773cbc7e765c8 (diff) | |
download | pdfium-4aa00d537a7e328c4ce23887fd93b87986e93589.tar.xz |
More CPDF_Colorspace cleanup.
- Mark subclass members as private.
- Use more constants.
Change-Id: Idc2bcb7dd2af3908d0ce1389d6832f3d6c434766
Reviewed-on: https://pdfium-review.googlesource.com/30794
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/page/cpdf_colorspace.cpp | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp index b6a0ed428b..26b4d14227 100644 --- a/core/fpdfapi/page/cpdf_colorspace.cpp +++ b/core/fpdfapi/page/cpdf_colorspace.cpp @@ -89,7 +89,9 @@ class CPDF_CalGray : public CPDF_ColorSpace { bool bTransMask) const override; private: - float m_Gamma; + static constexpr float kDefaultGamma = 1.0f; + + float m_Gamma = kDefaultGamma; float m_WhitePoint[3]; float m_BlackPoint[3]; }; @@ -112,12 +114,16 @@ class CPDF_CalRGB : public CPDF_ColorSpace { int image_height, bool bTransMask) const override; - bool m_bGamma; - bool m_bMatrix; + private: + static constexpr size_t kGammaCount = 3; + static constexpr size_t kMatrixCount = 9; + float m_WhitePoint[3]; float m_BlackPoint[3]; - float m_Gamma[3]; - float m_Matrix[9]; + float m_Gamma[kGammaCount]; + float m_Matrix[kMatrixCount]; + bool m_bGamma = false; + bool m_bMatrix = false; }; class CPDF_LabCS : public CPDF_ColorSpace { @@ -142,9 +148,12 @@ class CPDF_LabCS : public CPDF_ColorSpace { int image_height, bool bTransMask) const override; + private: + static constexpr size_t kRangesCount = 4; + float m_WhitePoint[3]; float m_BlackPoint[3]; - float m_Ranges[4]; + float m_Ranges[kRangesCount]; }; class CPDF_ICCBasedCS : public CPDF_ColorSpace { @@ -197,6 +206,7 @@ class CPDF_IndexedCS : public CPDF_ColorSpace { void EnableStdConversion(bool bEnabled) override; + private: CPDF_ColorSpace* m_pBaseCS = nullptr; UnownedPtr<CPDF_CountedColorSpace> m_pCountedBaseCS; uint32_t m_nBaseComponents = 0; @@ -221,6 +231,7 @@ class CPDF_SeparationCS : public CPDF_ColorSpace { bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override; void EnableStdConversion(bool bEnabled) override; + private: std::unique_ptr<CPDF_ColorSpace> m_pAltCS; std::unique_ptr<CPDF_Function> m_pFunc; enum { None, All, Colorant } m_Type; @@ -242,6 +253,7 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace { bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override; void EnableStdConversion(bool bEnabled) override; + private: std::unique_ptr<CPDF_ColorSpace> m_pAltCS; std::unique_ptr<CPDF_Function> m_pFunc; }; @@ -580,7 +592,7 @@ uint32_t CPDF_CalGray::v_Load(CPDF_Document* pDoc, m_Gamma = pDict->GetNumberFor("Gamma"); if (m_Gamma == 0) - m_Gamma = 1.0f; + m_Gamma = kDefaultGamma; return 1; } @@ -628,19 +640,15 @@ uint32_t CPDF_CalRGB::v_Load(CPDF_Document* pDoc, pParam = pDict->GetArrayFor("Gamma"); if (pParam) { m_bGamma = true; - for (int i = 0; i < 3; i++) + for (size_t i = 0; i < FX_ArraySize(m_Gamma); ++i) m_Gamma[i] = pParam->GetNumberAt(i); - } else { - m_bGamma = false; } pParam = pDict->GetArrayFor("Matrix"); if (pParam) { m_bMatrix = true; - for (int i = 0; i < 9; i++) + for (size_t i = 0; i < FX_ArraySize(m_Matrix); ++i) m_Matrix[i] = pParam->GetNumberAt(i); - } else { - m_bMatrix = false; } return 3; } @@ -737,8 +745,11 @@ uint32_t CPDF_LabCS::v_Load(CPDF_Document* pDoc, m_BlackPoint[i] = pParam ? pParam->GetNumberAt(i) : 0; pParam = pDict->GetArrayFor("Range"); - const float kDefaultRanges[4] = {-100.0f, 100.0f, -100.0f, 100.0f}; - for (size_t i = 0; i < FX_ArraySize(kDefaultRanges); i++) + static constexpr float kDefaultRanges[kRangesCount] = {-100.0f, 100.0f, + -100.0f, 100.0f}; + static_assert(FX_ArraySize(kDefaultRanges) == FX_ArraySize(m_Ranges), + "Range size mismatch"); + for (size_t i = 0; i < FX_ArraySize(kDefaultRanges); ++i) m_Ranges[i] = pParam ? pParam->GetNumberAt(i) : kDefaultRanges[i]; return 3; } |