diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-07-02 19:16:43 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-02 19:16:43 +0000 |
commit | 319ef06b2f695c7ebc26985d477b71fe8db93d3e (patch) | |
tree | 368c89c31a743c3d5e9c7fe1cc4a1eaacb2ee5c0 /core | |
parent | e353d72449a9298410dc479bf27410d83e56b215 (diff) | |
download | pdfium-319ef06b2f695c7ebc26985d477b71fe8db93d3e.tar.xz |
Add pdfium::Vector2D<>()
Many of the FX_Alloc's that have not been converted to std::vector
are using FX_Alloc2D and the safe math it performs under the covers.
Make an equivalent function for returning a vector to avoid burdening
callers with the safe math equivalents.
Use it in one place.
Change-Id: Ie4a280351b7370b755f2a1928f8b2d84fe007c03
Reviewed-on: https://pdfium-review.googlesource.com/36770
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/page/cpdf_colorspace.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp index 0138b81ca1..17b2914900 100644 --- a/core/fpdfapi/page/cpdf_colorspace.cpp +++ b/core/fpdfapi/page/cpdf_colorspace.cpp @@ -222,7 +222,7 @@ class CPDF_ICCBasedCS : public CPDF_ColorSpace { MaybeOwned<CPDF_ColorSpace> m_pAlterCS; RetainPtr<CPDF_IccProfile> m_pProfile; - mutable std::unique_ptr<uint8_t, FxFreeDeleter> m_pCache; + mutable std::vector<uint8_t> m_pCache; std::vector<float> m_pRanges; }; @@ -984,24 +984,22 @@ void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf, return; } - if (!m_pCache) { - m_pCache.reset(FX_Alloc2D(uint8_t, nMaxColors, 3)); - std::unique_ptr<uint8_t, FxFreeDeleter> temp_src( - FX_Alloc2D(uint8_t, nMaxColors, nComponents)); - uint8_t* pSrc = temp_src.get(); + if (m_pCache.empty()) { + m_pCache = pdfium::Vector2D<uint8_t>(nMaxColors, 3); + auto temp_src = pdfium::Vector2D<uint8_t>(nMaxColors, nComponents); + size_t src_index = 0; for (int i = 0; i < nMaxColors; i++) { uint32_t color = i; uint32_t order = nMaxColors / 52; for (uint32_t c = 0; c < nComponents; c++) { - *pSrc++ = static_cast<uint8_t>(color / order * 5); + temp_src[src_index++] = static_cast<uint8_t>(color / order * 5); color %= order; order /= 52; } } CPDF_ModuleMgr::Get()->GetIccModule()->TranslateScanline( - m_pProfile->transform(), m_pCache.get(), temp_src.get(), nMaxColors); + m_pProfile->transform(), m_pCache.data(), temp_src.data(), nMaxColors); } - uint8_t* pCachePtr = m_pCache.get(); for (int i = 0; i < pixels; i++) { int index = 0; for (uint32_t c = 0; c < nComponents; c++) { @@ -1009,9 +1007,9 @@ void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf, pSrcBuf++; } index *= 3; - *pDestBuf++ = pCachePtr[index]; - *pDestBuf++ = pCachePtr[index + 1]; - *pDestBuf++ = pCachePtr[index + 2]; + *pDestBuf++ = m_pCache[index]; + *pDestBuf++ = m_pCache[index + 1]; + *pDestBuf++ = m_pCache[index + 2]; } } |