Use DataVector<T> in fxbarcode/.
Easier to write than std::vector<T, FxAllocAllocator<T>>.
Change-Id: Ia3b0c4d0fa54552b3415a5314154822277e0d051
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96410
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/cbc_datamatrix.cpp b/fxbarcode/cbc_datamatrix.cpp
index 5a2365e..58ce9b4 100644
--- a/fxbarcode/cbc_datamatrix.cpp
+++ b/fxbarcode/cbc_datamatrix.cpp
@@ -21,11 +21,12 @@
#include "fxbarcode/cbc_datamatrix.h"
-#include <memory>
-#include <vector>
+#include <stdint.h>
+#include <memory>
+
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
#include "fxbarcode/datamatrix/BC_DataMatrixWriter.h"
CBC_DataMatrix::CBC_DataMatrix()
@@ -37,7 +38,7 @@
int32_t width;
int32_t height;
auto* pWriter = GetDataMatrixWriter();
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ DataVector<uint8_t> data =
pWriter->Encode(WideString(contents), &width, &height);
return pWriter->RenderResult(data, width, height);
}
diff --git a/fxbarcode/cbc_pdf417i.cpp b/fxbarcode/cbc_pdf417i.cpp
index 510d504..64b5e8d 100644
--- a/fxbarcode/cbc_pdf417i.cpp
+++ b/fxbarcode/cbc_pdf417i.cpp
@@ -21,10 +21,11 @@
#include "fxbarcode/cbc_pdf417i.h"
-#include <memory>
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include <memory>
+
+#include "core/fxcrt/data_vector.h"
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
namespace {
@@ -47,8 +48,7 @@
int32_t width;
int32_t height;
auto* pWriter = GetPDF417Writer();
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- pWriter->Encode(contents, &width, &height);
+ DataVector<uint8_t> data = pWriter->Encode(contents, &width, &height);
return pWriter->RenderResult(data, width, height);
}
diff --git a/fxbarcode/cbc_qrcode.cpp b/fxbarcode/cbc_qrcode.cpp
index 2544718..2175dce 100644
--- a/fxbarcode/cbc_qrcode.cpp
+++ b/fxbarcode/cbc_qrcode.cpp
@@ -21,10 +21,11 @@
#include "fxbarcode/cbc_qrcode.h"
-#include <memory>
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include <memory>
+
+#include "core/fxcrt/data_vector.h"
#include "fxbarcode/qrcode/BC_QRCodeWriter.h"
CBC_QRCode::CBC_QRCode() : CBC_CodeBase(std::make_unique<CBC_QRCodeWriter>()) {}
@@ -35,7 +36,7 @@
int32_t width;
int32_t height;
CBC_QRCodeWriter* pWriter = GetQRCodeWriter();
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data = pWriter->Encode(
+ DataVector<uint8_t> data = pWriter->Encode(
contents, pWriter->error_correction_level(), &width, &height);
return pWriter->RenderResult(data, width, height);
}
diff --git a/fxbarcode/common/BC_CommonByteMatrix.h b/fxbarcode/common/BC_CommonByteMatrix.h
index 970acf8..ea12db2 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.h
+++ b/fxbarcode/common/BC_CommonByteMatrix.h
@@ -9,9 +9,7 @@
#include <stdint.h>
-#include <vector>
-
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "third_party/base/span.h"
class CBC_CommonByteMatrix final {
@@ -30,7 +28,7 @@
private:
const size_t m_width;
const size_t m_height;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_bytes;
+ DataVector<uint8_t> m_bytes;
};
#endif // FXBARCODE_COMMON_BC_COMMONBYTEMATRIX_H_
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
index 6ce2b63..88ae579 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
@@ -22,8 +22,11 @@
#include "fxbarcode/datamatrix/BC_DataMatrixWriter.h"
+#include <stdint.h>
+
#include <memory>
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/stl_util.h"
#include "fxbarcode/BC_TwoDimWriter.h"
#include "fxbarcode/BC_Writer.h"
@@ -107,11 +110,10 @@
return true;
}
-std::vector<uint8_t, FxAllocAllocator<uint8_t>> CBC_DataMatrixWriter::Encode(
- const WideString& contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight) {
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> results;
+DataVector<uint8_t> CBC_DataMatrixWriter::Encode(const WideString& contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight) {
+ DataVector<uint8_t> results;
WideString encoded = CBC_HighLevelEncoder::EncodeHighLevel(contents);
if (encoded.IsEmpty())
return results;
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.h b/fxbarcode/datamatrix/BC_DataMatrixWriter.h
index 97340fe..4b940ce 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.h
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.h
@@ -7,9 +7,9 @@
#ifndef FXBARCODE_DATAMATRIX_BC_DATAMATRIXWRITER_H_
#define FXBARCODE_DATAMATRIX_BC_DATAMATRIXWRITER_H_
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/widestring.h"
#include "fxbarcode/BC_TwoDimWriter.h"
@@ -18,8 +18,9 @@
CBC_DataMatrixWriter();
~CBC_DataMatrixWriter() override;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>>
- Encode(const WideString& contents, int32_t* pOutWidth, int32_t* pOutHeight);
+ DataVector<uint8_t> Encode(const WideString& contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
index aaf4e9c..0cf5518 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
@@ -4,8 +4,9 @@
#include "fxbarcode/datamatrix/BC_DataMatrixWriter.h"
-#include <vector>
+#include <stdint.h>
+#include "core/fxcrt/data_vector.h"
#include "testing/gtest/include/gtest/gtest.h"
class CBC_DataMatrixWriterTest : public testing::Test {
@@ -39,8 +40,7 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"", &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"", &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -67,8 +67,7 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"helloworld", &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"helloworld", &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -91,8 +90,7 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"12345", &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"12345", &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -123,7 +121,7 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ DataVector<uint8_t> data =
writer.Encode(L"abcdefghijklmnopqrst", &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -132,8 +130,7 @@
EXPECT_EQ(kExpectedData[i], data[i]) << i;
}
{
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"hello world", &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"hello world", &width, &height);
ASSERT_TRUE(data.empty());
}
}
@@ -150,8 +147,7 @@
{
static constexpr int kExpectedDimension = 144;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(input.c_str(), &width, &height);
+ DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(20736u, data.size());
EXPECT_EQ(kExpectedDimension, width);
EXPECT_EQ(kExpectedDimension, height);
@@ -162,8 +158,7 @@
{
width = -1;
height = -1;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(input.c_str(), &width, &height);
+ DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(0u, data.size());
EXPECT_EQ(-1, width);
EXPECT_EQ(-1, height);
@@ -182,8 +177,7 @@
{
static constexpr int kExpectedDimension = 144;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(input.c_str(), &width, &height);
+ DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(20736u, data.size());
EXPECT_EQ(kExpectedDimension, width);
EXPECT_EQ(kExpectedDimension, height);
@@ -194,8 +188,7 @@
{
width = -1;
height = -1;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(input.c_str(), &width, &height);
+ DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(0u, data.size());
EXPECT_EQ(-1, width);
EXPECT_EQ(-1, height);
diff --git a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp
index c307a9d..1ca0891 100644
--- a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp
+++ b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp
@@ -22,8 +22,11 @@
#include "fxbarcode/datamatrix/BC_DefaultPlacement.h"
+#include <stdint.h>
+
#include <utility>
+#include "core/fxcrt/data_vector.h"
#include "fxbarcode/datamatrix/BC_Encoder.h"
CBC_DefaultPlacement::CBC_DefaultPlacement(WideString codewords,
@@ -43,22 +46,27 @@
int32_t CBC_DefaultPlacement::getNumrows() {
return m_numrows;
}
+
int32_t CBC_DefaultPlacement::getNumcols() {
return m_numcols;
}
-std::vector<uint8_t, FxAllocAllocator<uint8_t>>&
-CBC_DefaultPlacement::getBits() {
+
+DataVector<uint8_t>& CBC_DefaultPlacement::getBits() {
return m_bits;
}
+
bool CBC_DefaultPlacement::getBit(int32_t col, int32_t row) {
return m_bits[row * m_numcols + col] == 1;
}
+
void CBC_DefaultPlacement::setBit(int32_t col, int32_t row, bool bit) {
m_bits[row * m_numcols + col] = bit ? (uint8_t)1 : (uint8_t)0;
}
+
bool CBC_DefaultPlacement::hasBit(int32_t col, int32_t row) {
return m_bits[row * m_numcols + col] != 2;
}
+
void CBC_DefaultPlacement::place() {
int32_t pos = 0;
int32_t row = 4;
@@ -100,6 +108,7 @@
setBit(m_numcols - 2, m_numrows - 2, true);
}
}
+
void CBC_DefaultPlacement::module(int32_t row,
int32_t col,
int32_t pos,
@@ -116,6 +125,7 @@
v &= 1 << (8 - bit);
setBit(col, row, v != 0);
}
+
void CBC_DefaultPlacement::utah(int32_t row, int32_t col, int32_t pos) {
module(row - 2, col - 2, pos, 1);
module(row - 2, col - 1, pos, 2);
@@ -126,6 +136,7 @@
module(row, col - 1, pos, 7);
module(row, col, pos, 8);
}
+
void CBC_DefaultPlacement::corner1(int32_t pos) {
module(m_numrows - 1, 0, pos, 1);
module(m_numrows - 1, 1, pos, 2);
@@ -136,6 +147,7 @@
module(2, m_numcols - 1, pos, 7);
module(3, m_numcols - 1, pos, 8);
}
+
void CBC_DefaultPlacement::corner2(int32_t pos) {
module(m_numrows - 3, 0, pos, 1);
module(m_numrows - 2, 0, pos, 2);
@@ -146,6 +158,7 @@
module(0, m_numcols - 1, pos, 7);
module(1, m_numcols - 1, pos, 8);
}
+
void CBC_DefaultPlacement::corner3(int32_t pos) {
module(m_numrows - 3, 0, pos, 1);
module(m_numrows - 2, 0, pos, 2);
@@ -156,6 +169,7 @@
module(2, m_numcols - 1, pos, 7);
module(3, m_numcols - 1, pos, 8);
}
+
void CBC_DefaultPlacement::corner4(int32_t pos) {
module(m_numrows - 1, 0, pos, 1);
module(m_numrows - 1, m_numcols - 1, pos, 2);
diff --git a/fxbarcode/datamatrix/BC_DefaultPlacement.h b/fxbarcode/datamatrix/BC_DefaultPlacement.h
index eee3e93..28c7960 100644
--- a/fxbarcode/datamatrix/BC_DefaultPlacement.h
+++ b/fxbarcode/datamatrix/BC_DefaultPlacement.h
@@ -7,9 +7,9 @@
#ifndef FXBARCODE_DATAMATRIX_BC_DEFAULTPLACEMENT_H_
#define FXBARCODE_DATAMATRIX_BC_DEFAULTPLACEMENT_H_
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/widestring.h"
class CBC_DefaultPlacement final {
@@ -19,7 +19,7 @@
int32_t getNumrows();
int32_t getNumcols();
- std::vector<uint8_t, FxAllocAllocator<uint8_t>>& getBits();
+ DataVector<uint8_t>& getBits();
bool getBit(int32_t col, int32_t row);
void setBit(int32_t col, int32_t row, bool bit);
bool hasBit(int32_t col, int32_t row);
@@ -29,7 +29,7 @@
WideString m_codewords;
int32_t m_numrows;
int32_t m_numcols;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_bits;
+ DataVector<uint8_t> m_bits;
void module(int32_t row, int32_t col, int32_t pos, int32_t bit);
void utah(int32_t row, int32_t col, int32_t pos);
void corner1(int32_t pos);
diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
index cee4027..d6b4d5f 100644
--- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
+++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
@@ -22,10 +22,12 @@
#include "fxbarcode/datamatrix/BC_ErrorCorrection.h"
+#include <stdint.h>
+
#include <algorithm>
#include <vector>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "fxbarcode/datamatrix/BC_Encoder.h"
#include "fxbarcode/datamatrix/BC_SymbolInfo.h"
#include "third_party/base/check.h"
@@ -154,7 +156,7 @@
if (table >= kFactorTableNum)
return WideString();
- std::vector<uint16_t, FxAllocAllocator<uint16_t>> ecc(numECWords);
+ DataVector<uint16_t> ecc(numECWords);
for (size_t i = 0; i < len; ++i) {
uint16_t m = ecc[numECWords - 1] ^ codewords[i];
for (int32_t j = numECWords - 1; j > 0; --j) {
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
index 7a48353..f0c4b0f 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
@@ -21,6 +21,10 @@
*/
#include "fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h"
+
+#include <stdint.h>
+
+#include "core/fxcrt/data_vector.h"
#include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h"
CBC_BarcodeMatrix::CBC_BarcodeMatrix(size_t width, size_t height)
@@ -32,9 +36,8 @@
CBC_BarcodeMatrix::~CBC_BarcodeMatrix() = default;
-std::vector<uint8_t, FxAllocAllocator<uint8_t>>
-CBC_BarcodeMatrix::toBitArray() {
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> bitArray(m_width * m_height);
+DataVector<uint8_t> CBC_BarcodeMatrix::toBitArray() {
+ DataVector<uint8_t> bitArray(m_width * m_height);
for (size_t i = 0; i < m_height; ++i) {
const auto& bytearray = m_matrix[i]->GetRow();
for (size_t j = 0; j < m_width; ++j)
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
index cb88c62..658bada 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
@@ -7,10 +7,12 @@
#ifndef FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_
#define FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_
+#include <stdint.h>
+
#include <memory>
#include <vector>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
class CBC_BarcodeRow;
@@ -22,7 +24,7 @@
CBC_BarcodeRow* getRow(size_t row) const { return m_matrix[row].get(); }
size_t getWidth() const { return m_width; }
size_t getHeight() const { return m_height; }
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> toBitArray();
+ DataVector<uint8_t> toBitArray();
private:
std::vector<std::unique_ptr<CBC_BarcodeRow>> m_matrix;
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
index 280a79c..607e225 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
@@ -9,9 +9,7 @@
#include <stdint.h>
-#include <vector>
-
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
class CBC_BarcodeRow final {
public:
@@ -19,12 +17,10 @@
~CBC_BarcodeRow();
void AddBar(bool black, size_t width);
- const std::vector<uint8_t, FxAllocAllocator<uint8_t>>& GetRow() const {
- return row_;
- }
+ const DataVector<uint8_t>& GetRow() const { return row_; }
private:
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> row_;
+ DataVector<uint8_t> row_;
size_t offset_ = 0;
};
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
index f522cb9..fcc9675 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
@@ -22,9 +22,9 @@
#include "fxbarcode/pdf417/BC_PDF417ErrorCorrection.h"
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
namespace {
@@ -140,7 +140,7 @@
if (k < 0)
return absl::nullopt;
- std::vector<wchar_t, FxAllocAllocator<wchar_t>> ech(k);
+ DataVector<wchar_t> ech(k);
size_t sld = dataCodewords.GetLength();
for (size_t i = 0; i < sld; i++) {
int32_t t1 = (dataCodewords[i] + ech[k - 1]) % 929;
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.cpp b/fxbarcode/pdf417/BC_PDF417Writer.cpp
index 295432b..cbfe789 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -22,9 +22,12 @@
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
+#include <stdint.h>
+
#include <algorithm>
#include <utility>
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/stl_util.h"
#include "fxbarcode/BC_TwoDimWriter.h"
#include "fxbarcode/common/BC_CommonBitMatrix.h"
@@ -43,11 +46,10 @@
return true;
}
-std::vector<uint8_t, FxAllocAllocator<uint8_t>> CBC_PDF417Writer::Encode(
- WideStringView contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight) {
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> results;
+DataVector<uint8_t> CBC_PDF417Writer::Encode(WideStringView contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight) {
+ DataVector<uint8_t> results;
CBC_PDF417 encoder;
int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
int32_t row = m_Height / (m_ModuleWidth * 20);
@@ -61,8 +63,7 @@
return results;
CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> matrixData =
- barcodeMatrix->toBitArray();
+ DataVector<uint8_t> matrixData = barcodeMatrix->toBitArray();
int32_t matrixWidth = barcodeMatrix->getWidth();
int32_t matrixHeight = barcodeMatrix->getHeight();
@@ -78,11 +79,10 @@
return results;
}
-void CBC_PDF417Writer::RotateArray(
- std::vector<uint8_t, FxAllocAllocator<uint8_t>>* bitarray,
- int32_t height,
- int32_t width) {
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> temp = *bitarray;
+void CBC_PDF417Writer::RotateArray(DataVector<uint8_t>* bitarray,
+ int32_t height,
+ int32_t width) {
+ DataVector<uint8_t> temp = *bitarray;
for (int32_t ii = 0; ii < height; ii++) {
int32_t inverseii = height - ii - 1;
for (int32_t jj = 0; jj < width; jj++) {
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.h b/fxbarcode/pdf417/BC_PDF417Writer.h
index 65eea88..c2a2721 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.h
+++ b/fxbarcode/pdf417/BC_PDF417Writer.h
@@ -8,10 +8,9 @@
#define FXBARCODE_PDF417_BC_PDF417WRITER_H_
#include <stddef.h>
+#include <stdint.h>
-#include <vector>
-
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/widestring.h"
#include "fxbarcode/BC_TwoDimWriter.h"
@@ -20,14 +19,15 @@
CBC_PDF417Writer();
~CBC_PDF417Writer() override;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>>
- Encode(WideStringView contents, int32_t* pOutWidth, int32_t* pOutHeight);
+ DataVector<uint8_t> Encode(WideStringView contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
private:
- void RotateArray(std::vector<uint8_t, FxAllocAllocator<uint8_t>>* bitarray,
+ void RotateArray(DataVector<uint8_t>* bitarray,
int32_t width,
int32_t height);
};
diff --git a/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp b/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
index 9ecb0de..ab07dac 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
@@ -4,8 +4,9 @@
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
-#include <vector>
+#include <stdint.h>
+#include "core/fxcrt/data_vector.h"
#include "testing/gtest/include/gtest/gtest.h"
class CBC_PDF417WriterTest : public testing::Test {
@@ -413,8 +414,7 @@
1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1,
0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1};
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"", &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"", &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedWidth, width);
ASSERT_EQ(kExpectedHeight, height);
@@ -811,8 +811,7 @@
1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0,
0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1};
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"hello world", &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"hello world", &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedWidth, width);
ASSERT_EQ(kExpectedHeight, height);
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter.cpp b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
index 646e7e0..77fe042 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter.cpp
+++ b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
@@ -22,6 +22,9 @@
#include "fxbarcode/qrcode/BC_QRCodeWriter.h"
+#include <stdint.h>
+
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/stl_util.h"
#include "fxbarcode/common/BC_CommonByteMatrix.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
@@ -43,12 +46,11 @@
return true;
}
-std::vector<uint8_t, FxAllocAllocator<uint8_t>> CBC_QRCodeWriter::Encode(
- WideStringView contents,
- int32_t ecLevel,
- int32_t* pOutWidth,
- int32_t* pOutHeight) {
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> results;
+DataVector<uint8_t> CBC_QRCodeWriter::Encode(WideStringView contents,
+ int32_t ecLevel,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight) {
+ DataVector<uint8_t> results;
CBC_QRCoderErrorCorrectionLevel* ec = nullptr;
switch (ecLevel) {
case 0:
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter.h b/fxbarcode/qrcode/BC_QRCodeWriter.h
index b7ca6d1..e829f2f 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter.h
+++ b/fxbarcode/qrcode/BC_QRCodeWriter.h
@@ -7,9 +7,9 @@
#ifndef FXBARCODE_QRCODE_BC_QRCODEWRITER_H_
#define FXBARCODE_QRCODE_BC_QRCODEWRITER_H_
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/widestring.h"
#include "fxbarcode/BC_TwoDimWriter.h"
@@ -18,11 +18,10 @@
CBC_QRCodeWriter();
~CBC_QRCodeWriter() override;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> Encode(
- WideStringView contents,
- int32_t ecLevel,
- int32_t* pOutWidth,
- int32_t* pOutHeight);
+ DataVector<uint8_t> Encode(WideStringView contents,
+ int32_t ecLevel,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp b/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp
index d703caf..934a6ab 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp
+++ b/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp
@@ -4,8 +4,9 @@
#include "fxbarcode/qrcode/BC_QRCodeWriter.h"
-#include <vector>
+#include <stdint.h>
+#include "core/fxcrt/data_vector.h"
#include "testing/gtest/include/gtest/gtest.h"
class CBC_QRCodeWriterTest : public testing::Test {
@@ -50,8 +51,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"", 0, &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"", 0, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -85,8 +85,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"", 1, &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"", 1, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -120,8 +119,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"", 2, &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"", 2, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -155,8 +153,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
- writer.Encode(L"", 3, &width, &height);
+ DataVector<uint8_t> data = writer.Encode(L"", 3, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -190,7 +187,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ DataVector<uint8_t> data =
writer.Encode(L"hello world", 0, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -225,7 +222,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0
};
// clang-format on
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ DataVector<uint8_t> data =
writer.Encode(L"hello world", 1, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -263,7 +260,7 @@
0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1,
1};
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ DataVector<uint8_t> data =
writer.Encode(L"hello world", 2, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -301,7 +298,7 @@
0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1,
1};
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ DataVector<uint8_t> data =
writer.Encode(L"hello world", 3, &width, &height);
ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
diff --git a/fxbarcode/qrcode/BC_QRCoderBitVector.h b/fxbarcode/qrcode/BC_QRCoderBitVector.h
index a0f29fe..f2e7e2a 100644
--- a/fxbarcode/qrcode/BC_QRCoderBitVector.h
+++ b/fxbarcode/qrcode/BC_QRCoderBitVector.h
@@ -10,9 +10,7 @@
#include <stddef.h>
#include <stdint.h>
-#include <vector>
-
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
class CBC_QRCoderBitVector {
public:
@@ -33,7 +31,7 @@
void AppendByte(int8_t value);
size_t m_sizeInBits = 0;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_array;
+ DataVector<uint8_t> m_array;
};
#endif // FXBARCODE_QRCODE_BC_QRCODERBITVECTOR_H_
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index b4bc114..46aa0a3 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -22,12 +22,14 @@
#include "fxbarcode/qrcode/BC_QRCoderEncoder.h"
+#include <stdint.h>
+
#include <algorithm>
#include <memory>
#include <utility>
#include <vector>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_string.h"
#include "fxbarcode/common/BC_CommonByteMatrix.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomon.h"
@@ -50,8 +52,8 @@
CBC_ReedSolomonGF256* g_QRCodeField = nullptr;
struct QRCoderBlockPair {
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> data;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> ecc;
+ DataVector<uint8_t> data;
+ DataVector<uint8_t> ecc;
};
// This is a mapping for an ASCII table, starting at an index of 32.
@@ -179,19 +181,18 @@
return false;
}
-std::vector<uint8_t, FxAllocAllocator<uint8_t>> GenerateECBytes(
- pdfium::span<const uint8_t> dataBytes,
- size_t numEcBytesInBlock) {
+DataVector<uint8_t> GenerateECBytes(pdfium::span<const uint8_t> dataBytes,
+ size_t numEcBytesInBlock) {
// If |numEcBytesInBlock| is 0, the encoder will fail anyway.
DCHECK(numEcBytesInBlock > 0);
std::vector<int32_t> toEncode(dataBytes.size() + numEcBytesInBlock);
std::copy(dataBytes.begin(), dataBytes.end(), toEncode.begin());
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> ecBytes;
+ DataVector<uint8_t> ecBytes;
CBC_ReedSolomonEncoder encoder(g_QRCodeField);
if (encoder.Encode(&toEncode, numEcBytesInBlock)) {
- ecBytes = std::vector<uint8_t, FxAllocAllocator<uint8_t>>(
- toEncode.begin() + dataBytes.size(), toEncode.end());
+ ecBytes = DataVector<uint8_t>(toEncode.begin() + dataBytes.size(),
+ toEncode.end());
DCHECK_EQ(ecBytes.size(), static_cast<size_t>(numEcBytesInBlock));
}
return ecBytes;
@@ -318,12 +319,10 @@
if (numDataBytesInBlock < 0 || numEcBytesInBlock <= 0)
return false;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> dataBytes(
- numDataBytesInBlock);
+ DataVector<uint8_t> dataBytes(numDataBytesInBlock);
memcpy(dataBytes.data(), bits->GetArray() + dataBytesOffset,
numDataBytesInBlock);
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> ecBytes =
- GenerateECBytes(dataBytes, numEcBytesInBlock);
+ DataVector<uint8_t> ecBytes = GenerateECBytes(dataBytes, numEcBytesInBlock);
if (ecBytes.empty())
return false;
@@ -338,16 +337,14 @@
for (size_t x = 0; x < maxNumDataBytes; x++) {
for (size_t j = 0; j < blocks.size(); j++) {
- const std::vector<uint8_t, FxAllocAllocator<uint8_t>>& dataBytes =
- blocks[j].data;
+ const DataVector<uint8_t>& dataBytes = blocks[j].data;
if (x < dataBytes.size())
result->AppendBits(dataBytes[x], 8);
}
}
for (size_t y = 0; y < maxNumEcBytes; y++) {
for (size_t l = 0; l < blocks.size(); l++) {
- const std::vector<uint8_t, FxAllocAllocator<uint8_t>>& ecBytes =
- blocks[l].ecc;
+ const DataVector<uint8_t>& ecBytes = blocks[l].ecc;
if (y < ecBytes.size())
result->AppendBits(ecBytes[y], 8);
}