diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-07-03 20:46:36 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-03 20:46:36 +0000 |
commit | 82dafa4f1dd607561f6852c50c15b03977389dc2 (patch) | |
tree | 841cb1f4d8e74879084089c481e53d834af86218 /core/fpdfapi/page/cpdf_function.cpp | |
parent | a0aef45d9181aee30198fdb87557d61f62ad2a7c (diff) | |
download | pdfium-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/page/cpdf_function.cpp')
-rw-r--r-- | core/fpdfapi/page/cpdf_function.cpp | 44 |
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; } |