diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/page/cpdf_color.cpp | 7 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_colorspace.cpp | 14 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_colorspace.h | 9 |
3 files changed, 17 insertions, 13 deletions
diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp index d364e8e822..73e3d36ec4 100644 --- a/core/fpdfapi/page/cpdf_color.cpp +++ b/core/fpdfapi/page/cpdf_color.cpp @@ -60,6 +60,7 @@ bool CPDF_Color::IsPatternInternal() const { } void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS) { + ASSERT(pCS); if (m_pCS == pCS) { if (!m_pBuffer) m_pBuffer = pCS->CreateBuf(); @@ -72,10 +73,10 @@ void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS) { ReleaseColorSpace(); m_pCS = pCS; - if (pCS) { + if (IsPatternInternal()) m_pBuffer = pCS->CreateBuf(); - pCS->GetDefaultColor(m_pBuffer); - } + else + m_pBuffer = pCS->CreateBufAndSetDefaultColor(); } void CPDF_Color::SetValue(const float* comps) { diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp index 7cecb19188..d9717f1d58 100644 --- a/core/fpdfapi/page/cpdf_colorspace.cpp +++ b/core/fpdfapi/page/cpdf_colorspace.cpp @@ -485,25 +485,25 @@ void CPDF_ColorSpace::Release() { delete this; } -int CPDF_ColorSpace::GetBufSize() const { +size_t CPDF_ColorSpace::GetBufSize() const { if (m_Family == PDFCS_PATTERN) return sizeof(PatternValue); return m_nComponents * sizeof(float); } -float* CPDF_ColorSpace::CreateBuf() { - int size = GetBufSize(); - return reinterpret_cast<float*>(FX_Alloc(uint8_t, size)); +float* CPDF_ColorSpace::CreateBuf() const { + return reinterpret_cast<float*>(FX_Alloc(uint8_t, GetBufSize())); } -void CPDF_ColorSpace::GetDefaultColor(float* buf) const { - if (!buf || m_Family == PDFCS_PATTERN) - return; +float* CPDF_ColorSpace::CreateBufAndSetDefaultColor() const { + ASSERT(m_Family != PDFCS_PATTERN); + float* buf = CreateBuf(); float min; float max; for (uint32_t i = 0; i < m_nComponents; i++) GetDefaultValue(i, &buf[i], &min, &max); + return buf; } uint32_t CPDF_ColorSpace::CountComponents() const { diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h index e9108578f5..b9879d135c 100644 --- a/core/fpdfapi/page/cpdf_colorspace.h +++ b/core/fpdfapi/page/cpdf_colorspace.h @@ -53,9 +53,12 @@ class CPDF_ColorSpace { void Release(); - int GetBufSize() const; - float* CreateBuf(); - void GetDefaultColor(float* buf) const; + size_t GetBufSize() const; + float* CreateBuf() const; + + // Should only be called if this colorspace is not a pattern. + float* CreateBufAndSetDefaultColor() const; + uint32_t CountComponents() const; int GetFamily() const { return m_Family; } bool IsSpecial() const { |