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

Side by Side Diff: xfa/src/fxbarcode/qrcode/BC_QRAlignmentPatternFinder.cpp

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 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 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_QRAlignmentPattern.h" 26 #include "BC_QRAlignmentPattern.h"
27 #include "BC_QRAlignmentPatternFinder.h" 27 #include "BC_QRAlignmentPatternFinder.h"
28 CBC_QRAlignmentPatternFinder::CBC_QRAlignmentPatternFinder(CBC_CommonBitMatrix * image, 28 CBC_QRAlignmentPatternFinder::CBC_QRAlignmentPatternFinder(CBC_CommonBitMatrix * image,
29 FX_INT32 startX, 29 int32_t startX,
30 FX_INT32 startY, 30 int32_t startY,
31 FX_INT32 width, 31 int32_t width,
32 FX_INT32 height, 32 int32_t height,
33 FX_FLOAT moduleSize): m_image(image), 33 FX_FLOAT moduleSize): m_image(image),
34 m_startX(startX), 34 m_startX(startX),
35 m_startY(startY), 35 m_startY(startY),
36 m_width(width), 36 m_width(width),
37 m_height(height), 37 m_height(height),
38 m_moduleSize(moduleSize) 38 m_moduleSize(moduleSize)
39 39
40 { 40 {
41 m_crossCheckStateCount.SetSize(3); 41 m_crossCheckStateCount.SetSize(3);
42 } 42 }
43 CBC_QRAlignmentPatternFinder::~CBC_QRAlignmentPatternFinder() 43 CBC_QRAlignmentPatternFinder::~CBC_QRAlignmentPatternFinder()
44 { 44 {
45 for (FX_INT32 i = 0; i < m_possibleCenters.GetSize(); i++) { 45 for (int32_t i = 0; i < m_possibleCenters.GetSize(); i++) {
46 delete (CBC_QRAlignmentPattern*)m_possibleCenters[i]; 46 delete (CBC_QRAlignmentPattern*)m_possibleCenters[i];
47 } 47 }
48 m_possibleCenters.RemoveAll(); 48 m_possibleCenters.RemoveAll();
49 } 49 }
50 CBC_QRAlignmentPattern *CBC_QRAlignmentPatternFinder::Find(FX_INT32 &e) 50 CBC_QRAlignmentPattern *CBC_QRAlignmentPatternFinder::Find(int32_t &e)
51 { 51 {
52 FX_INT32 startX = m_startX; 52 int32_t startX = m_startX;
53 FX_INT32 height = m_height; 53 int32_t height = m_height;
54 FX_INT32 maxJ = startX + m_width; 54 int32_t maxJ = startX + m_width;
55 FX_INT32 middleI = m_startY + (height >> 1); 55 int32_t middleI = m_startY + (height >> 1);
56 CFX_Int32Array stateCount; 56 CFX_Int32Array stateCount;
57 stateCount.SetSize(3); 57 stateCount.SetSize(3);
58 for (FX_INT32 iGen = 0; iGen < height; iGen++) { 58 for (int32_t iGen = 0; iGen < height; iGen++) {
59 FX_INT32 i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1)); 59 int32_t i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1));
60 stateCount[0] = 0; 60 stateCount[0] = 0;
61 stateCount[1] = 0; 61 stateCount[1] = 0;
62 stateCount[2] = 0; 62 stateCount[2] = 0;
63 FX_INT32 j = startX; 63 int32_t j = startX;
64 while (j < maxJ && !m_image->Get(j, i)) { 64 while (j < maxJ && !m_image->Get(j, i)) {
65 j++; 65 j++;
66 } 66 }
67 FX_INT32 currentState = 0; 67 int32_t currentState = 0;
68 while (j < maxJ) { 68 while (j < maxJ) {
69 if (m_image->Get(j, i)) { 69 if (m_image->Get(j, i)) {
70 if (currentState == 1) { 70 if (currentState == 1) {
71 stateCount[currentState]++; 71 stateCount[currentState]++;
72 } else { 72 } else {
73 if (currentState == 2) { 73 if (currentState == 2) {
74 if (FoundPatternCross(stateCount)) { 74 if (FoundPatternCross(stateCount)) {
75 CBC_QRAlignmentPattern *confirmed = HandlePossibleC enter(stateCount, i, j); 75 CBC_QRAlignmentPattern *confirmed = HandlePossibleC enter(stateCount, i, j);
76 if (confirmed != NULL) { 76 if (confirmed != NULL) {
77 return confirmed; 77 return confirmed;
(...skipping 22 matching lines...) Expand all
100 } 100 }
101 } 101 }
102 } 102 }
103 if (m_possibleCenters.GetSize() != 0) { 103 if (m_possibleCenters.GetSize() != 0) {
104 return ((CBC_QRAlignmentPattern*) (m_possibleCenters[0]) )->Clone(); 104 return ((CBC_QRAlignmentPattern*) (m_possibleCenters[0]) )->Clone();
105 } 105 }
106 e = BCExceptionRead; 106 e = BCExceptionRead;
107 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 107 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
108 return NULL; 108 return NULL;
109 } 109 }
110 FX_FLOAT CBC_QRAlignmentPatternFinder::CenterFromEnd(const CFX_Int32Array &state Count, FX_INT32 end) 110 FX_FLOAT CBC_QRAlignmentPatternFinder::CenterFromEnd(const CFX_Int32Array &state Count, int32_t end)
111 { 111 {
112 return (FX_FLOAT) (end - stateCount[2]) - stateCount[1] / 2.0f; 112 return (FX_FLOAT) (end - stateCount[2]) - stateCount[1] / 2.0f;
113 } 113 }
114 FX_BOOL CBC_QRAlignmentPatternFinder::FoundPatternCross(const CFX_Int32Array &st ateCount) 114 FX_BOOL CBC_QRAlignmentPatternFinder::FoundPatternCross(const CFX_Int32Array &st ateCount)
115 { 115 {
116 FX_FLOAT moduleSize = m_moduleSize; 116 FX_FLOAT moduleSize = m_moduleSize;
117 FX_FLOAT maxVariance = moduleSize / 2.0f; 117 FX_FLOAT maxVariance = moduleSize / 2.0f;
118 for (FX_INT32 i = 0; i < 3; i++) { 118 for (int32_t i = 0; i < 3; i++) {
119 if (fabs(moduleSize - stateCount[i]) >= maxVariance) { 119 if (fabs(moduleSize - stateCount[i]) >= maxVariance) {
120 return false; 120 return false;
121 } 121 }
122 } 122 }
123 return TRUE; 123 return TRUE;
124 } 124 }
125 FX_FLOAT CBC_QRAlignmentPatternFinder::CrossCheckVertical(FX_INT32 startI, FX_IN T32 centerJ, FX_INT32 maxCount, FX_INT32 originalStateCountTotal) 125 FX_FLOAT CBC_QRAlignmentPatternFinder::CrossCheckVertical(int32_t startI, int32_ t centerJ, int32_t maxCount, int32_t originalStateCountTotal)
126 { 126 {
127 CBC_CommonBitMatrix *image = m_image; 127 CBC_CommonBitMatrix *image = m_image;
128 FX_INT32 maxI = m_image->GetHeight(); 128 int32_t maxI = m_image->GetHeight();
129 CFX_Int32Array stateCount; 129 CFX_Int32Array stateCount;
130 stateCount.Copy(m_crossCheckStateCount); 130 stateCount.Copy(m_crossCheckStateCount);
131 stateCount[0] = 0; 131 stateCount[0] = 0;
132 stateCount[1] = 0; 132 stateCount[1] = 0;
133 stateCount[2] = 0; 133 stateCount[2] = 0;
134 FX_INT32 i = startI; 134 int32_t i = startI;
135 while (i >= 0 && m_image->Get(centerJ, i) && stateCount[1] <= maxCount) { 135 while (i >= 0 && m_image->Get(centerJ, i) && stateCount[1] <= maxCount) {
136 stateCount[1]++; 136 stateCount[1]++;
137 i--; 137 i--;
138 } 138 }
139 if (i < 0 || stateCount[1] > maxCount) { 139 if (i < 0 || stateCount[1] > maxCount) {
140 return FXSYS_nan(); 140 return FXSYS_nan();
141 } 141 }
142 while (i >= 0 && !m_image->Get(centerJ, i) && stateCount[0] <= maxCount) { 142 while (i >= 0 && !m_image->Get(centerJ, i) && stateCount[0] <= maxCount) {
143 stateCount[0]++; 143 stateCount[0]++;
144 i--; 144 i--;
145 } 145 }
146 if (stateCount[0] > maxCount) { 146 if (stateCount[0] > maxCount) {
147 return FXSYS_nan(); 147 return FXSYS_nan();
148 } 148 }
149 i = startI + 1; 149 i = startI + 1;
150 while (i < maxI && m_image->Get(centerJ, i) && stateCount[1] <= maxCount) { 150 while (i < maxI && m_image->Get(centerJ, i) && stateCount[1] <= maxCount) {
151 stateCount[1]++; 151 stateCount[1]++;
152 i++; 152 i++;
153 } 153 }
154 if (i == maxI || stateCount[1] > maxCount) { 154 if (i == maxI || stateCount[1] > maxCount) {
155 return FXSYS_nan(); 155 return FXSYS_nan();
156 } 156 }
157 while (i < maxI && !m_image->Get(centerJ, i) && stateCount[2] <= maxCount) { 157 while (i < maxI && !m_image->Get(centerJ, i) && stateCount[2] <= maxCount) {
158 stateCount[2]++; 158 stateCount[2]++;
159 i++; 159 i++;
160 } 160 }
161 if (stateCount[2] > maxCount) { 161 if (stateCount[2] > maxCount) {
162 return FXSYS_nan(); 162 return FXSYS_nan();
163 } 163 }
164 FX_INT32 stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; 164 int32_t stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
165 if (5 * abs(stateCountTotal - originalStateCountTotal) >= originalStateCount Total) { 165 if (5 * abs(stateCountTotal - originalStateCountTotal) >= originalStateCount Total) {
166 return FXSYS_nan(); 166 return FXSYS_nan();
167 } 167 }
168 return FoundPatternCross(stateCount) ? CenterFromEnd(stateCount, i) : FXSYS_ nan(); 168 return FoundPatternCross(stateCount) ? CenterFromEnd(stateCount, i) : FXSYS_ nan();
169 } 169 }
170 CBC_QRAlignmentPattern *CBC_QRAlignmentPatternFinder::HandlePossibleCenter(const CFX_Int32Array &stateCount, FX_INT32 i, FX_INT32 j) 170 CBC_QRAlignmentPattern *CBC_QRAlignmentPatternFinder::HandlePossibleCenter(const CFX_Int32Array &stateCount, int32_t i, int32_t j)
171 { 171 {
172 FX_INT32 stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; 172 int32_t stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
173 FX_FLOAT centerJ = CenterFromEnd(stateCount, j); 173 FX_FLOAT centerJ = CenterFromEnd(stateCount, j);
174 FX_FLOAT centerI = CrossCheckVertical(i, (FX_INT32) centerJ, 2 * stateCount[ 1], stateCountTotal); 174 FX_FLOAT centerI = CrossCheckVertical(i, (int32_t) centerJ, 2 * stateCount[1 ], stateCountTotal);
175 if (!FXSYS_isnan(centerI)) { 175 if (!FXSYS_isnan(centerI)) {
176 FX_FLOAT estimatedModuleSize = (FX_FLOAT) (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f; 176 FX_FLOAT estimatedModuleSize = (FX_FLOAT) (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f;
177 FX_INT32 max = m_possibleCenters.GetSize(); 177 int32_t max = m_possibleCenters.GetSize();
178 for (FX_INT32 index = 0; index < max; index++) { 178 for (int32_t index = 0; index < max; index++) {
179 CBC_QRAlignmentPattern *center = (CBC_QRAlignmentPattern *)(m_possib leCenters[index]); 179 CBC_QRAlignmentPattern *center = (CBC_QRAlignmentPattern *)(m_possib leCenters[index]);
180 if (center->AboutEquals(estimatedModuleSize, centerI, centerJ)) { 180 if (center->AboutEquals(estimatedModuleSize, centerI, centerJ)) {
181 return FX_NEW CBC_QRAlignmentPattern(centerJ, centerI, estimated ModuleSize); 181 return FX_NEW CBC_QRAlignmentPattern(centerJ, centerI, estimated ModuleSize);
182 } 182 }
183 } 183 }
184 m_possibleCenters.Add(FX_NEW CBC_QRAlignmentPattern(centerJ, centerI, es timatedModuleSize)); 184 m_possibleCenters.Add(FX_NEW CBC_QRAlignmentPattern(centerJ, centerI, es timatedModuleSize));
185 } 185 }
186 return NULL; 186 return NULL;
187 } 187 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/qrcode/BC_QRAlignmentPatternFinder.h ('k') | xfa/src/fxbarcode/qrcode/BC_QRBitMatrixParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698