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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows: 6 // Original code is licensed as follows:
7 /* 7 /*
8 * Copyright 2009 ZXing authors 8 * Copyright 2009 ZXing authors
9 * 9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License. 11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at 12 * You may obtain a copy of the License at
13 * 13 *
14 * http://www.apache.org/licenses/LICENSE-2.0 14 * http://www.apache.org/licenses/LICENSE-2.0
15 * 15 *
16 * Unless required by applicable law or agreed to in writing, software 16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, 17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and 19 * See the License for the specific language governing permissions and
20 * limitations under the License. 20 * limitations under the License.
21 */ 21 */
22 22
23 #include <limits> 23 #include <limits>
24 #include <memory>
24 25
25 #include "xfa/fxbarcode/BC_BinaryBitmap.h" 26 #include "xfa/fxbarcode/BC_BinaryBitmap.h"
26 #include "xfa/fxbarcode/BC_BinaryBitmap.h" 27 #include "xfa/fxbarcode/BC_BinaryBitmap.h"
27 #include "xfa/fxbarcode/BC_DecoderResult.h" 28 #include "xfa/fxbarcode/BC_DecoderResult.h"
28 #include "xfa/fxbarcode/BC_Reader.h" 29 #include "xfa/fxbarcode/BC_Reader.h"
29 #include "xfa/fxbarcode/BC_ResultPoint.h" 30 #include "xfa/fxbarcode/BC_ResultPoint.h"
30 #include "xfa/fxbarcode/common/BC_CommonBitArray.h" 31 #include "xfa/fxbarcode/common/BC_CommonBitArray.h"
31 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" 32 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
32 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" 33 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
33 #include "xfa/fxbarcode/common/BC_CommonDecoderResult.h" 34 #include "xfa/fxbarcode/common/BC_CommonDecoderResult.h"
(...skipping 23 matching lines...) Expand all
57 CBC_PDF417Reader::~CBC_PDF417Reader() {} 58 CBC_PDF417Reader::~CBC_PDF417Reader() {}
58 59
59 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image, int32_t& e) { 60 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image, int32_t& e) {
60 return Decode(image, 0, e); 61 return Decode(image, 0, e);
61 } 62 }
62 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image, 63 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image,
63 FX_BOOL multiple, 64 FX_BOOL multiple,
64 int32_t hints, 65 int32_t hints,
65 int32_t& e) { 66 int32_t& e) {
66 CFX_ByteString results; 67 CFX_ByteString results;
67 CBC_PDF417DetectorResult* detectorResult = 68 std::unique_ptr<CBC_PDF417DetectorResult> detectorResult(
68 CBC_Detector::detect(image, hints, multiple, e); 69 CBC_Detector::detect(image, hints, multiple, e));
69 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 70 BC_EXCEPTION_CHECK_ReturnValue(e, "");
70 for (int32_t i = 0; i < detectorResult->getPoints()->GetSize(); i++) { 71 for (int32_t i = 0; i < detectorResult->getPoints()->GetSize(); i++) {
71 CFX_PtrArray* points = (CFX_PtrArray*)detectorResult->getPoints()->GetAt(i); 72 CBC_ResultPointArray* points = detectorResult->getPoints()->GetAt(i);
72 CBC_CommonDecoderResult* ResultTemp = CBC_PDF417ScanningDecoder::decode( 73 std::unique_ptr<CBC_CommonDecoderResult> ResultTemp(
73 detectorResult->getBits(), (CBC_ResultPoint*)points->GetAt(4), 74 CBC_PDF417ScanningDecoder::decode(
74 (CBC_ResultPoint*)points->GetAt(5), (CBC_ResultPoint*)points->GetAt(6), 75 detectorResult->getBits(), points->GetAt(4), points->GetAt(5),
75 (CBC_ResultPoint*)points->GetAt(7), getMinCodewordWidth(*points), 76 points->GetAt(6), points->GetAt(7), getMinCodewordWidth(*points),
76 getMaxCodewordWidth(*points), e); 77 getMaxCodewordWidth(*points), e));
77 if (ResultTemp == NULL) { 78 if (!ResultTemp) {
78 delete detectorResult;
79 e = BCExceptiontNotFoundInstance; 79 e = BCExceptiontNotFoundInstance;
80 return ""; 80 return CFX_ByteString();
81 } 81 }
82 results += ResultTemp->GetText(); 82 results += ResultTemp->GetText();
83 delete ResultTemp;
84 } 83 }
85 delete detectorResult;
86 return results; 84 return results;
87 } 85 }
86
88 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image, 87 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image,
89 int32_t hints, 88 int32_t hints,
90 int32_t& e) { 89 int32_t& e) {
91 CFX_ByteString bs = Decode(image, FALSE, 0, e); 90 CFX_ByteString bs = Decode(image, FALSE, 0, e);
92 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 91 BC_EXCEPTION_CHECK_ReturnValue(e, "");
93 return bs; 92 return bs;
94 } 93 }
95 int32_t CBC_PDF417Reader::getMaxWidth(CBC_ResultPoint* p1, 94 int32_t CBC_PDF417Reader::getMaxWidth(CBC_ResultPoint* p1,
96 CBC_ResultPoint* p2) { 95 CBC_ResultPoint* p2) {
97 if (p1 == NULL || p2 == NULL) { 96 if (p1 == NULL || p2 == NULL) {
98 return 0; 97 return 0;
99 } 98 }
100 return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX()); 99 return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX());
101 } 100 }
102 int32_t CBC_PDF417Reader::getMinWidth(CBC_ResultPoint* p1, 101 int32_t CBC_PDF417Reader::getMinWidth(CBC_ResultPoint* p1,
103 CBC_ResultPoint* p2) { 102 CBC_ResultPoint* p2) {
104 if (!p1 || !p2) 103 if (!p1 || !p2)
105 return std::numeric_limits<int32_t>::max(); 104 return std::numeric_limits<int32_t>::max();
106 return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX()); 105 return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX());
107 } 106 }
108 int32_t CBC_PDF417Reader::getMaxCodewordWidth(CFX_PtrArray& p) { 107
109 int32_t a = 108 int32_t CBC_PDF417Reader::getMaxCodewordWidth(
110 getMaxWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.GetAt(2)) * 109 CFX_ArrayTemplate<CBC_ResultPoint*>& p) {
111 CBC_PDF417Common::MODULES_IN_CODEWORD / 110 int32_t a = getMaxWidth(p.GetAt(6), p.GetAt(2)) *
112 CBC_PDF417Common::MODULES_IN_STOP_PATTERN; 111 CBC_PDF417Common::MODULES_IN_CODEWORD /
113 int32_t b = 112 CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
114 getMaxWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.GetAt(3)) * 113 int32_t b = getMaxWidth(p.GetAt(7), p.GetAt(3)) *
115 CBC_PDF417Common::MODULES_IN_CODEWORD / 114 CBC_PDF417Common::MODULES_IN_CODEWORD /
116 CBC_PDF417Common::MODULES_IN_STOP_PATTERN; 115 CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
117 int32_t c = getMaxWidth((CBC_ResultPoint*)p.GetAt(0), 116 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.
118 (CBC_ResultPoint*)p.GetAt(4)) < a 117 ? getMaxWidth(p.GetAt(0), p.GetAt(4))
119 ? getMaxWidth((CBC_ResultPoint*)p.GetAt(0),
120 (CBC_ResultPoint*)p.GetAt(4))
121 : a; 118 : a;
122 int32_t d = getMaxWidth((CBC_ResultPoint*)p.GetAt(1), 119 int32_t d = getMaxWidth(p.GetAt(1), p.GetAt(5)) < b
123 (CBC_ResultPoint*)p.GetAt(5)) < b 120 ? getMaxWidth(p.GetAt(1), p.GetAt(5))
124 ? getMaxWidth((CBC_ResultPoint*)p.GetAt(1),
125 (CBC_ResultPoint*)p.GetAt(5))
126 : b; 121 : b;
127 return c < d ? c : d; 122 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.
128 } 123 }
129 int32_t CBC_PDF417Reader::getMinCodewordWidth(CFX_PtrArray& p) { 124
130 int32_t a = 125 int32_t CBC_PDF417Reader::getMinCodewordWidth(
131 getMinWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.GetAt(2)) * 126 CFX_ArrayTemplate<CBC_ResultPoint*>& p) {
Lei Zhang 2016/05/02 19:13:25 Can this be a const ref?
132 CBC_PDF417Common::MODULES_IN_CODEWORD / 127 int32_t a = getMinWidth(p.GetAt(6), p.GetAt(2)) *
133 CBC_PDF417Common::MODULES_IN_STOP_PATTERN; 128 CBC_PDF417Common::MODULES_IN_CODEWORD /
134 int32_t b = 129 CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
135 getMinWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.GetAt(3)) * 130 int32_t b = getMinWidth(p.GetAt(7), p.GetAt(3)) *
136 CBC_PDF417Common::MODULES_IN_CODEWORD / 131 CBC_PDF417Common::MODULES_IN_CODEWORD /
137 CBC_PDF417Common::MODULES_IN_STOP_PATTERN; 132 CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
138 int32_t c = getMinWidth((CBC_ResultPoint*)p.GetAt(0), 133 int32_t c = getMinWidth(p.GetAt(0), p.GetAt(4)) < a
139 (CBC_ResultPoint*)p.GetAt(4)) < a 134 ? getMinWidth(p.GetAt(0), p.GetAt(4))
140 ? getMinWidth((CBC_ResultPoint*)p.GetAt(0),
141 (CBC_ResultPoint*)p.GetAt(4))
142 : a; 135 : a;
143 int32_t d = getMinWidth((CBC_ResultPoint*)p.GetAt(1), 136 int32_t d = getMinWidth(p.GetAt(1), p.GetAt(5)) < b
144 (CBC_ResultPoint*)p.GetAt(5)) < b 137 ? getMinWidth(p.GetAt(1), p.GetAt(5))
145 ? getMinWidth((CBC_ResultPoint*)p.GetAt(1),
146 (CBC_ResultPoint*)p.GetAt(5))
147 : b; 138 : b;
148 return c < d ? c : d; 139 return c < d ? c : d;
149 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698