Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp

Issue 1941863002: Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 11 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp
diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp b/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp
index 4d953e006abfcf69e37866a4479a79294e1fa896..bd953a93dcd4cb1aac38488980ce6eb129a15574 100644
--- a/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp
+++ b/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp
@@ -21,6 +21,7 @@
*/
#include <limits>
+#include <memory>
#include "xfa/fxbarcode/BC_BinaryBitmap.h"
#include "xfa/fxbarcode/BC_BinaryBitmap.h"
@@ -64,27 +65,25 @@ CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image,
int32_t hints,
int32_t& e) {
CFX_ByteString results;
- CBC_PDF417DetectorResult* detectorResult =
- CBC_Detector::detect(image, hints, multiple, e);
+ std::unique_ptr<CBC_PDF417DetectorResult> detectorResult(
+ CBC_Detector::detect(image, hints, multiple, e));
BC_EXCEPTION_CHECK_ReturnValue(e, "");
for (int32_t i = 0; i < detectorResult->getPoints()->GetSize(); i++) {
- CFX_PtrArray* points = (CFX_PtrArray*)detectorResult->getPoints()->GetAt(i);
- CBC_CommonDecoderResult* ResultTemp = CBC_PDF417ScanningDecoder::decode(
- detectorResult->getBits(), (CBC_ResultPoint*)points->GetAt(4),
- (CBC_ResultPoint*)points->GetAt(5), (CBC_ResultPoint*)points->GetAt(6),
- (CBC_ResultPoint*)points->GetAt(7), getMinCodewordWidth(*points),
- getMaxCodewordWidth(*points), e);
- if (ResultTemp == NULL) {
- delete detectorResult;
+ CBC_ResultPointArray* points = detectorResult->getPoints()->GetAt(i);
+ std::unique_ptr<CBC_CommonDecoderResult> ResultTemp(
+ CBC_PDF417ScanningDecoder::decode(
+ detectorResult->getBits(), points->GetAt(4), points->GetAt(5),
+ points->GetAt(6), points->GetAt(7), getMinCodewordWidth(*points),
+ getMaxCodewordWidth(*points), e));
+ if (!ResultTemp) {
e = BCExceptiontNotFoundInstance;
- return "";
+ return CFX_ByteString();
}
results += ResultTemp->GetText();
- delete ResultTemp;
}
- delete detectorResult;
return results;
}
+
CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image,
int32_t hints,
int32_t& e) {
@@ -105,45 +104,37 @@ int32_t CBC_PDF417Reader::getMinWidth(CBC_ResultPoint* p1,
return std::numeric_limits<int32_t>::max();
return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX());
}
-int32_t CBC_PDF417Reader::getMaxCodewordWidth(CFX_PtrArray& p) {
- int32_t a =
- getMaxWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.GetAt(2)) *
- CBC_PDF417Common::MODULES_IN_CODEWORD /
- CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
- int32_t b =
- getMaxWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.GetAt(3)) *
- CBC_PDF417Common::MODULES_IN_CODEWORD /
- CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
- int32_t c = getMaxWidth((CBC_ResultPoint*)p.GetAt(0),
- (CBC_ResultPoint*)p.GetAt(4)) < a
- ? getMaxWidth((CBC_ResultPoint*)p.GetAt(0),
- (CBC_ResultPoint*)p.GetAt(4))
+
+int32_t CBC_PDF417Reader::getMaxCodewordWidth(
+ CFX_ArrayTemplate<CBC_ResultPoint*>& p) {
+ int32_t a = getMaxWidth(p.GetAt(6), p.GetAt(2)) *
+ CBC_PDF417Common::MODULES_IN_CODEWORD /
+ CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
+ int32_t b = getMaxWidth(p.GetAt(7), p.GetAt(3)) *
+ CBC_PDF417Common::MODULES_IN_CODEWORD /
+ CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
+ int32_t c = getMaxWidth(p.GetAt(0), p.GetAt(4)) < a
Lei Zhang 2016/05/02 19:13:25 std::min(), for |d| as well.
Tom Sepez 2016/05/02 20:32:26 Done.
+ ? getMaxWidth(p.GetAt(0), p.GetAt(4))
: a;
- int32_t d = getMaxWidth((CBC_ResultPoint*)p.GetAt(1),
- (CBC_ResultPoint*)p.GetAt(5)) < b
- ? getMaxWidth((CBC_ResultPoint*)p.GetAt(1),
- (CBC_ResultPoint*)p.GetAt(5))
+ int32_t d = getMaxWidth(p.GetAt(1), p.GetAt(5)) < b
+ ? getMaxWidth(p.GetAt(1), p.GetAt(5))
: b;
return c < d ? c : d;
Lei Zhang 2016/05/02 19:13:25 Or std::min({a, b, getMaxWidth(p.GetAt(0), p.GetAt
Tom Sepez 2016/05/02 20:32:26 or std::min(c, d) at least.
}
-int32_t CBC_PDF417Reader::getMinCodewordWidth(CFX_PtrArray& p) {
- int32_t a =
- getMinWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.GetAt(2)) *
- CBC_PDF417Common::MODULES_IN_CODEWORD /
- CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
- int32_t b =
- getMinWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.GetAt(3)) *
- CBC_PDF417Common::MODULES_IN_CODEWORD /
- CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
- int32_t c = getMinWidth((CBC_ResultPoint*)p.GetAt(0),
- (CBC_ResultPoint*)p.GetAt(4)) < a
- ? getMinWidth((CBC_ResultPoint*)p.GetAt(0),
- (CBC_ResultPoint*)p.GetAt(4))
+
+int32_t CBC_PDF417Reader::getMinCodewordWidth(
+ CFX_ArrayTemplate<CBC_ResultPoint*>& p) {
Lei Zhang 2016/05/02 19:13:25 Can this be a const ref?
+ int32_t a = getMinWidth(p.GetAt(6), p.GetAt(2)) *
+ CBC_PDF417Common::MODULES_IN_CODEWORD /
+ CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
+ int32_t b = getMinWidth(p.GetAt(7), p.GetAt(3)) *
+ CBC_PDF417Common::MODULES_IN_CODEWORD /
+ CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
+ int32_t c = getMinWidth(p.GetAt(0), p.GetAt(4)) < a
+ ? getMinWidth(p.GetAt(0), p.GetAt(4))
: a;
- int32_t d = getMinWidth((CBC_ResultPoint*)p.GetAt(1),
- (CBC_ResultPoint*)p.GetAt(5)) < b
- ? getMinWidth((CBC_ResultPoint*)p.GetAt(1),
- (CBC_ResultPoint*)p.GetAt(5))
+ int32_t d = getMinWidth(p.GetAt(1), p.GetAt(5)) < b
+ ? getMinWidth(p.GetAt(1), p.GetAt(5))
: b;
return c < d ? c : d;
}

Powered by Google App Engine
This is Rietveld 408576698