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 2013 ZXing authors | 8 * Copyright 2013 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 m_isLeft ? boundingBox->getBottomLeft() : boundingBox->getBottomRight(); | 60 m_isLeft ? boundingBox->getBottomLeft() : boundingBox->getBottomRight(); |
61 int32_t firstRow = imageRowToCodewordIndex((int32_t)top->GetY()); | 61 int32_t firstRow = imageRowToCodewordIndex((int32_t)top->GetY()); |
62 int32_t lastRow = imageRowToCodewordIndex((int32_t)bottom->GetY()); | 62 int32_t lastRow = imageRowToCodewordIndex((int32_t)bottom->GetY()); |
63 FX_FLOAT averageRowHeight = | 63 FX_FLOAT averageRowHeight = |
64 (lastRow - firstRow) / (FX_FLOAT)barcodeMetadata.getRowCount(); | 64 (lastRow - firstRow) / (FX_FLOAT)barcodeMetadata.getRowCount(); |
65 int32_t barcodeRow = -1; | 65 int32_t barcodeRow = -1; |
66 int32_t maxRowHeight = 1; | 66 int32_t maxRowHeight = 1; |
67 int32_t currentRowHeight = 0; | 67 int32_t currentRowHeight = 0; |
68 for (int32_t codewordsRow = firstRow; codewordsRow < lastRow; | 68 for (int32_t codewordsRow = firstRow; codewordsRow < lastRow; |
69 codewordsRow++) { | 69 codewordsRow++) { |
70 if (codewords->GetAt(codewordsRow) == NULL) { | 70 if (!codewords->GetAt(codewordsRow)) |
71 continue; | 71 continue; |
72 } | 72 |
73 CBC_Codeword* codeword = codewords->GetAt(codewordsRow); | 73 CBC_Codeword* codeword = codewords->GetAt(codewordsRow); |
74 int32_t rowDifference = codeword->getRowNumber() - barcodeRow; | 74 int32_t rowDifference = codeword->getRowNumber() - barcodeRow; |
75 if (rowDifference == 0) { | 75 if (rowDifference == 0) { |
76 currentRowHeight++; | 76 currentRowHeight++; |
77 } else if (rowDifference == 1) { | 77 } else if (rowDifference == 1) { |
78 maxRowHeight = | 78 maxRowHeight = |
79 maxRowHeight > currentRowHeight ? maxRowHeight : currentRowHeight; | 79 maxRowHeight > currentRowHeight ? maxRowHeight : currentRowHeight; |
80 currentRowHeight = 1; | 80 currentRowHeight = 1; |
81 barcodeRow = codeword->getRowNumber(); | 81 barcodeRow = codeword->getRowNumber(); |
82 } else if (rowDifference < 0) { | 82 } else if (rowDifference < 0) { |
83 codewords->SetAt(codewordsRow, NULL); | 83 codewords->SetAt(codewordsRow, nullptr); |
84 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) { | 84 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) { |
85 codewords->SetAt(codewordsRow, NULL); | 85 codewords->SetAt(codewordsRow, nullptr); |
86 } else if (rowDifference > codewordsRow) { | 86 } else if (rowDifference > codewordsRow) { |
87 codewords->SetAt(codewordsRow, NULL); | 87 codewords->SetAt(codewordsRow, nullptr); |
88 } else { | 88 } else { |
89 int32_t checkedRows; | 89 int32_t checkedRows; |
90 if (maxRowHeight > 2) { | 90 if (maxRowHeight > 2) { |
91 checkedRows = (maxRowHeight - 2) * rowDifference; | 91 checkedRows = (maxRowHeight - 2) * rowDifference; |
92 } else { | 92 } else { |
93 checkedRows = rowDifference; | 93 checkedRows = rowDifference; |
94 } | 94 } |
95 FX_BOOL closePreviousCodewordFound = checkedRows >= codewordsRow; | 95 FX_BOOL closePreviousCodewordFound = checkedRows >= codewordsRow; |
96 for (int32_t i = 1; i <= checkedRows && !closePreviousCodewordFound; | 96 for (int32_t i = 1; i <= checkedRows && !closePreviousCodewordFound; |
97 i++) { | 97 i++) { |
98 closePreviousCodewordFound = codewords->GetAt(codewordsRow - i) != NULL; | 98 closePreviousCodewordFound = !!codewords->GetAt(codewordsRow - i); |
99 } | 99 } |
100 if (closePreviousCodewordFound) { | 100 if (closePreviousCodewordFound) { |
101 codewords->SetAt(codewordsRow, NULL); | 101 codewords->SetAt(codewordsRow, nullptr); |
102 } else { | 102 } else { |
103 barcodeRow = codeword->getRowNumber(); | 103 barcodeRow = codeword->getRowNumber(); |
104 currentRowHeight = 1; | 104 currentRowHeight = 1; |
105 } | 105 } |
106 } | 106 } |
107 } | 107 } |
108 return (int32_t)(averageRowHeight + 0.5); | 108 return (int32_t)(averageRowHeight + 0.5); |
109 } | 109 } |
110 CFX_Int32Array* CBC_DetectionResultRowIndicatorColumn::getRowHeights( | 110 CFX_Int32Array* CBC_DetectionResultRowIndicatorColumn::getRowHeights( |
111 int32_t& e) { | 111 int32_t& e) { |
112 CBC_BarcodeMetadata* barcodeMetadata = getBarcodeMetadata(); | 112 CBC_BarcodeMetadata* barcodeMetadata = getBarcodeMetadata(); |
113 if (barcodeMetadata == NULL) { | 113 if (!barcodeMetadata) { |
114 e = BCExceptionCannotMetadata; | 114 e = BCExceptionCannotMetadata; |
115 return NULL; | 115 return nullptr; |
116 } | 116 } |
117 adjustIncompleteIndicatorColumnRowNumbers(*barcodeMetadata); | 117 adjustIncompleteIndicatorColumnRowNumbers(*barcodeMetadata); |
118 CFX_Int32Array* result = new CFX_Int32Array; | 118 CFX_Int32Array* result = new CFX_Int32Array; |
119 result->SetSize(barcodeMetadata->getRowCount()); | 119 result->SetSize(barcodeMetadata->getRowCount()); |
120 for (int32_t i = 0; i < getCodewords()->GetSize(); i++) { | 120 for (int32_t i = 0; i < getCodewords()->GetSize(); i++) { |
121 CBC_Codeword* codeword = (CBC_Codeword*)getCodewords()->GetAt(i); | 121 CBC_Codeword* codeword = (CBC_Codeword*)getCodewords()->GetAt(i); |
122 if (codeword) { | 122 if (codeword) { |
123 result->SetAt(codeword->getRowNumber(), | 123 result->SetAt(codeword->getRowNumber(), |
124 result->GetAt(codeword->getRowNumber()) + 1); | 124 result->GetAt(codeword->getRowNumber()) + 1); |
125 } | 125 } |
(...skipping 11 matching lines...) Expand all Loading... |
137 int32_t firstRow = imageRowToCodewordIndex((int32_t)top->GetY()); | 137 int32_t firstRow = imageRowToCodewordIndex((int32_t)top->GetY()); |
138 int32_t lastRow = imageRowToCodewordIndex((int32_t)bottom->GetY()); | 138 int32_t lastRow = imageRowToCodewordIndex((int32_t)bottom->GetY()); |
139 FX_FLOAT averageRowHeight = | 139 FX_FLOAT averageRowHeight = |
140 (lastRow - firstRow) / (FX_FLOAT)barcodeMetadata.getRowCount(); | 140 (lastRow - firstRow) / (FX_FLOAT)barcodeMetadata.getRowCount(); |
141 CFX_ArrayTemplate<CBC_Codeword*>* codewords = getCodewords(); | 141 CFX_ArrayTemplate<CBC_Codeword*>* codewords = getCodewords(); |
142 int32_t barcodeRow = -1; | 142 int32_t barcodeRow = -1; |
143 int32_t maxRowHeight = 1; | 143 int32_t maxRowHeight = 1; |
144 int32_t currentRowHeight = 0; | 144 int32_t currentRowHeight = 0; |
145 for (int32_t codewordsRow = firstRow; codewordsRow < lastRow; | 145 for (int32_t codewordsRow = firstRow; codewordsRow < lastRow; |
146 codewordsRow++) { | 146 codewordsRow++) { |
147 if (codewords->GetAt(codewordsRow) == NULL) { | 147 if (!codewords->GetAt(codewordsRow)) |
148 continue; | 148 continue; |
149 } | 149 |
150 CBC_Codeword* codeword = codewords->GetAt(codewordsRow); | 150 CBC_Codeword* codeword = codewords->GetAt(codewordsRow); |
151 codeword->setRowNumberAsRowIndicatorColumn(); | 151 codeword->setRowNumberAsRowIndicatorColumn(); |
152 int32_t rowDifference = codeword->getRowNumber() - barcodeRow; | 152 int32_t rowDifference = codeword->getRowNumber() - barcodeRow; |
153 if (rowDifference == 0) { | 153 if (rowDifference == 0) { |
154 currentRowHeight++; | 154 currentRowHeight++; |
155 } else if (rowDifference == 1) { | 155 } else if (rowDifference == 1) { |
156 maxRowHeight = | 156 maxRowHeight = |
157 maxRowHeight > currentRowHeight ? maxRowHeight : currentRowHeight; | 157 maxRowHeight > currentRowHeight ? maxRowHeight : currentRowHeight; |
158 currentRowHeight = 1; | 158 currentRowHeight = 1; |
159 barcodeRow = codeword->getRowNumber(); | 159 barcodeRow = codeword->getRowNumber(); |
160 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) { | 160 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) { |
161 codewords->SetAt(codewordsRow, NULL); | 161 codewords->SetAt(codewordsRow, nullptr); |
162 } else { | 162 } else { |
163 barcodeRow = codeword->getRowNumber(); | 163 barcodeRow = codeword->getRowNumber(); |
164 currentRowHeight = 1; | 164 currentRowHeight = 1; |
165 } | 165 } |
166 } | 166 } |
167 return (int32_t)(averageRowHeight + 0.5); | 167 return (int32_t)(averageRowHeight + 0.5); |
168 } | 168 } |
169 CBC_BarcodeMetadata* | 169 CBC_BarcodeMetadata* |
170 CBC_DetectionResultRowIndicatorColumn::getBarcodeMetadata() { | 170 CBC_DetectionResultRowIndicatorColumn::getBarcodeMetadata() { |
171 CFX_ArrayTemplate<CBC_Codeword*>* codewords = getCodewords(); | 171 CFX_ArrayTemplate<CBC_Codeword*>* codewords = getCodewords(); |
172 CBC_BarcodeValue barcodeColumnCount; | 172 CBC_BarcodeValue barcodeColumnCount; |
173 CBC_BarcodeValue barcodeRowCountUpperPart; | 173 CBC_BarcodeValue barcodeRowCountUpperPart; |
174 CBC_BarcodeValue barcodeRowCountLowerPart; | 174 CBC_BarcodeValue barcodeRowCountLowerPart; |
175 CBC_BarcodeValue barcodeECLevel; | 175 CBC_BarcodeValue barcodeECLevel; |
176 for (int32_t i = 0; i < codewords->GetSize(); i++) { | 176 for (int32_t i = 0; i < codewords->GetSize(); i++) { |
177 CBC_Codeword* codeword = codewords->GetAt(i); | 177 CBC_Codeword* codeword = codewords->GetAt(i); |
178 if (codeword == NULL) { | 178 if (!codeword) |
179 continue; | 179 continue; |
180 } | 180 |
181 codeword->setRowNumberAsRowIndicatorColumn(); | 181 codeword->setRowNumberAsRowIndicatorColumn(); |
182 int32_t rowIndicatorValue = codeword->getValue() % 30; | 182 int32_t rowIndicatorValue = codeword->getValue() % 30; |
183 int32_t codewordRowNumber = codeword->getRowNumber(); | 183 int32_t codewordRowNumber = codeword->getRowNumber(); |
184 if (!m_isLeft) { | 184 if (!m_isLeft) { |
185 codewordRowNumber += 2; | 185 codewordRowNumber += 2; |
186 } | 186 } |
187 switch (codewordRowNumber % 3) { | 187 switch (codewordRowNumber % 3) { |
188 case 0: | 188 case 0: |
189 barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1); | 189 barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1); |
190 break; | 190 break; |
(...skipping 10 matching lines...) Expand all Loading... |
201 (barcodeRowCountUpperPart.getValue()->GetSize() == 0) || | 201 (barcodeRowCountUpperPart.getValue()->GetSize() == 0) || |
202 (barcodeRowCountLowerPart.getValue()->GetSize() == 0) || | 202 (barcodeRowCountLowerPart.getValue()->GetSize() == 0) || |
203 (barcodeECLevel.getValue()->GetSize() == 0) || | 203 (barcodeECLevel.getValue()->GetSize() == 0) || |
204 barcodeColumnCount.getValue()->GetAt(0) < 1 || | 204 barcodeColumnCount.getValue()->GetAt(0) < 1 || |
205 barcodeRowCountUpperPart.getValue()->GetAt(0) + | 205 barcodeRowCountUpperPart.getValue()->GetAt(0) + |
206 barcodeRowCountLowerPart.getValue()->GetAt(0) < | 206 barcodeRowCountLowerPart.getValue()->GetAt(0) < |
207 CBC_PDF417Common::MIN_ROWS_IN_BARCODE || | 207 CBC_PDF417Common::MIN_ROWS_IN_BARCODE || |
208 barcodeRowCountUpperPart.getValue()->GetAt(0) + | 208 barcodeRowCountUpperPart.getValue()->GetAt(0) + |
209 barcodeRowCountLowerPart.getValue()->GetAt(0) > | 209 barcodeRowCountLowerPart.getValue()->GetAt(0) > |
210 CBC_PDF417Common::MAX_ROWS_IN_BARCODE) { | 210 CBC_PDF417Common::MAX_ROWS_IN_BARCODE) { |
211 return NULL; | 211 return nullptr; |
212 } | 212 } |
213 CBC_BarcodeMetadata* barcodeMetadata = | 213 CBC_BarcodeMetadata* barcodeMetadata = |
214 new CBC_BarcodeMetadata(barcodeColumnCount.getValue()->GetAt(0), | 214 new CBC_BarcodeMetadata(barcodeColumnCount.getValue()->GetAt(0), |
215 barcodeRowCountUpperPart.getValue()->GetAt(0), | 215 barcodeRowCountUpperPart.getValue()->GetAt(0), |
216 barcodeRowCountLowerPart.getValue()->GetAt(0), | 216 barcodeRowCountLowerPart.getValue()->GetAt(0), |
217 barcodeECLevel.getValue()->GetAt(0)); | 217 barcodeECLevel.getValue()->GetAt(0)); |
218 removeIncorrectCodewords(codewords, *barcodeMetadata); | 218 removeIncorrectCodewords(codewords, *barcodeMetadata); |
219 return barcodeMetadata; | 219 return barcodeMetadata; |
220 } | 220 } |
221 FX_BOOL CBC_DetectionResultRowIndicatorColumn::isLeft() { | 221 FX_BOOL CBC_DetectionResultRowIndicatorColumn::isLeft() { |
222 return m_isLeft; | 222 return m_isLeft; |
223 } | 223 } |
224 CFX_ByteString CBC_DetectionResultRowIndicatorColumn::toString() { | 224 CFX_ByteString CBC_DetectionResultRowIndicatorColumn::toString() { |
225 return CFX_ByteString("IsLeft: ") + m_isLeft + '\n' + | 225 return CFX_ByteString("IsLeft: ") + m_isLeft + '\n' + |
226 CBC_DetectionResultColumn::toString(); | 226 CBC_DetectionResultColumn::toString(); |
227 } | 227 } |
228 void CBC_DetectionResultRowIndicatorColumn::removeIncorrectCodewords( | 228 void CBC_DetectionResultRowIndicatorColumn::removeIncorrectCodewords( |
229 CFX_ArrayTemplate<CBC_Codeword*>* codewords, | 229 CFX_ArrayTemplate<CBC_Codeword*>* codewords, |
230 CBC_BarcodeMetadata barcodeMetadata) { | 230 CBC_BarcodeMetadata barcodeMetadata) { |
231 for (int32_t codewordRow = 0; codewordRow < codewords->GetSize(); | 231 for (int32_t codewordRow = 0; codewordRow < codewords->GetSize(); |
232 codewordRow++) { | 232 codewordRow++) { |
233 CBC_Codeword* codeword = codewords->GetAt(codewordRow); | 233 CBC_Codeword* codeword = codewords->GetAt(codewordRow); |
234 if (codeword == NULL) { | 234 if (!codeword) |
235 continue; | 235 continue; |
236 } | 236 |
237 int32_t rowIndicatorValue = codeword->getValue() % 30; | 237 int32_t rowIndicatorValue = codeword->getValue() % 30; |
238 int32_t codewordRowNumber = codeword->getRowNumber(); | 238 int32_t codewordRowNumber = codeword->getRowNumber(); |
239 if (codewordRowNumber > barcodeMetadata.getRowCount()) { | 239 if (codewordRowNumber > barcodeMetadata.getRowCount()) { |
240 codewords->SetAt(codewordRow, NULL); | 240 codewords->SetAt(codewordRow, nullptr); |
241 continue; | 241 continue; |
242 } | 242 } |
243 if (!m_isLeft) { | 243 if (!m_isLeft) { |
244 codewordRowNumber += 2; | 244 codewordRowNumber += 2; |
245 } | 245 } |
246 switch (codewordRowNumber % 3) { | 246 switch (codewordRowNumber % 3) { |
247 case 0: | 247 case 0: |
248 if (rowIndicatorValue * 3 + 1 != | 248 if (rowIndicatorValue * 3 + 1 != |
249 barcodeMetadata.getRowCountUpperPart()) { | 249 barcodeMetadata.getRowCountUpperPart()) { |
250 codewords->SetAt(codewordRow, NULL); | 250 codewords->SetAt(codewordRow, nullptr); |
251 } | 251 } |
252 break; | 252 break; |
253 case 1: | 253 case 1: |
254 if (rowIndicatorValue / 3 != | 254 if (rowIndicatorValue / 3 != |
255 barcodeMetadata.getErrorCorrectionLevel() || | 255 barcodeMetadata.getErrorCorrectionLevel() || |
256 rowIndicatorValue % 3 != barcodeMetadata.getRowCountLowerPart()) { | 256 rowIndicatorValue % 3 != barcodeMetadata.getRowCountLowerPart()) { |
257 codewords->SetAt(codewordRow, NULL); | 257 codewords->SetAt(codewordRow, nullptr); |
258 } | 258 } |
259 break; | 259 break; |
260 case 2: | 260 case 2: |
261 if (rowIndicatorValue + 1 != barcodeMetadata.getColumnCount()) { | 261 if (rowIndicatorValue + 1 != barcodeMetadata.getColumnCount()) { |
262 codewords->SetAt(codewordRow, NULL); | 262 codewords->SetAt(codewordRow, nullptr); |
263 } | 263 } |
264 break; | 264 break; |
265 } | 265 } |
266 } | 266 } |
267 } | 267 } |
OLD | NEW |