summaryrefslogtreecommitdiff
path: root/fxbarcode/common/BC_CommonByteMatrix.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-03 15:57:03 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-03 15:57:03 +0000
commit1c14ae2fbe1ae95dac3a7f5e60d049d9630aef02 (patch)
tree2d121ae2a0436adce5c54379d1824b427dd03359 /fxbarcode/common/BC_CommonByteMatrix.cpp
parentd77e0ed72f73fb63305d04953ef03e2edab82d34 (diff)
downloadpdfium-1c14ae2fbe1ae95dac3a7f5e60d049d9630aef02.tar.xz
Avoid explicit allocs in fxbarcode matrix classes.
Other cleanups: Remove unused method. Fold Init() into constructor. Return span<> where possible. Change-Id: Ie38d32efb6e63d86ae24e93684903a6dd900810f Reviewed-on: https://pdfium-review.googlesource.com/36810 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode/common/BC_CommonByteMatrix.cpp')
-rw-r--r--fxbarcode/common/BC_CommonByteMatrix.cpp45
1 files changed, 16 insertions, 29 deletions
diff --git a/fxbarcode/common/BC_CommonByteMatrix.cpp b/fxbarcode/common/BC_CommonByteMatrix.cpp
index 2ab1e9ac50..db0a4a9647 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.cpp
+++ b/fxbarcode/common/BC_CommonByteMatrix.cpp
@@ -19,46 +19,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "fxbarcode/common/BC_CommonByteMatrix.h"
+#include <algorithm>
+#include <iterator>
#include "core/fxcrt/fx_memory.h"
-#include "fxbarcode/common/BC_CommonByteMatrix.h"
+#include "third_party/base/stl_util.h"
-CBC_CommonByteMatrix::CBC_CommonByteMatrix(int32_t width, int32_t height) {
- m_height = height;
- m_width = width;
- m_bytes = nullptr;
-}
-void CBC_CommonByteMatrix::Init() {
- m_bytes = FX_Alloc2D(uint8_t, m_height, m_width);
- memset(m_bytes, 0xff, m_height * m_width);
-}
-CBC_CommonByteMatrix::~CBC_CommonByteMatrix() {
- FX_Free(m_bytes);
-}
-int32_t CBC_CommonByteMatrix::GetHeight() {
- return m_height;
-}
-int32_t CBC_CommonByteMatrix::GetWidth() {
- return m_width;
+CBC_CommonByteMatrix::CBC_CommonByteMatrix(int32_t width, int32_t height)
+ : m_width(width), m_height(height) {
+ m_bytes = pdfium::Vector2D<uint8_t>(m_height, m_width);
+ clear(0xff);
}
-uint8_t CBC_CommonByteMatrix::Get(int32_t x, int32_t y) {
+
+CBC_CommonByteMatrix::~CBC_CommonByteMatrix() = default;
+
+uint8_t CBC_CommonByteMatrix::Get(int32_t x, int32_t y) const {
return m_bytes[y * m_width + x];
}
+
void CBC_CommonByteMatrix::Set(int32_t x, int32_t y, int32_t value) {
m_bytes[y * m_width + x] = (uint8_t)value;
}
+
void CBC_CommonByteMatrix::Set(int32_t x, int32_t y, uint8_t value) {
m_bytes[y * m_width + x] = value;
}
+
void CBC_CommonByteMatrix::clear(uint8_t value) {
- int32_t y;
- for (y = 0; y < m_height; y++) {
- int32_t x;
- for (x = 0; x < m_width; x++) {
- m_bytes[y * m_width + x] = value;
- }
- }
-}
-uint8_t* CBC_CommonByteMatrix::GetArray() {
- return m_bytes;
+ std::fill(std::begin(m_bytes), std::end(m_bytes), value);
}