From 2e6864282e65c55ff6809f5aaae011b31c3a361a Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 24 Feb 2016 18:20:51 -0800 Subject: Get rid of CBC_AutoPtr and use std::unique_ptr instead. Also fix IWYU in various fxbarcode headers. R=dsinclair@chromium.org Review URL: https://codereview.chromium.org/1734823002 . --- .../fxbarcode/datamatrix/BC_DataMatrixDetector.cpp | 64 +++++++++++----------- 1 file changed, 33 insertions(+), 31 deletions(-) (limited to 'xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp') diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp index b89ef7066b..c29c64862a 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp @@ -20,12 +20,14 @@ * limitations under the License. */ +#include "xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h" + #include +#include #include "xfa/src/fxbarcode/BC_ResultPoint.h" #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" #include "xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h" -#include "xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h" #include "xfa/src/fxbarcode/qrcode/BC_QRDetectorResult.h" #include "xfa/src/fxbarcode/qrcode/BC_QRFinderPatternFinder.h" #include "xfa/src/fxbarcode/qrcode/BC_QRGridSampler.h" @@ -121,10 +123,10 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) { } else { topRight = pointD; } - int32_t dimensionTop = CBC_AutoPtr( + int32_t dimensionTop = std::unique_ptr( TransitionsBetween(topLeft, topRight)) ->GetTransitions(); - int32_t dimensionRight = CBC_AutoPtr( + int32_t dimensionRight = std::unique_ptr( TransitionsBetween(bottomRight, topRight)) ->GetTransitions(); if ((dimensionTop & 0x01) == 1) { @@ -135,24 +137,24 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) { dimensionRight++; } dimensionRight += 2; - CBC_AutoPtr bits(NULL); - CBC_AutoPtr correctedTopRight(NULL); + std::unique_ptr bits; + std::unique_ptr correctedTopRight; if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) { - correctedTopRight = CBC_AutoPtr( + correctedTopRight.reset( CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, dimensionTop, dimensionRight)); if (correctedTopRight.get() == NULL) { - correctedTopRight = CBC_AutoPtr(topRight); + correctedTopRight.reset(topRight); } else { delete topRight; topRight = NULL; } - dimensionTop = CBC_AutoPtr( + dimensionTop = std::unique_ptr( TransitionsBetween(topLeft, correctedTopRight.get())) ->GetTransitions(); dimensionRight = - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(bottomRight, correctedTopRight.get())) ->GetTransitions(); if ((dimensionTop & 0x01) == 1) { @@ -161,34 +163,34 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) { if ((dimensionRight & 0x01) == 1) { dimensionRight++; } - bits = CBC_AutoPtr( - SampleGrid(m_image, topLeft, bottomLeft, bottomRight, - correctedTopRight.get(), dimensionTop, dimensionRight, e)); + bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight, + correctedTopRight.get(), dimensionTop, dimensionRight, + e)); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } else { int32_t dimension = std::min(dimensionRight, dimensionTop); - correctedTopRight = CBC_AutoPtr( + correctedTopRight.reset( CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension)); if (correctedTopRight.get() == NULL) { - correctedTopRight = CBC_AutoPtr(topRight); + correctedTopRight.reset(topRight); } else { delete topRight; topRight = NULL; } int32_t dimensionCorrected = - std::max(CBC_AutoPtr( + std::max(std::unique_ptr( TransitionsBetween(topLeft, correctedTopRight.get())) ->GetTransitions(), - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(bottomRight, correctedTopRight.get())) ->GetTransitions()); dimensionCorrected++; if ((dimensionCorrected & 0x01) == 1) { dimensionCorrected++; } - bits = CBC_AutoPtr(SampleGrid( - m_image, topLeft, bottomLeft, bottomRight, correctedTopRight.get(), - dimensionCorrected, dimensionCorrected, e)); + bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight, + correctedTopRight.get(), dimensionCorrected, + dimensionCorrected, e)); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } CFX_PtrArray* result = new CFX_PtrArray; @@ -210,13 +212,13 @@ CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular( int32_t norm = Distance(topLeft, topRight); FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm; FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm; - CBC_AutoPtr c1(new CBC_ResultPoint( + std::unique_ptr c1(new CBC_ResultPoint( topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); corr = Distance(bottomLeft, topLeft) / (FX_FLOAT)dimensionRight; norm = Distance(bottomRight, topRight); cos = (topRight->GetX() - bottomRight->GetX()) / norm; sin = (topRight->GetY() - bottomRight->GetY()) / norm; - CBC_AutoPtr c2(new CBC_ResultPoint( + std::unique_ptr c2(new CBC_ResultPoint( topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); if (!IsValid(c1.get())) { if (IsValid(c2.get())) { @@ -227,19 +229,19 @@ CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular( return c1.release(); } int32_t l1 = FXSYS_abs(dimensionTop - - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(topLeft, c1.get())) ->GetTransitions()) + FXSYS_abs(dimensionRight - - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(bottomRight, c1.get())) ->GetTransitions()); int32_t l2 = FXSYS_abs(dimensionTop - - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(topLeft, c2.get())) ->GetTransitions()) + FXSYS_abs(dimensionRight - - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(bottomRight, c2.get())) ->GetTransitions()); if (l1 <= l2) { @@ -257,13 +259,13 @@ CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRight( int32_t norm = Distance(topLeft, topRight); FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm; FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm; - CBC_AutoPtr c1(new CBC_ResultPoint( + std::unique_ptr c1(new CBC_ResultPoint( topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimension; norm = Distance(bottomRight, topRight); cos = (topRight->GetX() - bottomRight->GetX()) / norm; sin = (topRight->GetY() - bottomRight->GetY()) / norm; - CBC_AutoPtr c2(new CBC_ResultPoint( + std::unique_ptr c2(new CBC_ResultPoint( topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); if (!IsValid(c1.get())) { if (IsValid(c2.get())) { @@ -273,16 +275,16 @@ CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRight( } else if (!IsValid(c2.get())) { return c1.release(); } - int32_t l1 = FXSYS_abs(CBC_AutoPtr( + int32_t l1 = FXSYS_abs(std::unique_ptr( TransitionsBetween(topLeft, c1.get())) ->GetTransitions() - - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(bottomRight, c1.get())) ->GetTransitions()); - int32_t l2 = FXSYS_abs(CBC_AutoPtr( + int32_t l2 = FXSYS_abs(std::unique_ptr( TransitionsBetween(topLeft, c2.get())) ->GetTransitions() - - CBC_AutoPtr( + std::unique_ptr( TransitionsBetween(bottomRight, c2.get())) ->GetTransitions()); return l1 <= l2 ? c1.release() : c2.release(); -- cgit v1.2.3