From ac6e2a059dbd74f6f9f1c216600496cfa5676387 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 17 Mar 2017 11:16:18 -0700 Subject: Bring CPDF_ICCBasedCS closer to PDF spec. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spec says the N dictionary field is required and must be set to a valid value. Adjust the code based on this assertion. BUG=pdfium:675,chromium:691967,chromium:702238 Change-Id: Iaa76fa0e16ce4aaa9822ad471668cbf8af5fb7cb Reviewed-on: https://pdfium-review.googlesource.com/3112 Commit-Queue: Lei Zhang Reviewed-by: Nicolás Peña --- core/fpdfapi/page/fpdf_page_colors.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'core/fpdfapi/page/fpdf_page_colors.cpp') diff --git a/core/fpdfapi/page/fpdf_page_colors.cpp b/core/fpdfapi/page/fpdf_page_colors.cpp index 061aae807a..e69620ea9a 100644 --- a/core/fpdfapi/page/fpdf_page_colors.cpp +++ b/core/fpdfapi/page/fpdf_page_colors.cpp @@ -25,6 +25,11 @@ float NormalizeChannel(float fVal) { return std::min(std::max(fVal, 0.0f), 1.0f); } +bool DetectSRGB(const uint8_t* pData, uint32_t dwSize) { + return dwSize == 3144 && + FXSYS_memcmp(pData + 0x190, "sRGB IEC61966-2.1", 17) == 0; +} + } // namespace uint32_t ComponentsForFamily(int family) { @@ -214,16 +219,20 @@ void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf, } CPDF_IccProfile::CPDF_IccProfile(const uint8_t* pData, uint32_t dwSize) - : m_bsRGB(false), m_pTransform(nullptr), m_nSrcComponents(0) { - if (dwSize == 3144 && - FXSYS_memcmp(pData + 0x190, "sRGB IEC61966-2.1", 17) == 0) { - m_bsRGB = true; + : m_bsRGB(DetectSRGB(pData, dwSize)) { + if (m_bsRGB) { m_nSrcComponents = 3; - } else if (CPDF_ModuleMgr::Get()->GetIccModule()) { - m_pTransform = CPDF_ModuleMgr::Get()->GetIccModule()->CreateTransform_sRGB( - pData, dwSize, m_nSrcComponents); + return; + } + auto* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule(); + if (pIccModule) { + uint32_t nSrcComps = 0; + m_pTransform = pIccModule->CreateTransform_sRGB(pData, dwSize, nSrcComps); + if (m_pTransform) + m_nSrcComponents = nSrcComps; } } + CPDF_IccProfile::~CPDF_IccProfile() { if (m_pTransform) { CPDF_ModuleMgr::Get()->GetIccModule()->DestroyTransform(m_pTransform); -- cgit v1.2.3