summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_function.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/page/cpdf_function.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_function.cpp44
1 files changed, 17 insertions, 27 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;
}