summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp')
-rw-r--r--xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp407
1 files changed, 205 insertions, 202 deletions
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
index d59f619e25..1ab42eb831 100644
--- a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
+++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
@@ -23,235 +23,238 @@
#include "../../barcode.h"
#include "BC_ReedSolomonGF256.h"
#include "BC_ReedSolomonGF256Poly.h"
-CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, int32_t coefficients)
-{
- if(field == NULL) {
- return;
- }
- m_field = field;
- m_coefficients.Add(coefficients);
+CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field,
+ int32_t coefficients) {
+ if (field == NULL) {
+ return;
+ }
+ m_field = field;
+ m_coefficients.Add(coefficients);
}
-CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly()
-{
- m_field = NULL;
+CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() {
+ m_field = NULL;
}
-void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, CFX_Int32Array* coefficients, int32_t &e)
-{
- if(coefficients == NULL || coefficients->GetSize() == 0) {
- e = BCExceptionCoefficientsSizeIsNull;
- BC_EXCEPTION_CHECK_ReturnVoid(e);
+void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field,
+ CFX_Int32Array* coefficients,
+ int32_t& e) {
+ if (coefficients == NULL || coefficients->GetSize() == 0) {
+ e = BCExceptionCoefficientsSizeIsNull;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ m_field = field;
+ int32_t coefficientsLength = coefficients->GetSize();
+ if ((coefficientsLength > 1 && (*coefficients)[0] == 0)) {
+ int32_t firstNonZero = 1;
+ while ((firstNonZero < coefficientsLength) &&
+ ((*coefficients)[firstNonZero] == 0)) {
+ firstNonZero++;
}
- m_field = field;
- int32_t coefficientsLength = coefficients->GetSize();
- if((coefficientsLength > 1 && (*coefficients)[0] == 0)) {
- int32_t firstNonZero = 1;
- while((firstNonZero < coefficientsLength) && ((*coefficients)[firstNonZero] == 0)) {
- firstNonZero++;
- }
- if(firstNonZero == coefficientsLength) {
- m_coefficients.Copy( *(m_field->GetZero()->GetCoefficients()));
- } else {
- m_coefficients.SetSize(coefficientsLength - firstNonZero);
- for(int32_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) {
- m_coefficients[j] = coefficients->operator [](i);
- }
- }
+ if (firstNonZero == coefficientsLength) {
+ m_coefficients.Copy(*(m_field->GetZero()->GetCoefficients()));
} else {
- m_coefficients.Copy(*coefficients);
+ m_coefficients.SetSize(coefficientsLength - firstNonZero);
+ for (int32_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) {
+ m_coefficients[j] = coefficients->operator[](i);
+ }
}
+ } else {
+ m_coefficients.Copy(*coefficients);
+ }
}
-CFX_Int32Array* CBC_ReedSolomonGF256Poly::GetCoefficients()
-{
- return &m_coefficients;
+CFX_Int32Array* CBC_ReedSolomonGF256Poly::GetCoefficients() {
+ return &m_coefficients;
}
-int32_t CBC_ReedSolomonGF256Poly::GetDegree()
-{
- return m_coefficients.GetSize() - 1;
+int32_t CBC_ReedSolomonGF256Poly::GetDegree() {
+ return m_coefficients.GetSize() - 1;
}
-FX_BOOL CBC_ReedSolomonGF256Poly::IsZero()
-{
- return m_coefficients[0] == 0;
+FX_BOOL CBC_ReedSolomonGF256Poly::IsZero() {
+ return m_coefficients[0] == 0;
}
-int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree)
-{
- return m_coefficients[m_coefficients.GetSize() - 1 - degree];
+int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) {
+ return m_coefficients[m_coefficients.GetSize() - 1 - degree];
}
-int32_t CBC_ReedSolomonGF256Poly::EvaluateAt(int32_t a)
-{
- if(a == 0) {
- return GetCoefficients(0);
- }
- int32_t size = m_coefficients.GetSize();
- if(a == 1) {
- int32_t result = 0;
- for(int32_t i = 0; i < size; i++) {
- result = CBC_ReedSolomonGF256::AddOrSubtract(result, m_coefficients[i]);
- }
- return result;
- }
- int32_t result = m_coefficients[0];
- for(int32_t j = 1; j < size; j++) {
- result = CBC_ReedSolomonGF256::AddOrSubtract(
- m_field->Multiply(a, result),
- m_coefficients[j]);
+int32_t CBC_ReedSolomonGF256Poly::EvaluateAt(int32_t a) {
+ if (a == 0) {
+ return GetCoefficients(0);
+ }
+ int32_t size = m_coefficients.GetSize();
+ if (a == 1) {
+ int32_t result = 0;
+ for (int32_t i = 0; i < size; i++) {
+ result = CBC_ReedSolomonGF256::AddOrSubtract(result, m_coefficients[i]);
}
return result;
+ }
+ int32_t result = m_coefficients[0];
+ for (int32_t j = 1; j < size; j++) {
+ result = CBC_ReedSolomonGF256::AddOrSubtract(m_field->Multiply(a, result),
+ m_coefficients[j]);
+ }
+ return result;
}
-CBC_ReedSolomonGF256Poly *CBC_ReedSolomonGF256Poly::Clone(int32_t &e)
-{
- CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
- temp->Init(m_field, &m_coefficients, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return temp;
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Clone(int32_t& e) {
+ CBC_ReedSolomonGF256Poly* temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &m_coefficients, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
}
-CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract(CBC_ReedSolomonGF256Poly* other, int32_t &e)
-{
- if(IsZero()) {
- return other->Clone(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- }
- if(other->IsZero()) {
- return this->Clone(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- }
- CFX_Int32Array smallerCoefficients;
- smallerCoefficients.Copy(m_coefficients);
- CFX_Int32Array largerCoefficients;
- largerCoefficients.Copy( *(other->GetCoefficients()));
- if(smallerCoefficients.GetSize() > largerCoefficients.GetSize()) {
- CFX_Int32Array temp;
- temp.Copy(smallerCoefficients);
- smallerCoefficients.Copy(largerCoefficients);
- largerCoefficients.Copy(temp);
- }
- CFX_Int32Array sumDiff;
- sumDiff.SetSize(largerCoefficients.GetSize() );
- int32_t lengthDiff = largerCoefficients.GetSize() - smallerCoefficients.GetSize();
- for(int32_t i = 0; i < lengthDiff; i++) {
- sumDiff[i] = largerCoefficients[i];
- }
- for(int32_t j = lengthDiff; j < largerCoefficients.GetSize(); j++) {
- sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract(smallerCoefficients[j - lengthDiff],
- largerCoefficients[j]));
- }
- CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
- temp->Init(m_field, &sumDiff, e);
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract(
+ CBC_ReedSolomonGF256Poly* other,
+ int32_t& e) {
+ if (IsZero()) {
+ return other->Clone(e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return temp;
+ }
+ if (other->IsZero()) {
+ return this->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CFX_Int32Array smallerCoefficients;
+ smallerCoefficients.Copy(m_coefficients);
+ CFX_Int32Array largerCoefficients;
+ largerCoefficients.Copy(*(other->GetCoefficients()));
+ if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) {
+ CFX_Int32Array temp;
+ temp.Copy(smallerCoefficients);
+ smallerCoefficients.Copy(largerCoefficients);
+ largerCoefficients.Copy(temp);
+ }
+ CFX_Int32Array sumDiff;
+ sumDiff.SetSize(largerCoefficients.GetSize());
+ int32_t lengthDiff =
+ largerCoefficients.GetSize() - smallerCoefficients.GetSize();
+ for (int32_t i = 0; i < lengthDiff; i++) {
+ sumDiff[i] = largerCoefficients[i];
+ }
+ for (int32_t j = lengthDiff; j < largerCoefficients.GetSize(); j++) {
+ sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract(
+ smallerCoefficients[j - lengthDiff], largerCoefficients[j]));
+ }
+ CBC_ReedSolomonGF256Poly* temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &sumDiff, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
}
-CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(CBC_ReedSolomonGF256Poly* other, int32_t &e)
-{
- if(IsZero() || other->IsZero()) {
- CBC_ReedSolomonGF256Poly *temp = m_field->GetZero()->Clone(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return temp;
- }
- CFX_Int32Array aCoefficients ;
- aCoefficients.Copy(m_coefficients);
- int32_t aLength = m_coefficients.GetSize();
- CFX_Int32Array bCoefficients;
- bCoefficients.Copy(*(other->GetCoefficients()));
- int32_t bLength = other->GetCoefficients()->GetSize();
- CFX_Int32Array product;
- product.SetSize(aLength + bLength - 1);
- for(int32_t i = 0; i < aLength; i++) {
- int32_t aCoeff = m_coefficients[i];
- for(int32_t j = 0; j < bLength; j++) {
- product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract(
- product[i + j],
- m_field->Multiply(aCoeff, other->GetCoefficients()->operator [](j)));
- }
- }
- CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
- temp->Init(m_field, &product, e);
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(
+ CBC_ReedSolomonGF256Poly* other,
+ int32_t& e) {
+ if (IsZero() || other->IsZero()) {
+ CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
return temp;
-}
-CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, int32_t &e)
-{
- if(scalar == 0) {
- CBC_ReedSolomonGF256Poly *temp = m_field->GetZero()->Clone(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return temp;
- }
- if(scalar == 1) {
- return this->Clone(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CFX_Int32Array aCoefficients;
+ aCoefficients.Copy(m_coefficients);
+ int32_t aLength = m_coefficients.GetSize();
+ CFX_Int32Array bCoefficients;
+ bCoefficients.Copy(*(other->GetCoefficients()));
+ int32_t bLength = other->GetCoefficients()->GetSize();
+ CFX_Int32Array product;
+ product.SetSize(aLength + bLength - 1);
+ for (int32_t i = 0; i < aLength; i++) {
+ int32_t aCoeff = m_coefficients[i];
+ for (int32_t j = 0; j < bLength; j++) {
+ product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract(
+ product[i + j],
+ m_field->Multiply(aCoeff, other->GetCoefficients()->operator[](j)));
}
- int32_t size = m_coefficients.GetSize();
- CFX_Int32Array product;
- product.SetSize(size);
- for(int32_t i = 0; i < size; i++) {
- product[i] = m_field->Multiply(m_coefficients[i], scalar);
- }
- CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
- temp->Init(m_field, &product, e);
+ }
+ CBC_ReedSolomonGF256Poly* temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &product, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar,
+ int32_t& e) {
+ if (scalar == 0) {
+ CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
return temp;
+ }
+ if (scalar == 1) {
+ return this->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ int32_t size = m_coefficients.GetSize();
+ CFX_Int32Array product;
+ product.SetSize(size);
+ for (int32_t i = 0; i < size; i++) {
+ product[i] = m_field->Multiply(m_coefficients[i], scalar);
+ }
+ CBC_ReedSolomonGF256Poly* temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &product, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
}
-CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial(int32_t degree, int32_t coefficient, int32_t &e)
-{
- if(degree < 0) {
- e = BCExceptionDegreeIsNegative;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- }
- if(coefficient == 0) {
- CBC_ReedSolomonGF256Poly *temp = m_field->GetZero()->Clone(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return temp;
- }
- int32_t size = m_coefficients.GetSize();
- CFX_Int32Array product;
- product.SetSize(size + degree);
- for(int32_t i = 0; i < size; i++) {
- product[i] = (m_field->Multiply(m_coefficients[i], coefficient));
- }
- CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
- temp->Init(m_field, &product, e);
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial(
+ int32_t degree,
+ int32_t coefficient,
+ int32_t& e) {
+ if (degree < 0) {
+ e = BCExceptionDegreeIsNegative;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ if (coefficient == 0) {
+ CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
return temp;
+ }
+ int32_t size = m_coefficients.GetSize();
+ CFX_Int32Array product;
+ product.SetSize(size + degree);
+ for (int32_t i = 0; i < size; i++) {
+ product[i] = (m_field->Multiply(m_coefficients[i], coefficient));
+ }
+ CBC_ReedSolomonGF256Poly* temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &product, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
}
-CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly *other, int32_t &e)
-{
- if(other->IsZero()) {
- e = BCExceptionDivideByZero;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- }
- CBC_ReedSolomonGF256Poly* rsg1 = m_field->GetZero()->Clone(e);
+CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other,
+ int32_t& e) {
+ if (other->IsZero()) {
+ e = BCExceptionDivideByZero;
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CBC_ReedSolomonGF256Poly> quotient(rsg1);
- CBC_ReedSolomonGF256Poly* rsg2 = this->Clone(e);
+ }
+ CBC_ReedSolomonGF256Poly* rsg1 = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> quotient(rsg1);
+ CBC_ReedSolomonGF256Poly* rsg2 = this->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> remainder(rsg2);
+ int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
+ int32_t inverseDenominatorLeadingTeam =
+ m_field->Inverse(denominatorLeadingTerm, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ FX_BOOL bFirst = TRUE;
+ while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) {
+ int32_t degreeDifference = remainder->GetDegree() - other->GetDegree();
+ int32_t scale =
+ m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())),
+ inverseDenominatorLeadingTeam);
+ CBC_ReedSolomonGF256Poly* rsg3 =
+ other->MultiplyByMonomial(degreeDifference, scale, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CBC_ReedSolomonGF256Poly> remainder(rsg2);
- int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
- int32_t inverseDenominatorLeadingTeam = m_field->Inverse(denominatorLeadingTerm, e);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> term(rsg3);
+ CBC_ReedSolomonGF256Poly* rsg4 =
+ m_field->BuildMonomial(degreeDifference, scale, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- FX_BOOL bFirst = TRUE;
- while(remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) {
- int32_t degreeDifference = remainder->GetDegree() - other->GetDegree();
- int32_t scale = m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())),
- inverseDenominatorLeadingTeam);
- CBC_ReedSolomonGF256Poly* rsg3 = other->MultiplyByMonomial(degreeDifference, scale, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CBC_ReedSolomonGF256Poly> term(rsg3);
- CBC_ReedSolomonGF256Poly* rsg4 = m_field->BuildMonomial(degreeDifference, scale, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CBC_ReedSolomonGF256Poly> iteratorQuotient(rsg4);
- CBC_ReedSolomonGF256Poly* rsg5 = quotient->AddOrSubtract(iteratorQuotient.get(), e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsg5);
- quotient = temp;
- CBC_ReedSolomonGF256Poly* rsg6 = remainder->AddOrSubtract(term.get(), e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg6);
- remainder = temp1;
- }
- CFX_PtrArray* tempPtrA = FX_NEW CFX_PtrArray;
- tempPtrA->Add(quotient.release());
- tempPtrA->Add(remainder.release());
- return tempPtrA;
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> iteratorQuotient(rsg4);
+ CBC_ReedSolomonGF256Poly* rsg5 =
+ quotient->AddOrSubtract(iteratorQuotient.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsg5);
+ quotient = temp;
+ CBC_ReedSolomonGF256Poly* rsg6 = remainder->AddOrSubtract(term.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg6);
+ remainder = temp1;
+ }
+ CFX_PtrArray* tempPtrA = FX_NEW CFX_PtrArray;
+ tempPtrA->Add(quotient.release());
+ tempPtrA->Add(remainder.release());
+ return tempPtrA;
}
-CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly()
-{
- m_coefficients.RemoveAll();
+CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() {
+ m_coefficients.RemoveAll();
}