summaryrefslogtreecommitdiff
path: root/fxbarcode/common/BC_CommonBitMatrix.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-04-05 18:42:22 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-06 01:58:05 +0000
commit1b22880748c3f3b3740699ae4c953a33f65ad10f (patch)
tree57d7155639ea2f19dea22cb08ec3ce0b76bcbf9b /fxbarcode/common/BC_CommonBitMatrix.cpp
parent0b18e1599dc9d07355c4ab6a069de33a536f7ba8 (diff)
downloadpdfium-1b22880748c3f3b3740699ae4c953a33f65ad10f.tar.xz
Change some fxbarcode to use return values.
No caller cares about the exception values anyway. Remove the unused ones. Also use more std::unique_ptr to stop potential leaks. Change-Id: Ic5955fb0d879f55e1c6a005c0204df50246dab19 Reviewed-on: https://pdfium-review.googlesource.com/3715 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxbarcode/common/BC_CommonBitMatrix.cpp')
-rw-r--r--fxbarcode/common/BC_CommonBitMatrix.cpp74
1 files changed, 30 insertions, 44 deletions
diff --git a/fxbarcode/common/BC_CommonBitMatrix.cpp b/fxbarcode/common/BC_CommonBitMatrix.cpp
index a3e20ed28e..fe3546156e 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.cpp
+++ b/fxbarcode/common/BC_CommonBitMatrix.cpp
@@ -24,12 +24,8 @@
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "fxbarcode/utils.h"
-CBC_CommonBitMatrix::CBC_CommonBitMatrix() {
- m_width = 0;
- m_height = 0;
- m_rowSize = 0;
- m_bits = nullptr;
-}
+CBC_CommonBitMatrix::CBC_CommonBitMatrix() {}
+
void CBC_CommonBitMatrix::Init(int32_t dimension) {
m_width = dimension;
m_height = dimension;
@@ -38,6 +34,7 @@ void CBC_CommonBitMatrix::Init(int32_t dimension) {
m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
}
+
void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
m_width = width;
m_height = height;
@@ -46,61 +43,58 @@ void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
}
+
CBC_CommonBitMatrix::~CBC_CommonBitMatrix() {
FX_Free(m_bits);
}
-bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) {
+
+bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) const {
int32_t offset = y * m_rowSize + (x >> 5);
- if (offset >= m_rowSize * m_height || offset < 0) {
+ if (offset >= m_rowSize * m_height || offset < 0)
return false;
- }
return ((((uint32_t)m_bits[offset]) >> (x & 0x1f)) & 1) != 0;
}
+
int32_t* CBC_CommonBitMatrix::GetBits() {
return m_bits;
}
+
void CBC_CommonBitMatrix::Set(int32_t x, int32_t y) {
int32_t offset = y * m_rowSize + (x >> 5);
- if (offset >= m_rowSize * m_height || offset < 0) {
+ if (offset >= m_rowSize * m_height || offset < 0)
return;
- }
m_bits[offset] |= 1 << (x & 0x1f);
}
+
void CBC_CommonBitMatrix::Flip(int32_t x, int32_t y) {
int32_t offset = y * m_rowSize + (x >> 5);
m_bits[offset] ^= 1 << (x & 0x1f);
}
+
void CBC_CommonBitMatrix::Clear() {
memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
}
-void CBC_CommonBitMatrix::SetRegion(int32_t left,
+
+bool CBC_CommonBitMatrix::SetRegion(int32_t left,
int32_t top,
int32_t width,
- int32_t height,
- int32_t& e) {
- if (top < 0 || left < 0) {
- e = BCExceptionLeftAndTopMustBeNonnegative;
- return;
- }
- if (height < 1 || width < 1) {
- e = BCExceptionHeightAndWidthMustBeAtLeast1;
- return;
- }
+ int32_t height) {
+ if (top < 0 || left < 0 || height < 1 || width < 1)
+ return false;
+
int32_t right = left + width;
int32_t bottom = top + height;
- if (m_height < bottom || m_width < right) {
- e = BCExceptionRegionMustFitInsideMatrix;
- return;
- }
- int32_t y;
- for (y = top; y < bottom; y++) {
+ if (m_height < bottom || m_width < right)
+ return false;
+
+ for (int32_t y = top; y < bottom; y++) {
int32_t offset = y * m_rowSize;
- int32_t x;
- for (x = left; x < right; x++) {
+ for (int32_t x = left; x < right; x++)
m_bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
- }
}
+ return true;
}
+
CBC_CommonBitArray* CBC_CommonBitMatrix::GetRow(int32_t y,
CBC_CommonBitArray* row) {
CBC_CommonBitArray* rowArray = nullptr;
@@ -110,12 +104,11 @@ CBC_CommonBitArray* CBC_CommonBitMatrix::GetRow(int32_t y,
rowArray = new CBC_CommonBitArray(row);
}
int32_t offset = y * m_rowSize;
- int32_t x;
- for (x = 0; x < m_rowSize; x++) {
+ for (int32_t x = 0; x < m_rowSize; x++)
rowArray->SetBulk(x << 5, m_bits[offset + x]);
- }
return rowArray;
}
+
void CBC_CommonBitMatrix::SetRow(int32_t y, CBC_CommonBitArray* row) {
int32_t l = y * m_rowSize;
for (int32_t i = 0; i < m_rowSize; i++) {
@@ -129,19 +122,12 @@ void CBC_CommonBitMatrix::SetCol(int32_t y, CBC_CommonBitArray* col) {
m_bits[i * m_rowSize + y] = col->GetBitArray()[i];
}
-int32_t CBC_CommonBitMatrix::GetWidth() {
+int32_t CBC_CommonBitMatrix::GetWidth() const {
return m_width;
}
-int32_t CBC_CommonBitMatrix::GetHeight() {
+int32_t CBC_CommonBitMatrix::GetHeight() const {
return m_height;
}
-int32_t CBC_CommonBitMatrix::GetRowSize() {
+int32_t CBC_CommonBitMatrix::GetRowSize() const {
return m_rowSize;
}
-int32_t CBC_CommonBitMatrix::GetDimension(int32_t& e) {
- if (m_width != m_height) {
- e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix;
- return 0;
- }
- return m_width;
-}