diff options
author | tsepez <tsepez@chromium.org> | 2016-04-28 15:16:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-28 15:16:51 -0700 |
commit | 33a747db5c9ce18bdfaaaaea17b03ef26d14ff54 (patch) | |
tree | 9d8249844ea44f432891ffa67d7bca51bdb1f033 /xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp | |
parent | 18713d20e080c344e0ed09e3f0ac5bacb0645fc5 (diff) | |
download | pdfium-33a747db5c9ce18bdfaaaaea17b03ef26d14ff54.tar.xz |
Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, Part 5
Remove unused m_pdf417byteSegments, which was coped into from
an empty array and never again referenced.
Review-Url: https://codereview.chromium.org/1927253002
Diffstat (limited to 'xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp')
-rw-r--r-- | xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp b/xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp index ea08f1550d..dc63131d01 100644 --- a/xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp @@ -42,12 +42,12 @@ CBC_QRFinderPatternFinder::CBC_QRFinderPatternFinder( m_crossCheckStateCount.SetSize(5); m_hasSkipped = FALSE; } + CBC_QRFinderPatternFinder::~CBC_QRFinderPatternFinder() { - for (int32_t i = 0; i < m_possibleCenters.GetSize(); i++) { - delete (CBC_QRFinderPattern*)m_possibleCenters[i]; - } - m_possibleCenters.RemoveAll(); + for (int32_t i = 0; i < m_possibleCenters.GetSize(); i++) + delete m_possibleCenters[i]; } + class ClosestToAverageComparator { private: FX_FLOAT m_averageModuleSize; @@ -80,9 +80,12 @@ CFX_Int32Array& CBC_QRFinderPatternFinder::GetCrossCheckStateCount() { m_crossCheckStateCount[4] = 0; return m_crossCheckStateCount; } -CFX_PtrArray* CBC_QRFinderPatternFinder::GetPossibleCenters() { + +CFX_ArrayTemplate<CBC_QRFinderPattern*>* +CBC_QRFinderPatternFinder::GetPossibleCenters() { return &m_possibleCenters; } + CBC_QRFinderPatternInfo* CBC_QRFinderPatternFinder::Find(int32_t hint, int32_t& e) { int32_t maxI = m_image->GetHeight(); @@ -161,31 +164,32 @@ CBC_QRFinderPatternInfo* CBC_QRFinderPatternFinder::Find(int32_t hint, } } } - std::unique_ptr<CFX_PtrArray> patternInfo(SelectBestpatterns(e)); + std::unique_ptr<CFX_ArrayTemplate<CBC_QRFinderPattern*>> patternInfo( + SelectBestpatterns(e)); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); OrderBestPatterns(patternInfo.get()); return new CBC_QRFinderPatternInfo(patternInfo.get()); } -void CBC_QRFinderPatternFinder::OrderBestPatterns(CFX_PtrArray* patterns) { - FX_FLOAT abDistance = Distance((CBC_ResultPoint*)(*patterns)[0], - (CBC_ResultPoint*)(*patterns)[1]); - FX_FLOAT bcDistance = Distance((CBC_ResultPoint*)(*patterns)[1], - (CBC_ResultPoint*)(*patterns)[2]); - FX_FLOAT acDistance = Distance((CBC_ResultPoint*)(*patterns)[0], - (CBC_ResultPoint*)(*patterns)[2]); - CBC_QRFinderPattern *topLeft, *topRight, *bottomLeft; +void CBC_QRFinderPatternFinder::OrderBestPatterns( + CFX_ArrayTemplate<CBC_QRFinderPattern*>* patterns) { + FX_FLOAT abDistance = Distance((*patterns)[0], (*patterns)[1]); + FX_FLOAT bcDistance = Distance((*patterns)[1], (*patterns)[2]); + FX_FLOAT acDistance = Distance((*patterns)[0], (*patterns)[2]); + CBC_QRFinderPattern* topLeft; + CBC_QRFinderPattern* topRight; + CBC_QRFinderPattern* bottomLeft; if (bcDistance >= abDistance && bcDistance >= acDistance) { - topLeft = (CBC_QRFinderPattern*)(*patterns)[0]; - topRight = (CBC_QRFinderPattern*)(*patterns)[1]; - bottomLeft = (CBC_QRFinderPattern*)(*patterns)[2]; + topLeft = (*patterns)[0]; + topRight = (*patterns)[1]; + bottomLeft = (*patterns)[2]; } else if (acDistance >= bcDistance && acDistance >= abDistance) { - topLeft = (CBC_QRFinderPattern*)(*patterns)[1]; - topRight = (CBC_QRFinderPattern*)(*patterns)[0]; - bottomLeft = (CBC_QRFinderPattern*)(*patterns)[2]; + topLeft = (*patterns)[1]; + topRight = (*patterns)[0]; + bottomLeft = (*patterns)[2]; } else { - topLeft = (CBC_QRFinderPattern*)(*patterns)[2]; - topRight = (CBC_QRFinderPattern*)(*patterns)[0]; - bottomLeft = (CBC_QRFinderPattern*)(*patterns)[1]; + topLeft = (*patterns)[2]; + topRight = (*patterns)[0]; + bottomLeft = (*patterns)[1]; } if ((bottomLeft->GetY() - topLeft->GetY()) * (topRight->GetX() - topLeft->GetX()) < @@ -375,8 +379,7 @@ FX_BOOL CBC_QRFinderPatternFinder::HandlePossibleCenter( FX_BOOL found = FALSE; int32_t max = m_possibleCenters.GetSize(); for (int32_t index = 0; index < max; index++) { - CBC_QRFinderPattern* center = - (CBC_QRFinderPattern*)(m_possibleCenters[index]); + CBC_QRFinderPattern* center = m_possibleCenters[index]; if (center->AboutEquals(estimatedModuleSize, centerI, centerJ)) { center->IncrementCount(); found = TRUE; @@ -399,7 +402,7 @@ int32_t CBC_QRFinderPatternFinder::FindRowSkip() { } FinderPattern* firstConfirmedCenter = NULL; for (int32_t i = 0; i < max; i++) { - CBC_QRFinderPattern* center = (CBC_QRFinderPattern*)m_possibleCenters[i]; + CBC_QRFinderPattern* center = m_possibleCenters[i]; if (center->GetCount() >= CENTER_QUORUM) { if (firstConfirmedCenter == NULL) { firstConfirmedCenter = center; @@ -419,7 +422,7 @@ FX_BOOL CBC_QRFinderPatternFinder::HaveMultiplyConfirmedCenters() { int32_t max = m_possibleCenters.GetSize(); int32_t i; for (i = 0; i < max; i++) { - CBC_QRFinderPattern* pattern = (CBC_QRFinderPattern*)m_possibleCenters[i]; + CBC_QRFinderPattern* pattern = m_possibleCenters[i]; if (pattern->GetCount() >= CENTER_QUORUM) { confirmedCount++; totalModuleSize += pattern->GetEstimatedModuleSize(); @@ -431,16 +434,14 @@ FX_BOOL CBC_QRFinderPatternFinder::HaveMultiplyConfirmedCenters() { FX_FLOAT average = totalModuleSize / (FX_FLOAT)max; FX_FLOAT totalDeviation = 0.0f; for (i = 0; i < max; i++) { - CBC_QRFinderPattern* pattern = (CBC_QRFinderPattern*)m_possibleCenters[i]; + CBC_QRFinderPattern* pattern = m_possibleCenters[i]; totalDeviation += fabs(pattern->GetEstimatedModuleSize() - average); } return totalDeviation <= 0.05f * totalModuleSize; } -inline FX_BOOL centerComparator(void* a, void* b) { - return ((CBC_QRFinderPattern*)b)->GetCount() < - ((CBC_QRFinderPattern*)a)->GetCount(); -} -CFX_PtrArray* CBC_QRFinderPatternFinder::SelectBestpatterns(int32_t& e) { + +CFX_ArrayTemplate<CBC_QRFinderPattern*>* +CBC_QRFinderPatternFinder::SelectBestpatterns(int32_t& e) { int32_t startSize = m_possibleCenters.GetSize(); if (m_possibleCenters.GetSize() < 3) { e = BCExceptionRead; @@ -449,15 +450,14 @@ CFX_PtrArray* CBC_QRFinderPatternFinder::SelectBestpatterns(int32_t& e) { FX_FLOAT average = 0.0f; if (startSize > 3) { FX_FLOAT totalModuleSize = 0.0f; - for (int32_t i = 0; i < startSize; i++) { - totalModuleSize += ((CBC_QRFinderPattern*)m_possibleCenters[i]) - ->GetEstimatedModuleSize(); - } + for (int32_t i = 0; i < startSize; i++) + totalModuleSize += m_possibleCenters[i]->GetEstimatedModuleSize(); + average = totalModuleSize / (FX_FLOAT)startSize; for (int32_t j = 0; j < m_possibleCenters.GetSize() && m_possibleCenters.GetSize() > 3; j++) { - CBC_QRFinderPattern* pattern = (CBC_QRFinderPattern*)m_possibleCenters[j]; + CBC_QRFinderPattern* pattern = m_possibleCenters[j]; if (fabs(pattern->GetEstimatedModuleSize() - average) > 0.2f * average) { delete pattern; m_possibleCenters.RemoveAt(j); @@ -466,12 +466,17 @@ CFX_PtrArray* CBC_QRFinderPatternFinder::SelectBestpatterns(int32_t& e) { } } if (m_possibleCenters.GetSize() > 3) { - BC_FX_PtrArray_Sort(m_possibleCenters, centerComparator); - } - CFX_PtrArray* vec = new CFX_PtrArray(); + std::sort(m_possibleCenters.GetData(), + m_possibleCenters.GetData() + m_possibleCenters.GetSize(), + [](const CBC_QRFinderPattern* a, CBC_QRFinderPattern* b) { + return a->GetCount() > b->GetCount(); // e.g. Descending. + }); + } + CFX_ArrayTemplate<CBC_QRFinderPattern*>* vec = + new CFX_ArrayTemplate<CBC_QRFinderPattern*>(); vec->SetSize(3); - (*vec)[0] = ((CBC_QRFinderPattern*)m_possibleCenters[0])->Clone(); - (*vec)[1] = ((CBC_QRFinderPattern*)m_possibleCenters[1])->Clone(); - (*vec)[2] = ((CBC_QRFinderPattern*)m_possibleCenters[2])->Clone(); + (*vec)[0] = m_possibleCenters[0]->Clone(); + (*vec)[1] = m_possibleCenters[1]->Clone(); + (*vec)[2] = m_possibleCenters[2]->Clone(); return vec; } |