summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-16 20:02:37 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-16 20:02:37 +0000
commit219b0a63fad9dd99ad0bd79b721edf64996ac467 (patch)
treec148612868c5c6ec4f321e77b1a0b1b0cb60eb8c
parenta8c23df288d6fdfa2591ec43843ab3090bd95951 (diff)
downloadpdfium-219b0a63fad9dd99ad0bd79b721edf64996ac467.tar.xz
Consolidate Black/Whitepoint parsing code CPDF_ColorSpace.
Also use more constants. Change-Id: I02cb74d5ef5a44b1772d826be63ceb64b167c0db Reviewed-on: https://pdfium-review.googlesource.com/21913 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 593176bfbb..7fdee86dc5 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -96,6 +96,16 @@ void GetBlackPoint(const CPDF_Dictionary* pDict, float* pPoints) {
}
}
+bool GetWhitePoint(const CPDF_Dictionary* pDict, float* pPoints) {
+ const CPDF_Array* pParam = pDict->GetArrayFor("WhitePoint");
+ if (!pParam || pParam->GetCount() != kBlackWhitePointCount)
+ return false;
+
+ for (size_t i = 0; i < kBlackWhitePointCount; ++i)
+ pPoints[i] = pParam->GetNumberAt(i);
+ return pPoints[0] > 0.0f && pPoints[1] == 1.0f && pPoints[2] > 0.0f;
+}
+
class CPDF_CalGray : public CPDF_ColorSpace {
public:
explicit CPDF_CalGray(CPDF_Document* pDoc);
@@ -607,9 +617,8 @@ uint32_t CPDF_CalGray::v_Load(CPDF_Document* pDoc,
if (!pDict)
return 0;
- CPDF_Array* pParam = pDict->GetArrayFor("WhitePoint");
- for (size_t i = 0; i < kBlackWhitePointCount; ++i)
- m_WhitePoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
+ if (!GetWhitePoint(pDict, m_WhitePoint))
+ return 0;
GetBlackPoint(pDict, m_BlackPoint);
@@ -652,13 +661,12 @@ uint32_t CPDF_CalRGB::v_Load(CPDF_Document* pDoc,
if (!pDict)
return 0;
- CPDF_Array* pParam = pDict->GetArrayFor("WhitePoint");
- for (size_t i = 0; i < kBlackWhitePointCount; ++i)
- m_WhitePoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
+ if (!GetWhitePoint(pDict, m_WhitePoint))
+ return 0;
GetBlackPoint(pDict, m_BlackPoint);
- pParam = pDict->GetArrayFor("Gamma");
+ CPDF_Array* pParam = pDict->GetArrayFor("Gamma");
if (pParam) {
m_bGamma = true;
for (size_t i = 0; i < FX_ArraySize(m_Gamma); ++i)
@@ -757,13 +765,12 @@ uint32_t CPDF_LabCS::v_Load(CPDF_Document* pDoc,
if (!pDict)
return 0;
- CPDF_Array* pParam = pDict->GetArrayFor("WhitePoint");
- for (size_t i = 0; i < kBlackWhitePointCount; ++i)
- m_WhitePoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
+ if (!GetWhitePoint(pDict, m_WhitePoint))
+ return 0;
GetBlackPoint(pDict, m_BlackPoint);
- pParam = pDict->GetArrayFor("Range");
+ CPDF_Array* pParam = pDict->GetArrayFor("Range");
static constexpr float kDefaultRanges[kRangesCount] = {-100.0f, 100.0f,
-100.0f, 100.0f};
static_assert(FX_ArraySize(kDefaultRanges) == FX_ArraySize(m_Ranges),