summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-04-29 11:24:14 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-29 11:24:15 -0700
commitd5d07dcf59ddc6439f73382c6e0b9e6d1851000d (patch)
tree3430639a1c286570a60e946e1b850aeeedaaa05a
parentcd1e9ff4f432cbc29ed279e6891fb7ddc2ea3734 (diff)
downloadpdfium-d5d07dcf59ddc6439f73382c6e0b9e6d1851000d.tar.xz
Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 8
This also removes another hand-written bubblesort in favor of the std::sort() STL function. Review-Url: https://codereview.chromium.org/1937513002
-rw-r--r--xfa/fxbarcode/BC_Utils.cpp15
-rw-r--r--xfa/fxbarcode/common/BC_WhiteRectangleDetector.cpp62
-rw-r--r--xfa/fxbarcode/common/BC_WhiteRectangleDetector.h12
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp8
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp66
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h16
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp26
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h16
-rw-r--r--xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp35
-rw-r--r--xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h15
-rw-r--r--xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp29
-rw-r--r--xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp120
-rw-r--r--xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h17
-rw-r--r--xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp21
-rw-r--r--xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h2
-rw-r--r--xfa/fxbarcode/utils.h2
16 files changed, 228 insertions, 234 deletions
diff --git a/xfa/fxbarcode/BC_Utils.cpp b/xfa/fxbarcode/BC_Utils.cpp
index 2225f7ce50..ccc620218a 100644
--- a/xfa/fxbarcode/BC_Utils.cpp
+++ b/xfa/fxbarcode/BC_Utils.cpp
@@ -31,18 +31,3 @@ void BC_FX_ByteString_Append(CFX_ByteString& dst, const CFX_ByteArray& ba) {
dst += ba[i];
}
}
-void BC_FX_PtrArray_Sort(CFX_PtrArray& src, BC_PtrArrayCompareCallback fun) {
- int32_t nLength = src.GetSize();
- FX_BOOL changed = true;
- do {
- changed = false;
- for (int32_t i = 0; i < nLength - 1; i++) {
- if (fun(src[i + 1], src[i])) {
- void* temp = src[i];
- src.SetAt(i, src[i + 1]);
- src.SetAt(i + 1, temp);
- changed = true;
- }
- }
- } while (changed);
-}
diff --git a/xfa/fxbarcode/common/BC_WhiteRectangleDetector.cpp b/xfa/fxbarcode/common/BC_WhiteRectangleDetector.cpp
index 2aeacd1399..f64abb61c0 100644
--- a/xfa/fxbarcode/common/BC_WhiteRectangleDetector.cpp
+++ b/xfa/fxbarcode/common/BC_WhiteRectangleDetector.cpp
@@ -59,8 +59,11 @@ CBC_WhiteRectangleDetector::CBC_WhiteRectangleDetector(
m_upInit = y - halfsize;
m_downInit = y + halfsize;
}
+
CBC_WhiteRectangleDetector::~CBC_WhiteRectangleDetector() {}
-CFX_PtrArray* CBC_WhiteRectangleDetector::Detect(int32_t& e) {
+
+CFX_ArrayTemplate<CBC_ResultPoint*>* CBC_WhiteRectangleDetector::Detect(
+ int32_t& e) {
int32_t left = m_leftInit;
int32_t right = m_rightInit;
int32_t up = m_upInit;
@@ -131,9 +134,9 @@ CFX_PtrArray* CBC_WhiteRectangleDetector::Detect(int32_t& e) {
if (z)
break;
}
- if (z.get() == NULL) {
+ if (!z.get()) {
e = BCExceptionNotFound;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
std::unique_ptr<CBC_ResultPoint> t;
for (int32_t j = 1; j < maxSize; j++) {
@@ -142,9 +145,9 @@ CFX_PtrArray* CBC_WhiteRectangleDetector::Detect(int32_t& e) {
if (t)
break;
}
- if (t.get() == NULL) {
+ if (!t.get()) {
e = BCExceptionNotFound;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
std::unique_ptr<CBC_ResultPoint> x;
for (int32_t k = 1; k < maxSize; k++) {
@@ -153,9 +156,9 @@ CFX_PtrArray* CBC_WhiteRectangleDetector::Detect(int32_t& e) {
if (x)
break;
}
- if (x.get() == NULL) {
+ if (!x.get()) {
e = BCExceptionNotFound;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
std::unique_ptr<CBC_ResultPoint> y;
for (int32_t m = 1; m < maxSize; m++) {
@@ -164,17 +167,18 @@ CFX_PtrArray* CBC_WhiteRectangleDetector::Detect(int32_t& e) {
if (y)
break;
}
- if (y.get() == NULL) {
+ if (!y.get()) {
e = BCExceptionNotFound;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
return CenterEdges(y.get(), z.get(), x.get(), t.get());
- } else {
- e = BCExceptionNotFound;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
}
- return NULL;
+
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
+ return nullptr;
}
+
int32_t CBC_WhiteRectangleDetector::Round(FX_FLOAT d) {
return (int32_t)(d + 0.5f);
}
@@ -203,10 +207,16 @@ int32_t CBC_WhiteRectangleDetector::DistanceL2(FX_FLOAT aX,
float yDiff = aY - bY;
return Round((float)sqrt(xDiff * xDiff + yDiff * yDiff));
}
-CFX_PtrArray* CBC_WhiteRectangleDetector::CenterEdges(CBC_ResultPoint* y,
- CBC_ResultPoint* z,
- CBC_ResultPoint* x,
- CBC_ResultPoint* t) {
+
+CFX_ArrayTemplate<CBC_ResultPoint*>* CBC_WhiteRectangleDetector::CenterEdges(
+ CBC_ResultPoint* y,
+ CBC_ResultPoint* z,
+ CBC_ResultPoint* x,
+ CBC_ResultPoint* t) const {
+ CFX_ArrayTemplate<CBC_ResultPoint*>* result =
+ new CFX_ArrayTemplate<CBC_ResultPoint*>();
+ result->SetSize(4);
+
float yi = y->GetX();
float yj = y->GetY();
float zi = z->GetX();
@@ -215,24 +225,22 @@ CFX_PtrArray* CBC_WhiteRectangleDetector::CenterEdges(CBC_ResultPoint* y,
float xj = x->GetY();
float ti = t->GetX();
float tj = t->GetY();
+
if (yi < m_width / 2) {
- CFX_PtrArray* result = new CFX_PtrArray;
- result->SetSize(4);
(*result)[0] = new CBC_ResultPoint(ti - CORR, tj + CORR);
(*result)[1] = new CBC_ResultPoint(zi + CORR, zj + CORR);
(*result)[2] = new CBC_ResultPoint(xi - CORR, xj - CORR);
(*result)[3] = new CBC_ResultPoint(yi + CORR, yj - CORR);
return result;
- } else {
- CFX_PtrArray* result = new CFX_PtrArray;
- result->SetSize(4);
- (*result)[0] = new CBC_ResultPoint(ti + CORR, tj + CORR);
- (*result)[1] = new CBC_ResultPoint(zi + CORR, zj - CORR);
- (*result)[2] = new CBC_ResultPoint(xi - CORR, xj + CORR);
- (*result)[3] = new CBC_ResultPoint(yi - CORR, yj - CORR);
- return result;
}
+
+ (*result)[0] = new CBC_ResultPoint(ti + CORR, tj + CORR);
+ (*result)[1] = new CBC_ResultPoint(zi + CORR, zj - CORR);
+ (*result)[2] = new CBC_ResultPoint(xi - CORR, xj + CORR);
+ (*result)[3] = new CBC_ResultPoint(yi - CORR, yj - CORR);
+ return result;
}
+
FX_BOOL CBC_WhiteRectangleDetector::ContainsBlackPoint(int32_t a,
int32_t b,
int32_t fixed,
diff --git a/xfa/fxbarcode/common/BC_WhiteRectangleDetector.h b/xfa/fxbarcode/common/BC_WhiteRectangleDetector.h
index d713d0fa99..f3ac77a9c0 100644
--- a/xfa/fxbarcode/common/BC_WhiteRectangleDetector.h
+++ b/xfa/fxbarcode/common/BC_WhiteRectangleDetector.h
@@ -20,9 +20,10 @@ class CBC_WhiteRectangleDetector {
int32_t x,
int32_t y);
virtual ~CBC_WhiteRectangleDetector();
- CFX_PtrArray* Detect(int32_t& e);
virtual void Init(int32_t& e);
+ CFX_ArrayTemplate<CBC_ResultPoint*>* Detect(int32_t& e);
+
private:
int32_t Round(float d);
CBC_ResultPoint* GetBlackPointOnSegment(FX_FLOAT aX,
@@ -30,10 +31,11 @@ class CBC_WhiteRectangleDetector {
FX_FLOAT bX,
FX_FLOAT bY);
int32_t DistanceL2(FX_FLOAT aX, FX_FLOAT aY, FX_FLOAT bX, FX_FLOAT bY);
- CFX_PtrArray* CenterEdges(CBC_ResultPoint* y,
- CBC_ResultPoint* z,
- CBC_ResultPoint* x,
- CBC_ResultPoint* t);
+ CFX_ArrayTemplate<CBC_ResultPoint*>* CenterEdges(CBC_ResultPoint* y,
+ CBC_ResultPoint* z,
+ CBC_ResultPoint* x,
+ CBC_ResultPoint* t) const;
+
FX_BOOL ContainsBlackPoint(int32_t a,
int32_t b,
int32_t fixed,
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
index 00bd7811d8..40e5fa6625 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
@@ -79,10 +79,10 @@ void CBC_ReedSolomonEncoder::Encode(CFX_Int32Array* toEncode,
std::unique_ptr<CBC_ReedSolomonGF256Poly> infoTemp(
info.MultiplyByMonomial(ecBytes, 1, e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
- std::unique_ptr<CFX_PtrArray> temp(infoTemp->Divide(generator, e));
+ std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> temp(
+ infoTemp->Divide(generator, e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
- CBC_ReedSolomonGF256Poly* remainder =
- (CBC_ReedSolomonGF256Poly*)(temp->operator[](1));
+ CBC_ReedSolomonGF256Poly* remainder = (*temp)[1];
CFX_Int32Array* coefficients = remainder->GetCoefficients();
int32_t numZeroCoefficients = ecBytes - coefficients->GetSize();
for (int32_t i = 0; i < numZeroCoefficients; i++) {
@@ -93,7 +93,7 @@ void CBC_ReedSolomonEncoder::Encode(CFX_Int32Array* toEncode,
coefficients->operator[](y);
}
for (int32_t k = 0; k < temp->GetSize(); k++) {
- delete (CBC_ReedSolomonGF256Poly*)(*temp)[k];
+ delete (*temp)[k];
}
}
CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() {
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
index ff91c9ddc3..81abd56370 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
@@ -58,13 +58,11 @@ void CBC_ReedSolomonDecoder::Decode(CFX_Int32Array* received,
std::unique_ptr<CBC_ReedSolomonGF256Poly> temp(
m_field->BuildMonomial(twoS, 1, e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
- std::unique_ptr<CFX_PtrArray> sigmaOmega(
+ std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> sigmaOmega(
RunEuclideanAlgorithm(temp.get(), &syndrome, twoS, e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
- std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma(
- (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[0]);
- std::unique_ptr<CBC_ReedSolomonGF256Poly> omega(
- (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[1]);
+ std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma((*sigmaOmega)[0]);
+ std::unique_ptr<CBC_ReedSolomonGF256Poly> omega((*sigmaOmega)[1]);
std::unique_ptr<CFX_Int32Array> errorLocations(
FindErrorLocations(sigma.get(), e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
@@ -83,28 +81,29 @@ void CBC_ReedSolomonDecoder::Decode(CFX_Int32Array* received,
(*received)[position], (*errorMagnitudes)[k]);
}
}
-CFX_PtrArray* CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(
- CBC_ReedSolomonGF256Poly* a,
- CBC_ReedSolomonGF256Poly* b,
- int32_t R,
- int32_t& e) {
+
+CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>*
+CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(CBC_ReedSolomonGF256Poly* a,
+ CBC_ReedSolomonGF256Poly* b,
+ int32_t R,
+ int32_t& e) {
if (a->GetDegree() < b->GetDegree()) {
CBC_ReedSolomonGF256Poly* temp = a;
a = b;
b = temp;
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> rLast(a->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> r(b->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> sLast(m_field->GetOne()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> s(m_field->GetZero()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> tLast(m_field->GetZero()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> t(m_field->GetOne()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
while (r->GetDegree() >= R / 2) {
std::unique_ptr<CBC_ReedSolomonGF256Poly> rLastLast = std::move(rLast);
std::unique_ptr<CBC_ReedSolomonGF256Poly> sLastLast = std::move(sLast);
@@ -114,53 +113,54 @@ CFX_PtrArray* CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(
tLast = std::move(t);
if (rLast->IsZero()) {
e = BCExceptionR_I_1IsZero;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
r.reset(rLastLast->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> q(m_field->GetZero()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
int32_t denominatorLeadingTerm = rLast->GetCoefficients(rLast->GetDegree());
int32_t dltInverse = m_field->Inverse(denominatorLeadingTerm, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
while (r->GetDegree() >= rLast->GetDegree() && !(r->IsZero())) {
int32_t degreeDiff = r->GetDegree() - rLast->GetDegree();
int32_t scale =
m_field->Multiply(r->GetCoefficients(r->GetDegree()), dltInverse);
std::unique_ptr<CBC_ReedSolomonGF256Poly> build(
m_field->BuildMonomial(degreeDiff, scale, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
q.reset(q->AddOrSubtract(build.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> multiply(
rLast->MultiplyByMonomial(degreeDiff, scale, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
r.reset(r->AddOrSubtract(multiply.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> temp1(
q->Multiply(sLast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
s.reset(temp1->AddOrSubtract(sLastLast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> temp5(
q->Multiply(tLast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
t.reset(temp5->AddOrSubtract(tLastlast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
int32_t sigmaTildeAtZero = t->GetCoefficients(0);
if (sigmaTildeAtZero == 0) {
e = BCExceptionIsZero;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
int32_t inverse = m_field->Inverse(sigmaTildeAtZero, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma(t->Multiply(inverse, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> omega(r->Multiply(inverse, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CFX_PtrArray* temp = new CFX_PtrArray;
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
+ CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* temp =
+ new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>();
temp->Add(sigma.release());
temp->Add(omega.release());
return temp;
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h
index f44f92072e..d42af6a27a 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h
@@ -13,23 +13,25 @@ class CBC_ReedSolomonGF256;
class CBC_ReedSolomonGF256Poly;
class CBC_ReedSolomonDecoder {
- private:
- CBC_ReedSolomonGF256* m_field;
-
public:
CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256* field);
virtual ~CBC_ReedSolomonDecoder();
+
void Decode(CFX_Int32Array* received, int32_t twoS, int32_t& e);
- CFX_PtrArray* RunEuclideanAlgorithm(CBC_ReedSolomonGF256Poly* a,
- CBC_ReedSolomonGF256Poly* b,
- int32_t R,
- int32_t& e);
+ CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* RunEuclideanAlgorithm(
+ CBC_ReedSolomonGF256Poly* a,
+ CBC_ReedSolomonGF256Poly* b,
+ int32_t R,
+ int32_t& e);
CFX_Int32Array* FindErrorLocations(CBC_ReedSolomonGF256Poly* errorLocator,
int32_t& e);
CFX_Int32Array* FindErrorMagnitudes(CBC_ReedSolomonGF256Poly* errorEvaluator,
CFX_Int32Array* errorLocations,
FX_BOOL dataMatrix,
int32_t& e);
+
+ private:
+ CBC_ReedSolomonGF256* m_field;
};
#endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONDECODER_H_
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
index ee22390df6..b3c4326ed6 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
@@ -213,21 +213,23 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial(
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
return temp;
}
-CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other,
- int32_t& e) {
+
+CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide(
+ CBC_ReedSolomonGF256Poly* other,
+ int32_t& e) {
if (other->IsZero()) {
e = BCExceptionDivideByZero;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> quotient(
m_field->GetZero()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> remainder(Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
int32_t inverseDenominatorLeadingTeam =
m_field->Inverse(denominatorLeadingTerm, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) {
int32_t degreeDifference = remainder->GetDegree() - other->GetDegree();
int32_t scale =
@@ -235,20 +237,22 @@ CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other,
inverseDenominatorLeadingTeam);
std::unique_ptr<CBC_ReedSolomonGF256Poly> term(
other->MultiplyByMonomial(degreeDifference, scale, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> iteratorQuotient(
m_field->BuildMonomial(degreeDifference, scale, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
quotient.reset(quotient->AddOrSubtract(iteratorQuotient.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
remainder.reset(remainder->AddOrSubtract(term.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
- CFX_PtrArray* tempPtrA = new CFX_PtrArray;
+ CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* tempPtrA =
+ new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>();
tempPtrA->Add(quotient.release());
tempPtrA->Add(remainder.release());
return tempPtrA;
}
+
CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() {
m_coefficients.RemoveAll();
}
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
index aa549efe60..03580c2350 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
@@ -11,11 +11,15 @@
class CBC_ReedSolomonGF256;
-class CBC_ReedSolomonGF256Poly {
+class CBC_ReedSolomonGF256Poly final {
public:
CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, int32_t coefficients);
CBC_ReedSolomonGF256Poly();
- virtual ~CBC_ReedSolomonGF256Poly();
+ ~CBC_ReedSolomonGF256Poly();
+ void Init(CBC_ReedSolomonGF256* field,
+ CFX_Int32Array* coefficients,
+ int32_t& e);
+
int32_t GetCoefficients(int32_t degree);
CFX_Int32Array* GetCoefficients();
int32_t GetDegree();
@@ -29,11 +33,11 @@ class CBC_ReedSolomonGF256Poly {
CBC_ReedSolomonGF256Poly* MultiplyByMonomial(int32_t degree,
int32_t coefficient,
int32_t& e);
- CFX_PtrArray* Divide(CBC_ReedSolomonGF256Poly* other, int32_t& e);
+ CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* Divide(
+ CBC_ReedSolomonGF256Poly* other,
+ int32_t& e);
+
CBC_ReedSolomonGF256Poly* Clone(int32_t& e);
- virtual void Init(CBC_ReedSolomonGF256* field,
- CFX_Int32Array* coefficients,
- int32_t& e);
private:
CBC_ReedSolomonGF256* m_field;
diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp
index c70f8b1fc9..6b7680d1a8 100644
--- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp
+++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp
@@ -33,10 +33,10 @@ CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords,
m_codewords.Copy(*codewords);
m_numDataCodewords = numDataCodewords;
}
-CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks(
- CFX_ByteArray* rawCodewords,
- CBC_DataMatrixVersion* version,
- int32_t& e) {
+CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>*
+CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords,
+ CBC_DataMatrixVersion* version,
+ int32_t& e) {
ECBlocks* ecBlocks = version->GetECBlocks();
int32_t totalBlocks = 0;
const CFX_ArrayTemplate<ECB*>& ecBlockArray = ecBlocks->GetECBlocks();
@@ -44,7 +44,8 @@ CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks(
for (i = 0; i < ecBlockArray.GetSize(); i++) {
totalBlocks += ecBlockArray[i]->GetCount();
}
- std::unique_ptr<CFX_PtrArray> result(new CFX_PtrArray());
+ std::unique_ptr<CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>> result(
+ new CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>());
result->SetSize(totalBlocks);
int32_t numResultBlocks = 0;
int32_t j;
@@ -59,8 +60,7 @@ CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks(
codewords.SetSize(0);
}
}
- int32_t longerBlocksTotalCodewords =
- ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
+ int32_t longerBlocksTotalCodewords = (*result)[0]->GetCodewords()->GetSize();
int32_t longerBlocksNumDataCodewords =
longerBlocksTotalCodewords - ecBlocks->GetECCodewords();
int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1;
@@ -69,10 +69,8 @@ CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks(
int32_t j;
for (j = 0; j < numResultBlocks; j++) {
if (rawCodewordsOffset < rawCodewords->GetSize()) {
- ((CBC_DataMatrixDataBlock*)(*result)[j])
- ->GetCodewords()
- ->
- operator[](i) = (*rawCodewords)[rawCodewordsOffset++];
+ (*result)[j]->GetCodewords()->operator[](i) =
+ (*rawCodewords)[rawCodewordsOffset++];
}
}
}
@@ -80,24 +78,19 @@ CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks(
int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks;
for (j = 0; j < numLongerBlocks; j++) {
if (rawCodewordsOffset < rawCodewords->GetSize()) {
- ((CBC_DataMatrixDataBlock*)(*result)[j])
- ->GetCodewords()
- ->
- operator[](longerBlocksNumDataCodewords - 1) =
+ (*result)[j]->GetCodewords()->operator[](longerBlocksNumDataCodewords -
+ 1) =
(*rawCodewords)[rawCodewordsOffset++];
}
}
- int32_t max =
- ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
+ int32_t max = (*result)[0]->GetCodewords()->GetSize();
for (i = longerBlocksNumDataCodewords; i < max; i++) {
int32_t j;
for (j = 0; j < numResultBlocks; j++) {
int32_t iOffset = specialVersion && j > 7 ? i - 1 : i;
if (rawCodewordsOffset < rawCodewords->GetSize()) {
- ((CBC_DataMatrixDataBlock*)(*result)[j])
- ->GetCodewords()
- ->
- operator[](iOffset) = (*rawCodewords)[rawCodewordsOffset++];
+ (*result)[j]->GetCodewords()->operator[](iOffset) =
+ (*rawCodewords)[rawCodewordsOffset++];
}
}
}
diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h
index 039255268f..782e5ed319 100644
--- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h
+++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h
@@ -11,22 +11,23 @@
class CBC_DataMatrixVersion;
-class CBC_DataMatrixDataBlock {
+class CBC_DataMatrixDataBlock final {
public:
- virtual ~CBC_DataMatrixDataBlock();
+ ~CBC_DataMatrixDataBlock();
int32_t GetNumDataCodewords();
CFX_ByteArray* GetCodewords();
- static CFX_PtrArray* GetDataBlocks(CFX_ByteArray* rawCodewords,
- CBC_DataMatrixVersion* version,
- int32_t& e);
+ static CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>* GetDataBlocks(
+ CFX_ByteArray* rawCodewords,
+ CBC_DataMatrixVersion* version,
+ int32_t& e);
private:
+ CBC_DataMatrixDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords);
+
int32_t m_numDataCodewords;
CFX_ByteArray m_codewords;
-
- CBC_DataMatrixDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords);
};
#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDATABLOCK_H_
diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp
index 3f765aa8f9..4276066444 100644
--- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp
+++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp
@@ -42,40 +42,37 @@ void CBC_DataMatrixDecoder::Init() {
CBC_DataMatrixDecoder::~CBC_DataMatrixDecoder() {
delete m_rsDecoder;
}
+
CBC_CommonDecoderResult* CBC_DataMatrixDecoder::Decode(
CBC_CommonBitMatrix* bits,
int32_t& e) {
CBC_DataMatrixBitMatrixParser parser;
parser.Init(bits, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
CBC_DataMatrixVersion* version = parser.GetVersion();
std::unique_ptr<CFX_ByteArray> codewords(parser.ReadCodewords(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CFX_PtrArray* dataBlocks =
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
+ CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>* dataBlocks =
CBC_DataMatrixDataBlock::GetDataBlocks(codewords.get(), version, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
int32_t dataBlocksCount = dataBlocks->GetSize();
int32_t totalBytes = 0;
int32_t i, j;
for (i = 0; i < dataBlocksCount; i++) {
- totalBytes +=
- ((CBC_DataMatrixDataBlock*)(*dataBlocks)[i])->GetNumDataCodewords();
+ totalBytes += (*dataBlocks)[i]->GetNumDataCodewords();
}
CFX_ByteArray resultBytes;
resultBytes.SetSize(totalBytes);
for (j = 0; j < dataBlocksCount; j++) {
- CFX_ByteArray* codewordBytes =
- ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])->GetCodewords();
- int32_t numDataCodewords =
- ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])->GetNumDataCodewords();
+ CFX_ByteArray* codewordBytes = (*dataBlocks)[j]->GetCodewords();
+ int32_t numDataCodewords = (*dataBlocks)[j]->GetNumDataCodewords();
CorrectErrors(*codewordBytes, numDataCodewords, e);
if (e != BCExceptionNO) {
for (int32_t i = 0; i < dataBlocks->GetSize(); i++) {
- delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i];
+ delete (*dataBlocks)[i];
}
delete dataBlocks;
- dataBlocks = NULL;
- return NULL;
+ return nullptr;
}
int32_t i;
for (i = 0; i < numDataCodewords; i++) {
@@ -83,15 +80,15 @@ CBC_CommonDecoderResult* CBC_DataMatrixDecoder::Decode(
}
}
for (i = 0; i < (dataBlocks->GetSize()); i++) {
- delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i];
+ delete (*dataBlocks)[i];
}
delete dataBlocks;
- dataBlocks = NULL;
CBC_CommonDecoderResult* resultR =
CBC_DataMatrixDecodedBitStreamParser::Decode(resultBytes, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
return resultR;
}
+
void CBC_DataMatrixDecoder::CorrectErrors(CFX_ByteArray& codewordBytes,
int32_t numDataCodewords,
int32_t& e) {
diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp
index fd410097cc..9fd1bbc4a0 100644
--- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp
+++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp
@@ -35,7 +35,7 @@
const int32_t CBC_DataMatrixDetector::INTEGERS[5] = {0, 1, 2, 3, 4};
CBC_DataMatrixDetector::CBC_DataMatrixDetector(CBC_CommonBitMatrix* image)
- : m_image(image), m_rectangleDetector(NULL) {}
+ : m_image(image), m_rectangleDetector(nullptr) {}
void CBC_DataMatrixDetector::Init(int32_t& e) {
m_rectangleDetector = new CBC_WhiteRectangleDetector(m_image);
m_rectangleDetector->Init(e);
@@ -44,42 +44,44 @@ void CBC_DataMatrixDetector::Init(int32_t& e) {
CBC_DataMatrixDetector::~CBC_DataMatrixDetector() {
delete m_rectangleDetector;
}
-inline FX_BOOL ResultPointsAndTransitionsComparator(void* a, void* b) {
- return ((CBC_ResultPointsAndTransitions*)b)->GetTransitions() >
- ((CBC_ResultPointsAndTransitions*)a)->GetTransitions();
-}
+
CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
- CFX_PtrArray* cornerPoints = m_rectangleDetector->Detect(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_ResultPoint* pointA = (CBC_ResultPoint*)(*cornerPoints)[0];
- CBC_ResultPoint* pointB = (CBC_ResultPoint*)(*cornerPoints)[1];
- CBC_ResultPoint* pointC = (CBC_ResultPoint*)(*cornerPoints)[2];
- CBC_ResultPoint* pointD = (CBC_ResultPoint*)(*cornerPoints)[3];
+ CFX_ArrayTemplate<CBC_ResultPoint*>* cornerPoints =
+ m_rectangleDetector->Detect(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
+ CBC_ResultPoint* pointA = (*cornerPoints)[0];
+ CBC_ResultPoint* pointB = (*cornerPoints)[1];
+ CBC_ResultPoint* pointC = (*cornerPoints)[2];
+ CBC_ResultPoint* pointD = (*cornerPoints)[3];
delete cornerPoints;
- cornerPoints = NULL;
- CFX_PtrArray transitions;
+
+ CFX_ArrayTemplate<CBC_ResultPointsAndTransitions*> transitions;
transitions.Add(TransitionsBetween(pointA, pointB));
transitions.Add(TransitionsBetween(pointA, pointC));
transitions.Add(TransitionsBetween(pointB, pointD));
transitions.Add(TransitionsBetween(pointC, pointD));
- BC_FX_PtrArray_Sort(transitions, &ResultPointsAndTransitionsComparator);
- delete ((CBC_ResultPointsAndTransitions*)transitions[2]);
- delete ((CBC_ResultPointsAndTransitions*)transitions[3]);
- CBC_ResultPointsAndTransitions* lSideOne =
- (CBC_ResultPointsAndTransitions*)transitions[0];
- CBC_ResultPointsAndTransitions* lSideTwo =
- (CBC_ResultPointsAndTransitions*)transitions[1];
+ std::sort(transitions.GetData(),
+ transitions.GetData() + transitions.GetSize(),
+ [](const CBC_ResultPointsAndTransitions* a,
+ const CBC_ResultPointsAndTransitions* b) {
+ return a->GetTransitions() < b->GetTransitions();
+ });
+ delete transitions[2];
+ delete transitions[3];
+
+ CBC_ResultPointsAndTransitions* lSideOne = transitions[0];
+ CBC_ResultPointsAndTransitions* lSideTwo = transitions[1];
CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> pointCount;
Increment(pointCount, lSideOne->GetFrom());
Increment(pointCount, lSideOne->GetTo());
Increment(pointCount, lSideTwo->GetFrom());
Increment(pointCount, lSideTwo->GetTo());
- delete ((CBC_ResultPointsAndTransitions*)transitions[1]);
- delete ((CBC_ResultPointsAndTransitions*)transitions[0]);
+ delete transitions[1];
+ delete transitions[0];
transitions.RemoveAll();
- CBC_ResultPoint* maybeTopLeft = NULL;
- CBC_ResultPoint* bottomLeft = NULL;
- CBC_ResultPoint* maybeBottomRight = NULL;
+ CBC_ResultPoint* maybeTopLeft = nullptr;
+ CBC_ResultPoint* bottomLeft = nullptr;
+ CBC_ResultPoint* maybeBottomRight = nullptr;
FX_POSITION itBegin = pointCount.GetStartPosition();
while (itBegin) {
CBC_ResultPoint* key = 0;
@@ -88,31 +90,31 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
if (value == 2) {
bottomLeft = key;
} else {
- if (maybeBottomRight == NULL) {
- maybeBottomRight = key;
- } else {
+ if (maybeBottomRight) {
maybeTopLeft = key;
+ } else {
+ maybeBottomRight = key;
}
}
}
- if (maybeTopLeft == NULL || bottomLeft == NULL || maybeBottomRight == NULL) {
+ if (!maybeTopLeft || !bottomLeft || !maybeBottomRight) {
delete pointA;
delete pointB;
delete pointC;
delete pointD;
e = BCExceptionNotFound;
- return NULL;
+ return nullptr;
}
- CFX_PtrArray corners;
+ CFX_ArrayTemplate<CBC_ResultPoint*> corners;
corners.SetSize(3);
corners[0] = maybeTopLeft;
corners[1] = bottomLeft;
corners[2] = maybeBottomRight;
OrderBestPatterns(&corners);
- CBC_ResultPoint* bottomRight = (CBC_ResultPoint*)corners[0];
- bottomLeft = (CBC_ResultPoint*)corners[1];
- CBC_ResultPoint* topLeft = (CBC_ResultPoint*)corners[2];
- CBC_ResultPoint* topRight = NULL;
+ CBC_ResultPoint* bottomRight = corners[0];
+ bottomLeft = corners[1];
+ CBC_ResultPoint* topLeft = corners[2];
+ CBC_ResultPoint* topRight = nullptr;
int32_t value;
if (!pointCount.Lookup(pointA, value)) {
topRight = pointA;
@@ -144,11 +146,11 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
correctedTopRight.reset(
CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight,
dimensionTop, dimensionRight));
- if (correctedTopRight.get() == NULL) {
+ if (!correctedTopRight.get()) {
correctedTopRight.reset(topRight);
} else {
delete topRight;
- topRight = NULL;
+ topRight = nullptr;
}
dimensionTop = std::unique_ptr<CBC_ResultPointsAndTransitions>(
TransitionsBetween(topLeft, correctedTopRight.get()))
@@ -166,16 +168,16 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight,
correctedTopRight.get(), dimensionTop, dimensionRight,
e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
} else {
int32_t dimension = std::min(dimensionRight, dimensionTop);
correctedTopRight.reset(
CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension));
- if (correctedTopRight.get() == NULL) {
+ if (!correctedTopRight.get()) {
correctedTopRight.reset(topRight);
} else {
delete topRight;
- topRight = NULL;
+ topRight = nullptr;
}
int32_t dimensionCorrected =
std::max(std::unique_ptr<CBC_ResultPointsAndTransitions>(
@@ -191,7 +193,7 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight,
correctedTopRight.get(), dimensionCorrected,
dimensionCorrected, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
CFX_PtrArray* result = new CFX_PtrArray;
result->SetSize(4);
@@ -224,7 +226,7 @@ CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular(
if (IsValid(c2.get())) {
return c2.release();
}
- return NULL;
+ return nullptr;
} else if (!IsValid(c2.get())) {
return c1.release();
}
@@ -271,7 +273,7 @@ CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRight(
if (IsValid(c2.get())) {
return c2.release();
}
- return NULL;
+ return nullptr;
} else if (!IsValid(c2.get())) {
return c1.release();
}
@@ -328,7 +330,7 @@ CBC_CommonBitMatrix* CBC_DataMatrixDetector::SampleGrid(
topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(),
bottomRight->GetX(), bottomRight->GetY(), bottomLeft->GetX(),
bottomLeft->GetY(), e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
return cbm;
}
CBC_ResultPointsAndTransitions* CBC_DataMatrixDetector::TransitionsBetween(
@@ -371,26 +373,24 @@ CBC_ResultPointsAndTransitions* CBC_DataMatrixDetector::TransitionsBetween(
}
return new CBC_ResultPointsAndTransitions(from, to, transitions);
}
-void CBC_DataMatrixDetector::OrderBestPatterns(CFX_PtrArray* patterns) {
- FX_FLOAT abDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0],
- (CBC_ResultPoint*)(*patterns)[1]);
- FX_FLOAT bcDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[1],
- (CBC_ResultPoint*)(*patterns)[2]);
- FX_FLOAT acDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0],
- (CBC_ResultPoint*)(*patterns)[2]);
+void CBC_DataMatrixDetector::OrderBestPatterns(
+ CFX_ArrayTemplate<CBC_ResultPoint*>* patterns) {
+ FX_FLOAT abDistance = (FX_FLOAT)Distance((*patterns)[0], (*patterns)[1]);
+ FX_FLOAT bcDistance = (FX_FLOAT)Distance((*patterns)[1], (*patterns)[2]);
+ FX_FLOAT acDistance = (FX_FLOAT)Distance((*patterns)[0], (*patterns)[2]);
CBC_ResultPoint *topLeft, *topRight, *bottomLeft;
if (bcDistance >= abDistance && bcDistance >= acDistance) {
- topLeft = (CBC_ResultPoint*)(*patterns)[0];
- topRight = (CBC_ResultPoint*)(*patterns)[1];
- bottomLeft = (CBC_ResultPoint*)(*patterns)[2];
+ topLeft = (*patterns)[0];
+ topRight = (*patterns)[1];
+ bottomLeft = (*patterns)[2];
} else if (acDistance >= bcDistance && acDistance >= abDistance) {
- topLeft = (CBC_ResultPoint*)(*patterns)[1];
- topRight = (CBC_ResultPoint*)(*patterns)[0];
- bottomLeft = (CBC_ResultPoint*)(*patterns)[2];
+ topLeft = (*patterns)[1];
+ topRight = (*patterns)[0];
+ bottomLeft = (*patterns)[2];
} else {
- topLeft = (CBC_ResultPoint*)(*patterns)[2];
- topRight = (CBC_ResultPoint*)(*patterns)[0];
- bottomLeft = (CBC_ResultPoint*)(*patterns)[1];
+ topLeft = (*patterns)[2];
+ topRight = (*patterns)[0];
+ bottomLeft = (*patterns)[1];
}
if ((bottomLeft->GetY() - topLeft->GetY()) *
(topRight->GetX() - topLeft->GetX()) <
diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h
index 589825fc38..8ef053b334 100644
--- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h
+++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h
@@ -10,11 +10,11 @@
#include "core/fxcrt/include/fx_basic.h"
class CBC_CommonBitMatrix;
-class CBC_WhiteRectangleDetector;
-class CBC_ResultPoint;
-class CBC_QRDetectorResult;
class CBC_DataMatrixDetector;
-class ResultPointsAndTransitions;
+class CBC_QRDetectorResult;
+class CBC_ResultPoint;
+class CBC_WhiteRectangleDetector;
+
class CBC_ResultPointsAndTransitions {
public:
CBC_ResultPointsAndTransitions(CBC_ResultPoint* from,
@@ -25,15 +25,16 @@ class CBC_ResultPointsAndTransitions {
m_transitions = transitions;
}
~CBC_ResultPointsAndTransitions() {}
- CBC_ResultPoint* GetFrom() { return m_from; }
- CBC_ResultPoint* GetTo() { return m_to; }
- int32_t GetTransitions() { return m_transitions; }
+ CBC_ResultPoint* GetFrom() const { return m_from; }
+ CBC_ResultPoint* GetTo() const { return m_to; }
+ int32_t GetTransitions() const { return m_transitions; }
private:
CBC_ResultPoint* m_from;
CBC_ResultPoint* m_to;
int32_t m_transitions;
};
+
class CBC_DataMatrixDetector {
public:
CBC_DataMatrixDetector(CBC_CommonBitMatrix* image);
@@ -65,7 +66,7 @@ class CBC_DataMatrixDetector {
void Increment(CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t>& table,
CBC_ResultPoint* key);
int32_t Round(FX_FLOAT d);
- void OrderBestPatterns(CFX_PtrArray* patterns);
+ void OrderBestPatterns(CFX_ArrayTemplate<CBC_ResultPoint*>* patterns);
virtual void Init(int32_t& e);
private:
diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp
index e441a29e44..d1dcc23e7b 100644
--- a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp
+++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp
@@ -25,14 +25,15 @@
#include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h"
#include "xfa/fxbarcode/utils.h"
-CFX_PtrArray* CBC_DataMatrixVersion::VERSIONS = NULL;
+CFX_ArrayTemplate<CBC_DataMatrixVersion*>* CBC_DataMatrixVersion::VERSIONS =
+ nullptr;
void CBC_DataMatrixVersion::Initialize() {
- VERSIONS = new CFX_PtrArray();
+ VERSIONS = new CFX_ArrayTemplate<CBC_DataMatrixVersion*>();
}
void CBC_DataMatrixVersion::Finalize() {
for (int32_t i = 0; i < VERSIONS->GetSize(); i++) {
- delete ((CBC_DataMatrixVersion*)(VERSIONS->GetAt(i)));
+ delete VERSIONS->GetAt(i);
}
VERSIONS->RemoveAll();
delete VERSIONS;
@@ -84,7 +85,7 @@ ECBlocks* CBC_DataMatrixVersion::GetECBlocks() {
}
void CBC_DataMatrixVersion::ReleaseAll() {
for (int32_t i = 0; i < VERSIONS->GetSize(); i++) {
- delete (CBC_DataMatrixVersion*)VERSIONS->GetAt(i);
+ delete VERSIONS->GetAt(i);
}
VERSIONS->RemoveAll();
}
@@ -94,7 +95,7 @@ CBC_DataMatrixVersion* CBC_DataMatrixVersion::GetVersionForDimensions(
int32_t& e) {
if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
e = BCExceptionNotFound;
- return NULL;
+ return nullptr;
}
if (VERSIONS->GetSize() == 0) {
VERSIONS->Add(new CBC_DataMatrixVersion(1, 10, 10, 8, 8,
@@ -161,13 +162,11 @@ CBC_DataMatrixVersion* CBC_DataMatrixVersion::GetVersionForDimensions(
}
int32_t numVersions = VERSIONS->GetSize();
for (int32_t i = 0; i < numVersions; ++i) {
- if (((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeRows ==
- numRows &&
- ((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeColumns ==
- numColumns) {
- return (CBC_DataMatrixVersion*)(*VERSIONS)[i];
+ if ((*VERSIONS)[i]->m_symbolSizeRows == numRows &&
+ (*VERSIONS)[i]->m_symbolSizeColumns == numColumns) {
+ return (*VERSIONS)[i];
}
}
e = BCExceptionNotFound;
- return NULL;
+ return nullptr;
}
diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h
index 74433cc4f2..b4585d20bc 100644
--- a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h
+++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h
@@ -80,7 +80,7 @@ class CBC_DataMatrixVersion {
int32_t m_dataRegionSizeColumns;
ECBlocks* m_ecBlocks;
int32_t m_totalCodewords;
- static CFX_PtrArray* VERSIONS;
+ static CFX_ArrayTemplate<CBC_DataMatrixVersion*>* VERSIONS;
};
#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXVERSION_H_
diff --git a/xfa/fxbarcode/utils.h b/xfa/fxbarcode/utils.h
index da10555e2e..ca2f3214c0 100644
--- a/xfa/fxbarcode/utils.h
+++ b/xfa/fxbarcode/utils.h
@@ -17,8 +17,6 @@ FX_BOOL BC_FX_ByteString_Replace(CFX_ByteString& dst,
FX_CHAR c);
void BC_FX_ByteString_Append(CFX_ByteString& dst, int32_t count, FX_CHAR c);
void BC_FX_ByteString_Append(CFX_ByteString& dst, const CFX_ByteArray& ba);
-typedef FX_BOOL (*BC_PtrArrayCompareCallback)(void* l, void* r);
-void BC_FX_PtrArray_Sort(CFX_PtrArray& src, BC_PtrArrayCompareCallback fun);
#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_)
#include <limits>