From dd2a629f9ede484e0e570ce09d1e9d8906aa11be Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 20 Apr 2018 19:14:53 +0000 Subject: Add CPDF_PatternCS::GetPatternRGB(const PatternValue& value). Currently, one gets data from CPDF_PatternCS via its parent class's GetRGB(const float* pBuf) method. To squeeze through this interface, the caller has to pass in a float*, and CPDF_PatternCS::GetRGB() has to cast it to PatternValue*. Instead of doing casting, add a specialized GetPatternRGB() method to CPDF_PatternCS. In its parent class, CPDF_ColorSpace, add AsPatternCS() so callers can get a CPDF_PatternCS* from a CPDF_ColorSpace*. Change existing callers to use these new methods. Change-Id: Id476c9ece7ce8d3499a718acc682bc25036a5407 Reviewed-on: https://pdfium-review.googlesource.com/31030 Reviewed-by: Henrique Nakashima Commit-Queue: Lei Zhang --- core/fpdfapi/page/cpdf_color.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'core/fpdfapi/page/cpdf_color.cpp') diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp index dfee9d93ca..b3dd141103 100644 --- a/core/fpdfapi/page/cpdf_color.cpp +++ b/core/fpdfapi/page/cpdf_color.cpp @@ -7,6 +7,7 @@ #include "core/fpdfapi/page/cpdf_color.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" +#include "core/fpdfapi/page/cpdf_patterncs.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fxcrt/fx_system.h" @@ -155,13 +156,21 @@ bool CPDF_Color::IsColorSpaceRGB() const { } bool CPDF_Color::GetRGB(int* R, int* G, int* B) const { - if (!m_pCS || !m_pBuffer) + if (!m_pBuffer) return false; float r = 0.0f; float g = 0.0f; float b = 0.0f; - if (!m_pCS->GetRGB(m_pBuffer, &r, &g, &b)) + bool result; + if (IsPatternInternal()) { + const CPDF_PatternCS* pPatternCS = m_pCS->AsPatternCS(); + const auto* pValue = reinterpret_cast(m_pBuffer); + result = pPatternCS->GetPatternRGB(*pValue, &r, &g, &b); + } else { + result = m_pCS->GetRGB(m_pBuffer, &r, &g, &b); + } + if (!result) return false; *R = static_cast(r * 255 + 0.5f); -- cgit v1.2.3