From 1b22880748c3f3b3740699ae4c953a33f65ad10f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 5 Apr 2017 18:42:22 -0700 Subject: 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 Reviewed-by: Tom Sepez --- fxbarcode/BC_TwoDimWriter.cpp | 15 +- fxbarcode/common/BC_CommonBitArray.cpp | 34 ----- fxbarcode/common/BC_CommonBitArray.h | 1 - fxbarcode/common/BC_CommonBitMatrix.cpp | 74 ++++----- fxbarcode/common/BC_CommonBitMatrix.h | 29 ++-- fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp | 103 ++++++------- fxbarcode/common/reedsolomon/BC_ReedSolomon.h | 13 +- .../common/reedsolomon/BC_ReedSolomonGF256.cpp | 15 +- fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h | 10 +- .../common/reedsolomon/BC_ReedSolomonGF256Poly.cpp | 169 ++++++++++----------- .../common/reedsolomon/BC_ReedSolomonGF256Poly.h | 40 +++-- fxbarcode/oned/BC_OneDimWriter.cpp | 10 +- fxbarcode/oned/BC_OnedCode128Writer.cpp | 2 +- fxbarcode/oned/BC_OnedCode39Writer.cpp | 11 +- fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 22 +-- fxbarcode/qrcode/BC_QRCoderVersion.cpp | 91 ++--------- fxbarcode/qrcode/BC_QRCoderVersion.h | 13 +- fxbarcode/utils.h | 51 ------- 18 files changed, 252 insertions(+), 451 deletions(-) (limited to 'fxbarcode') diff --git a/fxbarcode/BC_TwoDimWriter.cpp b/fxbarcode/BC_TwoDimWriter.cpp index 65d28a2090..8043244b2b 100644 --- a/fxbarcode/BC_TwoDimWriter.cpp +++ b/fxbarcode/BC_TwoDimWriter.cpp @@ -124,14 +124,8 @@ void CBC_TwoDimWriter::RenderResult(uint8_t* code, multiX = std::min(multiX, multiY); multiY = multiX; } - int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; - int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; - if (leftPadding < 0) { - leftPadding = 0; - } - if (topPadding < 0) { - topPadding = 0; - } + int32_t leftPadding = std::max((outputWidth - (inputWidth * multiX)) / 2, 0); + int32_t topPadding = std::max((outputHeight - (inputHeight * multiY)) / 2, 0); m_output = pdfium::MakeUnique(); m_output->Init(outputWidth, outputHeight); for (int32_t inputY = 0, outputY = topPadding; @@ -141,9 +135,10 @@ void CBC_TwoDimWriter::RenderResult(uint8_t* code, (inputX < inputWidth) && (outputX < outputWidth - multiX); inputX++, outputX += multiX) { if (code[inputX + inputY * inputWidth] == 1) { - m_output->SetRegion(outputX, outputY, multiX, multiY, e); - if (e != BCExceptionNO) + if (!m_output->SetRegion(outputX, outputY, multiX, multiY)) { + e = BCExceptionGeneric; return; + } } } } diff --git a/fxbarcode/common/BC_CommonBitArray.cpp b/fxbarcode/common/BC_CommonBitArray.cpp index 34cdb65174..10da9bef1b 100644 --- a/fxbarcode/common/BC_CommonBitArray.cpp +++ b/fxbarcode/common/BC_CommonBitArray.cpp @@ -76,40 +76,6 @@ void CBC_CommonBitArray::Clear() { value = 0; } -bool CBC_CommonBitArray::IsRange(size_t start, - size_t end, - bool value, - int32_t& e) { - if (end < start) { - e = BCExceptionEndLessThanStart; - return false; - } - if (end == start) { - return true; - } - end--; - int32_t firstInt = start >> 5; - int32_t lastInt = end >> 5; - int32_t i; - for (i = firstInt; i <= lastInt; i++) { - int32_t firstBit = i > firstInt ? 0 : start & 0x1F; - int32_t lastBit = i < lastInt ? 31 : end & 0x1F; - int32_t mask; - if (firstBit == 0 && lastBit == 31) { - mask = -1; - } else { - mask = 0; - for (int32_t j = firstBit; j <= lastBit; j++) { - mask |= 1 << j; - } - } - if ((m_bits[i] & mask) != (value ? mask : 0)) { - return false; - } - } - return true; -} - int32_t* CBC_CommonBitArray::GetBitArray() { return m_bits.data(); } diff --git a/fxbarcode/common/BC_CommonBitArray.h b/fxbarcode/common/BC_CommonBitArray.h index 504e3038f6..f3d0a5ed83 100644 --- a/fxbarcode/common/BC_CommonBitArray.h +++ b/fxbarcode/common/BC_CommonBitArray.h @@ -26,7 +26,6 @@ class CBC_CommonBitArray { void Set(size_t i); void Flip(size_t i); void SetBulk(size_t i, int32_t newBits); - bool IsRange(size_t start, size_t end, bool value, int32_t& e); void Reverse(); void Clear(); 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; -} diff --git a/fxbarcode/common/BC_CommonBitMatrix.h b/fxbarcode/common/BC_CommonBitMatrix.h index 2bb3f64843..744461903d 100644 --- a/fxbarcode/common/BC_CommonBitMatrix.h +++ b/fxbarcode/common/BC_CommonBitMatrix.h @@ -14,35 +14,30 @@ class CBC_CommonBitArray; class CBC_CommonBitMatrix { public: CBC_CommonBitMatrix(); - virtual ~CBC_CommonBitMatrix(); + ~CBC_CommonBitMatrix(); - virtual void Init(int32_t dimension); - virtual void Init(int32_t width, int32_t height); + void Init(int32_t dimension); + void Init(int32_t width, int32_t height); - bool Get(int32_t x, int32_t y); + bool Get(int32_t x, int32_t y) const; void Set(int32_t x, int32_t y); void Flip(int32_t x, int32_t y); void Clear(); - void SetRegion(int32_t left, - int32_t top, - int32_t width, - int32_t height, - int32_t& e); + bool SetRegion(int32_t left, int32_t top, int32_t width, int32_t height); CBC_CommonBitArray* GetRow(int32_t y, CBC_CommonBitArray* row); void SetRow(int32_t y, CBC_CommonBitArray* row); CBC_CommonBitArray* GetCol(int32_t y, CBC_CommonBitArray* row); void SetCol(int32_t y, CBC_CommonBitArray* col); - int32_t GetWidth(); - int32_t GetHeight(); - int32_t GetRowSize(); - int32_t GetDimension(int32_t& e); + int32_t GetWidth() const; + int32_t GetHeight() const; + int32_t GetRowSize() const; int32_t* GetBits(); private: - int32_t m_width; - int32_t m_height; - int32_t m_rowSize; - int32_t* m_bits; + int32_t m_width = 0; + int32_t m_height = 0; + int32_t m_rowSize = 0; + int32_t* m_bits = nullptr; }; #endif // FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_ diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp index bb33bbd0e9..ca65f72043 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp @@ -23,83 +23,78 @@ #include "fxbarcode/common/reedsolomon/BC_ReedSolomon.h" #include +#include #include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" #include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" +#include "third_party/base/ptr_util.h" -CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field) { - m_field = field; -} +CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field) + : m_field(field) {} + +CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() {} void CBC_ReedSolomonEncoder::Init() { - m_cachedGenerators.push_back(new CBC_ReedSolomonGF256Poly(m_field, 1)); + m_cachedGenerators.push_back( + pdfium::MakeUnique(m_field, 1)); } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(size_t degree, - int32_t& e) { +CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator( + size_t degree) { if (degree >= m_cachedGenerators.size()) { - CBC_ReedSolomonGF256Poly* lastGenerator = m_cachedGenerators.back(); + CBC_ReedSolomonGF256Poly* lastGenerator = m_cachedGenerators.back().get(); for (size_t d = m_cachedGenerators.size(); d <= degree; ++d) { std::vector temp = {1, m_field->Exp(d - 1)}; CBC_ReedSolomonGF256Poly temp_poly; - temp_poly.Init(m_field, &temp, e); - if (e != BCExceptionNO) + if (!temp_poly.Init(m_field, &temp)) return nullptr; - CBC_ReedSolomonGF256Poly* nextGenerator = - lastGenerator->Multiply(&temp_poly, e); - if (e != BCExceptionNO) + + auto nextGenerator = lastGenerator->Multiply(&temp_poly); + if (!nextGenerator) return nullptr; - m_cachedGenerators.push_back(nextGenerator); - lastGenerator = nextGenerator; + + lastGenerator = nextGenerator.get(); + m_cachedGenerators.push_back(std::move(nextGenerator)); } } - return m_cachedGenerators[degree]; + return m_cachedGenerators[degree].get(); } -void CBC_ReedSolomonEncoder::Encode(std::vector* toEncode, - size_t ecBytes, - int32_t& e) { - if (ecBytes == 0) { - e = BCExceptionNoCorrectionBytes; - return; - } - if (toEncode->size() <= ecBytes) { - e = BCExceptionNoDataBytesProvided; - return; - } - CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e); - if (e != BCExceptionNO) - return; +bool CBC_ReedSolomonEncoder::Encode(std::vector* toEncode, + size_t ecBytes) { + if (ecBytes == 0) + return false; + + if (toEncode->size() <= ecBytes) + return false; + + CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes); + if (!generator) + return false; + size_t dataBytes = toEncode->size() - ecBytes; std::vector infoCoefficients(dataBytes); - for (size_t x = 0; x < dataBytes; x++) { + for (size_t x = 0; x < dataBytes; x++) infoCoefficients[x] = (*toEncode)[x]; - } + CBC_ReedSolomonGF256Poly info; - info.Init(m_field, &infoCoefficients, e); - if (e != BCExceptionNO) - return; - std::unique_ptr infoTemp( - info.MultiplyByMonomial(ecBytes, 1, e)); - if (e != BCExceptionNO) - return; - std::unique_ptr> temp( - infoTemp->Divide(generator, e)); - if (e != BCExceptionNO) - return; - CBC_ReedSolomonGF256Poly* remainder = (*temp)[1]; - std::vector* coefficients = remainder->GetCoefficients(); + if (!info.Init(m_field, &infoCoefficients)) + return false; + + auto infoTemp = info.MultiplyByMonomial(ecBytes, 1); + if (!infoTemp) + return false; + + auto remainder = infoTemp->Divide(generator); + if (!remainder) + return false; + + const auto& coefficients = remainder->GetCoefficients(); size_t numZeroCoefficients = - ecBytes > coefficients->size() ? ecBytes - coefficients->size() : 0; + ecBytes > coefficients.size() ? ecBytes - coefficients.size() : 0; for (size_t i = 0; i < numZeroCoefficients; i++) (*toEncode)[dataBytes + i] = 0; - 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 (size_t i = 0; i < m_cachedGenerators.size(); i++) - delete m_cachedGenerators[i]; + for (size_t y = 0; y < coefficients.size(); y++) + (*toEncode)[dataBytes + numZeroCoefficients + y] = coefficients[y]; + return true; } diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomon.h b/fxbarcode/common/reedsolomon/BC_ReedSolomon.h index 42a1e002ca..68d4ee0624 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomon.h +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomon.h @@ -7,6 +7,7 @@ #ifndef FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ #define FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ +#include #include #include "core/fxcrt/fx_basic.h" @@ -17,16 +18,16 @@ class CBC_ReedSolomonGF256Poly; class CBC_ReedSolomonEncoder { public: explicit CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field); - virtual ~CBC_ReedSolomonEncoder(); + ~CBC_ReedSolomonEncoder(); - void Encode(std::vector* toEncode, size_t ecBytes, int32_t& e); - virtual void Init(); + void Init(); + bool Encode(std::vector* toEncode, size_t ecBytes); private: - CBC_ReedSolomonGF256Poly* BuildGenerator(size_t degree, int32_t& e); + CBC_ReedSolomonGF256Poly* BuildGenerator(size_t degree); - CBC_ReedSolomonGF256* m_field; - std::vector m_cachedGenerators; + CBC_ReedSolomonGF256* const m_field; + std::vector> m_cachedGenerators; }; #endif // FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp index b2af2a54b4..3f761054c4 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp @@ -74,7 +74,7 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() const { return m_one.get(); } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial( +std::unique_ptr CBC_ReedSolomonGF256::BuildMonomial( int32_t degree, int32_t coefficient, int32_t& e) { @@ -83,17 +83,18 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial( return nullptr; } if (coefficient == 0) { - CBC_ReedSolomonGF256Poly* temp = m_zero->Clone(e); - if (e != BCExceptionNO) - return nullptr; + auto temp = m_zero->Clone(); + if (!temp) + e = BCExceptionGeneric; return temp; } std::vector coefficients(degree + 1); coefficients[0] = coefficient; - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(this, &coefficients, e); - if (e != BCExceptionNO) + auto temp = pdfium::MakeUnique(); + if (!temp->Init(this, &coefficients)) { + e = BCExceptionGeneric; return nullptr; + } return temp; } diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h index d4b303c5ff..6d8225dfb0 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h @@ -17,22 +17,22 @@ class CBC_ReedSolomonGF256Poly; class CBC_ReedSolomonGF256 { public: explicit CBC_ReedSolomonGF256(int32_t primitive); - virtual ~CBC_ReedSolomonGF256(); + ~CBC_ReedSolomonGF256(); static void Initialize(); static void Finalize(); CBC_ReedSolomonGF256Poly* GetZero() const; CBC_ReedSolomonGF256Poly* GetOne() const; - CBC_ReedSolomonGF256Poly* BuildMonomial(int32_t degree, - int32_t coefficient, - int32_t& e); + std::unique_ptr BuildMonomial(int32_t degree, + int32_t coefficient, + int32_t& e); static int32_t AddOrSubtract(int32_t a, int32_t b); int32_t Exp(int32_t a); int32_t Log(int32_t a, int32_t& e); int32_t Inverse(int32_t a, int32_t& e); int32_t Multiply(int32_t a, int32_t b); - virtual void Init(); + void Init(); static CBC_ReedSolomonGF256* QRCodeField; static CBC_ReedSolomonGF256* DataMatrixField; diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp index a062589218..5c26188f53 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp @@ -26,6 +26,7 @@ #include #include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, @@ -41,13 +42,11 @@ CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() { m_field = nullptr; } -void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, - std::vector* coefficients, - int32_t& e) { - if (!coefficients || coefficients->empty()) { - e = BCExceptionCoefficientsSizeIsNull; - return; - } +bool CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, + const std::vector* coefficients) { + if (!coefficients || coefficients->empty()) + return false; + m_field = field; size_t coefficientsLength = coefficients->size(); if (coefficientsLength > 1 && coefficients->front() == 0) { @@ -57,7 +56,7 @@ void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, firstNonZero++; } if (firstNonZero == coefficientsLength) { - m_coefficients = *(m_field->GetZero()->GetCoefficients()); + m_coefficients = m_field->GetZero()->GetCoefficients(); } else { m_coefficients.resize(coefficientsLength - firstNonZero); for (size_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) @@ -66,28 +65,29 @@ void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, } else { m_coefficients = *coefficients; } + return true; } -std::vector* CBC_ReedSolomonGF256Poly::GetCoefficients() { - return &m_coefficients; +const std::vector& CBC_ReedSolomonGF256Poly::GetCoefficients() const { + return m_coefficients; } -int32_t CBC_ReedSolomonGF256Poly::GetDegree() { +int32_t CBC_ReedSolomonGF256Poly::GetDegree() const { return pdfium::CollectionSize(m_coefficients) - 1; } -bool CBC_ReedSolomonGF256Poly::IsZero() { +bool CBC_ReedSolomonGF256Poly::IsZero() const { return m_coefficients.front() == 0; } -int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) { +int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) const { return m_coefficients[m_coefficients.size() - 1 - degree]; } int32_t CBC_ReedSolomonGF256Poly::EvaluateAt(int32_t a) { - if (a == 0) { + if (a == 0) return GetCoefficients(0); - } + size_t size = m_coefficients.size(); if (a == 1) { int32_t result = 0; @@ -103,121 +103,114 @@ int32_t CBC_ReedSolomonGF256Poly::EvaluateAt(int32_t a) { return result; } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Clone(int32_t& e) { - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &m_coefficients, e); - if (e != BCExceptionNO) +std::unique_ptr CBC_ReedSolomonGF256Poly::Clone() + const { + auto temp = pdfium::MakeUnique(); + if (!temp->Init(m_field, &m_coefficients)) return nullptr; return temp; } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( - CBC_ReedSolomonGF256Poly* other, - int32_t& e) { + +std::unique_ptr +CBC_ReedSolomonGF256Poly::AddOrSubtract(const CBC_ReedSolomonGF256Poly* other) { if (IsZero()) - return other->Clone(e); + return other->Clone(); if (other->IsZero()) - return Clone(e); + return Clone(); std::vector smallerCoefficients = m_coefficients; - std::vector largerCoefficients = *(other->GetCoefficients()); - if (smallerCoefficients.size() > largerCoefficients.size()) { + std::vector largerCoefficients = other->GetCoefficients(); + if (smallerCoefficients.size() > largerCoefficients.size()) std::swap(smallerCoefficients, largerCoefficients); - } + std::vector sumDiff(largerCoefficients.size()); size_t lengthDiff = largerCoefficients.size() - smallerCoefficients.size(); - for (size_t i = 0; i < lengthDiff; i++) { + for (size_t i = 0; i < lengthDiff; i++) sumDiff[i] = largerCoefficients[i]; - } + for (size_t j = lengthDiff; j < largerCoefficients.size(); j++) { sumDiff[j] = CBC_ReedSolomonGF256::AddOrSubtract( smallerCoefficients[j - lengthDiff], largerCoefficients[j]); } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &sumDiff, e); - if (e != BCExceptionNO) + auto temp = pdfium::MakeUnique(); + if (!temp->Init(m_field, &sumDiff)) return nullptr; return temp; } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply( - CBC_ReedSolomonGF256Poly* other, - int32_t& e) { + +std::unique_ptr CBC_ReedSolomonGF256Poly::Multiply( + const CBC_ReedSolomonGF256Poly* other) { if (IsZero() || other->IsZero()) - return m_field->GetZero()->Clone(e); + return m_field->GetZero()->Clone(); - std::vector aCoefficients = m_coefficients; - std::vector bCoefficients = *(other->GetCoefficients()); + const std::vector& aCoefficients = m_coefficients; + const std::vector& bCoefficients = other->GetCoefficients(); size_t aLength = aCoefficients.size(); size_t bLength = bCoefficients.size(); std::vector product(aLength + bLength - 1); for (size_t i = 0; i < aLength; i++) { - int32_t aCoeff = m_coefficients[i]; + int32_t aCoeff = aCoefficients[i]; for (size_t j = 0; j < bLength; j++) { product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract( - product[i + j], - m_field->Multiply(aCoeff, (*other->GetCoefficients())[j])); + product[i + j], m_field->Multiply(aCoeff, bCoefficients[j])); } } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &product, e); - if (e != BCExceptionNO) + auto temp = pdfium::MakeUnique(); + if (!temp->Init(m_field, &product)) return nullptr; return temp; } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, - int32_t& e) { + +std::unique_ptr CBC_ReedSolomonGF256Poly::Multiply( + int32_t scalar) { if (scalar == 0) - return m_field->GetZero()->Clone(e); + return m_field->GetZero()->Clone(); if (scalar == 1) - return Clone(e); + return Clone(); size_t size = m_coefficients.size(); std::vector product(size); - for (size_t i = 0; i < size; i++) { + for (size_t i = 0; i < size; i++) product[i] = m_field->Multiply(m_coefficients[i], scalar); - } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &product, e); - if (e != BCExceptionNO) + + auto temp = pdfium::MakeUnique(); + if (!temp->Init(m_field, &product)) return nullptr; return temp; } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial( - int32_t degree, - int32_t coefficient, - int32_t& e) { - if (degree < 0) { - e = BCExceptionDegreeIsNegative; + +std::unique_ptr +CBC_ReedSolomonGF256Poly::MultiplyByMonomial(int32_t degree, + int32_t coefficient) const { + if (degree < 0) return nullptr; - } if (coefficient == 0) - return m_field->GetZero()->Clone(e); + return m_field->GetZero()->Clone(); size_t size = m_coefficients.size(); std::vector product(size + degree); - for (size_t i = 0; i < size; i++) { + for (size_t i = 0; i < size; i++) product[i] = m_field->Multiply(m_coefficients[i], coefficient); - } - CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); - temp->Init(m_field, &product, e); - if (e != BCExceptionNO) + + auto temp = pdfium::MakeUnique(); + if (!temp->Init(m_field, &product)) return nullptr; return temp; } -std::vector* CBC_ReedSolomonGF256Poly::Divide( - CBC_ReedSolomonGF256Poly* other, - int32_t& e) { - if (other->IsZero()) { - e = BCExceptionDivideByZero; +std::unique_ptr CBC_ReedSolomonGF256Poly::Divide( + const CBC_ReedSolomonGF256Poly* other) { + if (other->IsZero()) return nullptr; - } - std::unique_ptr quotient( - m_field->GetZero()->Clone(e)); - if (e != BCExceptionNO) + + auto quotient = m_field->GetZero()->Clone(); + if (!quotient) return nullptr; - std::unique_ptr remainder(Clone(e)); - if (e != BCExceptionNO) + auto remainder = Clone(); + if (!remainder) return nullptr; + + int e = BCExceptionNO; int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); int32_t inverseDenominatorLeadingTeam = m_field->Inverse(denominatorLeadingTerm, e); @@ -228,26 +221,20 @@ std::vector* CBC_ReedSolomonGF256Poly::Divide( int32_t scale = m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())), inverseDenominatorLeadingTeam); - std::unique_ptr term( - other->MultiplyByMonomial(degreeDifference, scale, e)); - if (e != BCExceptionNO) + auto term = other->MultiplyByMonomial(degreeDifference, scale); + if (!term) return nullptr; - std::unique_ptr iteratorQuotient( - m_field->BuildMonomial(degreeDifference, scale, e)); + auto iteratorQuotient = m_field->BuildMonomial(degreeDifference, scale, e); if (e != BCExceptionNO) return nullptr; - quotient.reset(quotient->AddOrSubtract(iteratorQuotient.get(), e)); - if (e != BCExceptionNO) + quotient = quotient->AddOrSubtract(iteratorQuotient.get()); + if (!quotient) return nullptr; - remainder.reset(remainder->AddOrSubtract(term.get(), e)); - if (e != BCExceptionNO) + remainder = remainder->AddOrSubtract(term.get()); + if (!remainder) return nullptr; } - std::vector* tempPtrA = - new std::vector(); - tempPtrA->push_back(quotient.release()); - tempPtrA->push_back(remainder.release()); - return tempPtrA; + return remainder; } CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() {} diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h index 284b531e81..ce8a572704 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h @@ -7,6 +7,7 @@ #ifndef FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ #define FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ +#include #include #include "core/fxcrt/fx_basic.h" @@ -18,28 +19,25 @@ class CBC_ReedSolomonGF256Poly final { CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, int32_t coefficients); CBC_ReedSolomonGF256Poly(); ~CBC_ReedSolomonGF256Poly(); - void Init(CBC_ReedSolomonGF256* field, - std::vector* coefficients, - int32_t& e); - - int32_t GetCoefficients(int32_t degree); - std::vector* GetCoefficients(); - int32_t GetDegree(); - bool IsZero(); + bool Init(CBC_ReedSolomonGF256* field, + const std::vector* coefficients); + + int32_t GetCoefficients(int32_t degree) const; + const std::vector& GetCoefficients() const; + int32_t GetDegree() const; + bool IsZero() const; int32_t EvaluateAt(int32_t a); - CBC_ReedSolomonGF256Poly* AddOrSubtract(CBC_ReedSolomonGF256Poly* other, - int32_t& e); - CBC_ReedSolomonGF256Poly* Multiply(CBC_ReedSolomonGF256Poly* other, - int32_t& e); - CBC_ReedSolomonGF256Poly* Multiply(int32_t scalar, int32_t& e); - CBC_ReedSolomonGF256Poly* MultiplyByMonomial(int32_t degree, - int32_t coefficient, - int32_t& e); - std::vector* Divide( - CBC_ReedSolomonGF256Poly* other, - int32_t& e); - - CBC_ReedSolomonGF256Poly* Clone(int32_t& e); + std::unique_ptr AddOrSubtract( + const CBC_ReedSolomonGF256Poly* other); + std::unique_ptr Multiply( + const CBC_ReedSolomonGF256Poly* other); + std::unique_ptr Multiply(int32_t scalar); + std::unique_ptr MultiplyByMonomial( + int32_t degree, + int32_t coefficient) const; + std::unique_ptr Divide( + const CBC_ReedSolomonGF256Poly* other); + std::unique_ptr Clone() const; private: CBC_ReedSolomonGF256* m_field; diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp index 95244ae614..f6b33f37a9 100644 --- a/fxbarcode/oned/BC_OneDimWriter.cpp +++ b/fxbarcode/oned/BC_OneDimWriter.cpp @@ -455,12 +455,16 @@ void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, break; } if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) { - m_output->SetRegion(outputX, 0, outputWidth - outputX, outputHeight, e); + if (!m_output->SetRegion(outputX, 0, outputWidth - outputX, + outputHeight)) { + e = BCExceptionGeneric; + } break; } - m_output->SetRegion(outputX, 0, m_multiple, outputHeight, e); - if (e != BCExceptionNO) + if (!m_output->SetRegion(outputX, 0, m_multiple, outputHeight)) { + e = BCExceptionGeneric; return; + } } outputX += m_multiple; } diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp index d4f05a3bc6..53f4d01449 100644 --- a/fxbarcode/oned/BC_OnedCode128Writer.cpp +++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp @@ -184,7 +184,7 @@ uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, int32_t& outLength, int32_t& e) { if (contents.GetLength() < 1 || contents.GetLength() > 80) { - e = BCExceptionContentsLengthShouldBetween1and80; + e = BCExceptionGeneric; return nullptr; } std::vector patterns; diff --git a/fxbarcode/oned/BC_OnedCode39Writer.cpp b/fxbarcode/oned/BC_OnedCode39Writer.cpp index d454985478..bcc64d83bd 100644 --- a/fxbarcode/oned/BC_OnedCode39Writer.cpp +++ b/fxbarcode/oned/BC_OnedCode39Writer.cpp @@ -158,7 +158,7 @@ char CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents, int32_t& e) { int32_t length = contents.GetLength(); if (length > 80) { - e = BCExceptionContentsLengthShouldBetween1and80; + e = BCExceptionGeneric; return '*'; } int32_t checksum = 0; @@ -167,16 +167,13 @@ char CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents, int32_t j = 0; for (; j < len; j++) { if (ALPHABET_STRING[j] == contents[i]) { - if (contents[i] != '*') { + if (contents[i] != '*') checksum += j; - break; - } else { - break; - } + break; } } if (j >= len) { - e = BCExceptionUnSupportedString; + e = BCExceptionGeneric; return '*'; } } diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp index d74063d3fe..0971caab51 100644 --- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp @@ -171,8 +171,8 @@ bool AppendLengthInfo(int32_t numLetters, CBC_QRCoderMode* mode, CBC_QRCoderBitVector* bits) { int32_t e = BCExceptionNO; - CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version, e); - if (e != BCExceptionNO) + CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version); + if (!qcv) return false; int32_t numBits = mode->GetCharacterCountBits(qcv, e); if (e != BCExceptionNO) @@ -214,8 +214,8 @@ void InitQRCode(int32_t numInputBytes, qrCode->SetMode(mode); for (int32_t versionNum = 1; versionNum <= kMaxVersion; versionNum++) { CBC_QRCoderVersion* version = - CBC_QRCoderVersion::GetVersionForNumber(versionNum, e); - if (e != BCExceptionNO) + CBC_QRCoderVersion::GetVersionForNumber(versionNum); + if (!version) return; int32_t numBytes = version->GetTotalCodeWords(); CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel); @@ -237,16 +237,14 @@ void InitQRCode(int32_t numInputBytes, std::unique_ptr GenerateECBytes( CBC_CommonByteArray* dataBytes, - int32_t numEcBytesInBlock, - int32_t& e) { + int32_t numEcBytesInBlock) { int32_t numDataBytes = dataBytes->Size(); std::vector toEncode(numDataBytes + numEcBytesInBlock); for (int32_t i = 0; i < numDataBytes; ++i) toEncode[i] = dataBytes->At(i); CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeField); encode.Init(); - encode.Encode(&toEncode, numEcBytesInBlock, e); - if (e != BCExceptionNO) + if (!encode.Encode(&toEncode, numEcBytesInBlock)) return nullptr; auto ecBytes = pdfium::MakeUnique(numEcBytesInBlock); for (int32_t i = 0; i < numEcBytesInBlock; ++i) @@ -543,10 +541,12 @@ void InterleaveWithECBytes(CBC_QRCoderBitVector* bits, numEcBytesInBlosk); auto dataBytes = pdfium::MakeUnique(); dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock); - std::unique_ptr ecBytes( - GenerateECBytes(dataBytes.get(), numEcBytesInBlosk, e)); - if (e != BCExceptionNO) + std::unique_ptr ecBytes = + GenerateECBytes(dataBytes.get(), numEcBytesInBlosk); + if (!ecBytes) { + e = BCExceptionGeneric; return; + } maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size()); maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size()); blocks[i].SetData(std::move(dataBytes), std::move(ecBytes)); diff --git a/fxbarcode/qrcode/BC_QRCoderVersion.cpp b/fxbarcode/qrcode/BC_QRCoderVersion.cpp index f0b708dfc3..67ca42804c 100644 --- a/fxbarcode/qrcode/BC_QRCoderVersion.cpp +++ b/fxbarcode/qrcode/BC_QRCoderVersion.cpp @@ -28,25 +28,6 @@ #include "fxbarcode/qrcode/BC_QRCoderVersion.h" #include "fxbarcode/utils.h" -namespace { - -const uint8_t BITS_SET_IN_HALF_BYTE[] = {0, 1, 1, 2, 1, 2, 2, 3, - 1, 2, 2, 3, 2, 3, 3, 4}; - -int32_t NumBitsDiffering(int32_t a, int32_t b) { - a ^= b; - return BITS_SET_IN_HALF_BYTE[a & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 4) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 8) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 12) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 16) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 20) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 24) & 0x0F] + - BITS_SET_IN_HALF_BYTE[(a >> 28) & 0x0F]; -} - -} // namespace - const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = { 0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, 0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, @@ -367,57 +348,16 @@ CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel( CBC_QRCoderErrorCorrectionLevel* ecLevel) { return m_ecBlocksArray[ecLevel->Ordinal()]; } -CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension( - int32_t dimension, - int32_t& e) { - if ((dimension % 4) != 1) { - e = BCExceptionRead; - return nullptr; - } - CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e); - if (e != BCExceptionNO) - return nullptr; - return qcv; -} -CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation( - int32_t versionBits, - int32_t& e) { - int32_t bestDifference = INT_MAX; - int32_t bestVersion = 0; - for (int32_t i = 0; i < 34; i++) { - int32_t targetVersion = VERSION_DECODE_INFO[i]; - if (targetVersion == versionBits) { - CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e); - if (e != BCExceptionNO) - return nullptr; - return qcv; - } - int32_t bitsDifference = NumBitsDiffering(versionBits, targetVersion); - if (bitsDifference < bestDifference) { - bestVersion = i + 7; - bestDifference = bitsDifference; - } - } - if (bestDifference <= 3) { - CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e); - if (e != BCExceptionNO) - return nullptr; - return qcv; - } - return nullptr; -} + CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) { int32_t dimension = GetDimensionForVersion(); CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix(); bitMatrix->Init(dimension); - bitMatrix->SetRegion(0, 0, 9, 9, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(0, 0, 9, 9)) return nullptr; - bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(dimension - 8, 0, 8, 9)) return nullptr; - bitMatrix->SetRegion(0, dimension - 8, 9, 8, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(0, dimension - 8, 9, 8)) return nullptr; size_t max = m_alignmentPatternCenters.size(); for (size_t x = 0; x < max; x++) { @@ -426,30 +366,25 @@ CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) { if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) { continue; } - bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5)) return nullptr; } } - bitMatrix->SetRegion(6, 9, 1, dimension - 17, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(6, 9, 1, dimension - 17)) return nullptr; - bitMatrix->SetRegion(9, 6, dimension - 17, 1, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(9, 6, dimension - 17, 1)) return nullptr; if (m_versionNumber > 6) { - bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(dimension - 11, 0, 3, 6)) return nullptr; - bitMatrix->SetRegion(0, dimension - 11, 6, 3, e); - if (e != BCExceptionNO) + if (!bitMatrix->SetRegion(0, dimension - 11, 6, 3)) return nullptr; } return bitMatrix; } + CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber( - int32_t versionNumber, - int32_t& e) { + int32_t versionNumber) { if (VERSION->empty()) { VERSION->push_back(new CBC_QRCoderVersion( 1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)), @@ -780,10 +715,8 @@ CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber( new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15), new CBC_QRCoderECB(61, 16)))); } - if (versionNumber < 1 || versionNumber > 40) { - e = BCExceptionIllegalArgument; + if (versionNumber < 1 || versionNumber > 40) return nullptr; - } return (*VERSION)[versionNumber - 1]; } diff --git a/fxbarcode/qrcode/BC_QRCoderVersion.h b/fxbarcode/qrcode/BC_QRCoderVersion.h index 78ded0d30c..b6dad2299d 100644 --- a/fxbarcode/qrcode/BC_QRCoderVersion.h +++ b/fxbarcode/qrcode/BC_QRCoderVersion.h @@ -17,10 +17,13 @@ class CBC_QRCoderErrorCorrectionLevel; class CBC_QRCoderVersion { public: - virtual ~CBC_QRCoderVersion(); + ~CBC_QRCoderVersion(); static void Initialize(); static void Finalize(); + static CBC_QRCoderVersion* GetVersionForNumber(int32_t versionNumber); + static void Destroy(); + int32_t GetVersionNumber(); int32_t GetTotalCodeWords(); int32_t GetDimensionForVersion(); @@ -28,14 +31,6 @@ class CBC_QRCoderVersion { std::vector* GetAlignmentPatternCenters(); CBC_QRCoderECBlocks* GetECBlocksForLevel( CBC_QRCoderErrorCorrectionLevel* ecLevel); - static CBC_QRCoderVersion* GetVersionForNumber(int32_t versionNumber, - int32_t& e); - static CBC_QRCoderVersion* GetProvisionalVersionForDimension( - int32_t dimension, - int32_t& e); - static CBC_QRCoderVersion* DecodeVersionInformation(int32_t versionBits, - int32_t& e); - static void Destroy(); private: CBC_QRCoderVersion(); diff --git a/fxbarcode/utils.h b/fxbarcode/utils.h index df84091e9f..442e327784 100644 --- a/fxbarcode/utils.h +++ b/fxbarcode/utils.h @@ -59,63 +59,24 @@ enum BCFORMAT { #define BCFORMAT_ECLEVEL_H 3 #include #define BCExceptionNO 0 -#define BCExceptionNotFound 1 -#define BCExceptionEndLessThanStart 2 -#define BCExceptionUnknownDecoder 3 -#define BCExceptionRotateNotSupported 4 #define BCExceptionHeightAndWidthMustBeAtLeast1 5 -#define BCExceptionRegionMustFitInsideMatrix 6 -#define BCExceptionCanNotCallGetDimensionOnNonSquareMatrix 7 #define BCExceptionFormatException 8 -#define BCExceptionIllegalArgumentMustMatchVersionSize 9 -#define BCExceptionChecksumException 10 -#define BCExceptionIllegalArgumentInvalidFirstDigit 11 -#define BCExceptionIllegalArgumentInvalidSecondDigit 12 -#define BCExceptionRuntimeDecodingInvalidISO_IEC 13 -#define BCExceptionRuntimeDecodingInvalidAlphanumeric 14 -#define BCExceptionLeftAndTopMustBeNonnegative 15 #define BCExceptionIllegalArgument 16 -#define BCExceptionBadECI 17 -#define BCExceptionUnSupportedBarcode 18 -#define BCExceptionUnSupportedString 19 #define BCExceptionDigitLengthMustBe8 20 -#define BCExceptionDataCheckException 21 -#define BCExceptionExtractNumberValueFromBitArray 22 -#define BCExceptionRead 23 -#define BCExceptionRequestedRowIsOutSizeTheImage 24 #define BCExceptionNoContents 26 #define BCExceptionUnSupportEclevel 27 -#define BCExceptionUnSupportMode 28 -#define BCExceptionReferenceMustBeBetween0And7 29 -#define BCExceptionBadErrorLocation 30 #define BCExceptionDegreeIsNegative 31 -#define BCExceptionDivideByZero 32 -#define BCExceptionCoefficientsSizeIsNull 33 -#define BCExceptionNoCorrectionBytes 34 -#define BCExceptionNoDataBytesProvided 35 -#define BCExceptionR_I_1IsZero 36 #define BCExceptionAIsZero 37 -#define BCExceptionIsZero 38 -#define BCExceptionDegreeNotMatchRoots 39 -#define BCExceptionContentsLengthShouldBetween1and80 40 #define BCExceptionOnlyEncodeCODE_128 41 #define BCExceptionOnlyEncodeCODE_39 42 #define BCExceptionOnlyEncodeEAN_13 43 #define BCExceptionOnlyEncodeEAN_8 44 -#define BCExceptionOnlyEncodeITF 45 #define BCExceptionDigitLengthShould13 46 -#define BCExceptionDigitLengthMustBe6or8or10or12or14or16or20or24or44 47 #define BCExceptionOnlyEncodeUPC_A 48 -#define BCExceptionDigitLengthShouldBe12 49 #define BCExceptionValueMustBeEither0or1 50 -#define BCExceptionReedsolomnDecodeException 51 #define BCExceptionBadIndexException 52 -#define BCExceptionBadValueException 53 -#define BCExceptionVersionMust1_40 56 -#define BCExceptionUnknown 57 #define BCExceptionNoSuchVersion 58 #define BCExceptionCannotFindBlockInfo 59 -#define BCExceptionDataTooBig 60 #define BCExceptionInvalidQRCode 61 #define BCExceptionDataTooMany 62 #define BCExceptionBitsNotEqualCacity 63 @@ -131,15 +92,8 @@ enum BCFORMAT { #define BCExceptionCharacterNotThisMode 75 #define BCExceptionBitsBytesNotMatch 76 #define BCExceptionInvalidateData 77 -#define BCExceptionLoadFile 78 -#define BCExceptionPDF417EncodeFail 79 #define BCExceptionFailToCreateBitmap 80 -#define BCExceptionLoadFontFail 81 #define BCExceptionOnlyEncodeCODEBAR 82 -#define BCExceptionCodabarShouldStartWithOneOfABCD 83 -#define BCExceptionCodabarShouldEndWithOneOfTNE 84 -#define BCExceptionCodabarEncodeCharsInvalid 85 -#define BCExceptionOnlyEncodeDATAMATRIX 86 #define BCExceptionCharactersOutsideISO88591Encoding 87 #define BCExceptionIllegalDataCodewords 88 #define BCExceptionCannotHandleThisNumberOfDataRegions 89 @@ -155,11 +109,6 @@ enum BCFORMAT { #define BCExceptionUnableToFitMessageInColumns 100 #define BCExceptionEncodedMessageContainsTooManyCodeWords 101 #define BCExceptionBitmapSizeError 102 -#define BCExceptionFormatInstance 102 -#define BCExceptionChecksumInstance 103 -#define BCExceptiontNotFoundInstance 104 -#define BCExceptionNotFoundInstance 105 -#define BCExceptionCannotMetadata 106 #define BCExceptionGeneric 107 #endif // FXBARCODE_UTILS_H_ -- cgit v1.2.3