summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-12 17:56:35 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 17:56:35 +0000
commit6998bc502dd2798115024c48b95e6e9180b2b3ee (patch)
tree5a666d322c0ce76738bf905d06da7235e1edec83 /core/fpdfapi/page
parenta8db06a715cd0090a8c838a7b2861ca3c657f6a2 (diff)
downloadpdfium-6998bc502dd2798115024c48b95e6e9180b2b3ee.tar.xz
Make the input data to CPDF_ColorSpace::GetRGB() const.
Make a copy of the input data when clamping it in CPDF_Function::Call(). Change-Id: I1d2b3d080977f0f9a4c3ccaf111780867668991a Reviewed-on: https://pdfium-review.googlesource.com/30350 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp43
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.h5
-rw-r--r--core/fpdfapi/page/cpdf_devicecs.cpp5
-rw-r--r--core/fpdfapi/page/cpdf_devicecs.h2
-rw-r--r--core/fpdfapi/page/cpdf_function.cpp9
-rw-r--r--core/fpdfapi/page/cpdf_function.h2
-rw-r--r--core/fpdfapi/page/cpdf_patterncs.cpp7
-rw-r--r--core/fpdfapi/page/cpdf_patterncs.h2
8 files changed, 51 insertions, 24 deletions
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 528c6ea3cf..7cecb19188 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -80,7 +80,7 @@ class CPDF_CalGray : public CPDF_ColorSpace {
uint32_t v_Load(CPDF_Document* pDoc,
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void TranslateImageLine(uint8_t* pDestBuf,
const uint8_t* pSrcBuf,
int pixels,
@@ -103,7 +103,7 @@ class CPDF_CalRGB : public CPDF_ColorSpace {
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void TranslateImageLine(uint8_t* pDestBuf,
const uint8_t* pSrcBuf,
@@ -133,7 +133,7 @@ class CPDF_LabCS : public CPDF_ColorSpace {
float* value,
float* min,
float* max) const override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void TranslateImageLine(uint8_t* pDestBuf,
const uint8_t* pSrcBuf,
@@ -156,7 +156,7 @@ class CPDF_ICCBasedCS : public CPDF_ColorSpace {
uint32_t v_Load(CPDF_Document* pDoc,
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void EnableStdConversion(bool bEnabled) override;
void TranslateImageLine(uint8_t* pDestBuf,
const uint8_t* pSrcBuf,
@@ -193,7 +193,7 @@ class CPDF_IndexedCS : public CPDF_ColorSpace {
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void EnableStdConversion(bool bEnabled) override;
@@ -218,7 +218,7 @@ class CPDF_SeparationCS : public CPDF_ColorSpace {
uint32_t v_Load(CPDF_Document* pDoc,
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void EnableStdConversion(bool bEnabled) override;
std::unique_ptr<CPDF_ColorSpace> m_pAltCS;
@@ -239,7 +239,7 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace {
uint32_t v_Load(CPDF_Document* pDoc,
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void EnableStdConversion(bool bEnabled) override;
std::unique_ptr<CPDF_ColorSpace> m_pAltCS;
@@ -582,7 +582,10 @@ uint32_t CPDF_CalGray::v_Load(CPDF_Document* pDoc,
return 1;
}
-bool CPDF_CalGray::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_CalGray::GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const {
*R = *pBuf;
*G = *pBuf;
*B = *pBuf;
@@ -640,7 +643,10 @@ uint32_t CPDF_CalRGB::v_Load(CPDF_Document* pDoc,
return 3;
}
-bool CPDF_CalRGB::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_CalRGB::GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const {
float A_ = pBuf[0];
float B_ = pBuf[1];
float C_ = pBuf[2];
@@ -735,7 +741,7 @@ uint32_t CPDF_LabCS::v_Load(CPDF_Document* pDoc,
return 3;
}
-bool CPDF_LabCS::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_LabCS::GetRGB(const float* pBuf, float* R, float* G, float* B) const {
float Lstar = pBuf[0];
float astar = pBuf[1];
float bstar = pBuf[2];
@@ -843,7 +849,10 @@ uint32_t CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc,
return nComponents;
}
-bool CPDF_ICCBasedCS::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_ICCBasedCS::GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const {
ASSERT(m_pProfile);
if (IsSRGB()) {
*R = pBuf[0];
@@ -1066,7 +1075,10 @@ uint32_t CPDF_IndexedCS::v_Load(CPDF_Document* pDoc,
return 1;
}
-bool CPDF_IndexedCS::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_IndexedCS::GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const {
int32_t index = static_cast<int32_t>(*pBuf);
if (index < 0 || index > m_MaxIndex)
return false;
@@ -1143,7 +1155,7 @@ uint32_t CPDF_SeparationCS::v_Load(CPDF_Document* pDoc,
return 1;
}
-bool CPDF_SeparationCS::GetRGB(float* pBuf,
+bool CPDF_SeparationCS::GetRGB(const float* pBuf,
float* R,
float* G,
float* B) const {
@@ -1221,7 +1233,10 @@ uint32_t CPDF_DeviceNCS::v_Load(CPDF_Document* pDoc,
return pObj->GetCount();
}
-bool CPDF_DeviceNCS::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_DeviceNCS::GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const {
if (!m_pFunc)
return false;
diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h
index 7f3a739d8f..e9108578f5 100644
--- a/core/fpdfapi/page/cpdf_colorspace.h
+++ b/core/fpdfapi/page/cpdf_colorspace.h
@@ -68,7 +68,10 @@ class CPDF_ColorSpace {
float* min,
float* max) const;
- virtual bool GetRGB(float* pBuf, float* R, float* G, float* B) const = 0;
+ virtual bool GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const = 0;
virtual void TranslateImageLine(uint8_t* dest_buf,
const uint8_t* src_buf,
diff --git a/core/fpdfapi/page/cpdf_devicecs.cpp b/core/fpdfapi/page/cpdf_devicecs.cpp
index 9eb4123b25..bf9b3768e7 100644
--- a/core/fpdfapi/page/cpdf_devicecs.cpp
+++ b/core/fpdfapi/page/cpdf_devicecs.cpp
@@ -71,7 +71,10 @@ uint32_t CPDF_DeviceCS::v_Load(CPDF_Document* pDoc,
return 0;
}
-bool CPDF_DeviceCS::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_DeviceCS::GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const {
switch (m_Family) {
case PDFCS_DEVICEGRAY:
*R = NormalizeChannel(*pBuf);
diff --git a/core/fpdfapi/page/cpdf_devicecs.h b/core/fpdfapi/page/cpdf_devicecs.h
index 65e8ec8bd9..aecda71a41 100644
--- a/core/fpdfapi/page/cpdf_devicecs.h
+++ b/core/fpdfapi/page/cpdf_devicecs.h
@@ -20,7 +20,7 @@ class CPDF_DeviceCS : public CPDF_ColorSpace {
uint32_t v_Load(CPDF_Document* pDoc,
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
void TranslateImageLine(uint8_t* pDestBuf,
const uint8_t* pSrcBuf,
int pixels,
diff --git a/core/fpdfapi/page/cpdf_function.cpp b/core/fpdfapi/page/cpdf_function.cpp
index 3e99eb8176..bf5c3e065f 100644
--- a/core/fpdfapi/page/cpdf_function.cpp
+++ b/core/fpdfapi/page/cpdf_function.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/page/cpdf_function.h"
+#include <vector>
+
#include "core/fpdfapi/page/cpdf_expintfunc.h"
#include "core/fpdfapi/page/cpdf_psfunc.h"
#include "core/fpdfapi/page/cpdf_sampledfunc.h"
@@ -113,7 +115,7 @@ bool CPDF_Function::Init(CPDF_Object* pObj, std::set<CPDF_Object*>* pVisited) {
return true;
}
-bool CPDF_Function::Call(float* inputs,
+bool CPDF_Function::Call(const float* inputs,
uint32_t ninputs,
float* results,
int* nresults) const {
@@ -121,11 +123,12 @@ bool CPDF_Function::Call(float* inputs,
return false;
*nresults = m_nOutputs;
+ std::vector<float> clamped_inputs(m_nInputs);
for (uint32_t i = 0; i < m_nInputs; i++) {
- inputs[i] =
+ clamped_inputs[i] =
pdfium::clamp(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1]);
}
- v_Call(inputs, results);
+ v_Call(clamped_inputs.data(), results);
if (!m_pRanges)
return true;
diff --git a/core/fpdfapi/page/cpdf_function.h b/core/fpdfapi/page/cpdf_function.h
index 7966194ade..615c6a68d4 100644
--- a/core/fpdfapi/page/cpdf_function.h
+++ b/core/fpdfapi/page/cpdf_function.h
@@ -30,7 +30,7 @@ class CPDF_Function {
virtual ~CPDF_Function();
- bool Call(float* inputs,
+ bool Call(const float* inputs,
uint32_t ninputs,
float* results,
int* nresults) const;
diff --git a/core/fpdfapi/page/cpdf_patterncs.cpp b/core/fpdfapi/page/cpdf_patterncs.cpp
index b4b680f026..5da176984b 100644
--- a/core/fpdfapi/page/cpdf_patterncs.cpp
+++ b/core/fpdfapi/page/cpdf_patterncs.cpp
@@ -50,10 +50,13 @@ uint32_t CPDF_PatternCS::v_Load(CPDF_Document* pDoc,
return m_pBaseCS->CountComponents() + 1;
}
-bool CPDF_PatternCS::GetRGB(float* pBuf, float* R, float* G, float* B) const {
+bool CPDF_PatternCS::GetRGB(const float* pBuf,
+ float* R,
+ float* G,
+ float* B) const {
if (m_pBaseCS) {
ASSERT(m_pBaseCS->GetFamily() != PDFCS_PATTERN);
- PatternValue* pvalue = reinterpret_cast<PatternValue*>(pBuf);
+ const auto* pvalue = reinterpret_cast<const PatternValue*>(pBuf);
if (m_pBaseCS->GetRGB(pvalue->m_Comps, R, G, B))
return true;
}
diff --git a/core/fpdfapi/page/cpdf_patterncs.h b/core/fpdfapi/page/cpdf_patterncs.h
index d1d0d48c1e..0646a71fb4 100644
--- a/core/fpdfapi/page/cpdf_patterncs.h
+++ b/core/fpdfapi/page/cpdf_patterncs.h
@@ -25,7 +25,7 @@ class CPDF_PatternCS : public CPDF_ColorSpace {
uint32_t v_Load(CPDF_Document* pDoc,
CPDF_Array* pArray,
std::set<CPDF_Object*>* pVisited) override;
- bool GetRGB(float* pBuf, float* R, float* G, float* B) const override;
+ bool GetRGB(const float* pBuf, float* R, float* G, float* B) const override;
private:
CPDF_ColorSpace* m_pBaseCS;