OLD | NEW |
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"); |
(...skipping 10 matching lines...) Expand all Loading... |
21 */ | 21 */ |
22 | 22 |
23 #include "../barcode.h" | 23 #include "../barcode.h" |
24 #include "../BC_ResultPoint.h" | 24 #include "../BC_ResultPoint.h" |
25 #include "../BC_BinaryBitmap.h" | 25 #include "../BC_BinaryBitmap.h" |
26 #include "../common/BC_CommonBitMatrix.h" | 26 #include "../common/BC_CommonBitMatrix.h" |
27 #include "../common/BC_CommonBitArray.h" | 27 #include "../common/BC_CommonBitArray.h" |
28 #include "BC_PDF417DetectorResult.h" | 28 #include "BC_PDF417DetectorResult.h" |
29 #include "BC_PDF417Detector.h" | 29 #include "BC_PDF417Detector.h" |
30 #define INTERGER_MAX 2147483647 | 30 #define INTERGER_MAX 2147483647 |
31 FX_INT32 CBC_Detector::INDEXES_START_PATTERN[] = {0, 4, 1, 5}; | 31 int32_t CBC_Detector::INDEXES_START_PATTERN[] = {0, 4, 1, 5}; |
32 FX_INT32 CBC_Detector::INDEXES_STOP_PATTERN[] = {6, 2, 7, 3}; | 32 int32_t CBC_Detector::INDEXES_STOP_PATTERN[] = {6, 2, 7, 3}; |
33 FX_INT32 CBC_Detector::INTEGER_MATH_SHIFT = 8; | 33 int32_t CBC_Detector::INTEGER_MATH_SHIFT = 8; |
34 FX_INT32 CBC_Detector::PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHI
FT; | 34 int32_t CBC_Detector::PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIF
T; |
35 FX_INT32 CBC_Detector::MAX_AVG_VARIANCE = (FX_INT32) (PATTERN_MATCH_RESULT_SCALE
_FACTOR * 0.42f); | 35 int32_t CBC_Detector::MAX_AVG_VARIANCE = (int32_t) (PATTERN_MATCH_RESULT_SCALE_F
ACTOR * 0.42f); |
36 FX_INT32 CBC_Detector::MAX_INDIVIDUAL_VARIANCE = (FX_INT32) (PATTERN_MATCH_RESUL
T_SCALE_FACTOR * 0.8f); | 36 int32_t CBC_Detector::MAX_INDIVIDUAL_VARIANCE = (int32_t) (PATTERN_MATCH_RESULT_
SCALE_FACTOR * 0.8f); |
37 FX_INT32 CBC_Detector::START_PATTERN[] = {8, 1, 1, 1, 1, 1, 1, 3}; | 37 int32_t CBC_Detector::START_PATTERN[] = {8, 1, 1, 1, 1, 1, 1, 3}; |
38 FX_INT32 CBC_Detector::STOP_PATTERN[] = {7, 1, 1, 3, 1, 1, 1, 2, 1}; | 38 int32_t CBC_Detector::STOP_PATTERN[] = {7, 1, 1, 3, 1, 1, 1, 2, 1}; |
39 FX_INT32 CBC_Detector::MAX_PIXEL_DRIFT = 3; | 39 int32_t CBC_Detector::MAX_PIXEL_DRIFT = 3; |
40 FX_INT32 CBC_Detector::MAX_PATTERN_DRIFT = 5; | 40 int32_t CBC_Detector::MAX_PATTERN_DRIFT = 5; |
41 FX_INT32 CBC_Detector::SKIPPED_ROW_COUNT_MAX = 25; | 41 int32_t CBC_Detector::SKIPPED_ROW_COUNT_MAX = 25; |
42 FX_INT32 CBC_Detector::ROW_STEP = 5; | 42 int32_t CBC_Detector::ROW_STEP = 5; |
43 FX_INT32 CBC_Detector::BARCODE_MIN_HEIGHT = 10; | 43 int32_t CBC_Detector::BARCODE_MIN_HEIGHT = 10; |
44 CBC_Detector::CBC_Detector() | 44 CBC_Detector::CBC_Detector() |
45 { | 45 { |
46 } | 46 } |
47 CBC_Detector::~CBC_Detector() | 47 CBC_Detector::~CBC_Detector() |
48 { | 48 { |
49 } | 49 } |
50 CBC_PDF417DetectorResult* CBC_Detector::detect(CBC_BinaryBitmap* image, FX_INT32
hints, FX_BOOL multiple, FX_INT32 &e) | 50 CBC_PDF417DetectorResult* CBC_Detector::detect(CBC_BinaryBitmap* image, int32_t
hints, FX_BOOL multiple, int32_t &e) |
51 { | 51 { |
52 CBC_CommonBitMatrix* bitMatrix = image->GetBlackMatrix(e); | 52 CBC_CommonBitMatrix* bitMatrix = image->GetBlackMatrix(e); |
53 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 53 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
54 CFX_PtrArray* barcodeCoordinates = detect(multiple, bitMatrix); | 54 CFX_PtrArray* barcodeCoordinates = detect(multiple, bitMatrix); |
55 if (barcodeCoordinates->GetSize() == 0) { | 55 if (barcodeCoordinates->GetSize() == 0) { |
56 rotate180(bitMatrix); | 56 rotate180(bitMatrix); |
57 barcodeCoordinates = detect(multiple, bitMatrix); | 57 barcodeCoordinates = detect(multiple, bitMatrix); |
58 } | 58 } |
59 if (barcodeCoordinates->GetSize() == 0) { | 59 if (barcodeCoordinates->GetSize() == 0) { |
60 e = BCExceptionUnSupportedBarcode; | 60 e = BCExceptionUnSupportedBarcode; |
61 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 61 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
62 } | 62 } |
63 CBC_PDF417DetectorResult* detectorResult = FX_NEW CBC_PDF417DetectorResult(b
itMatrix, barcodeCoordinates); | 63 CBC_PDF417DetectorResult* detectorResult = FX_NEW CBC_PDF417DetectorResult(b
itMatrix, barcodeCoordinates); |
64 return detectorResult; | 64 return detectorResult; |
65 } | 65 } |
66 void CBC_Detector::rotate180(CBC_CommonBitMatrix* bitMatrix) | 66 void CBC_Detector::rotate180(CBC_CommonBitMatrix* bitMatrix) |
67 { | 67 { |
68 FX_INT32 width = bitMatrix->GetWidth(); | 68 int32_t width = bitMatrix->GetWidth(); |
69 FX_INT32 height = bitMatrix->GetHeight(); | 69 int32_t height = bitMatrix->GetHeight(); |
70 CBC_CommonBitArray* firstRowBitArray = FX_NEW CBC_CommonBitArray(width); | 70 CBC_CommonBitArray* firstRowBitArray = FX_NEW CBC_CommonBitArray(width); |
71 CBC_CommonBitArray* secondRowBitArray = FX_NEW CBC_CommonBitArray(width); | 71 CBC_CommonBitArray* secondRowBitArray = FX_NEW CBC_CommonBitArray(width); |
72 CBC_CommonBitArray* tmpBitArray = FX_NEW CBC_CommonBitArray(width); | 72 CBC_CommonBitArray* tmpBitArray = FX_NEW CBC_CommonBitArray(width); |
73 for (FX_INT32 y = 0; y < (height + 1) >> 1; y++) { | 73 for (int32_t y = 0; y < (height + 1) >> 1; y++) { |
74 CBC_CommonBitArray* temp = bitMatrix->GetRow(height - 1 - y, secondRowBi
tArray); | 74 CBC_CommonBitArray* temp = bitMatrix->GetRow(height - 1 - y, secondRowBi
tArray); |
75 CBC_CommonBitArray* tempfirstRow = firstRowBitArray; | 75 CBC_CommonBitArray* tempfirstRow = firstRowBitArray; |
76 firstRowBitArray = bitMatrix->GetRow(y, tempfirstRow); | 76 firstRowBitArray = bitMatrix->GetRow(y, tempfirstRow); |
77 delete tempfirstRow; | 77 delete tempfirstRow; |
78 CBC_CommonBitArray* row = mirror(temp, tmpBitArray); | 78 CBC_CommonBitArray* row = mirror(temp, tmpBitArray); |
79 delete temp; | 79 delete temp; |
80 bitMatrix->SetRow(y, row); | 80 bitMatrix->SetRow(y, row); |
81 delete row; | 81 delete row; |
82 CBC_CommonBitArray* rowfirstRow = mirror(firstRowBitArray, tmpBitArray); | 82 CBC_CommonBitArray* rowfirstRow = mirror(firstRowBitArray, tmpBitArray); |
83 bitMatrix->SetRow(height - 1 - y, rowfirstRow); | 83 bitMatrix->SetRow(height - 1 - y, rowfirstRow); |
84 delete rowfirstRow; | 84 delete rowfirstRow; |
85 } | 85 } |
86 delete tmpBitArray; | 86 delete tmpBitArray; |
87 delete firstRowBitArray; | 87 delete firstRowBitArray; |
88 delete secondRowBitArray; | 88 delete secondRowBitArray; |
89 } | 89 } |
90 CBC_CommonBitArray* CBC_Detector::mirror(CBC_CommonBitArray* input, CBC_CommonBi
tArray* result) | 90 CBC_CommonBitArray* CBC_Detector::mirror(CBC_CommonBitArray* input, CBC_CommonBi
tArray* result) |
91 { | 91 { |
92 CBC_CommonBitArray* array = FX_NEW CBC_CommonBitArray(result->GetSize()); | 92 CBC_CommonBitArray* array = FX_NEW CBC_CommonBitArray(result->GetSize()); |
93 array->Clear(); | 93 array->Clear(); |
94 FX_INT32 size = input->GetSize(); | 94 int32_t size = input->GetSize(); |
95 for (FX_INT32 i = 0; i < size; i++) { | 95 for (int32_t i = 0; i < size; i++) { |
96 if (input->Get(i)) { | 96 if (input->Get(i)) { |
97 array->Set(size - 1 - i); | 97 array->Set(size - 1 - i); |
98 } | 98 } |
99 } | 99 } |
100 return array; | 100 return array; |
101 } | 101 } |
102 CFX_PtrArray* CBC_Detector::detect(FX_BOOL multiple, CBC_CommonBitMatrix* bitMat
rix) | 102 CFX_PtrArray* CBC_Detector::detect(FX_BOOL multiple, CBC_CommonBitMatrix* bitMat
rix) |
103 { | 103 { |
104 CFX_PtrArray* barcodeCoordinates = FX_NEW CFX_PtrArray; | 104 CFX_PtrArray* barcodeCoordinates = FX_NEW CFX_PtrArray; |
105 FX_INT32 row = 0; | 105 int32_t row = 0; |
106 FX_INT32 column = 0; | 106 int32_t column = 0; |
107 FX_BOOL foundBarcodeInRow = FALSE; | 107 FX_BOOL foundBarcodeInRow = FALSE; |
108 while (row < bitMatrix->GetHeight()) { | 108 while (row < bitMatrix->GetHeight()) { |
109 CFX_PtrArray* vertices = findVertices(bitMatrix, row, column); | 109 CFX_PtrArray* vertices = findVertices(bitMatrix, row, column); |
110 if (vertices->GetAt(0) == NULL && vertices->GetAt(3) == NULL) { | 110 if (vertices->GetAt(0) == NULL && vertices->GetAt(3) == NULL) { |
111 if (!foundBarcodeInRow) { | 111 if (!foundBarcodeInRow) { |
112 if (vertices) { | 112 if (vertices) { |
113 delete(vertices); | 113 delete(vertices); |
114 } | 114 } |
115 break; | 115 break; |
116 } | 116 } |
117 foundBarcodeInRow = FALSE; | 117 foundBarcodeInRow = FALSE; |
118 column = 0; | 118 column = 0; |
119 for (FX_INT32 i = 0; i < barcodeCoordinates->GetSize(); i++) { | 119 for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) { |
120 CFX_PtrArray* barcodeCoordinate = (CFX_PtrArray*)barcodeCoordina
tes->GetAt(i); | 120 CFX_PtrArray* barcodeCoordinate = (CFX_PtrArray*)barcodeCoordina
tes->GetAt(i); |
121 if (barcodeCoordinate->GetAt(1) != NULL) { | 121 if (barcodeCoordinate->GetAt(1) != NULL) { |
122 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(1))-
>GetY(); | 122 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(1))-
>GetY(); |
123 } | 123 } |
124 if (barcodeCoordinate->GetAt(3) != NULL) { | 124 if (barcodeCoordinate->GetAt(3) != NULL) { |
125 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(3))-
>GetY(); | 125 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(3))-
>GetY(); |
126 } | 126 } |
127 } | 127 } |
128 row += ROW_STEP; | 128 row += ROW_STEP; |
129 if (vertices) { | 129 if (vertices) { |
130 delete(vertices); | 130 delete(vertices); |
131 } | 131 } |
132 continue; | 132 continue; |
133 } | 133 } |
134 foundBarcodeInRow = TRUE; | 134 foundBarcodeInRow = TRUE; |
135 barcodeCoordinates->Add(vertices); | 135 barcodeCoordinates->Add(vertices); |
136 if (!multiple) { | 136 if (!multiple) { |
137 break; | 137 break; |
138 } | 138 } |
139 if (vertices->GetAt(2) != NULL) { | 139 if (vertices->GetAt(2) != NULL) { |
140 column = (FX_INT32) ((CBC_ResultPoint*)vertices->GetAt(2))->GetX(); | 140 column = (int32_t) ((CBC_ResultPoint*)vertices->GetAt(2))->GetX(); |
141 row = (FX_INT32) ((CBC_ResultPoint*)vertices->GetAt(2))->GetY(); | 141 row = (int32_t) ((CBC_ResultPoint*)vertices->GetAt(2))->GetY(); |
142 } else { | 142 } else { |
143 column = (FX_INT32) ((CBC_ResultPoint*)vertices->GetAt(4))->GetX(); | 143 column = (int32_t) ((CBC_ResultPoint*)vertices->GetAt(4))->GetX(); |
144 row = (FX_INT32) ((CBC_ResultPoint*)vertices->GetAt(4))->GetY(); | 144 row = (int32_t) ((CBC_ResultPoint*)vertices->GetAt(4))->GetY(); |
145 } | 145 } |
146 } | 146 } |
147 return barcodeCoordinates; | 147 return barcodeCoordinates; |
148 } | 148 } |
149 CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix, FX_INT32 s
tartRow, FX_INT32 startColumn) | 149 CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix, int32_t st
artRow, int32_t startColumn) |
150 { | 150 { |
151 FX_INT32 height = matrix->GetHeight(); | 151 int32_t height = matrix->GetHeight(); |
152 FX_INT32 width = matrix->GetWidth(); | 152 int32_t width = matrix->GetWidth(); |
153 CFX_PtrArray* result = FX_NEW CFX_PtrArray; | 153 CFX_PtrArray* result = FX_NEW CFX_PtrArray; |
154 result->SetSize(8); | 154 result->SetSize(8); |
155 CFX_PtrArray* startptr = findRowsWithPattern(matrix, height, width, startRo
w, startColumn, START_PATTERN, sizeof(START_PATTERN) / sizeof(START_PATTERN[0]))
; | 155 CFX_PtrArray* startptr = findRowsWithPattern(matrix, height, width, startRo
w, startColumn, START_PATTERN, sizeof(START_PATTERN) / sizeof(START_PATTERN[0]))
; |
156 copyToResult(result, startptr, INDEXES_START_PATTERN, sizeof(INDEXES_START_P
ATTERN) / sizeof(INDEXES_START_PATTERN[0])); | 156 copyToResult(result, startptr, INDEXES_START_PATTERN, sizeof(INDEXES_START_P
ATTERN) / sizeof(INDEXES_START_PATTERN[0])); |
157 startptr->RemoveAll(); | 157 startptr->RemoveAll(); |
158 delete startptr; | 158 delete startptr; |
159 if (result->GetAt(4) != NULL) { | 159 if (result->GetAt(4) != NULL) { |
160 startColumn = (FX_INT32) ((CBC_ResultPoint*)result->GetAt(4))->GetX(); | 160 startColumn = (int32_t) ((CBC_ResultPoint*)result->GetAt(4))->GetX(); |
161 startRow = (FX_INT32) ((CBC_ResultPoint*)result->GetAt(4))->GetY(); | 161 startRow = (int32_t) ((CBC_ResultPoint*)result->GetAt(4))->GetY(); |
162 } | 162 } |
163 CFX_PtrArray* stopptr = findRowsWithPattern(matrix, height, width, startRow
, startColumn, STOP_PATTERN, sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0])); | 163 CFX_PtrArray* stopptr = findRowsWithPattern(matrix, height, width, startRow
, startColumn, STOP_PATTERN, sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0])); |
164 copyToResult(result, stopptr, INDEXES_STOP_PATTERN, sizeof(INDEXES_STOP_PATT
ERN) / sizeof(INDEXES_STOP_PATTERN[0])); | 164 copyToResult(result, stopptr, INDEXES_STOP_PATTERN, sizeof(INDEXES_STOP_PATT
ERN) / sizeof(INDEXES_STOP_PATTERN[0])); |
165 stopptr->RemoveAll(); | 165 stopptr->RemoveAll(); |
166 delete stopptr; | 166 delete stopptr; |
167 return result; | 167 return result; |
168 } | 168 } |
169 void CBC_Detector::copyToResult(CFX_PtrArray *result, CFX_PtrArray* tmpResult, F
X_INT32* destinationIndexes, FX_INT32 destinationLength) | 169 void CBC_Detector::copyToResult(CFX_PtrArray *result, CFX_PtrArray* tmpResult, i
nt32_t* destinationIndexes, int32_t destinationLength) |
170 { | 170 { |
171 for (FX_INT32 i = 0; i < destinationLength; i++) { | 171 for (int32_t i = 0; i < destinationLength; i++) { |
172 result->SetAt(destinationIndexes[i], tmpResult->GetAt(i)); | 172 result->SetAt(destinationIndexes[i], tmpResult->GetAt(i)); |
173 } | 173 } |
174 } | 174 } |
175 CFX_PtrArray* CBC_Detector::findRowsWithPattern(CBC_CommonBitMatrix* matrix, FX_
INT32 height, FX_INT32 width, FX_INT32 startRow, FX_INT32 startColumn, FX_INT32*
pattern, FX_INT32 patternLength) | 175 CFX_PtrArray* CBC_Detector::findRowsWithPattern(CBC_CommonBitMatrix* matrix, int
32_t height, int32_t width, int32_t startRow, int32_t startColumn, int32_t* patt
ern, int32_t patternLength) |
176 { | 176 { |
177 CFX_PtrArray* result = FX_NEW CFX_PtrArray; | 177 CFX_PtrArray* result = FX_NEW CFX_PtrArray; |
178 result->SetSize(4); | 178 result->SetSize(4); |
179 FX_BOOL found = FALSE; | 179 FX_BOOL found = FALSE; |
180 CFX_Int32Array counters; | 180 CFX_Int32Array counters; |
181 counters.SetSize(patternLength); | 181 counters.SetSize(patternLength); |
182 for (; startRow < height; startRow += ROW_STEP) { | 182 for (; startRow < height; startRow += ROW_STEP) { |
183 CFX_Int32Array* loc = findGuardPattern(matrix, startColumn, startRow, wi
dth, FALSE, pattern, patternLength, counters); | 183 CFX_Int32Array* loc = findGuardPattern(matrix, startColumn, startRow, wi
dth, FALSE, pattern, patternLength, counters); |
184 if (loc != NULL) { | 184 if (loc != NULL) { |
185 while (startRow > 0) { | 185 while (startRow > 0) { |
186 CFX_Int32Array* previousRowLoc = findGuardPattern(matrix, startC
olumn, --startRow, width, FALSE, pattern, patternLength, counters); | 186 CFX_Int32Array* previousRowLoc = findGuardPattern(matrix, startC
olumn, --startRow, width, FALSE, pattern, patternLength, counters); |
187 if (previousRowLoc != NULL) { | 187 if (previousRowLoc != NULL) { |
188 delete loc; | 188 delete loc; |
189 loc = previousRowLoc; | 189 loc = previousRowLoc; |
190 } else { | 190 } else { |
191 startRow++; | 191 startRow++; |
192 break; | 192 break; |
193 } | 193 } |
194 } | 194 } |
195 result->SetAt(0, FX_NEW CBC_ResultPoint((FX_FLOAT)loc->GetAt(0), (FX
_FLOAT)startRow)); | 195 result->SetAt(0, FX_NEW CBC_ResultPoint((FX_FLOAT)loc->GetAt(0), (FX
_FLOAT)startRow)); |
196 result->SetAt(1, FX_NEW CBC_ResultPoint((FX_FLOAT)loc->GetAt(1), (FX
_FLOAT)startRow)); | 196 result->SetAt(1, FX_NEW CBC_ResultPoint((FX_FLOAT)loc->GetAt(1), (FX
_FLOAT)startRow)); |
197 found = TRUE; | 197 found = TRUE; |
198 delete loc; | 198 delete loc; |
199 break; | 199 break; |
200 } | 200 } |
201 } | 201 } |
202 FX_INT32 stopRow = startRow + 1; | 202 int32_t stopRow = startRow + 1; |
203 if (found) { | 203 if (found) { |
204 FX_INT32 skippedRowCount = 0; | 204 int32_t skippedRowCount = 0; |
205 CFX_Int32Array previousRowLoc; | 205 CFX_Int32Array previousRowLoc; |
206 previousRowLoc.Add((FX_INT32)((CBC_ResultPoint*)result->GetAt(0))->GetX(
)); | 206 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(0))->GetX()
); |
207 previousRowLoc.Add((FX_INT32)((CBC_ResultPoint*)result->GetAt(1))->GetX(
)); | 207 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(1))->GetX()
); |
208 for (; stopRow < height; stopRow++) { | 208 for (; stopRow < height; stopRow++) { |
209 CFX_Int32Array* loc = findGuardPattern(matrix, previousRowLoc[0], st
opRow, width, FALSE, pattern, patternLength, counters); | 209 CFX_Int32Array* loc = findGuardPattern(matrix, previousRowLoc[0], st
opRow, width, FALSE, pattern, patternLength, counters); |
210 if (loc != NULL && | 210 if (loc != NULL && |
211 abs(previousRowLoc[0] - loc->GetAt(0)) < MAX_PATTERN_DRIFT &
& | 211 abs(previousRowLoc[0] - loc->GetAt(0)) < MAX_PATTERN_DRIFT &
& |
212 abs(previousRowLoc[1] - loc->GetAt(1)) < MAX_PATTERN_DRIFT)
{ | 212 abs(previousRowLoc[1] - loc->GetAt(1)) < MAX_PATTERN_DRIFT)
{ |
213 previousRowLoc.Copy(*loc); | 213 previousRowLoc.Copy(*loc); |
214 skippedRowCount = 0; | 214 skippedRowCount = 0; |
215 } else { | 215 } else { |
216 if (skippedRowCount > SKIPPED_ROW_COUNT_MAX) { | 216 if (skippedRowCount > SKIPPED_ROW_COUNT_MAX) { |
217 delete loc; | 217 delete loc; |
218 break; | 218 break; |
219 } else { | 219 } else { |
220 skippedRowCount++; | 220 skippedRowCount++; |
221 } | 221 } |
222 } | 222 } |
223 delete loc; | 223 delete loc; |
224 } | 224 } |
225 stopRow -= skippedRowCount + 1; | 225 stopRow -= skippedRowCount + 1; |
226 result->SetAt(2, FX_NEW CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(0
), (FX_FLOAT)stopRow)); | 226 result->SetAt(2, FX_NEW CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(0
), (FX_FLOAT)stopRow)); |
227 result->SetAt(3, FX_NEW CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(1
), (FX_FLOAT)stopRow)); | 227 result->SetAt(3, FX_NEW CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(1
), (FX_FLOAT)stopRow)); |
228 } | 228 } |
229 if (stopRow - startRow < BARCODE_MIN_HEIGHT) { | 229 if (stopRow - startRow < BARCODE_MIN_HEIGHT) { |
230 for (FX_INT32 i = 0; i < result->GetSize(); i++) { | 230 for (int32_t i = 0; i < result->GetSize(); i++) { |
231 result->SetAt(i, NULL); | 231 result->SetAt(i, NULL); |
232 } | 232 } |
233 } | 233 } |
234 return result; | 234 return result; |
235 } | 235 } |
236 CFX_Int32Array* CBC_Detector::findGuardPattern(CBC_CommonBitMatrix* matrix, FX_I
NT32 column, FX_INT32 row, FX_INT32 width, FX_BOOL whiteFirst, FX_INT32* pattern
, FX_INT32 patternLength, CFX_Int32Array &counters) | 236 CFX_Int32Array* CBC_Detector::findGuardPattern(CBC_CommonBitMatrix* matrix, int3
2_t column, int32_t row, int32_t width, FX_BOOL whiteFirst, int32_t* pattern, in
t32_t patternLength, CFX_Int32Array &counters) |
237 { | 237 { |
238 for (FX_INT32 i = 0; i < counters.GetSize(); i++) { | 238 for (int32_t i = 0; i < counters.GetSize(); i++) { |
239 counters.SetAt(i, 0); | 239 counters.SetAt(i, 0); |
240 } | 240 } |
241 FX_BOOL isWhite = whiteFirst; | 241 FX_BOOL isWhite = whiteFirst; |
242 FX_INT32 patternStart = column; | 242 int32_t patternStart = column; |
243 FX_INT32 pixelDrift = 0; | 243 int32_t pixelDrift = 0; |
244 CFX_Int32Array* intarray = FX_NEW CFX_Int32Array; | 244 CFX_Int32Array* intarray = FX_NEW CFX_Int32Array; |
245 while (matrix->Get(patternStart, row) && patternStart > 0 && pixelDrift++ <
MAX_PIXEL_DRIFT) { | 245 while (matrix->Get(patternStart, row) && patternStart > 0 && pixelDrift++ <
MAX_PIXEL_DRIFT) { |
246 patternStart--; | 246 patternStart--; |
247 } | 247 } |
248 FX_INT32 x = patternStart; | 248 int32_t x = patternStart; |
249 FX_INT32 counterPosition = 0; | 249 int32_t counterPosition = 0; |
250 for (; x < width; x++) { | 250 for (; x < width; x++) { |
251 FX_BOOL pixel = matrix->Get(x, row); | 251 FX_BOOL pixel = matrix->Get(x, row); |
252 if (pixel ^ isWhite) { | 252 if (pixel ^ isWhite) { |
253 counters[counterPosition]++; | 253 counters[counterPosition]++; |
254 } else { | 254 } else { |
255 if (counterPosition == patternLength - 1) { | 255 if (counterPosition == patternLength - 1) { |
256 if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIA
NCE) < MAX_AVG_VARIANCE) { | 256 if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIA
NCE) < MAX_AVG_VARIANCE) { |
257 intarray->Add(patternStart); | 257 intarray->Add(patternStart); |
258 intarray->Add(x); | 258 intarray->Add(x); |
259 return intarray; | 259 return intarray; |
260 } | 260 } |
261 patternStart += counters[0] + counters[1]; | 261 patternStart += counters[0] + counters[1]; |
262 for (FX_INT32 l = 2, k = 0; l < patternLength; l++, k++) { | 262 for (int32_t l = 2, k = 0; l < patternLength; l++, k++) { |
263 counters.SetAt(k, counters.GetAt(l)); | 263 counters.SetAt(k, counters.GetAt(l)); |
264 } | 264 } |
265 counters.SetAt(patternLength - 2, 0); | 265 counters.SetAt(patternLength - 2, 0); |
266 counters.SetAt(patternLength - 1, 0); | 266 counters.SetAt(patternLength - 1, 0); |
267 counterPosition--; | 267 counterPosition--; |
268 } else { | 268 } else { |
269 counterPosition++; | 269 counterPosition++; |
270 } | 270 } |
271 counters[counterPosition] = 1; | 271 counters[counterPosition] = 1; |
272 isWhite = !isWhite; | 272 isWhite = !isWhite; |
273 } | 273 } |
274 } | 274 } |
275 if (counterPosition == patternLength - 1) { | 275 if (counterPosition == patternLength - 1) { |
276 if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < M
AX_AVG_VARIANCE) { | 276 if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < M
AX_AVG_VARIANCE) { |
277 intarray->Add(patternStart); | 277 intarray->Add(patternStart); |
278 intarray->Add(x - 1); | 278 intarray->Add(x - 1); |
279 return intarray; | 279 return intarray; |
280 } | 280 } |
281 } | 281 } |
282 delete intarray; | 282 delete intarray; |
283 return NULL; | 283 return NULL; |
284 } | 284 } |
285 FX_INT32 CBC_Detector::patternMatchVariance(CFX_Int32Array &counters, FX_INT32*
pattern, FX_INT32 maxIndividualVariance) | 285 int32_t CBC_Detector::patternMatchVariance(CFX_Int32Array &counters, int32_t* pa
ttern, int32_t maxIndividualVariance) |
286 { | 286 { |
287 FX_INT32 numCounters = counters.GetSize(); | 287 int32_t numCounters = counters.GetSize(); |
288 FX_INT32 total = 0; | 288 int32_t total = 0; |
289 FX_INT32 patternLength = 0; | 289 int32_t patternLength = 0; |
290 for (FX_INT32 i = 0; i < numCounters; i++) { | 290 for (int32_t i = 0; i < numCounters; i++) { |
291 total += counters[i]; | 291 total += counters[i]; |
292 patternLength += pattern[i]; | 292 patternLength += pattern[i]; |
293 } | 293 } |
294 if (total < patternLength) { | 294 if (total < patternLength) { |
295 return INTERGER_MAX; | 295 return INTERGER_MAX; |
296 } | 296 } |
297 FX_INT32 unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength; | 297 int32_t unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength; |
298 maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MA
TH_SHIFT; | 298 maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MA
TH_SHIFT; |
299 FX_INT32 totalVariance = 0; | 299 int32_t totalVariance = 0; |
300 for (FX_INT32 x = 0; x < numCounters; x++) { | 300 for (int32_t x = 0; x < numCounters; x++) { |
301 FX_INT32 counter = counters[x] << INTEGER_MATH_SHIFT; | 301 int32_t counter = counters[x] << INTEGER_MATH_SHIFT; |
302 FX_INT32 scaledPattern = pattern[x] * unitBarWidth; | 302 int32_t scaledPattern = pattern[x] * unitBarWidth; |
303 FX_INT32 variance = counter > scaledPattern ? counter - scaledPattern :
scaledPattern - counter; | 303 int32_t variance = counter > scaledPattern ? counter - scaledPattern : s
caledPattern - counter; |
304 if (variance > maxIndividualVariance) { | 304 if (variance > maxIndividualVariance) { |
305 return INTERGER_MAX; | 305 return INTERGER_MAX; |
306 } | 306 } |
307 totalVariance += variance; | 307 totalVariance += variance; |
308 } | 308 } |
309 return totalVariance / total; | 309 return totalVariance / total; |
310 } | 310 } |
311 | 311 |
OLD | NEW |