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 2007 ZXing authors | 8 * Copyright 2007 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 "../barcode.h" | 23 #include "../barcode.h" |
24 #include "../BC_ResultPoint.h" | 24 #include "../BC_ResultPoint.h" |
25 #include "../common/BC_CommonBitMatrix.h" | 25 #include "../common/BC_CommonBitMatrix.h" |
26 #include "BC_QRFinderPatternFinder.h" | 26 #include "BC_QRFinderPatternFinder.h" |
27 #include "BC_FinderPatternInfo.h" | 27 #include "BC_FinderPatternInfo.h" |
28 #include "BC_QRFinderPattern.h" | 28 #include "BC_QRFinderPattern.h" |
29 const FX_INT32 CBC_QRFinderPatternFinder::CENTER_QUORUM = 2; | 29 const int32_t CBC_QRFinderPatternFinder::CENTER_QUORUM = 2; |
30 const FX_INT32 CBC_QRFinderPatternFinder::MIN_SKIP = 3; | 30 const int32_t CBC_QRFinderPatternFinder::MIN_SKIP = 3; |
31 const FX_INT32 CBC_QRFinderPatternFinder::MAX_MODULES = 57; | 31 const int32_t CBC_QRFinderPatternFinder::MAX_MODULES = 57; |
32 const FX_INT32 CBC_QRFinderPatternFinder::INTEGER_MATH_SHIFT = 8; | 32 const int32_t CBC_QRFinderPatternFinder::INTEGER_MATH_SHIFT = 8; |
33 CBC_QRFinderPatternFinder::CBC_QRFinderPatternFinder(CBC_CommonBitMatrix* image) | 33 CBC_QRFinderPatternFinder::CBC_QRFinderPatternFinder(CBC_CommonBitMatrix* image) |
34 { | 34 { |
35 m_image = image; | 35 m_image = image; |
36 m_crossCheckStateCount.SetSize(5); | 36 m_crossCheckStateCount.SetSize(5); |
37 m_hasSkipped = FALSE; | 37 m_hasSkipped = FALSE; |
38 } | 38 } |
39 CBC_QRFinderPatternFinder::~CBC_QRFinderPatternFinder() | 39 CBC_QRFinderPatternFinder::~CBC_QRFinderPatternFinder() |
40 { | 40 { |
41 for(FX_INT32 i = 0; i < m_possibleCenters.GetSize(); i++) { | 41 for(int32_t i = 0; i < m_possibleCenters.GetSize(); i++) { |
42 delete (CBC_QRFinderPattern*)m_possibleCenters[i]; | 42 delete (CBC_QRFinderPattern*)m_possibleCenters[i]; |
43 } | 43 } |
44 m_possibleCenters.RemoveAll(); | 44 m_possibleCenters.RemoveAll(); |
45 } | 45 } |
46 class ClosestToAverageComparator | 46 class ClosestToAverageComparator |
47 { | 47 { |
48 private: | 48 private: |
49 FX_FLOAT m_averageModuleSize; | 49 FX_FLOAT m_averageModuleSize; |
50 public: | 50 public: |
51 ClosestToAverageComparator(FX_FLOAT averageModuleSize) : m_averageModuleSize
(averageModuleSize) | 51 ClosestToAverageComparator(FX_FLOAT averageModuleSize) : m_averageModuleSize
(averageModuleSize) |
52 { | 52 { |
53 } | 53 } |
54 FX_INT32 operator()(FinderPattern *a, FinderPattern *b) | 54 int32_t operator()(FinderPattern *a, FinderPattern *b) |
55 { | 55 { |
56 FX_FLOAT dA = (FX_FLOAT)fabs(a->GetEstimatedModuleSize() - m_averageModu
leSize); | 56 FX_FLOAT dA = (FX_FLOAT)fabs(a->GetEstimatedModuleSize() - m_averageModu
leSize); |
57 FX_FLOAT dB = (FX_FLOAT)fabs(b->GetEstimatedModuleSize() - m_averageModu
leSize); | 57 FX_FLOAT dB = (FX_FLOAT)fabs(b->GetEstimatedModuleSize() - m_averageModu
leSize); |
58 return dA < dB ? -1 : dA > dB ? 1 : 0; | 58 return dA < dB ? -1 : dA > dB ? 1 : 0; |
59 } | 59 } |
60 }; | 60 }; |
61 class CenterComparator | 61 class CenterComparator |
62 { | 62 { |
63 public: | 63 public: |
64 FX_INT32 operator()(FinderPattern *a, FinderPattern *b) | 64 int32_t operator()(FinderPattern *a, FinderPattern *b) |
65 { | 65 { |
66 return b->GetCount() - a->GetCount(); | 66 return b->GetCount() - a->GetCount(); |
67 } | 67 } |
68 }; | 68 }; |
69 CBC_CommonBitMatrix *CBC_QRFinderPatternFinder::GetImage() | 69 CBC_CommonBitMatrix *CBC_QRFinderPatternFinder::GetImage() |
70 { | 70 { |
71 return m_image; | 71 return m_image; |
72 } | 72 } |
73 CFX_Int32Array &CBC_QRFinderPatternFinder::GetCrossCheckStateCount() | 73 CFX_Int32Array &CBC_QRFinderPatternFinder::GetCrossCheckStateCount() |
74 { | 74 { |
75 m_crossCheckStateCount[0] = 0; | 75 m_crossCheckStateCount[0] = 0; |
76 m_crossCheckStateCount[1] = 0; | 76 m_crossCheckStateCount[1] = 0; |
77 m_crossCheckStateCount[2] = 0; | 77 m_crossCheckStateCount[2] = 0; |
78 m_crossCheckStateCount[3] = 0; | 78 m_crossCheckStateCount[3] = 0; |
79 m_crossCheckStateCount[4] = 0; | 79 m_crossCheckStateCount[4] = 0; |
80 return m_crossCheckStateCount; | 80 return m_crossCheckStateCount; |
81 } | 81 } |
82 CFX_PtrArray *CBC_QRFinderPatternFinder::GetPossibleCenters() | 82 CFX_PtrArray *CBC_QRFinderPatternFinder::GetPossibleCenters() |
83 { | 83 { |
84 return &m_possibleCenters; | 84 return &m_possibleCenters; |
85 } | 85 } |
86 CBC_QRFinderPatternInfo* CBC_QRFinderPatternFinder::Find(FX_INT32 hint, FX_INT32
&e) | 86 CBC_QRFinderPatternInfo* CBC_QRFinderPatternFinder::Find(int32_t hint, int32_t &
e) |
87 { | 87 { |
88 FX_INT32 maxI = m_image->GetHeight(); | 88 int32_t maxI = m_image->GetHeight(); |
89 FX_INT32 maxJ = m_image->GetWidth(); | 89 int32_t maxJ = m_image->GetWidth(); |
90 FX_INT32 iSkip = (3 * maxI) / (4 * MAX_MODULES); | 90 int32_t iSkip = (3 * maxI) / (4 * MAX_MODULES); |
91 if(iSkip < MIN_SKIP || 0) { | 91 if(iSkip < MIN_SKIP || 0) { |
92 iSkip = MIN_SKIP; | 92 iSkip = MIN_SKIP; |
93 } | 93 } |
94 FX_BOOL done = FALSE; | 94 FX_BOOL done = FALSE; |
95 CFX_Int32Array stateCount; | 95 CFX_Int32Array stateCount; |
96 stateCount.SetSize(5); | 96 stateCount.SetSize(5); |
97 for(FX_INT32 i = iSkip - 1; i < maxI && !done; i += iSkip) { | 97 for(int32_t i = iSkip - 1; i < maxI && !done; i += iSkip) { |
98 stateCount[0] = 0; | 98 stateCount[0] = 0; |
99 stateCount[1] = 0; | 99 stateCount[1] = 0; |
100 stateCount[2] = 0; | 100 stateCount[2] = 0; |
101 stateCount[3] = 0; | 101 stateCount[3] = 0; |
102 stateCount[4] = 0; | 102 stateCount[4] = 0; |
103 FX_INT32 currentState = 0; | 103 int32_t currentState = 0; |
104 for(FX_INT32 j = 0; j < maxJ; j++) { | 104 for(int32_t j = 0; j < maxJ; j++) { |
105 if(m_image->Get(j, i)) { | 105 if(m_image->Get(j, i)) { |
106 if((currentState & 1) == 1) { | 106 if((currentState & 1) == 1) { |
107 currentState++; | 107 currentState++; |
108 } | 108 } |
109 stateCount[currentState]++; | 109 stateCount[currentState]++; |
110 } else { | 110 } else { |
111 if((currentState & 1) == 0) { | 111 if((currentState & 1) == 0) { |
112 if(currentState == 4) { | 112 if(currentState == 4) { |
113 if(FoundPatternCross(stateCount)) { | 113 if(FoundPatternCross(stateCount)) { |
114 FX_BOOL confirmed = HandlePossibleCenter(stateCount,
i, j); | 114 FX_BOOL confirmed = HandlePossibleCenter(stateCount,
i, j); |
115 if(confirmed) { | 115 if(confirmed) { |
116 iSkip = 2; | 116 iSkip = 2; |
117 if(m_hasSkipped) { | 117 if(m_hasSkipped) { |
118 done = HaveMultiplyConfirmedCenters(); | 118 done = HaveMultiplyConfirmedCenters(); |
119 } else { | 119 } else { |
120 FX_INT32 rowSkip = FindRowSkip(); | 120 int32_t rowSkip = FindRowSkip(); |
121 if(rowSkip > stateCount[2]) { | 121 if(rowSkip > stateCount[2]) { |
122 i += rowSkip - stateCount[2] - iSkip; | 122 i += rowSkip - stateCount[2] - iSkip; |
123 j = maxJ - 1; | 123 j = maxJ - 1; |
124 } | 124 } |
125 } | 125 } |
126 } else { | 126 } else { |
127 do { | 127 do { |
128 j++; | 128 j++; |
129 } while (j < maxJ && !m_image->Get(j, i)); | 129 } while (j < maxJ && !m_image->Get(j, i)); |
130 j--; | 130 j--; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 (*patterns)[0] = bottomLeft; | 195 (*patterns)[0] = bottomLeft; |
196 (*patterns)[1] = topLeft; | 196 (*patterns)[1] = topLeft; |
197 (*patterns)[2] = topRight; | 197 (*patterns)[2] = topRight; |
198 } | 198 } |
199 FX_FLOAT CBC_QRFinderPatternFinder::Distance(CBC_ResultPoint* point1, CBC_Result
Point* point2) | 199 FX_FLOAT CBC_QRFinderPatternFinder::Distance(CBC_ResultPoint* point1, CBC_Result
Point* point2) |
200 { | 200 { |
201 FX_FLOAT dx = point1->GetX() - point2->GetX(); | 201 FX_FLOAT dx = point1->GetX() - point2->GetX(); |
202 FX_FLOAT dy = point1->GetY() - point2->GetY(); | 202 FX_FLOAT dy = point1->GetY() - point2->GetY(); |
203 return (FX_FLOAT)FXSYS_sqrt(dx * dx + dy * dy); | 203 return (FX_FLOAT)FXSYS_sqrt(dx * dx + dy * dy); |
204 } | 204 } |
205 FX_FLOAT CBC_QRFinderPatternFinder::CenterFromEnd(const CFX_Int32Array &stateCou
nt, FX_INT32 end) | 205 FX_FLOAT CBC_QRFinderPatternFinder::CenterFromEnd(const CFX_Int32Array &stateCou
nt, int32_t end) |
206 { | 206 { |
207 return (FX_FLOAT)(end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0
f; | 207 return (FX_FLOAT)(end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0
f; |
208 } | 208 } |
209 FX_BOOL CBC_QRFinderPatternFinder::FoundPatternCross(const CFX_Int32Array &state
Count) | 209 FX_BOOL CBC_QRFinderPatternFinder::FoundPatternCross(const CFX_Int32Array &state
Count) |
210 { | 210 { |
211 FX_INT32 totalModuleSize = 0; | 211 int32_t totalModuleSize = 0; |
212 for (FX_INT32 i = 0; i < 5; i++) { | 212 for (int32_t i = 0; i < 5; i++) { |
213 FX_INT32 count = stateCount[i]; | 213 int32_t count = stateCount[i]; |
214 if (count == 0) { | 214 if (count == 0) { |
215 return FALSE; | 215 return FALSE; |
216 } | 216 } |
217 totalModuleSize += count; | 217 totalModuleSize += count; |
218 } | 218 } |
219 if (totalModuleSize < 7) { | 219 if (totalModuleSize < 7) { |
220 return FALSE; | 220 return FALSE; |
221 } | 221 } |
222 FX_INT32 moduleSize = (totalModuleSize << INTEGER_MATH_SHIFT) / 7; | 222 int32_t moduleSize = (totalModuleSize << INTEGER_MATH_SHIFT) / 7; |
223 FX_INT32 maxVariance = moduleSize / 2; | 223 int32_t maxVariance = moduleSize / 2; |
224 return FXSYS_abs(moduleSize - (stateCount[0] << INTEGER_MATH_SHIFT)) < maxVa
riance && | 224 return FXSYS_abs(moduleSize - (stateCount[0] << INTEGER_MATH_SHIFT)) < maxVa
riance && |
225 FXSYS_abs(moduleSize - (stateCount[1] << INTEGER_MATH_SHIFT)) < maxVa
riance && | 225 FXSYS_abs(moduleSize - (stateCount[1] << INTEGER_MATH_SHIFT)) < maxVa
riance && |
226 FXSYS_abs(3 * moduleSize - (stateCount[2] << INTEGER_MATH_SHIFT)) < 3
* maxVariance && | 226 FXSYS_abs(3 * moduleSize - (stateCount[2] << INTEGER_MATH_SHIFT)) < 3
* maxVariance && |
227 FXSYS_abs(moduleSize - (stateCount[3] << INTEGER_MATH_SHIFT)) < maxVa
riance && | 227 FXSYS_abs(moduleSize - (stateCount[3] << INTEGER_MATH_SHIFT)) < maxVa
riance && |
228 FXSYS_abs(moduleSize - (stateCount[4] << INTEGER_MATH_SHIFT)) < maxVa
riance; | 228 FXSYS_abs(moduleSize - (stateCount[4] << INTEGER_MATH_SHIFT)) < maxVa
riance; |
229 } | 229 } |
230 FX_FLOAT CBC_QRFinderPatternFinder::CrossCheckVertical(FX_INT32 startI, FX_INT32
centerJ, FX_INT32 maxCount, | 230 FX_FLOAT CBC_QRFinderPatternFinder::CrossCheckVertical(int32_t startI, int32_t c
enterJ, int32_t maxCount, |
231 FX_INT32 originalStateCountTotal) | 231 int32_t originalStateCountTotal) |
232 { | 232 { |
233 CBC_CommonBitMatrix *image = m_image; | 233 CBC_CommonBitMatrix *image = m_image; |
234 FX_INT32 maxI = image->GetHeight(); | 234 int32_t maxI = image->GetHeight(); |
235 CFX_Int32Array &stateCount = GetCrossCheckStateCount(); | 235 CFX_Int32Array &stateCount = GetCrossCheckStateCount(); |
236 FX_INT32 i = startI; | 236 int32_t i = startI; |
237 while(i >= 0 && image->Get(centerJ, i)) { | 237 while(i >= 0 && image->Get(centerJ, i)) { |
238 stateCount[2]++; | 238 stateCount[2]++; |
239 i--; | 239 i--; |
240 } | 240 } |
241 if(i < 0) { | 241 if(i < 0) { |
242 return FXSYS_nan(); | 242 return FXSYS_nan(); |
243 } | 243 } |
244 while(i >= 0 && !image->Get(centerJ, i) && stateCount[1] <= maxCount) { | 244 while(i >= 0 && !image->Get(centerJ, i) && stateCount[1] <= maxCount) { |
245 stateCount[1]++; | 245 stateCount[1]++; |
246 i--; | 246 i--; |
(...skipping 23 matching lines...) Expand all Loading... |
270 if (i == maxI || stateCount[3] >= maxCount) { | 270 if (i == maxI || stateCount[3] >= maxCount) { |
271 return FXSYS_nan(); | 271 return FXSYS_nan(); |
272 } | 272 } |
273 while (i < maxI && image->Get(centerJ, i) && stateCount[4] < maxCount) { | 273 while (i < maxI && image->Get(centerJ, i) && stateCount[4] < maxCount) { |
274 stateCount[4]++; | 274 stateCount[4]++; |
275 i++; | 275 i++; |
276 } | 276 } |
277 if (stateCount[4] >= maxCount) { | 277 if (stateCount[4] >= maxCount) { |
278 return FXSYS_nan(); | 278 return FXSYS_nan(); |
279 } | 279 } |
280 FX_INT32 stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + s
tateCount[3] + stateCount[4]; | 280 int32_t stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + st
ateCount[3] + stateCount[4]; |
281 if (5 * FXSYS_abs(stateCountTotal - originalStateCountTotal) >= originalStat
eCountTotal) { | 281 if (5 * FXSYS_abs(stateCountTotal - originalStateCountTotal) >= originalStat
eCountTotal) { |
282 return FXSYS_nan(); | 282 return FXSYS_nan(); |
283 } | 283 } |
284 return FoundPatternCross(stateCount) ? CenterFromEnd(stateCount, i) : FXSYS_
nan(); | 284 return FoundPatternCross(stateCount) ? CenterFromEnd(stateCount, i) : FXSYS_
nan(); |
285 } | 285 } |
286 FX_FLOAT CBC_QRFinderPatternFinder::CrossCheckHorizontal(FX_INT32 startJ, FX_INT
32 centerI, FX_INT32 maxCount, FX_INT32 originalStateCountTotal) | 286 FX_FLOAT CBC_QRFinderPatternFinder::CrossCheckHorizontal(int32_t startJ, int32_t
centerI, int32_t maxCount, int32_t originalStateCountTotal) |
287 { | 287 { |
288 CBC_CommonBitMatrix *image = m_image; | 288 CBC_CommonBitMatrix *image = m_image; |
289 FX_INT32 maxJ = image->GetWidth(); | 289 int32_t maxJ = image->GetWidth(); |
290 CFX_Int32Array &stateCount = GetCrossCheckStateCount(); | 290 CFX_Int32Array &stateCount = GetCrossCheckStateCount(); |
291 FX_INT32 j = startJ; | 291 int32_t j = startJ; |
292 while (j >= 0 && image->Get(j, centerI)) { | 292 while (j >= 0 && image->Get(j, centerI)) { |
293 stateCount[2]++; | 293 stateCount[2]++; |
294 j--; | 294 j--; |
295 } | 295 } |
296 if (j < 0) { | 296 if (j < 0) { |
297 return FXSYS_nan(); | 297 return FXSYS_nan(); |
298 } | 298 } |
299 while (j >= 0 && !image->Get(j, centerI) && stateCount[1] <= maxCount) { | 299 while (j >= 0 && !image->Get(j, centerI) && stateCount[1] <= maxCount) { |
300 stateCount[1]++; | 300 stateCount[1]++; |
301 j--; | 301 j--; |
(...skipping 23 matching lines...) Expand all Loading... |
325 if (j == maxJ || stateCount[3] >= maxCount) { | 325 if (j == maxJ || stateCount[3] >= maxCount) { |
326 return FXSYS_nan(); | 326 return FXSYS_nan(); |
327 } | 327 } |
328 while (j < maxJ && image->Get(j, centerI) && stateCount[4] < maxCount) { | 328 while (j < maxJ && image->Get(j, centerI) && stateCount[4] < maxCount) { |
329 stateCount[4]++; | 329 stateCount[4]++; |
330 j++; | 330 j++; |
331 } | 331 } |
332 if (stateCount[4] >= maxCount) { | 332 if (stateCount[4] >= maxCount) { |
333 return FXSYS_nan(); | 333 return FXSYS_nan(); |
334 } | 334 } |
335 FX_INT32 stateCountTotal = stateCount[0] + stateCount[1] + | 335 int32_t stateCountTotal = stateCount[0] + stateCount[1] + |
336 stateCount[2] + stateCount[3] + | 336 stateCount[2] + stateCount[3] + |
337 stateCount[4]; | 337 stateCount[4]; |
338 if (5 * FXSYS_abs(stateCountTotal - originalStateCountTotal) >= originalStat
eCountTotal) { | 338 if (5 * FXSYS_abs(stateCountTotal - originalStateCountTotal) >= originalStat
eCountTotal) { |
339 return FXSYS_nan(); | 339 return FXSYS_nan(); |
340 } | 340 } |
341 return FoundPatternCross(stateCount) ? CenterFromEnd(stateCount, j) : FXSYS_
nan(); | 341 return FoundPatternCross(stateCount) ? CenterFromEnd(stateCount, j) : FXSYS_
nan(); |
342 } | 342 } |
343 FX_BOOL CBC_QRFinderPatternFinder::HandlePossibleCenter(const CFX_Int32Array &st
ateCount, FX_INT32 i, FX_INT32 j) | 343 FX_BOOL CBC_QRFinderPatternFinder::HandlePossibleCenter(const CFX_Int32Array &st
ateCount, int32_t i, int32_t j) |
344 { | 344 { |
345 FX_INT32 stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + s
tateCount[3] + stateCount[4]; | 345 int32_t stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + st
ateCount[3] + stateCount[4]; |
346 FX_FLOAT centerJ = CenterFromEnd(stateCount, j); | 346 FX_FLOAT centerJ = CenterFromEnd(stateCount, j); |
347 FX_FLOAT centerI = CrossCheckVertical(i, (FX_INT32) centerJ, stateCount[2],
stateCountTotal); | 347 FX_FLOAT centerI = CrossCheckVertical(i, (int32_t) centerJ, stateCount[2], s
tateCountTotal); |
348 if(!FXSYS_isnan(centerI)) { | 348 if(!FXSYS_isnan(centerI)) { |
349 centerJ = CrossCheckHorizontal((FX_INT32) centerJ, (FX_INT32) centerI, s
tateCount[2], stateCountTotal); | 349 centerJ = CrossCheckHorizontal((int32_t) centerJ, (int32_t) centerI, sta
teCount[2], stateCountTotal); |
350 if(!FXSYS_isnan(centerJ)) { | 350 if(!FXSYS_isnan(centerJ)) { |
351 FX_FLOAT estimatedModuleSize = (FX_FLOAT) stateCountTotal / 7.0f; | 351 FX_FLOAT estimatedModuleSize = (FX_FLOAT) stateCountTotal / 7.0f; |
352 FX_BOOL found = FALSE; | 352 FX_BOOL found = FALSE; |
353 FX_INT32 max = m_possibleCenters.GetSize(); | 353 int32_t max = m_possibleCenters.GetSize(); |
354 for(FX_INT32 index = 0; index < max; index++) { | 354 for(int32_t index = 0; index < max; index++) { |
355 CBC_QRFinderPattern *center = (CBC_QRFinderPattern*)(m_possibleC
enters[index]); | 355 CBC_QRFinderPattern *center = (CBC_QRFinderPattern*)(m_possibleC
enters[index]); |
356 if(center->AboutEquals(estimatedModuleSize, centerI, centerJ)) { | 356 if(center->AboutEquals(estimatedModuleSize, centerI, centerJ)) { |
357 center->IncrementCount(); | 357 center->IncrementCount(); |
358 found = TRUE; | 358 found = TRUE; |
359 break; | 359 break; |
360 } | 360 } |
361 } | 361 } |
362 if(!found) { | 362 if(!found) { |
363 m_possibleCenters.Add(FX_NEW CBC_QRFinderPattern(centerJ, center
I, estimatedModuleSize)); | 363 m_possibleCenters.Add(FX_NEW CBC_QRFinderPattern(centerJ, center
I, estimatedModuleSize)); |
364 } | 364 } |
365 return TRUE; | 365 return TRUE; |
366 } | 366 } |
367 } | 367 } |
368 return FALSE; | 368 return FALSE; |
369 } | 369 } |
370 FX_INT32 CBC_QRFinderPatternFinder::FindRowSkip() | 370 int32_t CBC_QRFinderPatternFinder::FindRowSkip() |
371 { | 371 { |
372 FX_INT32 max = m_possibleCenters.GetSize(); | 372 int32_t max = m_possibleCenters.GetSize(); |
373 if (max <= 1) { | 373 if (max <= 1) { |
374 return 0; | 374 return 0; |
375 } | 375 } |
376 FinderPattern *firstConfirmedCenter = NULL; | 376 FinderPattern *firstConfirmedCenter = NULL; |
377 for (FX_INT32 i = 0; i < max; i++) { | 377 for (int32_t i = 0; i < max; i++) { |
378 CBC_QRFinderPattern *center = (CBC_QRFinderPattern*)m_possibleCenters[i]
; | 378 CBC_QRFinderPattern *center = (CBC_QRFinderPattern*)m_possibleCenters[i]
; |
379 if (center->GetCount() >= CENTER_QUORUM) { | 379 if (center->GetCount() >= CENTER_QUORUM) { |
380 if (firstConfirmedCenter == NULL) { | 380 if (firstConfirmedCenter == NULL) { |
381 firstConfirmedCenter = center; | 381 firstConfirmedCenter = center; |
382 } else { | 382 } else { |
383 m_hasSkipped = TRUE; | 383 m_hasSkipped = TRUE; |
384 return (FX_INT32) ((fabs(firstConfirmedCenter->GetX() - center->
GetX()) - | 384 return (int32_t) ((fabs(firstConfirmedCenter->GetX() - center->G
etX()) - |
385 fabs(firstConfirmedCenter->GetY() - center->
GetY())) / 2); | 385 fabs(firstConfirmedCenter->GetY() - center->
GetY())) / 2); |
386 } | 386 } |
387 } | 387 } |
388 } | 388 } |
389 return 0; | 389 return 0; |
390 } | 390 } |
391 FX_BOOL CBC_QRFinderPatternFinder::HaveMultiplyConfirmedCenters() | 391 FX_BOOL CBC_QRFinderPatternFinder::HaveMultiplyConfirmedCenters() |
392 { | 392 { |
393 FX_INT32 confirmedCount = 0; | 393 int32_t confirmedCount = 0; |
394 FX_FLOAT totalModuleSize = 0.0f; | 394 FX_FLOAT totalModuleSize = 0.0f; |
395 FX_INT32 max = m_possibleCenters.GetSize(); | 395 int32_t max = m_possibleCenters.GetSize(); |
396 FX_INT32 i; | 396 int32_t i; |
397 for (i = 0; i < max; i++) { | 397 for (i = 0; i < max; i++) { |
398 CBC_QRFinderPattern *pattern = (CBC_QRFinderPattern*)m_possibleCenters[i
]; | 398 CBC_QRFinderPattern *pattern = (CBC_QRFinderPattern*)m_possibleCenters[i
]; |
399 if (pattern->GetCount() >= CENTER_QUORUM) { | 399 if (pattern->GetCount() >= CENTER_QUORUM) { |
400 confirmedCount++; | 400 confirmedCount++; |
401 totalModuleSize += pattern->GetEstimatedModuleSize(); | 401 totalModuleSize += pattern->GetEstimatedModuleSize(); |
402 } | 402 } |
403 } | 403 } |
404 if (confirmedCount < 3) { | 404 if (confirmedCount < 3) { |
405 return FALSE; | 405 return FALSE; |
406 } | 406 } |
407 FX_FLOAT average = totalModuleSize / (FX_FLOAT) max; | 407 FX_FLOAT average = totalModuleSize / (FX_FLOAT) max; |
408 FX_FLOAT totalDeviation = 0.0f; | 408 FX_FLOAT totalDeviation = 0.0f; |
409 for (i = 0; i < max; i++) { | 409 for (i = 0; i < max; i++) { |
410 CBC_QRFinderPattern *pattern = (CBC_QRFinderPattern*)m_possibleCenters[i
]; | 410 CBC_QRFinderPattern *pattern = (CBC_QRFinderPattern*)m_possibleCenters[i
]; |
411 totalDeviation += fabs(pattern->GetEstimatedModuleSize() - average); | 411 totalDeviation += fabs(pattern->GetEstimatedModuleSize() - average); |
412 } | 412 } |
413 return totalDeviation <= 0.05f * totalModuleSize; | 413 return totalDeviation <= 0.05f * totalModuleSize; |
414 } | 414 } |
415 inline FX_BOOL centerComparator(FX_LPVOID a, FX_LPVOID b) | 415 inline FX_BOOL centerComparator(FX_LPVOID a, FX_LPVOID b) |
416 { | 416 { |
417 return ((CBC_QRFinderPattern*)b)->GetCount() < ((CBC_QRFinderPattern*)a)->Ge
tCount(); | 417 return ((CBC_QRFinderPattern*)b)->GetCount() < ((CBC_QRFinderPattern*)a)->Ge
tCount(); |
418 } | 418 } |
419 CFX_PtrArray *CBC_QRFinderPatternFinder::SelectBestpatterns(FX_INT32 &e) | 419 CFX_PtrArray *CBC_QRFinderPatternFinder::SelectBestpatterns(int32_t &e) |
420 { | 420 { |
421 FX_INT32 startSize = m_possibleCenters.GetSize(); | 421 int32_t startSize = m_possibleCenters.GetSize(); |
422 if(m_possibleCenters.GetSize() < 3) { | 422 if(m_possibleCenters.GetSize() < 3) { |
423 e = BCExceptionRead; | 423 e = BCExceptionRead; |
424 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 424 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
425 } | 425 } |
426 FX_FLOAT average = 0.0f; | 426 FX_FLOAT average = 0.0f; |
427 if(startSize > 3) { | 427 if(startSize > 3) { |
428 FX_FLOAT totalModuleSize = 0.0f; | 428 FX_FLOAT totalModuleSize = 0.0f; |
429 for(FX_INT32 i = 0; i < startSize; i++) { | 429 for(int32_t i = 0; i < startSize; i++) { |
430 totalModuleSize += ((CBC_QRFinderPattern*)m_possibleCenters[i])->Get
EstimatedModuleSize(); | 430 totalModuleSize += ((CBC_QRFinderPattern*)m_possibleCenters[i])->Get
EstimatedModuleSize(); |
431 } | 431 } |
432 average = totalModuleSize / (FX_FLOAT)startSize; | 432 average = totalModuleSize / (FX_FLOAT)startSize; |
433 for(FX_INT32 j = 0; j < m_possibleCenters.GetSize() && m_possibleCenters
.GetSize() > 3; j++) { | 433 for(int32_t j = 0; j < m_possibleCenters.GetSize() && m_possibleCenters.
GetSize() > 3; j++) { |
434 CBC_QRFinderPattern *pattern = (CBC_QRFinderPattern*)m_possibleCente
rs[j]; | 434 CBC_QRFinderPattern *pattern = (CBC_QRFinderPattern*)m_possibleCente
rs[j]; |
435 if(fabs(pattern->GetEstimatedModuleSize() - average) > 0.2f * averag
e) { | 435 if(fabs(pattern->GetEstimatedModuleSize() - average) > 0.2f * averag
e) { |
436 delete pattern; | 436 delete pattern; |
437 m_possibleCenters.RemoveAt(j); | 437 m_possibleCenters.RemoveAt(j); |
438 j--; | 438 j--; |
439 } | 439 } |
440 } | 440 } |
441 } | 441 } |
442 if(m_possibleCenters.GetSize() > 3) { | 442 if(m_possibleCenters.GetSize() > 3) { |
443 BC_FX_PtrArray_Sort(m_possibleCenters, centerComparator); | 443 BC_FX_PtrArray_Sort(m_possibleCenters, centerComparator); |
444 } | 444 } |
445 CFX_PtrArray *vec = FX_NEW CFX_PtrArray(); | 445 CFX_PtrArray *vec = FX_NEW CFX_PtrArray(); |
446 vec->SetSize(3); | 446 vec->SetSize(3); |
447 (*vec)[0] = ((CBC_QRFinderPattern*)m_possibleCenters[0])->Clone(); | 447 (*vec)[0] = ((CBC_QRFinderPattern*)m_possibleCenters[0])->Clone(); |
448 (*vec)[1] = ((CBC_QRFinderPattern*)m_possibleCenters[1])->Clone(); | 448 (*vec)[1] = ((CBC_QRFinderPattern*)m_possibleCenters[1])->Clone(); |
449 (*vec)[2] = ((CBC_QRFinderPattern*)m_possibleCenters[2])->Clone(); | 449 (*vec)[2] = ((CBC_QRFinderPattern*)m_possibleCenters[2])->Clone(); |
450 return vec; | 450 return vec; |
451 } | 451 } |
OLD | NEW |