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"); |
(...skipping 22 matching lines...) Expand all Loading... |
33 int32_t height, | 33 int32_t height, |
34 FX_FLOAT moduleSize) | 34 FX_FLOAT moduleSize) |
35 : m_image(image), | 35 : m_image(image), |
36 m_startX(startX), | 36 m_startX(startX), |
37 m_startY(startY), | 37 m_startY(startY), |
38 m_width(width), | 38 m_width(width), |
39 m_height(height), | 39 m_height(height), |
40 m_moduleSize(moduleSize) { | 40 m_moduleSize(moduleSize) { |
41 m_crossCheckStateCount.SetSize(3); | 41 m_crossCheckStateCount.SetSize(3); |
42 } | 42 } |
| 43 |
43 CBC_QRAlignmentPatternFinder::~CBC_QRAlignmentPatternFinder() { | 44 CBC_QRAlignmentPatternFinder::~CBC_QRAlignmentPatternFinder() { |
44 for (int32_t i = 0; i < m_possibleCenters.GetSize(); i++) { | 45 for (int32_t i = 0; i < m_possibleCenters.GetSize(); i++) |
45 delete (CBC_QRAlignmentPattern*)m_possibleCenters[i]; | 46 delete m_possibleCenters[i]; |
46 } | |
47 m_possibleCenters.RemoveAll(); | |
48 } | 47 } |
| 48 |
49 CBC_QRAlignmentPattern* CBC_QRAlignmentPatternFinder::Find(int32_t& e) { | 49 CBC_QRAlignmentPattern* CBC_QRAlignmentPatternFinder::Find(int32_t& e) { |
50 int32_t startX = m_startX; | 50 int32_t startX = m_startX; |
51 int32_t height = m_height; | 51 int32_t height = m_height; |
52 int32_t maxJ = startX + m_width; | 52 int32_t maxJ = startX + m_width; |
53 int32_t middleI = m_startY + (height >> 1); | 53 int32_t middleI = m_startY + (height >> 1); |
54 CFX_Int32Array stateCount; | 54 CFX_Int32Array stateCount; |
55 stateCount.SetSize(3); | 55 stateCount.SetSize(3); |
56 for (int32_t iGen = 0; iGen < height; iGen++) { | 56 for (int32_t iGen = 0; iGen < height; iGen++) { |
57 int32_t i = | 57 int32_t i = |
58 middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1)); | 58 middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 if (FoundPatternCross(stateCount)) { | 96 if (FoundPatternCross(stateCount)) { |
97 CBC_QRAlignmentPattern* confirmed = | 97 CBC_QRAlignmentPattern* confirmed = |
98 HandlePossibleCenter(stateCount, i, maxJ); | 98 HandlePossibleCenter(stateCount, i, maxJ); |
99 if (confirmed) { | 99 if (confirmed) { |
100 return confirmed; | 100 return confirmed; |
101 } | 101 } |
102 } | 102 } |
103 } | 103 } |
104 if (m_possibleCenters.GetSize() != 0) { | 104 if (m_possibleCenters.GetSize() != 0) { |
105 return ((CBC_QRAlignmentPattern*)(m_possibleCenters[0]))->Clone(); | 105 return m_possibleCenters[0]->Clone(); |
106 } | 106 } |
107 e = BCExceptionRead; | 107 e = BCExceptionRead; |
108 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 108 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
109 return NULL; | 109 return NULL; |
110 } | 110 } |
111 FX_FLOAT CBC_QRAlignmentPatternFinder::CenterFromEnd( | 111 FX_FLOAT CBC_QRAlignmentPatternFinder::CenterFromEnd( |
112 const CFX_Int32Array& stateCount, | 112 const CFX_Int32Array& stateCount, |
113 int32_t end) { | 113 int32_t end) { |
114 return (FX_FLOAT)(end - stateCount[2]) - stateCount[1] / 2.0f; | 114 return (FX_FLOAT)(end - stateCount[2]) - stateCount[1] / 2.0f; |
115 } | 115 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 int32_t j) { | 179 int32_t j) { |
180 int32_t stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; | 180 int32_t stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; |
181 FX_FLOAT centerJ = CenterFromEnd(stateCount, j); | 181 FX_FLOAT centerJ = CenterFromEnd(stateCount, j); |
182 FX_FLOAT centerI = CrossCheckVertical(i, (int32_t)centerJ, 2 * stateCount[1], | 182 FX_FLOAT centerI = CrossCheckVertical(i, (int32_t)centerJ, 2 * stateCount[1], |
183 stateCountTotal); | 183 stateCountTotal); |
184 if (!FXSYS_isnan(centerI)) { | 184 if (!FXSYS_isnan(centerI)) { |
185 FX_FLOAT estimatedModuleSize = | 185 FX_FLOAT estimatedModuleSize = |
186 (FX_FLOAT)(stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f; | 186 (FX_FLOAT)(stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f; |
187 int32_t max = m_possibleCenters.GetSize(); | 187 int32_t max = m_possibleCenters.GetSize(); |
188 for (int32_t index = 0; index < max; index++) { | 188 for (int32_t index = 0; index < max; index++) { |
189 CBC_QRAlignmentPattern* center = | 189 CBC_QRAlignmentPattern* center = m_possibleCenters[index]; |
190 (CBC_QRAlignmentPattern*)(m_possibleCenters[index]); | |
191 if (center->AboutEquals(estimatedModuleSize, centerI, centerJ)) { | 190 if (center->AboutEquals(estimatedModuleSize, centerI, centerJ)) { |
192 return new CBC_QRAlignmentPattern(centerJ, centerI, | 191 return new CBC_QRAlignmentPattern(centerJ, centerI, |
193 estimatedModuleSize); | 192 estimatedModuleSize); |
194 } | 193 } |
195 } | 194 } |
196 m_possibleCenters.Add( | 195 m_possibleCenters.Add( |
197 new CBC_QRAlignmentPattern(centerJ, centerI, estimatedModuleSize)); | 196 new CBC_QRAlignmentPattern(centerJ, centerI, estimatedModuleSize)); |
198 } | 197 } |
199 return NULL; | 198 return NULL; |
200 } | 199 } |
OLD | NEW |