diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-28 12:06:45 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-28 19:22:50 +0000 |
commit | 8b6186f89002099d406508acecf4bccc4ef64c95 (patch) | |
tree | df104ee415cfa90a53a23b88f1f66c3c2fd8d84e /xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp | |
parent | b0baff546bdcd911c80007829d9af5f05d0c04b0 (diff) | |
download | pdfium-8b6186f89002099d406508acecf4bccc4ef64c95.tar.xz |
Remove CFX_ArrayTemplate from FX barcode code.
This is now the last usage in pdfium, types to be removed
in a follow-on CL.
Change-Id: I16f67eb3eb99f21bb231829168203be125129ad7
Reviewed-on: https://pdfium-review.googlesource.com/3247
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp')
-rw-r--r-- | xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp index 7698890366..82a729b067 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp @@ -30,18 +30,17 @@ CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field) { m_field = field; } + void CBC_ReedSolomonEncoder::Init() { - m_cachedGenerators.Add(new CBC_ReedSolomonGF256Poly(m_field, 1)); + m_cachedGenerators.push_back(new CBC_ReedSolomonGF256Poly(m_field, 1)); } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree, + +CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(size_t degree, int32_t& e) { - if (degree >= m_cachedGenerators.GetSize()) { - CBC_ReedSolomonGF256Poly* lastGenerator = - m_cachedGenerators[m_cachedGenerators.GetSize() - 1]; - for (int32_t d = m_cachedGenerators.GetSize(); d <= degree; d++) { - CFX_ArrayTemplate<int32_t> temp; - temp.Add(1); - temp.Add(m_field->Exp(d - 1)); + if (degree >= m_cachedGenerators.size()) { + CBC_ReedSolomonGF256Poly* lastGenerator = m_cachedGenerators.back(); + for (size_t d = m_cachedGenerators.size(); d <= degree; ++d) { + std::vector<int32_t> temp = {1, m_field->Exp(d - 1)}; CBC_ReedSolomonGF256Poly temp_poly; temp_poly.Init(m_field, &temp, e); if (e != BCExceptionNO) @@ -50,31 +49,31 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree, lastGenerator->Multiply(&temp_poly, e); if (e != BCExceptionNO) return nullptr; - m_cachedGenerators.Add(nextGenerator); + m_cachedGenerators.push_back(nextGenerator); lastGenerator = nextGenerator; } } return m_cachedGenerators[degree]; } -void CBC_ReedSolomonEncoder::Encode(CFX_ArrayTemplate<int32_t>* toEncode, - int32_t ecBytes, + +void CBC_ReedSolomonEncoder::Encode(std::vector<int32_t>* toEncode, + size_t ecBytes, int32_t& e) { if (ecBytes == 0) { e = BCExceptionNoCorrectionBytes; return; } - int32_t dataBytes = toEncode->GetSize() - ecBytes; - if (dataBytes <= 0) { + if (toEncode->size() <= ecBytes) { e = BCExceptionNoDataBytesProvided; return; } CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e); if (e != BCExceptionNO) return; - CFX_ArrayTemplate<int32_t> infoCoefficients; - infoCoefficients.SetSize(dataBytes); - for (int32_t x = 0; x < dataBytes; x++) { - infoCoefficients[x] = toEncode->operator[](x); + size_t dataBytes = toEncode->size() - ecBytes; + std::vector<int32_t> infoCoefficients(dataBytes); + for (size_t x = 0; x < dataBytes; x++) { + infoCoefficients[x] = (*toEncode)[x]; } CBC_ReedSolomonGF256Poly info; info.Init(m_field, &infoCoefficients, e); @@ -84,25 +83,23 @@ void CBC_ReedSolomonEncoder::Encode(CFX_ArrayTemplate<int32_t>* toEncode, info.MultiplyByMonomial(ecBytes, 1, e)); if (e != BCExceptionNO) return; - std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> temp( + std::unique_ptr<std::vector<CBC_ReedSolomonGF256Poly*>> temp( infoTemp->Divide(generator, e)); if (e != BCExceptionNO) return; CBC_ReedSolomonGF256Poly* remainder = (*temp)[1]; - CFX_ArrayTemplate<int32_t>* coefficients = remainder->GetCoefficients(); - int32_t numZeroCoefficients = ecBytes - coefficients->GetSize(); - for (int32_t i = 0; i < numZeroCoefficients; i++) { + std::vector<int32_t>* coefficients = remainder->GetCoefficients(); + size_t numZeroCoefficients = + ecBytes > coefficients->size() ? ecBytes - coefficients->size() : 0; + for (size_t i = 0; i < numZeroCoefficients; i++) (*toEncode)[dataBytes + i] = 0; - } - for (int32_t y = 0; y < coefficients->GetSize(); y++) { - (*toEncode)[dataBytes + numZeroCoefficients + y] = - coefficients->operator[](y); - } - for (int32_t k = 0; k < temp->GetSize(); k++) { + for (size_t y = 0; y < coefficients->size(); y++) + (*toEncode)[dataBytes + numZeroCoefficients + y] = (*coefficients)[y]; + for (size_t k = 0; k < temp->size(); k++) delete (*temp)[k]; - } } + CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() { - for (int32_t i = 0; i < m_cachedGenerators.GetSize(); i++) + for (size_t i = 0; i < m_cachedGenerators.size(); i++) delete m_cachedGenerators[i]; } |