summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/fpdf_page_colors.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-03-17 11:16:18 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-17 22:11:51 +0000
commitac6e2a059dbd74f6f9f1c216600496cfa5676387 (patch)
treee844921177b0f7ba09c2a3c34ead15b0c24b4000 /core/fpdfapi/page/fpdf_page_colors.cpp
parent7a1220dc1c0051f2a6bf50f3f38419ae51ecb9a1 (diff)
downloadpdfium-ac6e2a059dbd74f6f9f1c216600496cfa5676387.tar.xz
Bring CPDF_ICCBasedCS closer to PDF spec.
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 <thestig@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/fpdf_page_colors.cpp')
-rw-r--r--core/fpdfapi/page/fpdf_page_colors.cpp23
1 files changed, 16 insertions, 7 deletions
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);