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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (vertices) { | 114 if (vertices) { |
115 delete (vertices); | 115 delete (vertices); |
116 } | 116 } |
117 break; | 117 break; |
118 } | 118 } |
119 foundBarcodeInRow = FALSE; | 119 foundBarcodeInRow = FALSE; |
120 column = 0; | 120 column = 0; |
121 for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) { | 121 for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) { |
122 CFX_PtrArray* barcodeCoordinate = | 122 CFX_PtrArray* barcodeCoordinate = |
123 (CFX_PtrArray*)barcodeCoordinates->GetAt(i); | 123 (CFX_PtrArray*)barcodeCoordinates->GetAt(i); |
124 if (barcodeCoordinate->GetAt(1) != NULL) { | 124 if (barcodeCoordinate->GetAt(1)) { |
125 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(1))->GetY(); | 125 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(1))->GetY(); |
126 } | 126 } |
127 if (barcodeCoordinate->GetAt(3) != NULL) { | 127 if (barcodeCoordinate->GetAt(3)) { |
128 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(3))->GetY(); | 128 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(3))->GetY(); |
129 } | 129 } |
130 } | 130 } |
131 row += ROW_STEP; | 131 row += ROW_STEP; |
132 if (vertices) { | 132 if (vertices) { |
133 delete (vertices); | 133 delete (vertices); |
134 } | 134 } |
135 continue; | 135 continue; |
136 } | 136 } |
137 foundBarcodeInRow = TRUE; | 137 foundBarcodeInRow = TRUE; |
138 barcodeCoordinates->Add(vertices); | 138 barcodeCoordinates->Add(vertices); |
139 if (!multiple) { | 139 if (!multiple) { |
140 break; | 140 break; |
141 } | 141 } |
142 if (vertices->GetAt(2) != NULL) { | 142 if (vertices->GetAt(2)) { |
143 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetX(); | 143 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetX(); |
144 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetY(); | 144 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetY(); |
145 } else { | 145 } else { |
146 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetX(); | 146 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetX(); |
147 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetY(); | 147 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetY(); |
148 } | 148 } |
149 } | 149 } |
150 return barcodeCoordinates; | 150 return barcodeCoordinates; |
151 } | 151 } |
152 CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix, | 152 CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix, |
153 int32_t startRow, | 153 int32_t startRow, |
154 int32_t startColumn) { | 154 int32_t startColumn) { |
155 int32_t height = matrix->GetHeight(); | 155 int32_t height = matrix->GetHeight(); |
156 int32_t width = matrix->GetWidth(); | 156 int32_t width = matrix->GetWidth(); |
157 CFX_PtrArray* result = new CFX_PtrArray; | 157 CFX_PtrArray* result = new CFX_PtrArray; |
158 result->SetSize(8); | 158 result->SetSize(8); |
159 CFX_PtrArray* startptr = findRowsWithPattern( | 159 CFX_PtrArray* startptr = findRowsWithPattern( |
160 matrix, height, width, startRow, startColumn, START_PATTERN, | 160 matrix, height, width, startRow, startColumn, START_PATTERN, |
161 sizeof(START_PATTERN) / sizeof(START_PATTERN[0])); | 161 sizeof(START_PATTERN) / sizeof(START_PATTERN[0])); |
162 copyToResult( | 162 copyToResult( |
163 result, startptr, INDEXES_START_PATTERN, | 163 result, startptr, INDEXES_START_PATTERN, |
164 sizeof(INDEXES_START_PATTERN) / sizeof(INDEXES_START_PATTERN[0])); | 164 sizeof(INDEXES_START_PATTERN) / sizeof(INDEXES_START_PATTERN[0])); |
165 startptr->RemoveAll(); | 165 startptr->RemoveAll(); |
166 delete startptr; | 166 delete startptr; |
167 if (result->GetAt(4) != NULL) { | 167 if (result->GetAt(4)) { |
168 startColumn = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetX(); | 168 startColumn = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetX(); |
169 startRow = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetY(); | 169 startRow = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetY(); |
170 } | 170 } |
171 CFX_PtrArray* stopptr = findRowsWithPattern( | 171 CFX_PtrArray* stopptr = findRowsWithPattern( |
172 matrix, height, width, startRow, startColumn, STOP_PATTERN, | 172 matrix, height, width, startRow, startColumn, STOP_PATTERN, |
173 sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0])); | 173 sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0])); |
174 copyToResult(result, stopptr, INDEXES_STOP_PATTERN, | 174 copyToResult(result, stopptr, INDEXES_STOP_PATTERN, |
175 sizeof(INDEXES_STOP_PATTERN) / sizeof(INDEXES_STOP_PATTERN[0])); | 175 sizeof(INDEXES_STOP_PATTERN) / sizeof(INDEXES_STOP_PATTERN[0])); |
176 stopptr->RemoveAll(); | 176 stopptr->RemoveAll(); |
177 delete stopptr; | 177 delete stopptr; |
(...skipping 16 matching lines...) Expand all Loading... |
194 int32_t patternLength) { | 194 int32_t patternLength) { |
195 CFX_PtrArray* result = new CFX_PtrArray; | 195 CFX_PtrArray* result = new CFX_PtrArray; |
196 result->SetSize(4); | 196 result->SetSize(4); |
197 FX_BOOL found = FALSE; | 197 FX_BOOL found = FALSE; |
198 CFX_Int32Array counters; | 198 CFX_Int32Array counters; |
199 counters.SetSize(patternLength); | 199 counters.SetSize(patternLength); |
200 for (; startRow < height; startRow += ROW_STEP) { | 200 for (; startRow < height; startRow += ROW_STEP) { |
201 CFX_Int32Array* loc = | 201 CFX_Int32Array* loc = |
202 findGuardPattern(matrix, startColumn, startRow, width, FALSE, pattern, | 202 findGuardPattern(matrix, startColumn, startRow, width, FALSE, pattern, |
203 patternLength, counters); | 203 patternLength, counters); |
204 if (loc != NULL) { | 204 if (loc) { |
205 while (startRow > 0) { | 205 while (startRow > 0) { |
206 CFX_Int32Array* previousRowLoc = | 206 CFX_Int32Array* previousRowLoc = |
207 findGuardPattern(matrix, startColumn, --startRow, width, FALSE, | 207 findGuardPattern(matrix, startColumn, --startRow, width, FALSE, |
208 pattern, patternLength, counters); | 208 pattern, patternLength, counters); |
209 if (previousRowLoc != NULL) { | 209 if (previousRowLoc) { |
210 delete loc; | 210 delete loc; |
211 loc = previousRowLoc; | 211 loc = previousRowLoc; |
212 } else { | 212 } else { |
213 startRow++; | 213 startRow++; |
214 break; | 214 break; |
215 } | 215 } |
216 } | 216 } |
217 result->SetAt( | 217 result->SetAt( |
218 0, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(0), (FX_FLOAT)startRow)); | 218 0, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(0), (FX_FLOAT)startRow)); |
219 result->SetAt( | 219 result->SetAt( |
220 1, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(1), (FX_FLOAT)startRow)); | 220 1, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(1), (FX_FLOAT)startRow)); |
221 found = TRUE; | 221 found = TRUE; |
222 delete loc; | 222 delete loc; |
223 break; | 223 break; |
224 } | 224 } |
225 } | 225 } |
226 int32_t stopRow = startRow + 1; | 226 int32_t stopRow = startRow + 1; |
227 if (found) { | 227 if (found) { |
228 int32_t skippedRowCount = 0; | 228 int32_t skippedRowCount = 0; |
229 CFX_Int32Array previousRowLoc; | 229 CFX_Int32Array previousRowLoc; |
230 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(0))->GetX()); | 230 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(0))->GetX()); |
231 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(1))->GetX()); | 231 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(1))->GetX()); |
232 for (; stopRow < height; stopRow++) { | 232 for (; stopRow < height; stopRow++) { |
233 CFX_Int32Array* loc = | 233 CFX_Int32Array* loc = |
234 findGuardPattern(matrix, previousRowLoc[0], stopRow, width, FALSE, | 234 findGuardPattern(matrix, previousRowLoc[0], stopRow, width, FALSE, |
235 pattern, patternLength, counters); | 235 pattern, patternLength, counters); |
236 if (loc != NULL && | 236 if (loc && abs(previousRowLoc[0] - loc->GetAt(0)) < MAX_PATTERN_DRIFT && |
237 abs(previousRowLoc[0] - loc->GetAt(0)) < MAX_PATTERN_DRIFT && | |
238 abs(previousRowLoc[1] - loc->GetAt(1)) < MAX_PATTERN_DRIFT) { | 237 abs(previousRowLoc[1] - loc->GetAt(1)) < MAX_PATTERN_DRIFT) { |
239 previousRowLoc.Copy(*loc); | 238 previousRowLoc.Copy(*loc); |
240 skippedRowCount = 0; | 239 skippedRowCount = 0; |
241 } else { | 240 } else { |
242 if (skippedRowCount > SKIPPED_ROW_COUNT_MAX) { | 241 if (skippedRowCount > SKIPPED_ROW_COUNT_MAX) { |
243 delete loc; | 242 delete loc; |
244 break; | 243 break; |
245 } else { | 244 } else { |
246 skippedRowCount++; | 245 skippedRowCount++; |
247 } | 246 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 int32_t scaledPattern = pattern[x] * unitBarWidth; | 340 int32_t scaledPattern = pattern[x] * unitBarWidth; |
342 int32_t variance = counter > scaledPattern ? counter - scaledPattern | 341 int32_t variance = counter > scaledPattern ? counter - scaledPattern |
343 : scaledPattern - counter; | 342 : scaledPattern - counter; |
344 if (variance > maxIndividualVariance) { | 343 if (variance > maxIndividualVariance) { |
345 return INTERGER_MAX; | 344 return INTERGER_MAX; |
346 } | 345 } |
347 totalVariance += variance; | 346 totalVariance += variance; |
348 } | 347 } |
349 return totalVariance / total; | 348 return totalVariance / total; |
350 } | 349 } |
OLD | NEW |