From 5de481e71bcde25d31452b23a017bb783163a204 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Tue, 8 May 2018 19:13:28 +0000 Subject: Remove almost all usages of CFX_FixedBufGrow with std::vector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tested by running safetynet_compare.py on this patch vs master. The results were 0 regressions and 0 improvements. The two remaining usages cannot be replaced because they would cause a regression. Bug: pdfium:177 Change-Id: I43eddf4ffaac2eb063f2004d6606bc3cd6e627ac Reviewed-on: https://pdfium-review.googlesource.com/32159 Reviewed-by: dsinclair Reviewed-by: Tom Sepez Commit-Queue: Nicolás Peña Moreno --- core/fpdfapi/page/cpdf_colorspace.cpp | 47 +++++++++++++---------------------- 1 file changed, 17 insertions(+), 30 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp index 3cdc96a000..d7fb18edd7 100644 --- a/core/fpdfapi/page/cpdf_colorspace.cpp +++ b/core/fpdfapi/page/cpdf_colorspace.cpp @@ -31,7 +31,6 @@ #include "core/fpdfdoc/cpdf_action.h" #include "core/fxcodec/codec/ccodec_iccmodule.h" #include "core/fxcodec/fx_codec.h" -#include "core/fxcrt/cfx_fixedbufgrow.h" #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/maybe_owned.h" #include "third_party/base/stl_util.h" @@ -574,8 +573,7 @@ void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, int image_width, int image_height, bool bTransMask) const { - CFX_FixedBufGrow srcbuf(m_nComponents); - float* src = srcbuf; + std::vector src(m_nComponents); float R; float G; float B; @@ -583,7 +581,7 @@ void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, for (int i = 0; i < pixels; i++) { for (uint32_t j = 0; j < m_nComponents; j++) src[j] = static_cast(*src_buf++) / divisor; - GetRGB(src, &R, &G, &B); + GetRGB(src.data(), &R, &G, &B); *dest_buf++ = static_cast(B * 255); *dest_buf++ = static_cast(G * 255); *dest_buf++ = static_cast(R * 255); @@ -1151,15 +1149,15 @@ bool CPDF_IndexedCS::GetRGB(const float* pBuf, return false; } } - CFX_FixedBufGrow Comps(m_nBaseComponents); - float* comps = Comps; + std::vector comps; + comps.reserve(m_nBaseComponents); const uint8_t* pTable = m_Table.raw_str(); for (uint32_t i = 0; i < m_nBaseComponents; i++) { - comps[i] = - m_pCompMinMax[i * 2] + - m_pCompMinMax[i * 2 + 1] * pTable[index * m_nBaseComponents + i] / 255; + comps.push_back(m_pCompMinMax[i * 2] + + m_pCompMinMax[i * 2 + 1] * + pTable[index * m_nBaseComponents + i] / 255); } - return m_pBaseCS->GetRGB(comps, R, G, B); + return m_pBaseCS->GetRGB(comps.data(), R, G, B); } void CPDF_IndexedCS::EnableStdConversion(bool bEnabled) { @@ -1216,32 +1214,21 @@ bool CPDF_SeparationCS::GetRGB(const float* pBuf, float* R, float* G, float* B) const { - if (m_Type == None) + if (m_Type == None || !m_pAltCS) return false; if (!m_pFunc) { - if (!m_pAltCS) - return false; - int nComps = m_pAltCS->CountComponents(); - CFX_FixedBufGrow results(nComps); - for (int i = 0; i < nComps; i++) - results[i] = *pBuf; - return m_pAltCS->GetRGB(results, R, G, B); + std::vector results(nComps, *pBuf); + return m_pAltCS->GetRGB(results.data(), R, G, B); } - CFX_FixedBufGrow results(m_pFunc->CountOutputs()); + std::vector results2(m_pFunc->CountOutputs()); int nresults = 0; - if (!m_pFunc->Call(pBuf, 1, results, &nresults) || nresults == 0) + if (!m_pFunc->Call(pBuf, 1, results2.data(), &nresults) || nresults == 0) return false; - if (m_pAltCS) - return m_pAltCS->GetRGB(results, R, G, B); - - R = 0; - G = 0; - B = 0; - return false; + return m_pAltCS->GetRGB(results2.data(), R, G, B); } void CPDF_SeparationCS::EnableStdConversion(bool bEnabled) { @@ -1296,14 +1283,14 @@ bool CPDF_DeviceNCS::GetRGB(const float* pBuf, if (!m_pFunc) return false; - CFX_FixedBufGrow results(m_pFunc->CountOutputs()); + std::vector results(m_pFunc->CountOutputs()); int nresults = 0; - if (!m_pFunc->Call(pBuf, CountComponents(), results, &nresults) || + if (!m_pFunc->Call(pBuf, CountComponents(), results.data(), &nresults) || nresults == 0) { return false; } - return m_pAltCS->GetRGB(results, R, G, B); + return m_pAltCS->GetRGB(results.data(), R, G, B); } void CPDF_DeviceNCS::EnableStdConversion(bool bEnabled) { -- cgit v1.2.3