diff options
author | tsepez <tsepez@chromium.org> | 2016-05-02 09:34:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-02 09:34:35 -0700 |
commit | 8f0d0da1b12e29133fb48a778603c03bf0056124 (patch) | |
tree | eacee99738a238d488c74723fef01a6b5c2f485d /xfa | |
parent | a86d113be692153d7707da377d11d4f09cb12c9b (diff) | |
download | pdfium-8f0d0da1b12e29133fb48a778603c03bf0056124.tar.xz |
Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 10
Review-Url: https://codereview.chromium.org/1936733002
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fxbarcode/BC_ResultPoint.h | 5 | ||||
-rw-r--r-- | xfa/fxbarcode/pdf417/BC_PDF417Detector.cpp | 99 | ||||
-rw-r--r-- | xfa/fxbarcode/pdf417/BC_PDF417Detector.h | 30 | ||||
-rw-r--r-- | xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.cpp | 28 | ||||
-rw-r--r-- | xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h | 16 | ||||
-rw-r--r-- | xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.cpp | 101 | ||||
-rw-r--r-- | xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h | 9 | ||||
-rw-r--r-- | xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp | 2 | ||||
-rw-r--r-- | xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp | 14 | ||||
-rw-r--r-- | xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp | 22 | ||||
-rw-r--r-- | xfa/fxbarcode/qrcode/BC_QRDataBlock.h | 25 | ||||
-rw-r--r-- | xfa/fxbarcode/qrcode/BC_QRDataMask.cpp | 34 | ||||
-rw-r--r-- | xfa/fxbarcode/qrcode/BC_QRDataMask.h | 7 |
13 files changed, 198 insertions, 194 deletions
diff --git a/xfa/fxbarcode/BC_ResultPoint.h b/xfa/fxbarcode/BC_ResultPoint.h index 1497b311fc..e819fa5f6e 100644 --- a/xfa/fxbarcode/BC_ResultPoint.h +++ b/xfa/fxbarcode/BC_ResultPoint.h @@ -7,7 +7,7 @@ #ifndef XFA_FXBARCODE_BC_RESULTPOINT_H_ #define XFA_FXBARCODE_BC_RESULTPOINT_H_ -#include "core/fxcrt/include/fx_system.h" +#include "core/fxcrt/include/fx_basic.h" class CBC_ResultPoint { public: @@ -22,4 +22,7 @@ class CBC_ResultPoint { FX_FLOAT m_y; }; +using CBC_ResultPointArray = CFX_ArrayTemplate<CBC_ResultPoint*>; +using CBC_ResultPointArrayArray = CFX_ArrayTemplate<CBC_ResultPointArray*>; + #endif // XFA_FXBARCODE_BC_RESULTPOINT_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Detector.cpp b/xfa/fxbarcode/pdf417/BC_PDF417Detector.cpp index 345efd5648..6c217621b2 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417Detector.cpp +++ b/xfa/fxbarcode/pdf417/BC_PDF417Detector.cpp @@ -20,6 +20,8 @@ * limitations under the License. */ +#include <memory> + #include "xfa/fxbarcode/BC_BinaryBitmap.h" #include "xfa/fxbarcode/BC_ResultPoint.h" #include "xfa/fxbarcode/common/BC_CommonBitArray.h" @@ -49,13 +51,14 @@ int32_t CBC_Detector::BARCODE_MIN_HEIGHT = 10; CBC_Detector::CBC_Detector() {} CBC_Detector::~CBC_Detector() {} + CBC_PDF417DetectorResult* CBC_Detector::detect(CBC_BinaryBitmap* image, int32_t hints, FX_BOOL multiple, int32_t& e) { CBC_CommonBitMatrix* bitMatrix = image->GetBlackMatrix(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); - CFX_PtrArray* barcodeCoordinates = detect(multiple, bitMatrix); + CBC_ResultPointArrayArray* barcodeCoordinates = detect(multiple, bitMatrix); if (barcodeCoordinates->GetSize() == 0) { rotate180(bitMatrix); barcodeCoordinates = detect(multiple, bitMatrix); @@ -64,9 +67,7 @@ CBC_PDF417DetectorResult* CBC_Detector::detect(CBC_BinaryBitmap* image, e = BCExceptionUnSupportedBarcode; BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } - CBC_PDF417DetectorResult* detectorResult = - new CBC_PDF417DetectorResult(bitMatrix, barcodeCoordinates); - return detectorResult; + return new CBC_PDF417DetectorResult(bitMatrix, barcodeCoordinates); } void CBC_Detector::rotate180(CBC_CommonBitMatrix* bitMatrix) { int32_t width = bitMatrix->GetWidth(); @@ -104,14 +105,16 @@ CBC_CommonBitArray* CBC_Detector::mirror(CBC_CommonBitArray* input, } return array; } -CFX_PtrArray* CBC_Detector::detect(FX_BOOL multiple, - CBC_CommonBitMatrix* bitMatrix) { - CFX_PtrArray* barcodeCoordinates = new CFX_PtrArray; + +CBC_ResultPointArrayArray* CBC_Detector::detect( + FX_BOOL multiple, + CBC_CommonBitMatrix* bitMatrix) { + CBC_ResultPointArrayArray* barcodeCoordinates = new CBC_ResultPointArrayArray; int32_t row = 0; int32_t column = 0; FX_BOOL foundBarcodeInRow = FALSE; while (row < bitMatrix->GetHeight()) { - CFX_PtrArray* vertices = findVertices(bitMatrix, row, column); + CBC_ResultPointArray* vertices = findVertices(bitMatrix, row, column); if (vertices->GetAt(0) == NULL && vertices->GetAt(3) == NULL) { if (!foundBarcodeInRow) { delete vertices; @@ -120,13 +123,12 @@ CFX_PtrArray* CBC_Detector::detect(FX_BOOL multiple, foundBarcodeInRow = FALSE; column = 0; for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) { - CFX_PtrArray* barcodeCoordinate = - (CFX_PtrArray*)barcodeCoordinates->GetAt(i); + CBC_ResultPointArray* barcodeCoordinate = barcodeCoordinates->GetAt(i); if (barcodeCoordinate->GetAt(1)) { - row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(1))->GetY(); + row = row > barcodeCoordinate->GetAt(1)->GetY(); } if (barcodeCoordinate->GetAt(3)) { - row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(3))->GetY(); + row = row > barcodeCoordinate->GetAt(3)->GetY(); } } row += ROW_STEP; @@ -139,59 +141,58 @@ CFX_PtrArray* CBC_Detector::detect(FX_BOOL multiple, break; } if (vertices->GetAt(2)) { - column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetX(); - row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetY(); + column = (int32_t)vertices->GetAt(2)->GetX(); + row = (int32_t)vertices->GetAt(2)->GetY(); } else { - column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetX(); - row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetY(); + column = (int32_t)vertices->GetAt(4)->GetX(); + row = (int32_t)vertices->GetAt(4)->GetY(); } } return barcodeCoordinates; } -CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix, - int32_t startRow, - int32_t startColumn) { + +CBC_ResultPointArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix, + int32_t startRow, + int32_t startColumn) { int32_t height = matrix->GetHeight(); int32_t width = matrix->GetWidth(); - CFX_PtrArray* result = new CFX_PtrArray; + CBC_ResultPointArray* result = new CBC_ResultPointArray; result->SetSize(8); - CFX_PtrArray* startptr = findRowsWithPattern( - matrix, height, width, startRow, startColumn, START_PATTERN, - sizeof(START_PATTERN) / sizeof(START_PATTERN[0])); - copyToResult( - result, startptr, INDEXES_START_PATTERN, - sizeof(INDEXES_START_PATTERN) / sizeof(INDEXES_START_PATTERN[0])); - startptr->RemoveAll(); - delete startptr; + std::unique_ptr<CBC_ResultPointArray> startptr( + findRowsWithPattern(matrix, height, width, startRow, startColumn, + START_PATTERN, FX_ArraySize(START_PATTERN))); + copyToResult(result, startptr.get(), INDEXES_START_PATTERN, + FX_ArraySize(INDEXES_START_PATTERN)); if (result->GetAt(4)) { - startColumn = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetX(); - startRow = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetY(); + startColumn = (int32_t)result->GetAt(4)->GetX(); + startRow = (int32_t)result->GetAt(4)->GetY(); } - CFX_PtrArray* stopptr = findRowsWithPattern( - matrix, height, width, startRow, startColumn, STOP_PATTERN, - sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0])); - copyToResult(result, stopptr, INDEXES_STOP_PATTERN, - sizeof(INDEXES_STOP_PATTERN) / sizeof(INDEXES_STOP_PATTERN[0])); - stopptr->RemoveAll(); - delete stopptr; + std::unique_ptr<CBC_ResultPointArray> stopptr( + findRowsWithPattern(matrix, height, width, startRow, startColumn, + STOP_PATTERN, FX_ArraySize(STOP_PATTERN))); + copyToResult(result, stopptr.get(), INDEXES_STOP_PATTERN, + FX_ArraySize(INDEXES_STOP_PATTERN)); return result; } -void CBC_Detector::copyToResult(CFX_PtrArray* result, - CFX_PtrArray* tmpResult, + +void CBC_Detector::copyToResult(CBC_ResultPointArray* result, + CBC_ResultPointArray* tmpResult, int32_t* destinationIndexes, int32_t destinationLength) { for (int32_t i = 0; i < destinationLength; i++) { result->SetAt(destinationIndexes[i], tmpResult->GetAt(i)); } } -CFX_PtrArray* CBC_Detector::findRowsWithPattern(CBC_CommonBitMatrix* matrix, - int32_t height, - int32_t width, - int32_t startRow, - int32_t startColumn, - int32_t* pattern, - int32_t patternLength) { - CFX_PtrArray* result = new CFX_PtrArray; + +CBC_ResultPointArray* CBC_Detector::findRowsWithPattern( + CBC_CommonBitMatrix* matrix, + int32_t height, + int32_t width, + int32_t startRow, + int32_t startColumn, + int32_t* pattern, + int32_t patternLength) { + CBC_ResultPointArray* result = new CBC_ResultPointArray; result->SetSize(4); FX_BOOL found = FALSE; CFX_Int32Array counters; @@ -226,8 +227,8 @@ CFX_PtrArray* CBC_Detector::findRowsWithPattern(CBC_CommonBitMatrix* matrix, if (found) { int32_t skippedRowCount = 0; CFX_Int32Array previousRowLoc; - previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(0))->GetX()); - previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(1))->GetX()); + previousRowLoc.Add((int32_t)result->GetAt(0)->GetX()); + previousRowLoc.Add((int32_t)result->GetAt(1)->GetX()); for (; stopRow < height; stopRow++) { CFX_Int32Array* loc = findGuardPattern(matrix, previousRowLoc[0], stopRow, width, FALSE, diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Detector.h b/xfa/fxbarcode/pdf417/BC_PDF417Detector.h index dda039d6d5..c6fa6f6e7e 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417Detector.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417Detector.h @@ -7,7 +7,8 @@ #ifndef XFA_FXBARCODE_PDF417_BC_PDF417DETECTOR_H_ #define XFA_FXBARCODE_PDF417_BC_PDF417DETECTOR_H_ -class CBC_PDF417DetectorResult; +#include "xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h" + class CBC_BinaryBitmap; class CBC_CommonBitMatrix; class CBC_CommonBitArray; @@ -38,21 +39,22 @@ class CBC_Detector { static int32_t SKIPPED_ROW_COUNT_MAX; static int32_t ROW_STEP; static int32_t BARCODE_MIN_HEIGHT; - static CFX_PtrArray* detect(FX_BOOL multiple, CBC_CommonBitMatrix* bitMatrix); - static CFX_PtrArray* findVertices(CBC_CommonBitMatrix* matrix, - int32_t startRow, - int32_t startColumn); - static void copyToResult(CFX_PtrArray* result, - CFX_PtrArray* tmpResult, + static CBC_ResultPointArrayArray* detect(FX_BOOL multiple, + CBC_CommonBitMatrix* bitMatrix); + static CBC_ResultPointArray* findVertices(CBC_CommonBitMatrix* matrix, + int32_t startRow, + int32_t startColumn); + static void copyToResult(CBC_ResultPointArray* result, + CBC_ResultPointArray* tmpResult, int32_t* destinationIndexes, int32_t destinationLength); - static CFX_PtrArray* findRowsWithPattern(CBC_CommonBitMatrix* matrix, - int32_t height, - int32_t width, - int32_t startRow, - int32_t startColumn, - int32_t* pattern, - int32_t patternLength); + static CBC_ResultPointArray* findRowsWithPattern(CBC_CommonBitMatrix* matrix, + int32_t height, + int32_t width, + int32_t startRow, + int32_t startColumn, + int32_t* pattern, + int32_t patternLength); static CFX_Int32Array* findGuardPattern(CBC_CommonBitMatrix* matrix, int32_t column, int32_t row, diff --git a/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.cpp b/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.cpp index 557d50d951..4b68bdf678 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.cpp +++ b/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.cpp @@ -24,27 +24,25 @@ #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" #include "xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h" -CBC_PDF417DetectorResult::CBC_PDF417DetectorResult(CBC_CommonBitMatrix* bits, - CFX_PtrArray* points) { - m_bits = bits; - m_points = points; -} +CBC_PDF417DetectorResult::CBC_PDF417DetectorResult( + CBC_CommonBitMatrix* bits, + CBC_ResultPointArrayArray* points) + : m_bits(bits), m_points(points) {} + CBC_PDF417DetectorResult::~CBC_PDF417DetectorResult() { for (int32_t i = 0; i < m_points->GetSize(); i++) { - CFX_PtrArray* temp = (CFX_PtrArray*)m_points->GetAt(i); - for (int32_t j = 0; j < temp->GetSize(); j++) { - delete (CBC_ResultPoint*)temp->GetAt(j); - } - temp->RemoveAll(); + CBC_ResultPointArray* temp = m_points->GetAt(i); + for (int32_t j = 0; j < temp->GetSize(); j++) + delete temp->GetAt(j); + delete temp; } - m_points->RemoveAll(); - delete m_points; } -CBC_CommonBitMatrix* CBC_PDF417DetectorResult::getBits() { + +CBC_CommonBitMatrix* CBC_PDF417DetectorResult::getBits() const { return m_bits; } -CFX_PtrArray* CBC_PDF417DetectorResult::getPoints() { - return m_points; +CBC_ResultPointArrayArray* CBC_PDF417DetectorResult::getPoints() const { + return m_points.get(); } diff --git a/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h b/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h index 558111a28a..afb200a4ea 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417DetectorResult.h @@ -8,19 +8,23 @@ #define XFA_FXBARCODE_PDF417_BC_PDF417DETECTORRESULT_H_ #include "core/fxcrt/include/fx_basic.h" +#include "xfa/fxbarcode/BC_ResultPoint.h" class CBC_CommonBitMatrix; -class CBC_PDF417DetectorResult { +class CBC_PDF417DetectorResult final { public: - CBC_PDF417DetectorResult(CBC_CommonBitMatrix* bits, CFX_PtrArray* points); - virtual ~CBC_PDF417DetectorResult(); - CBC_CommonBitMatrix* getBits(); - CFX_PtrArray* getPoints(); + // Takes ownership of |points|. + CBC_PDF417DetectorResult(CBC_CommonBitMatrix* bits, + CBC_ResultPointArrayArray* points); + ~CBC_PDF417DetectorResult(); + + CBC_CommonBitMatrix* getBits() const; + CBC_ResultPointArrayArray* getPoints() const; private: CBC_CommonBitMatrix* m_bits; - CFX_PtrArray* m_points; + std::unique_ptr<CBC_ResultPointArrayArray> m_points; }; #endif // XFA_FXBARCODE_PDF417_BC_PDF417DETECTORRESULT_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.cpp b/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.cpp index d0bbe5ab0a..47fbcce5d0 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.cpp +++ b/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.cpp @@ -20,6 +20,8 @@ * limitations under the License. */ +#include <memory> + #include "xfa/fxbarcode/pdf417/BC_PDF417Common.h" #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" @@ -212,19 +214,20 @@ CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiply(int32_t scalar, BC_EXCEPTION_CHECK_ReturnValue(e, NULL); return modulusPoly; } + CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiplyByMonomial( int32_t degree, int32_t coefficient, int32_t& e) { if (degree < 0) { e = BCExceptionIllegalArgument; - return NULL; + return nullptr; } - CBC_PDF417ECModulusPoly* modulusPoly = NULL; + CBC_PDF417ECModulusPoly* modulusPoly = nullptr; if (coefficient == 0) { modulusPoly = new CBC_PDF417ECModulusPoly( m_field->getZero()->m_field, m_field->getZero()->m_coefficients, e); - BC_EXCEPTION_CHECK_ReturnValue(e, NULL); + BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); return modulusPoly; } int32_t size = m_coefficients.GetSize(); @@ -234,74 +237,62 @@ CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiplyByMonomial( product[i] = m_field->multiply(m_coefficients[i], coefficient); } modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e); - BC_EXCEPTION_CHECK_ReturnValue(e, NULL); + BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); return modulusPoly; } -CFX_PtrArray* CBC_PDF417ECModulusPoly::divide(CBC_PDF417ECModulusPoly* other, - int32_t& e) { + +CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>* CBC_PDF417ECModulusPoly::divide( + CBC_PDF417ECModulusPoly* other, + int32_t& e) { if (other->isZero()) { e = BCExceptionDivideByZero; - return NULL; - } - CBC_PDF417ECModulusPoly* quotient = new CBC_PDF417ECModulusPoly( - m_field->getZero()->m_field, m_field->getZero()->m_coefficients, e); - BC_EXCEPTION_CHECK_ReturnValue(e, NULL); - CBC_PDF417ECModulusPoly* remainder = - new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); - if (e != BCExceptionNO) { - delete quotient; - return NULL; + return nullptr; } + std::unique_ptr<CBC_PDF417ECModulusPoly> quotient(new CBC_PDF417ECModulusPoly( + m_field->getZero()->m_field, m_field->getZero()->m_coefficients, e)); + BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); + std::unique_ptr<CBC_PDF417ECModulusPoly> remainder( + new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e)); + if (e != BCExceptionNO) + return nullptr; + int32_t denominatorLeadingTerm = other->getCoefficient(other->getDegree()); int32_t inverseDenominatorLeadingTerm = m_field->inverse(denominatorLeadingTerm, e); - if (e != BCExceptionNO) { - delete quotient; - delete remainder; - return NULL; - } + if (e != BCExceptionNO) + return nullptr; + while (remainder->getDegree() >= other->getDegree() && !remainder->isZero()) { int32_t degreeDifference = remainder->getDegree() - other->getDegree(); int32_t scale = m_field->multiply(remainder->getCoefficient(remainder->getDegree()), inverseDenominatorLeadingTerm); - CBC_PDF417ECModulusPoly* term = - other->multiplyByMonomial(degreeDifference, scale, e); - if (e != BCExceptionNO) { - delete quotient; - delete remainder; - return NULL; - } - CBC_PDF417ECModulusPoly* iterationQuotient = - m_field->buildMonomial(degreeDifference, scale, e); - if (e != BCExceptionNO) { - delete quotient; - delete remainder; - delete term; - return NULL; - } - CBC_PDF417ECModulusPoly* temp = quotient; - quotient = temp->add(iterationQuotient, e); - delete iterationQuotient; - delete temp; - if (e != BCExceptionNO) { - delete remainder; - return NULL; - } - temp = remainder; - remainder = temp->subtract(term, e); - delete term; - delete temp; - if (e != BCExceptionNO) { - delete quotient; - return NULL; - } + std::unique_ptr<CBC_PDF417ECModulusPoly> term( + other->multiplyByMonomial(degreeDifference, scale, e)); + if (e != BCExceptionNO) + return nullptr; + + std::unique_ptr<CBC_PDF417ECModulusPoly> iterationQuotient( + m_field->buildMonomial(degreeDifference, scale, e)); + if (e != BCExceptionNO) + return nullptr; + + quotient.reset(quotient->add(iterationQuotient.get(), e)); + if (e != BCExceptionNO) + return nullptr; + + remainder.reset(remainder->subtract(term.get(), e)); + if (e != BCExceptionNO) + return nullptr; } - CFX_PtrArray* modulusPoly = new CFX_PtrArray; - modulusPoly->Add(quotient); - modulusPoly->Add(remainder); + + CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>* modulusPoly = + new CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>(); + modulusPoly->Add(quotient.release()); + modulusPoly->Add(remainder.release()); return modulusPoly; } + CFX_ByteString CBC_PDF417ECModulusPoly::toString() { CFX_ByteString result; for (int32_t degree = getDegree(); degree >= 0; degree--) { diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h b/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h index 2eff3ef1ce..173972be6e 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h @@ -8,12 +8,13 @@ #define XFA_FXBARCODE_PDF417_BC_PDF417ECMODULUSPOLY_H_ class CBC_PDF417ECModulusGF; -class CBC_PDF417ECModulusPoly { +class CBC_PDF417ECModulusPoly final { public: CBC_PDF417ECModulusPoly(CBC_PDF417ECModulusGF* field, CFX_Int32Array& coefficients, int32_t& e); - virtual ~CBC_PDF417ECModulusPoly(); + ~CBC_PDF417ECModulusPoly(); + CFX_Int32Array& getCoefficients(); CBC_PDF417ECModulusGF* getField(); int32_t getDegree(); @@ -28,7 +29,9 @@ class CBC_PDF417ECModulusPoly { CBC_PDF417ECModulusPoly* multiplyByMonomial(int32_t degree, int32_t coefficient, int32_t& e); - CFX_PtrArray* divide(CBC_PDF417ECModulusPoly* other, int32_t& e); + CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>* divide( + CBC_PDF417ECModulusPoly* other, + int32_t& e); CFX_ByteString toString(); private: diff --git a/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp b/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp index 53803588b5..3fe6783d38 100644 --- a/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp @@ -142,7 +142,7 @@ CFX_ByteArray* CBC_QRBitMatrixParser::ReadCodewords(int32_t& e) { BC_EXCEPTION_CHECK_ReturnValue(e, NULL); int32_t dimension = m_bitMatrix->GetDimension(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); - dataMask->UnmaskBitMatirx(m_bitMatrix, dimension); + dataMask->UnmaskBitMatrix(m_bitMatrix, dimension); std::unique_ptr<CBC_CommonBitMatrix> functionPattern( version->BuildFunctionPattern(e)); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp index 1966146805..360a69a0ec 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp @@ -74,26 +74,24 @@ CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(CBC_CommonBitMatrix* bits, CBC_QRCoderErrorCorrectionLevel* ecLevel = temp->GetErrorCorrectionLevel(); std::unique_ptr<CFX_ByteArray> codewords(parser.ReadCodewords(e)); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); - CFX_PtrArray* dataBlocks = + CFX_ArrayTemplate<CBC_QRDataBlock*>* dataBlocks = CBC_QRDataBlock::GetDataBlocks(codewords.get(), version, ecLevel, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); int32_t totalBytes = 0; for (int32_t i = 0; i < dataBlocks->GetSize(); i++) { - totalBytes += ((CBC_QRDataBlock*)((*dataBlocks)[i]))->GetNumDataCodewords(); + totalBytes += (*dataBlocks)[i]->GetNumDataCodewords(); } CFX_ByteArray resultBytes; for (int32_t j = 0; j < dataBlocks->GetSize(); j++) { - CBC_QRDataBlock* dataBlock = (CBC_QRDataBlock*)((*dataBlocks)[j]); + CBC_QRDataBlock* dataBlock = (*dataBlocks)[j]; CFX_ByteArray* codewordBytes = dataBlock->GetCodewords(); int32_t numDataCodewords = dataBlock->GetNumDataCodewords(); CorrectErrors(codewordBytes, numDataCodewords, e); if (e != BCExceptionNO) { for (int32_t k = 0; k < dataBlocks->GetSize(); k++) { - delete (CBC_QRDataBlock*)(*dataBlocks)[k]; + delete (*dataBlocks)[k]; } - dataBlocks->RemoveAll(); delete dataBlocks; - dataBlocks = NULL; return NULL; } for (int32_t i = 0; i < numDataCodewords; i++) { @@ -101,11 +99,9 @@ CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(CBC_CommonBitMatrix* bits, } } for (int32_t k = 0; k < dataBlocks->GetSize(); k++) { - delete (CBC_QRDataBlock*)(*dataBlocks)[k]; + delete (*dataBlocks)[k]; } - dataBlocks->RemoveAll(); delete dataBlocks; - dataBlocks = NULL; CBC_CommonDecoderResult* cdr = CBC_QRDecodedBitStreamParser::Decode( &resultBytes, version, ecLevel, byteModeDecode, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); diff --git a/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp b/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp index 721301cccc..31f0b1841d 100644 --- a/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp @@ -41,7 +41,7 @@ int32_t CBC_QRDataBlock::GetNumDataCodewords() { CFX_ByteArray* CBC_QRDataBlock::GetCodewords() { return m_codewords; } -CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks( +CFX_ArrayTemplate<CBC_QRDataBlock*>* CBC_QRDataBlock::GetDataBlocks( CFX_ByteArray* rawCodewords, CBC_QRCoderVersion* version, CBC_QRCoderErrorCorrectionLevel* ecLevel, @@ -57,7 +57,8 @@ CFX_PtrArray* CBC_QRDataBlock::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_QRDataBlock*>> result( + new CFX_ArrayTemplate<CBC_QRDataBlock*>()); result->SetSize(totalBlocks); int32_t numResultBlocks = 0; for (int32_t j = 0; j < ecBlockArray->GetSize(); j++) { @@ -72,12 +73,11 @@ CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks( new CBC_QRDataBlock(numDataCodewords, bytearray); } } - int32_t shorterBlocksTotalCodewords = - ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize(); + int32_t shorterBlocksTotalCodewords = (*result)[0]->m_codewords->GetSize(); int32_t longerBlocksStartAt = result->GetSize() - 1; while (longerBlocksStartAt >= 0) { - int32_t numCodewords = ((CBC_QRDataBlock*)(*result)[longerBlocksStartAt]) - ->m_codewords->GetSize(); + int32_t numCodewords = + (*result)[longerBlocksStartAt]->m_codewords->GetSize(); if (numCodewords == shorterBlocksTotalCodewords) { break; } @@ -90,20 +90,18 @@ CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks( int32_t x = 0; for (int32_t k = 0; k < shorterBlocksNumDataCodewords; k++) { for (x = 0; x < numResultBlocks; x++) { - (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[k] = - (*rawCodewords)[rawCodewordsOffset++]; + (*((*result)[x]->m_codewords))[k] = (*rawCodewords)[rawCodewordsOffset++]; } } for (x = longerBlocksStartAt; x < numResultBlocks; x++) { - (*(((CBC_QRDataBlock*)(*result)[x]) - ->m_codewords))[shorterBlocksNumDataCodewords] = + (*((*result)[x]->m_codewords))[shorterBlocksNumDataCodewords] = (*rawCodewords)[rawCodewordsOffset++]; } - int32_t max = ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize(); + int32_t max = (*result)[0]->m_codewords->GetSize(); for (i = shorterBlocksNumDataCodewords; i < max; i++) { for (int32_t y = 0; y < numResultBlocks; y++) { int32_t iOffset = y < longerBlocksStartAt ? i : i + 1; - (*(((CBC_QRDataBlock*)(*result)[y])->m_codewords))[iOffset] = + (*((*result)[y]->m_codewords))[iOffset] = (*rawCodewords)[rawCodewordsOffset++]; } } diff --git a/xfa/fxbarcode/qrcode/BC_QRDataBlock.h b/xfa/fxbarcode/qrcode/BC_QRDataBlock.h index 873904f7c6..014018dec0 100644 --- a/xfa/fxbarcode/qrcode/BC_QRDataBlock.h +++ b/xfa/fxbarcode/qrcode/BC_QRDataBlock.h @@ -9,22 +9,25 @@ #include "core/fxcrt/include/fx_basic.h" -class CBC_QRCoderVersion; class CBC_QRCoderErrorCorrectionLevel; -class CBC_QRDataBlock { - private: - int32_t m_numDataCodewords; - CFX_ByteArray* m_codewords; - CBC_QRDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords); +class CBC_QRCoderVersion; +class CBC_QRDataBlock final { public: - virtual ~CBC_QRDataBlock(); + ~CBC_QRDataBlock(); int32_t GetNumDataCodewords(); CFX_ByteArray* GetCodewords(); - static CFX_PtrArray* GetDataBlocks(CFX_ByteArray* rawCodewords, - CBC_QRCoderVersion* version, - CBC_QRCoderErrorCorrectionLevel* ecLevel, - int32_t& e); + static CFX_ArrayTemplate<CBC_QRDataBlock*>* GetDataBlocks( + CFX_ByteArray* rawCodewords, + CBC_QRCoderVersion* version, + CBC_QRCoderErrorCorrectionLevel* ecLevel, + int32_t& e); + + private: + CBC_QRDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords); + + int32_t m_numDataCodewords; + CFX_ByteArray* m_codewords; }; #endif // XFA_FXBARCODE_QRCODE_BC_QRDATABLOCK_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp b/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp index 20f94069f4..9b5e3ca014 100644 --- a/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp @@ -24,43 +24,47 @@ #include "xfa/fxbarcode/qrcode/BC_QRDataMask.h" #include "xfa/fxbarcode/utils.h" -static int32_t N_DATA_MASKS = 0; -CFX_PtrArray* CBC_QRDataMask::DATA_MASKS = NULL; +namespace { + +int32_t N_DATA_MASKS = 0; +CFX_ArrayTemplate<CBC_QRDataMask*>* DATA_MASKS = nullptr; + +} // namespace void CBC_QRDataMask::Initialize() { - DATA_MASKS = new CFX_PtrArray(); + DATA_MASKS = new CFX_ArrayTemplate<CBC_QRDataMask*>(); N_DATA_MASKS = BuildDataMasks(); } + void CBC_QRDataMask::Finalize() { Destroy(); delete DATA_MASKS; + DATA_MASKS = nullptr; } + void CBC_QRDataMask::Destroy() { - int32_t i; - for (i = 0; i < N_DATA_MASKS; i++) { - CBC_QRDataMask* p = (CBC_QRDataMask*)(*DATA_MASKS)[i]; - if (p) { - delete p; - } - } + for (int32_t i = 0; i < N_DATA_MASKS; ++i) + delete (*DATA_MASKS)[i]; } -void CBC_QRDataMask::UnmaskBitMatirx(CBC_CommonBitMatrix* bits, + +void CBC_QRDataMask::UnmaskBitMatrix(CBC_CommonBitMatrix* bits, int32_t dimension) { for (int32_t i = 0; i < dimension; i++) { for (int32_t j = 0; j < dimension; j++) { - if (IsMasked(i, j)) { + if (IsMasked(i, j)) bits->Flip(j, i); - } } } } + CBC_QRDataMask* CBC_QRDataMask::ForReference(int32_t reference, int32_t& e) { if (reference < 0 || reference > 7) { e = BCExceptionReferenceMustBeBetween0And7; - BC_EXCEPTION_CHECK_ReturnValue(e, NULL); + BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); } - return (CBC_QRDataMask*)(*DATA_MASKS)[reference]; + return (*DATA_MASKS)[reference]; } + class DataMask000 : public CBC_QRDataMask { public: FX_BOOL IsMasked(int32_t x, int32_t y) { return ((x + y) % 2) == 0; } diff --git a/xfa/fxbarcode/qrcode/BC_QRDataMask.h b/xfa/fxbarcode/qrcode/BC_QRDataMask.h index 88aa1140ea..dc8cf498b3 100644 --- a/xfa/fxbarcode/qrcode/BC_QRDataMask.h +++ b/xfa/fxbarcode/qrcode/BC_QRDataMask.h @@ -13,16 +13,17 @@ class CBC_CommonBitMatrix; class CBC_QRDataMask { public: - static CFX_PtrArray* DATA_MASKS; CBC_QRDataMask(); virtual ~CBC_QRDataMask(); + static void Initialize(); static void Finalize(); - virtual FX_BOOL IsMasked(int32_t i, int32_t j) = 0; - void UnmaskBitMatirx(CBC_CommonBitMatrix* bits, int32_t dimension); static CBC_QRDataMask* ForReference(int32_t reference, int32_t& e); static int32_t BuildDataMasks(); static void Destroy(); + + virtual FX_BOOL IsMasked(int32_t i, int32_t j) = 0; + void UnmaskBitMatrix(CBC_CommonBitMatrix* bits, int32_t dimension); }; #endif // XFA_FXBARCODE_QRCODE_BC_QRDATAMASK_H_ |