Add core/fxcrt/data_vector.h and define fxcrt::DataVector.
Since std::vector<uint8_t, FxAllocAllocator<uint8_t>> is slightly
unwieldy, add an alias for it to make it easier to use. Use it in
core/fpdfapi/page/ to simplify the code.
Change-Id: I1432d12362cc3a8d96969a65602f068fa408b811
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96330
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index a1dd6c0..6478bd5 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/page/cpdf_colorspace.h"
#include <math.h>
+#include <stdint.h>
#include <algorithm>
#include <limits>
@@ -31,6 +32,8 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/maybe_owned.h"
#include "core/fxcrt/scoped_set_insertion.h"
@@ -244,7 +247,7 @@
uint32_t nComponents);
RetainPtr<CPDF_IccProfile> m_pProfile;
- mutable std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_pCache;
+ mutable DataVector<uint8_t> m_pCache;
std::vector<float> m_pRanges;
};
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index 5867bea..32f2198 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/page/cpdf_dib.h"
+#include <stdint.h>
+
#include <algorithm>
#include <memory>
#include <utility>
@@ -30,6 +32,7 @@
#include "core/fxcodec/jpeg/jpegmodule.h"
#include "core/fxcodec/jpx/cjpx_decoder.h"
#include "core/fxcodec/scanlinedecoder.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/span_util.h"
#include "core/fxge/calculate_pitch.h"
@@ -192,14 +195,14 @@
if (!pitch.has_value())
return false;
- m_LineBuf = std::vector<uint8_t, FxAllocAllocator<uint8_t>>(pitch.value());
+ m_LineBuf = DataVector<uint8_t>(pitch.value());
LoadPalette();
if (m_bColorKey) {
m_Format = FXDIB_Format::kArgb;
pitch = fxge::CalculatePitch32(GetBppFromFormat(m_Format), m_Width);
if (!pitch.has_value())
return false;
- m_MaskBuf = std::vector<uint8_t, FxAllocAllocator<uint8_t>>(pitch.value());
+ m_MaskBuf = DataVector<uint8_t>(pitch.value());
}
m_Pitch = pitch.value();
return true;
diff --git a/core/fpdfapi/page/cpdf_dib.h b/core/fpdfapi/page/cpdf_dib.h
index 1bf5c32..155a1f9 100644
--- a/core/fpdfapi/page/cpdf_dib.h
+++ b/core/fpdfapi/page/cpdf_dib.h
@@ -7,11 +7,13 @@
#ifndef CORE_FPDFAPI_PAGE_CPDF_DIB_H_
#define CORE_FPDFAPI_PAGE_CPDF_DIB_H_
+#include <stdint.h>
+
#include <memory>
#include <vector>
#include "core/fpdfapi/page/cpdf_colorspace.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxge/dib/cfx_dibbase.h"
@@ -72,7 +74,7 @@
int width;
int height;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data;
+ DataVector<uint8_t> data;
};
bool LoadInternal(const CPDF_Dictionary* pFormResources,
@@ -122,8 +124,8 @@
bool m_bHasMask = false;
bool m_bStdCS = false;
std::vector<DIB_COMP_DATA> m_CompData;
- mutable std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_LineBuf;
- mutable std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_MaskBuf;
+ mutable DataVector<uint8_t> m_LineBuf;
+ mutable DataVector<uint8_t> m_MaskBuf;
RetainPtr<CFX_DIBitmap> m_pCachedBitmap;
// Note: Must not create a cycle between CPDF_DIB instances.
RetainPtr<CPDF_DIB> m_pMask;
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 710cc00..d6b5495 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -6,10 +6,11 @@
#include "core/fpdfapi/page/cpdf_image.h"
+#include <stdint.h>
+
#include <algorithm>
#include <memory>
#include <utility>
-#include <vector>
#include "constants/stream_dict_common.h"
#include "core/fpdfapi/page/cpdf_dib.h"
@@ -24,6 +25,7 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fxcodec/jpeg/jpegmodule.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/span_util.h"
@@ -132,7 +134,7 @@
return;
uint32_t dwEstimateSize = std::min(size, 8192U);
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data(dwEstimateSize);
+ DataVector<uint8_t> data(dwEstimateSize);
if (!pFile->ReadBlockAtOffset(data.data(), 0, dwEstimateSize))
return;
@@ -153,7 +155,7 @@
if (!size)
return;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data(size);
+ DataVector<uint8_t> data(size);
if (!pFile->ReadBlockAtOffset(data.data(), 0, size))
return;
diff --git a/core/fpdfapi/page/cpdf_transferfunc.cpp b/core/fpdfapi/page/cpdf_transferfunc.cpp
index 29690a9..f1a0a5b 100644
--- a/core/fpdfapi/page/cpdf_transferfunc.cpp
+++ b/core/fpdfapi/page/cpdf_transferfunc.cpp
@@ -6,18 +6,20 @@
#include "core/fpdfapi/page/cpdf_transferfunc.h"
+#include <stdint.h>
+
#include <utility>
#include "core/fpdfapi/page/cpdf_transferfuncdib.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxge/dib/cfx_dibbase.h"
#include "third_party/base/check_op.h"
-CPDF_TransferFunc::CPDF_TransferFunc(
- bool bIdentify,
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_r,
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_g,
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_b)
+CPDF_TransferFunc::CPDF_TransferFunc(bool bIdentify,
+ DataVector<uint8_t> samples_r,
+ DataVector<uint8_t> samples_g,
+ DataVector<uint8_t> samples_b)
: m_bIdentity(bIdentify),
m_SamplesR(std::move(samples_r)),
m_SamplesG(std::move(samples_g)),
diff --git a/core/fpdfapi/page/cpdf_transferfunc.h b/core/fpdfapi/page/cpdf_transferfunc.h
index 3c43eb1..b558559 100644
--- a/core/fpdfapi/page/cpdf_transferfunc.h
+++ b/core/fpdfapi/page/cpdf_transferfunc.h
@@ -7,9 +7,9 @@
#ifndef CORE_FPDFAPI_PAGE_CPDF_TRANSFERFUNC_H_
#define CORE_FPDFAPI_PAGE_CPDF_TRANSFERFUNC_H_
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/observed_ptr.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxge/dib/fx_dib.h"
@@ -35,15 +35,15 @@
private:
CPDF_TransferFunc(bool bIdentify,
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_r,
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_g,
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_b);
+ DataVector<uint8_t> samples_r,
+ DataVector<uint8_t> samples_g,
+ DataVector<uint8_t> samples_b);
~CPDF_TransferFunc() override;
const bool m_bIdentity;
- const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesR;
- const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesG;
- const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesB;
+ const DataVector<uint8_t> m_SamplesR;
+ const DataVector<uint8_t> m_SamplesG;
+ const DataVector<uint8_t> m_SamplesB;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_TRANSFERFUNC_H_
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.h b/core/fpdfapi/page/cpdf_transferfuncdib.h
index ed4d17f..4993323 100644
--- a/core/fpdfapi/page/cpdf_transferfuncdib.h
+++ b/core/fpdfapi/page/cpdf_transferfuncdib.h
@@ -7,9 +7,9 @@
#ifndef CORE_FPDFAPI_PAGE_CPDF_TRANSFERFUNCDIB_H_
#define CORE_FPDFAPI_PAGE_CPDF_TRANSFERFUNCDIB_H_
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxge/dib/cfx_dibbase.h"
#include "third_party/base/span.h"
@@ -36,7 +36,7 @@
const pdfium::span<const uint8_t> m_RampR;
const pdfium::span<const uint8_t> m_RampG;
const pdfium::span<const uint8_t> m_RampB;
- mutable std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_Scanline;
+ mutable DataVector<uint8_t> m_Scanline;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_TRANSFERFUNCDIB_H_
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index 82ea88f..a565779 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -33,6 +33,7 @@
"cfx_utf8decoder.h",
"cfx_utf8encoder.cpp",
"cfx_utf8encoder.h",
+ "data_vector.h",
"fileaccess_iface.h",
"fx_bidi.cpp",
"fx_bidi.h",
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index cf2c007..03bf631 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -6,14 +6,15 @@
#include "core/fxcrt/cfx_seekablestreamproxy.h"
+#include <stdint.h>
+
#include <algorithm>
#include <limits>
#include <utility>
-#include <vector>
#include "build/build_config.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_extension.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/check.h"
#include "third_party/base/check_op.h"
@@ -207,7 +208,7 @@
if (iBytes == 0)
return 0;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> buf(iBytes);
+ DataVector<uint8_t> buf(iBytes);
size_t iLen = ReadData(buf.data(), iBytes);
if (m_wCodePage != FX_CodePage::kUTF8)
return 0;
diff --git a/core/fxcrt/cfx_utf8encoder.h b/core/fxcrt/cfx_utf8encoder.h
index 7dc330a..b2d9f64 100644
--- a/core/fxcrt/cfx_utf8encoder.h
+++ b/core/fxcrt/cfx_utf8encoder.h
@@ -7,10 +7,10 @@
#ifndef CORE_FXCRT_CFX_UTF8ENCODER_H_
#define CORE_FXCRT_CFX_UTF8ENCODER_H_
-#include <vector>
+#include <stdint.h>
#include "core/fxcrt/bytestring.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
class CFX_UTF8Encoder {
public:
@@ -26,7 +26,7 @@
}
private:
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_Buffer;
+ DataVector<uint8_t> m_Buffer;
};
#endif // CORE_FXCRT_CFX_UTF8ENCODER_H_
diff --git a/core/fxcrt/data_vector.h b/core/fxcrt/data_vector.h
new file mode 100644
index 0000000..a003870
--- /dev/null
+++ b/core/fxcrt/data_vector.h
@@ -0,0 +1,21 @@
+// Copyright 2022 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CORE_FXCRT_DATA_VECTOR_H_
+#define CORE_FXCRT_DATA_VECTOR_H_
+
+#include <vector>
+
+#include "core/fxcrt/fx_memory_wrappers.h"
+
+namespace fxcrt {
+
+template <typename T>
+using DataVector = std::vector<T, FxAllocAllocator<T>>;
+
+} // namespace fxcrt
+
+using fxcrt::DataVector;
+
+#endif // CORE_FXCRT_DATA_VECTOR_H_