diff options
Diffstat (limited to 'xfa/fxbarcode/pdf417')
-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 |
6 files changed, 141 insertions, 142 deletions
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: |