summaryrefslogtreecommitdiff
path: root/fxbarcode/common
diff options
context:
space:
mode:
Diffstat (limited to 'fxbarcode/common')
-rw-r--r--fxbarcode/common/BC_CommonBitMatrix.cpp16
-rw-r--r--fxbarcode/common/BC_CommonBitMatrix.h5
-rw-r--r--fxbarcode/common/BC_CommonByteMatrix.cpp45
-rw-r--r--fxbarcode/common/BC_CommonByteMatrix.h18
4 files changed, 36 insertions, 48 deletions
diff --git a/fxbarcode/common/BC_CommonBitMatrix.cpp b/fxbarcode/common/BC_CommonBitMatrix.cpp
index 6fe447db6f..a8a6e53bc1 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.cpp
+++ b/fxbarcode/common/BC_CommonBitMatrix.cpp
@@ -22,9 +22,13 @@
#include "fxbarcode/common/BC_CommonBitMatrix.h"
+#include <algorithm>
+#include <iterator>
+
#include "fxbarcode/common/BC_CommonBitArray.h"
#include "fxbarcode/utils.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
CBC_CommonBitMatrix::CBC_CommonBitMatrix() {}
@@ -33,8 +37,7 @@ void CBC_CommonBitMatrix::Init(int32_t dimension) {
m_height = dimension;
int32_t rowSize = (m_height + 31) >> 5;
m_rowSize = rowSize;
- m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
- memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
+ m_bits = pdfium::Vector2D<int32_t>(m_rowSize, m_height);
}
void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
@@ -42,13 +45,10 @@ void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
m_height = height;
int32_t rowSize = (width + 31) >> 5;
m_rowSize = rowSize;
- m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
- memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
+ m_bits = pdfium::Vector2D<int32_t>(m_rowSize, m_height);
}
-CBC_CommonBitMatrix::~CBC_CommonBitMatrix() {
- FX_Free(m_bits);
-}
+CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default;
bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) const {
int32_t offset = y * m_rowSize + (x >> 5);
@@ -70,7 +70,7 @@ void CBC_CommonBitMatrix::Flip(int32_t x, int32_t y) {
}
void CBC_CommonBitMatrix::Clear() {
- memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
+ std::fill(std::begin(m_bits), std::end(m_bits), 0);
}
bool CBC_CommonBitMatrix::SetRegion(int32_t left,
diff --git a/fxbarcode/common/BC_CommonBitMatrix.h b/fxbarcode/common/BC_CommonBitMatrix.h
index 67c0f888cc..51c3728a7a 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.h
+++ b/fxbarcode/common/BC_CommonBitMatrix.h
@@ -7,7 +7,7 @@
#ifndef FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
#define FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
-#include <memory>
+#include <vector>
#include "core/fxcrt/fx_system.h"
@@ -31,13 +31,12 @@ class CBC_CommonBitMatrix {
void SetCol(int32_t y, CBC_CommonBitArray* col);
int32_t GetWidth() const { return m_width; }
int32_t GetHeight() const { return m_height; }
- int32_t* GetBits() const { return m_bits; }
private:
int32_t m_width = 0;
int32_t m_height = 0;
int32_t m_rowSize = 0;
- int32_t* m_bits = nullptr;
+ std::vector<int32_t> m_bits;
};
#endif // FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
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);
}
diff --git a/fxbarcode/common/BC_CommonByteMatrix.h b/fxbarcode/common/BC_CommonByteMatrix.h
index 9f13a376d1..c5a66a3e82 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.h
+++ b/fxbarcode/common/BC_CommonByteMatrix.h
@@ -9,27 +9,29 @@
#include <stdint.h>
+#include <vector>
+
#include "core/fxcrt/fx_system.h"
+#include "third_party/base/span.h"
-class CBC_CommonByteMatrix {
+class CBC_CommonByteMatrix final {
public:
CBC_CommonByteMatrix(int32_t width, int32_t height);
- virtual ~CBC_CommonByteMatrix();
+ ~CBC_CommonByteMatrix();
- int32_t GetHeight();
- int32_t GetWidth();
- uint8_t Get(int32_t x, int32_t y);
- uint8_t* GetArray();
+ int32_t GetWidth() const { return m_width; }
+ int32_t GetHeight() const { return m_height; }
+ pdfium::span<const uint8_t> GetArray() const { return m_bytes; }
+ uint8_t Get(int32_t x, int32_t y) const;
void Set(int32_t x, int32_t y, int32_t value);
void Set(int32_t x, int32_t y, uint8_t value);
void clear(uint8_t value);
- virtual void Init();
private:
- uint8_t* m_bytes;
int32_t m_width;
int32_t m_height;
+ std::vector<uint8_t> m_bytes;
};
#endif // FXBARCODE_COMMON_BC_COMMONBYTEMATRIX_H_