summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/common/reedsolomon
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxbarcode/common/reedsolomon')
-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
5 files changed, 71 insertions, 61 deletions
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;