Take buffers from partition in faxmodule.cpp - Pass pointer to data rather than vector itself in one place to keep local function unaware of allocator types. - Update Vector2D<> template to be allocator-aware. - Simplify ctor while we're at it. Change-Id: I013a4e2f9917783199395c98ad3d7609e88bc483 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/62790 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcodec/fax/faxmodule.cpp b/core/fxcodec/fax/faxmodule.cpp index da39918..22ba764 100644 --- a/core/fxcodec/fax/faxmodule.cpp +++ b/core/fxcodec/fax/faxmodule.cpp
@@ -15,7 +15,7 @@ #include "core/fxcodec/fx_codec.h" #include "core/fxcodec/scanlinedecoder.h" #include "core/fxcrt/cfx_binarybuf.h" -#include "core/fxcrt/fx_memory.h" +#include "core/fxcrt/fx_memory_wrappers.h" #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" @@ -420,7 +420,7 @@ void FaxGet1DLine(const uint8_t* src_buf, int bitsize, int* bitpos, - std::vector<uint8_t>* dest_buf, + uint8_t* dest_buf, int columns) { bool color = true; int startpos = 0; @@ -444,7 +444,7 @@ break; } if (!color) - FaxFillBits(dest_buf->data(), columns, startpos, startpos + run_len); + FaxFillBits(dest_buf, columns, startpos, startpos + run_len); startpos += run_len; if (startpos >= columns) @@ -479,8 +479,8 @@ const bool m_bEndOfLine; const bool m_bBlack; const pdfium::span<const uint8_t> m_SrcSpan; - std::vector<uint8_t> m_ScanlineBuf; - std::vector<uint8_t> m_RefBuf; + std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_ScanlineBuf; + std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_RefBuf; }; FaxDecoder::FaxDecoder(pdfium::span<const uint8_t> src_span, @@ -525,11 +525,11 @@ m_RefBuf, m_OrigWidth); m_RefBuf = m_ScanlineBuf; } else if (m_Encoding == 0) { - FaxGet1DLine(m_SrcSpan.data(), bitsize, &m_bitpos, &m_ScanlineBuf, + FaxGet1DLine(m_SrcSpan.data(), bitsize, &m_bitpos, m_ScanlineBuf.data(), m_OrigWidth); } else { if (NextBit(m_SrcSpan.data(), &m_bitpos)) { - FaxGet1DLine(m_SrcSpan.data(), bitsize, &m_bitpos, &m_ScanlineBuf, + FaxGet1DLine(m_SrcSpan.data(), bitsize, &m_bitpos, m_ScanlineBuf.data(), m_OrigWidth); } else { FaxG4GetRow(m_SrcSpan.data(), bitsize, &m_bitpos, m_ScanlineBuf.data(), @@ -611,7 +611,7 @@ uint8_t* dest_buf) { ASSERT(pitch != 0); - std::vector<uint8_t> ref_buf(pitch, 0xff); + std::vector<uint8_t, FxAllocAllocator<uint8_t>> ref_buf(pitch, 0xff); int bitpos = starting_bitpos; for (int iRow = 0; iRow < height; ++iRow) { uint8_t* line_buf = dest_buf + iRow * pitch; @@ -678,21 +678,24 @@ void FaxEncodeRun(int run, bool bWhite); void AddBitStream(int data, int bitlen); - CFX_BinaryBuf m_DestBuf; - std::vector<uint8_t> m_RefLine; - std::vector<uint8_t> m_LineBuf; - int m_DestBitpos; + int m_DestBitpos = 0; const int m_Cols; const int m_Rows; const int m_Pitch; const uint8_t* m_pSrcBuf; + CFX_BinaryBuf m_DestBuf; + std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_RefLine; + std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_LineBuf; }; FaxEncoder::FaxEncoder(const uint8_t* src_buf, int width, int height, int pitch) - : m_Cols(width), m_Rows(height), m_Pitch(pitch), m_pSrcBuf(src_buf) { - m_RefLine.resize(pitch); - std::fill(std::begin(m_RefLine), std::end(m_RefLine), 0xff); - m_LineBuf = pdfium::Vector2D<uint8_t>(8, m_Pitch); + : m_Cols(width), + m_Rows(height), + m_Pitch(pitch), + m_pSrcBuf(src_buf), + m_RefLine(pitch, 0xff), + m_LineBuf( + pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(8, pitch)) { m_DestBuf.SetAllocStep(10240); }
diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h index 8163b73..925c96a 100644 --- a/third_party/base/stl_util.h +++ b/third_party/base/stl_util.h
@@ -89,11 +89,11 @@ } // Safely allocate a 1-dim vector big enough for |w| by |h| or die. -template <typename T> -std::vector<T> Vector2D(size_t w, size_t h) { +template <typename T, typename A = std::allocator<T>> +std::vector<T, A> Vector2D(size_t w, size_t h) { pdfium::base::CheckedNumeric<size_t> safe_size = w; safe_size *= h; - return std::vector<T>(safe_size.ValueOrDie()); + return std::vector<T, A>(safe_size.ValueOrDie()); } } // namespace pdfium