From 81e0830e67344ffd7c7eb98055c892fb748db5c4 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Wed, 22 Aug 2018 21:28:36 +0000 Subject: Simplify internal state of CBC_BarcodeMatrix. Change-Id: Icd66f42c240984df6821c2bae640bbfacfa62ad2 Reviewed-on: https://pdfium-review.googlesource.com/41010 Commit-Queue: Henrique Nakashima Reviewed-by: Ryan Harrison Reviewed-by: Lei Zhang --- fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp | 33 +++++++++-------------------- fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h | 15 ++++++------- 2 files changed, 16 insertions(+), 32 deletions(-) (limited to 'fxbarcode') diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp index 4fc55a2d10..7fb1259154 100644 --- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp +++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp @@ -24,16 +24,11 @@ #include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h" #include "third_party/base/ptr_util.h" -CBC_BarcodeMatrix::CBC_BarcodeMatrix(int32_t height, int32_t width) { - m_matrix.resize(height); - for (size_t i = 0; i < m_matrix.size(); ++i) - m_matrix[i] = pdfium::MakeUnique((width + 4) * 17 + 1); - - m_width = width * 17; - m_height = height; - m_currentRow = 0; - m_outHeight = 0; - m_outWidth = 0; +CBC_BarcodeMatrix::CBC_BarcodeMatrix(size_t height, size_t width) + : m_width((width + 4) * 17 + 1), m_height(height) { + m_matrix.resize(m_height); + for (size_t i = 0; i < m_height; ++i) + m_matrix[i] = pdfium::MakeUnique(m_width); } CBC_BarcodeMatrix::~CBC_BarcodeMatrix() {} @@ -43,19 +38,11 @@ void CBC_BarcodeMatrix::nextRow() { } std::vector& CBC_BarcodeMatrix::getMatrix() { - std::vector bytearray = m_matrix[0]->getRow(); - size_t xMax = bytearray.size(); - size_t yMax = m_height; - m_matrixOut.resize(xMax * yMax); - m_outWidth = xMax; - m_outHeight = yMax; - int32_t k = 0; - for (size_t i = 0; i < yMax; i++) { - if (i != 0) - bytearray = m_matrix[i]->getRow(); - k = i * xMax; - for (size_t l = 0; l < xMax; l++) - m_matrixOut[k + l] = bytearray[l]; + m_matrixOut.resize(m_width * m_height); + for (size_t i = 0; i < m_height; ++i) { + std::vector& bytearray = m_matrix[i]->getRow(); + for (size_t j = 0; j < m_width; ++j) + m_matrixOut[i * m_width + j] = bytearray[j]; } return m_matrixOut; } diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h index 43906d8821..badb0ce3cd 100644 --- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h +++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h @@ -14,24 +14,21 @@ class CBC_BarcodeRow; class CBC_BarcodeMatrix { public: - CBC_BarcodeMatrix(); - CBC_BarcodeMatrix(int32_t height, int32_t width); + CBC_BarcodeMatrix(size_t height, size_t width); virtual ~CBC_BarcodeMatrix(); CBC_BarcodeRow* getCurrentRow() const { return m_matrix[m_currentRow].get(); } - int32_t getWidth() const { return m_outWidth; } - int32_t getHeight() const { return m_outHeight; } + size_t getWidth() const { return m_width; } + size_t getHeight() const { return m_height; } void nextRow(); std::vector& getMatrix(); private: std::vector> m_matrix; std::vector m_matrixOut; - int32_t m_currentRow; - int32_t m_height; - int32_t m_width; - int32_t m_outWidth; - int32_t m_outHeight; + size_t m_currentRow = 0; + size_t m_width; + size_t m_height; }; #endif // FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_ -- cgit v1.2.3