summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-03 20:46:36 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-03 20:46:36 +0000
commit82dafa4f1dd607561f6852c50c15b03977389dc2 (patch)
tree841cb1f4d8e74879084089c481e53d834af86218 /core/fpdfapi
parenta0aef45d9181aee30198fdb87557d61f62ad2a7c (diff)
downloadpdfium-82dafa4f1dd607561f6852c50c15b03977389dc2.tar.xz
Use std::vector<float> in CPDF_Function.
Change-Id: Ia994118f93f34b5c0c2f2f5ddfd70fe11e9ec549 Reviewed-on: https://pdfium-review.googlesource.com/37010 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_function.cpp44
-rw-r--r--core/fpdfapi/page/cpdf_function.h13
-rw-r--r--core/fpdfapi/page/cpdf_sampledfunc.cpp6
-rw-r--r--core/fpdfapi/page/cpdf_stitchfunc.cpp4
4 files changed, 28 insertions, 39 deletions
diff --git a/core/fpdfapi/page/cpdf_function.cpp b/core/fpdfapi/page/cpdf_function.cpp
index b9753abeef..def72992cd 100644
--- a/core/fpdfapi/page/cpdf_function.cpp
+++ b/core/fpdfapi/page/cpdf_function.cpp
@@ -71,13 +71,9 @@ CPDF_Function::Type CPDF_Function::IntegerToFunctionType(int iType) {
}
}
-CPDF_Function::CPDF_Function(Type type)
- : m_pDomains(nullptr), m_pRanges(nullptr), m_Type(type) {}
+CPDF_Function::CPDF_Function(Type type) : m_Type(type) {}
-CPDF_Function::~CPDF_Function() {
- FX_Free(m_pDomains);
- FX_Free(m_pRanges);
-}
+CPDF_Function::~CPDF_Function() = default;
bool CPDF_Function::Init(const CPDF_Object* pObj,
std::set<const CPDF_Object*>* pVisited) {
@@ -93,42 +89,36 @@ bool CPDF_Function::Init(const CPDF_Object* pObj,
if (m_nInputs == 0)
return false;
- {
- size_t nInputs = m_nInputs * 2;
- m_pDomains = FX_Alloc(float, nInputs);
- for (size_t i = 0; i < nInputs; ++i)
- m_pDomains[i] = pDomains->GetFloatAt(i);
- }
+ size_t nInputs = m_nInputs * 2;
+ m_Domains = std::vector<float>(nInputs);
+ for (size_t i = 0; i < nInputs; ++i)
+ m_Domains[i] = pDomains->GetFloatAt(i);
const CPDF_Array* pRanges = pDict->GetArrayFor("Range");
m_nOutputs = pRanges ? pRanges->GetCount() / 2 : 0;
// Ranges are required for type 0 and type 4 functions. A non-zero
// |m_nOutputs| here implied Ranges meets the requirements.
- {
- bool bRangeRequired =
- m_Type == Type::kType0Sampled || m_Type == Type::kType4PostScript;
- if (bRangeRequired && m_nOutputs == 0)
- return false;
- }
+ bool bRangeRequired =
+ m_Type == Type::kType0Sampled || m_Type == Type::kType4PostScript;
+ if (bRangeRequired && m_nOutputs == 0)
+ return false;
if (m_nOutputs > 0) {
size_t nOutputs = m_nOutputs * 2;
- m_pRanges = FX_Alloc(float, nOutputs);
+ m_Ranges = std::vector<float>(nOutputs);
for (size_t i = 0; i < nOutputs; ++i)
- m_pRanges[i] = pRanges->GetFloatAt(i);
+ m_Ranges[i] = pRanges->GetFloatAt(i);
}
uint32_t old_outputs = m_nOutputs;
if (!v_Init(pObj, pVisited))
return false;
- if (m_pRanges && m_nOutputs > old_outputs) {
+ if (!m_Ranges.empty() && m_nOutputs > old_outputs) {
FX_SAFE_SIZE_T nOutputs = m_nOutputs;
nOutputs *= 2;
- m_pRanges = FX_Realloc(float, m_pRanges, nOutputs.ValueOrDie());
- memset(m_pRanges + (old_outputs * 2), 0,
- sizeof(float) * (m_nOutputs - old_outputs) * 2);
+ m_Ranges.resize(nOutputs.ValueOrDie());
}
return true;
}
@@ -144,17 +134,17 @@ bool CPDF_Function::Call(const float* inputs,
std::vector<float> clamped_inputs(m_nInputs);
for (uint32_t i = 0; i < m_nInputs; i++) {
clamped_inputs[i] =
- pdfium::clamp(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1]);
+ pdfium::clamp(inputs[i], m_Domains[i * 2], m_Domains[i * 2 + 1]);
}
if (!v_Call(clamped_inputs.data(), results))
return false;
- if (!m_pRanges)
+ if (m_Ranges.empty())
return true;
for (uint32_t i = 0; i < m_nOutputs; i++) {
results[i] =
- pdfium::clamp(results[i], m_pRanges[i * 2], m_pRanges[i * 2 + 1]);
+ pdfium::clamp(results[i], m_Ranges[i * 2], m_Ranges[i * 2 + 1]);
}
return true;
}
diff --git a/core/fpdfapi/page/cpdf_function.h b/core/fpdfapi/page/cpdf_function.h
index c2f2a4bb4e..5f4e125fa5 100644
--- a/core/fpdfapi/page/cpdf_function.h
+++ b/core/fpdfapi/page/cpdf_function.h
@@ -9,6 +9,7 @@
#include <memory>
#include <set>
+#include <vector>
class CPDF_ExpIntFunc;
class CPDF_Object;
@@ -36,8 +37,8 @@ class CPDF_Function {
int* nresults) const;
uint32_t CountInputs() const { return m_nInputs; }
uint32_t CountOutputs() const { return m_nOutputs; }
- float GetDomain(int i) const { return m_pDomains[i]; }
- float GetRange(int i) const { return m_pRanges[i]; }
+ float GetDomain(int i) const { return m_Domains[i]; }
+ float GetRange(int i) const { return m_Ranges[i]; }
float Interpolate(float x,
float xmin,
float xmax,
@@ -59,13 +60,11 @@ class CPDF_Function {
std::set<const CPDF_Object*>* pVisited) = 0;
virtual bool v_Call(const float* inputs, float* results) const = 0;
+ const Type m_Type;
uint32_t m_nInputs;
uint32_t m_nOutputs;
- float* m_pDomains;
- float* m_pRanges;
-
- private:
- const Type m_Type;
+ std::vector<float> m_Domains;
+ std::vector<float> m_Ranges;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_FUNCTION_H_
diff --git a/core/fpdfapi/page/cpdf_sampledfunc.cpp b/core/fpdfapi/page/cpdf_sampledfunc.cpp
index 8ac4bb5be4..143aeb4f8a 100644
--- a/core/fpdfapi/page/cpdf_sampledfunc.cpp
+++ b/core/fpdfapi/page/cpdf_sampledfunc.cpp
@@ -88,8 +88,8 @@ bool CPDF_SampledFunc::v_Init(const CPDF_Object* pObj,
m_DecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i);
m_DecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1);
} else {
- m_DecodeInfo[i].decode_min = m_pRanges[i * 2];
- m_DecodeInfo[i].decode_max = m_pRanges[i * 2 + 1];
+ m_DecodeInfo[i].decode_min = m_Ranges[i * 2];
+ m_DecodeInfo[i].decode_max = m_Ranges[i * 2 + 1];
}
}
return true;
@@ -108,7 +108,7 @@ bool CPDF_SampledFunc::v_Call(const float* inputs, float* results) const {
else
blocksize[i] = blocksize[i - 1] * m_EncodeInfo[i - 1].sizes;
encoded_input[i] =
- Interpolate(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1],
+ Interpolate(inputs[i], m_Domains[i * 2], m_Domains[i * 2 + 1],
m_EncodeInfo[i].encode_min, m_EncodeInfo[i].encode_max);
index[i] = pdfium::clamp(static_cast<uint32_t>(encoded_input[i]), 0U,
m_EncodeInfo[i].sizes - 1);
diff --git a/core/fpdfapi/page/cpdf_stitchfunc.cpp b/core/fpdfapi/page/cpdf_stitchfunc.cpp
index 042e090062..b400a987c0 100644
--- a/core/fpdfapi/page/cpdf_stitchfunc.cpp
+++ b/core/fpdfapi/page/cpdf_stitchfunc.cpp
@@ -96,10 +96,10 @@ bool CPDF_StitchFunc::v_Init(const CPDF_Object* pObj,
}
m_bounds.reserve(nSubs + 1);
- m_bounds.push_back(m_pDomains[0]);
+ m_bounds.push_back(m_Domains[0]);
for (uint32_t i = 0; i < nSubs - 1; i++)
m_bounds.push_back(pBoundsArray->GetFloatAt(i));
- m_bounds.push_back(m_pDomains[1]);
+ m_bounds.push_back(m_Domains[1]);
m_encode.reserve(nSubs * 2);
for (uint32_t i = 0; i < nSubs * 2; i++)