From 9914d4dc1e7ad761cd52a68bc8cf64471c297cf8 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 19 Apr 2018 16:55:02 +0000 Subject: Make CPDF_StitchFunc use more vectors. Change-Id: Iaa3988cea5cdc6ce723c59ad051800925216d81b Reviewed-on: https://pdfium-review.googlesource.com/30990 Commit-Queue: Lei Zhang Reviewed-by: Henrique Nakashima --- core/fpdfapi/page/cpdf_stitchfunc.cpp | 23 ++++++++++------------- core/fpdfapi/page/cpdf_stitchfunc.h | 6 +++--- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_stitchfunc.cpp b/core/fpdfapi/page/cpdf_stitchfunc.cpp index 1e5329b337..aed17828d9 100644 --- a/core/fpdfapi/page/cpdf_stitchfunc.cpp +++ b/core/fpdfapi/page/cpdf_stitchfunc.cpp @@ -20,10 +20,7 @@ constexpr uint32_t kRequiredNumInputs = 1; CPDF_StitchFunc::CPDF_StitchFunc() : CPDF_Function(Type::kType3Stitching) {} -CPDF_StitchFunc::~CPDF_StitchFunc() { - FX_Free(m_pBounds); - FX_Free(m_pEncode); -} +CPDF_StitchFunc::~CPDF_StitchFunc() {} bool CPDF_StitchFunc::v_Init(CPDF_Object* pObj, std::set* pVisited) { @@ -98,15 +95,15 @@ bool CPDF_StitchFunc::v_Init(CPDF_Object* pObj, m_nOutputs = *nOutputs; } - m_pBounds = FX_Alloc(float, nSubs + 1); - m_pBounds[0] = m_pDomains[0]; + m_bounds.reserve(nSubs + 1); + m_bounds.push_back(m_pDomains[0]); for (uint32_t i = 0; i < nSubs - 1; i++) - m_pBounds[i + 1] = pBoundsArray->GetFloatAt(i); - m_pBounds[nSubs] = m_pDomains[1]; + m_bounds.push_back(pBoundsArray->GetFloatAt(i)); + m_bounds.push_back(m_pDomains[1]); - m_pEncode = FX_Alloc2D(float, nSubs, 2); + m_encode.reserve(nSubs * 2); for (uint32_t i = 0; i < nSubs * 2; i++) - m_pEncode[i] = pEncodeArray->GetFloatAt(i); + m_encode.push_back(pEncodeArray->GetFloatAt(i)); return true; } @@ -114,11 +111,11 @@ bool CPDF_StitchFunc::v_Call(const float* inputs, float* results) const { float input = inputs[0]; size_t i; for (i = 0; i < m_pSubFunctions.size() - 1; i++) { - if (input < m_pBounds[i + 1]) + if (input < m_bounds[i + 1]) break; } - input = Interpolate(input, m_pBounds[i], m_pBounds[i + 1], m_pEncode[i * 2], - m_pEncode[i * 2 + 1]); + input = Interpolate(input, m_bounds[i], m_bounds[i + 1], m_encode[i * 2], + m_encode[i * 2 + 1]); int nresults; return m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, results, &nresults); diff --git a/core/fpdfapi/page/cpdf_stitchfunc.h b/core/fpdfapi/page/cpdf_stitchfunc.h index 360b789072..d6dd63d2d5 100644 --- a/core/fpdfapi/page/cpdf_stitchfunc.h +++ b/core/fpdfapi/page/cpdf_stitchfunc.h @@ -25,12 +25,12 @@ class CPDF_StitchFunc : public CPDF_Function { const std::vector>& GetSubFunctions() const { return m_pSubFunctions; } - float GetBound(size_t i) const { return m_pBounds[i]; } + float GetBound(size_t i) const { return m_bounds[i]; } private: std::vector> m_pSubFunctions; - float* m_pBounds = nullptr; - float* m_pEncode = nullptr; + std::vector m_bounds; + std::vector m_encode; }; #endif // CORE_FPDFAPI_PAGE_CPDF_STITCHFUNC_H_ -- cgit v1.2.3