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

Side by Side Diff: xfa/src/fxbarcode/pdf417/BC_PDF417DetectionResultRowIndicatorColumn.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 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 21 matching lines...) Expand all
32 CBC_DetectionResultRowIndicatorColumn::CBC_DetectionResultRowIndicatorColumn(CBC _BoundingBox* boundingBox, FX_BOOL isLeft) 32 CBC_DetectionResultRowIndicatorColumn::CBC_DetectionResultRowIndicatorColumn(CBC _BoundingBox* boundingBox, FX_BOOL isLeft)
33 : CBC_DetectionResultColumn(boundingBox) 33 : CBC_DetectionResultColumn(boundingBox)
34 { 34 {
35 m_isLeft = isLeft; 35 m_isLeft = isLeft;
36 } 36 }
37 CBC_DetectionResultRowIndicatorColumn::~CBC_DetectionResultRowIndicatorColumn() 37 CBC_DetectionResultRowIndicatorColumn::~CBC_DetectionResultRowIndicatorColumn()
38 { 38 {
39 } 39 }
40 void CBC_DetectionResultRowIndicatorColumn::setRowNumbers() 40 void CBC_DetectionResultRowIndicatorColumn::setRowNumbers()
41 { 41 {
42 for (FX_INT32 i = 0; i < m_codewords->GetSize(); i++) { 42 for (int32_t i = 0; i < m_codewords->GetSize(); i++) {
43 CBC_Codeword * codeword = (CBC_Codeword*)m_codewords->GetAt(i); 43 CBC_Codeword * codeword = (CBC_Codeword*)m_codewords->GetAt(i);
44 if (codeword != NULL) { 44 if (codeword != NULL) {
45 codeword->setRowNumberAsRowIndicatorColumn(); 45 codeword->setRowNumberAsRowIndicatorColumn();
46 } 46 }
47 } 47 }
48 } 48 }
49 FX_INT32 CBC_DetectionResultRowIndicatorColumn::adjustCompleteIndicatorColumnRow Numbers(CBC_BarcodeMetadata barcodeMetadata) 49 int32_t CBC_DetectionResultRowIndicatorColumn::adjustCompleteIndicatorColumnRowN umbers(CBC_BarcodeMetadata barcodeMetadata)
50 { 50 {
51 CFX_PtrArray* codewords = getCodewords(); 51 CFX_PtrArray* codewords = getCodewords();
52 setRowNumbers(); 52 setRowNumbers();
53 removeIncorrectCodewords(codewords, barcodeMetadata); 53 removeIncorrectCodewords(codewords, barcodeMetadata);
54 CBC_BoundingBox* boundingBox = getBoundingBox(); 54 CBC_BoundingBox* boundingBox = getBoundingBox();
55 CBC_ResultPoint* top = m_isLeft ? boundingBox->getTopLeft() : boundingBox->g etTopRight(); 55 CBC_ResultPoint* top = m_isLeft ? boundingBox->getTopLeft() : boundingBox->g etTopRight();
56 CBC_ResultPoint* bottom = m_isLeft ? boundingBox->getBottomLeft() : bounding Box->getBottomRight(); 56 CBC_ResultPoint* bottom = m_isLeft ? boundingBox->getBottomLeft() : bounding Box->getBottomRight();
57 FX_INT32 firstRow = imageRowToCodewordIndex((FX_INT32) top->GetY()); 57 int32_t firstRow = imageRowToCodewordIndex((int32_t) top->GetY());
58 FX_INT32 lastRow = imageRowToCodewordIndex((FX_INT32) bottom->GetY()); 58 int32_t lastRow = imageRowToCodewordIndex((int32_t) bottom->GetY());
59 FX_FLOAT averageRowHeight = (lastRow - firstRow) / (FX_FLOAT) barcodeMetadat a.getRowCount(); 59 FX_FLOAT averageRowHeight = (lastRow - firstRow) / (FX_FLOAT) barcodeMetadat a.getRowCount();
60 FX_INT32 barcodeRow = -1; 60 int32_t barcodeRow = -1;
61 FX_INT32 maxRowHeight = 1; 61 int32_t maxRowHeight = 1;
62 FX_INT32 currentRowHeight = 0; 62 int32_t currentRowHeight = 0;
63 for (FX_INT32 codewordsRow = firstRow; codewordsRow < lastRow; codewordsRow+ +) { 63 for (int32_t codewordsRow = firstRow; codewordsRow < lastRow; codewordsRow++ ) {
64 if (codewords->GetAt(codewordsRow) == NULL) { 64 if (codewords->GetAt(codewordsRow) == NULL) {
65 continue; 65 continue;
66 } 66 }
67 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(codewordsRow); 67 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(codewordsRow);
68 FX_INT32 rowDifference = codeword->getRowNumber() - barcodeRow; 68 int32_t rowDifference = codeword->getRowNumber() - barcodeRow;
69 if (rowDifference == 0) { 69 if (rowDifference == 0) {
70 currentRowHeight++; 70 currentRowHeight++;
71 } else if (rowDifference == 1) { 71 } else if (rowDifference == 1) {
72 maxRowHeight = maxRowHeight > currentRowHeight ? maxRowHeight : curr entRowHeight; 72 maxRowHeight = maxRowHeight > currentRowHeight ? maxRowHeight : curr entRowHeight;
73 currentRowHeight = 1; 73 currentRowHeight = 1;
74 barcodeRow = codeword->getRowNumber(); 74 barcodeRow = codeword->getRowNumber();
75 } else if (rowDifference < 0) { 75 } else if (rowDifference < 0) {
76 codewords->SetAt(codewordsRow, NULL); 76 codewords->SetAt(codewordsRow, NULL);
77 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) { 77 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) {
78 codewords->SetAt(codewordsRow, NULL); 78 codewords->SetAt(codewordsRow, NULL);
79 } else if (rowDifference > codewordsRow) { 79 } else if (rowDifference > codewordsRow) {
80 codewords->SetAt(codewordsRow, NULL); 80 codewords->SetAt(codewordsRow, NULL);
81 } else { 81 } else {
82 FX_INT32 checkedRows; 82 int32_t checkedRows;
83 if (maxRowHeight > 2) { 83 if (maxRowHeight > 2) {
84 checkedRows = (maxRowHeight - 2) * rowDifference; 84 checkedRows = (maxRowHeight - 2) * rowDifference;
85 } else { 85 } else {
86 checkedRows = rowDifference; 86 checkedRows = rowDifference;
87 } 87 }
88 FX_BOOL closePreviousCodewordFound = checkedRows >= codewordsRow; 88 FX_BOOL closePreviousCodewordFound = checkedRows >= codewordsRow;
89 for (FX_INT32 i = 1; i <= checkedRows && !closePreviousCodewordFound ; i++) { 89 for (int32_t i = 1; i <= checkedRows && !closePreviousCodewordFound; i++) {
90 closePreviousCodewordFound = codewords->GetAt(codewordsRow - i) != NULL; 90 closePreviousCodewordFound = codewords->GetAt(codewordsRow - i) != NULL;
91 } 91 }
92 if (closePreviousCodewordFound) { 92 if (closePreviousCodewordFound) {
93 codewords->SetAt(codewordsRow, NULL); 93 codewords->SetAt(codewordsRow, NULL);
94 } else { 94 } else {
95 barcodeRow = codeword->getRowNumber(); 95 barcodeRow = codeword->getRowNumber();
96 currentRowHeight = 1; 96 currentRowHeight = 1;
97 } 97 }
98 } 98 }
99 } 99 }
100 return (FX_INT32) (averageRowHeight + 0.5); 100 return (int32_t) (averageRowHeight + 0.5);
101 } 101 }
102 CFX_Int32Array* CBC_DetectionResultRowIndicatorColumn::getRowHeights(FX_INT32 &e ) 102 CFX_Int32Array* CBC_DetectionResultRowIndicatorColumn::getRowHeights(int32_t &e)
103 { 103 {
104 CBC_BarcodeMetadata* barcodeMetadata = getBarcodeMetadata(); 104 CBC_BarcodeMetadata* barcodeMetadata = getBarcodeMetadata();
105 if (barcodeMetadata == NULL) { 105 if (barcodeMetadata == NULL) {
106 e = BCExceptionCannotMetadata; 106 e = BCExceptionCannotMetadata;
107 return NULL; 107 return NULL;
108 } 108 }
109 adjustIncompleteIndicatorColumnRowNumbers(*barcodeMetadata); 109 adjustIncompleteIndicatorColumnRowNumbers(*barcodeMetadata);
110 CFX_Int32Array* result = FX_NEW CFX_Int32Array; 110 CFX_Int32Array* result = FX_NEW CFX_Int32Array;
111 result->SetSize(barcodeMetadata->getRowCount()); 111 result->SetSize(barcodeMetadata->getRowCount());
112 for (FX_INT32 i = 0; i < getCodewords()->GetSize(); i++) { 112 for (int32_t i = 0; i < getCodewords()->GetSize(); i++) {
113 CBC_Codeword* codeword = (CBC_Codeword*)getCodewords()->GetAt(i); 113 CBC_Codeword* codeword = (CBC_Codeword*)getCodewords()->GetAt(i);
114 if (codeword != NULL) { 114 if (codeword != NULL) {
115 result->SetAt(codeword->getRowNumber(), result->GetAt(codeword->get RowNumber()) + 1); 115 result->SetAt(codeword->getRowNumber(), result->GetAt(codeword->get RowNumber()) + 1);
116 } 116 }
117 } 117 }
118 return result; 118 return result;
119 } 119 }
120 FX_INT32 CBC_DetectionResultRowIndicatorColumn::adjustIncompleteIndicatorColumnR owNumbers(CBC_BarcodeMetadata barcodeMetadata) 120 int32_t CBC_DetectionResultRowIndicatorColumn::adjustIncompleteIndicatorColumnRo wNumbers(CBC_BarcodeMetadata barcodeMetadata)
121 { 121 {
122 CBC_BoundingBox* boundingBox = getBoundingBox(); 122 CBC_BoundingBox* boundingBox = getBoundingBox();
123 CBC_ResultPoint* top = m_isLeft ? boundingBox->getTopLeft() : boundingBox->g etTopRight(); 123 CBC_ResultPoint* top = m_isLeft ? boundingBox->getTopLeft() : boundingBox->g etTopRight();
124 CBC_ResultPoint* bottom = m_isLeft ? boundingBox->getBottomLeft() : bounding Box->getBottomRight(); 124 CBC_ResultPoint* bottom = m_isLeft ? boundingBox->getBottomLeft() : bounding Box->getBottomRight();
125 FX_INT32 firstRow = imageRowToCodewordIndex((FX_INT32) top->GetY()); 125 int32_t firstRow = imageRowToCodewordIndex((int32_t) top->GetY());
126 FX_INT32 lastRow = imageRowToCodewordIndex((FX_INT32) bottom->GetY()); 126 int32_t lastRow = imageRowToCodewordIndex((int32_t) bottom->GetY());
127 FX_FLOAT averageRowHeight = (lastRow - firstRow) / (FX_FLOAT) barcodeMetadat a.getRowCount(); 127 FX_FLOAT averageRowHeight = (lastRow - firstRow) / (FX_FLOAT) barcodeMetadat a.getRowCount();
128 CFX_PtrArray* codewords = getCodewords(); 128 CFX_PtrArray* codewords = getCodewords();
129 FX_INT32 barcodeRow = -1; 129 int32_t barcodeRow = -1;
130 FX_INT32 maxRowHeight = 1; 130 int32_t maxRowHeight = 1;
131 FX_INT32 currentRowHeight = 0; 131 int32_t currentRowHeight = 0;
132 for (FX_INT32 codewordsRow = firstRow; codewordsRow < lastRow; codewordsRow+ +) { 132 for (int32_t codewordsRow = firstRow; codewordsRow < lastRow; codewordsRow++ ) {
133 if (codewords->GetAt(codewordsRow) == NULL) { 133 if (codewords->GetAt(codewordsRow) == NULL) {
134 continue; 134 continue;
135 } 135 }
136 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(codewordsRow); 136 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(codewordsRow);
137 codeword->setRowNumberAsRowIndicatorColumn(); 137 codeword->setRowNumberAsRowIndicatorColumn();
138 FX_INT32 rowDifference = codeword->getRowNumber() - barcodeRow; 138 int32_t rowDifference = codeword->getRowNumber() - barcodeRow;
139 if (rowDifference == 0) { 139 if (rowDifference == 0) {
140 currentRowHeight++; 140 currentRowHeight++;
141 } else if (rowDifference == 1) { 141 } else if (rowDifference == 1) {
142 maxRowHeight = maxRowHeight > currentRowHeight ? maxRowHeight : curr entRowHeight; 142 maxRowHeight = maxRowHeight > currentRowHeight ? maxRowHeight : curr entRowHeight;
143 currentRowHeight = 1; 143 currentRowHeight = 1;
144 barcodeRow = codeword->getRowNumber(); 144 barcodeRow = codeword->getRowNumber();
145 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) { 145 } else if (codeword->getRowNumber() >= barcodeMetadata.getRowCount()) {
146 codewords->SetAt(codewordsRow, NULL); 146 codewords->SetAt(codewordsRow, NULL);
147 } else { 147 } else {
148 barcodeRow = codeword->getRowNumber(); 148 barcodeRow = codeword->getRowNumber();
149 currentRowHeight = 1; 149 currentRowHeight = 1;
150 } 150 }
151 } 151 }
152 return (FX_INT32) (averageRowHeight + 0.5); 152 return (int32_t) (averageRowHeight + 0.5);
153 } 153 }
154 CBC_BarcodeMetadata* CBC_DetectionResultRowIndicatorColumn::getBarcodeMetadata() 154 CBC_BarcodeMetadata* CBC_DetectionResultRowIndicatorColumn::getBarcodeMetadata()
155 { 155 {
156 CFX_PtrArray* codewords = getCodewords(); 156 CFX_PtrArray* codewords = getCodewords();
157 CBC_BarcodeValue barcodeColumnCount; 157 CBC_BarcodeValue barcodeColumnCount;
158 CBC_BarcodeValue barcodeRowCountUpperPart; 158 CBC_BarcodeValue barcodeRowCountUpperPart;
159 CBC_BarcodeValue barcodeRowCountLowerPart; 159 CBC_BarcodeValue barcodeRowCountLowerPart;
160 CBC_BarcodeValue barcodeECLevel; 160 CBC_BarcodeValue barcodeECLevel;
161 for (FX_INT32 i = 0; i < codewords->GetSize(); i++) { 161 for (int32_t i = 0; i < codewords->GetSize(); i++) {
162 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(i); 162 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(i);
163 if (codeword == NULL) { 163 if (codeword == NULL) {
164 continue; 164 continue;
165 } 165 }
166 codeword->setRowNumberAsRowIndicatorColumn(); 166 codeword->setRowNumberAsRowIndicatorColumn();
167 FX_INT32 rowIndicatorValue = codeword->getValue() % 30; 167 int32_t rowIndicatorValue = codeword->getValue() % 30;
168 FX_INT32 codewordRowNumber = codeword->getRowNumber(); 168 int32_t codewordRowNumber = codeword->getRowNumber();
169 if (!m_isLeft) { 169 if (!m_isLeft) {
170 codewordRowNumber += 2; 170 codewordRowNumber += 2;
171 } 171 }
172 switch (codewordRowNumber % 3) { 172 switch (codewordRowNumber % 3) {
173 case 0: 173 case 0:
174 barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1); 174 barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1);
175 break; 175 break;
176 case 1: 176 case 1:
177 barcodeECLevel.setValue(rowIndicatorValue / 3); 177 barcodeECLevel.setValue(rowIndicatorValue / 3);
178 barcodeRowCountLowerPart.setValue(rowIndicatorValue % 3); 178 barcodeRowCountLowerPart.setValue(rowIndicatorValue % 3);
(...skipping 19 matching lines...) Expand all
198 FX_BOOL CBC_DetectionResultRowIndicatorColumn::isLeft() 198 FX_BOOL CBC_DetectionResultRowIndicatorColumn::isLeft()
199 { 199 {
200 return m_isLeft; 200 return m_isLeft;
201 } 201 }
202 CFX_ByteString CBC_DetectionResultRowIndicatorColumn::toString() 202 CFX_ByteString CBC_DetectionResultRowIndicatorColumn::toString()
203 { 203 {
204 return (CFX_ByteString)"IsLeft: " + (CFX_ByteString)m_isLeft + '\n' + CBC_De tectionResultColumn::toString(); 204 return (CFX_ByteString)"IsLeft: " + (CFX_ByteString)m_isLeft + '\n' + CBC_De tectionResultColumn::toString();
205 } 205 }
206 void CBC_DetectionResultRowIndicatorColumn::removeIncorrectCodewords(CFX_PtrArra y* codewords, CBC_BarcodeMetadata barcodeMetadata) 206 void CBC_DetectionResultRowIndicatorColumn::removeIncorrectCodewords(CFX_PtrArra y* codewords, CBC_BarcodeMetadata barcodeMetadata)
207 { 207 {
208 for (FX_INT32 codewordRow = 0; codewordRow < codewords->GetSize(); codewordR ow++) { 208 for (int32_t codewordRow = 0; codewordRow < codewords->GetSize(); codewordRo w++) {
209 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(codewordRow); 209 CBC_Codeword* codeword = (CBC_Codeword*)codewords->GetAt(codewordRow);
210 if (codeword == NULL) { 210 if (codeword == NULL) {
211 continue; 211 continue;
212 } 212 }
213 FX_INT32 rowIndicatorValue = codeword->getValue() % 30; 213 int32_t rowIndicatorValue = codeword->getValue() % 30;
214 FX_INT32 codewordRowNumber = codeword->getRowNumber(); 214 int32_t codewordRowNumber = codeword->getRowNumber();
215 if (codewordRowNumber > barcodeMetadata.getRowCount()) { 215 if (codewordRowNumber > barcodeMetadata.getRowCount()) {
216 codewords->SetAt(codewordRow, NULL); 216 codewords->SetAt(codewordRow, NULL);
217 continue; 217 continue;
218 } 218 }
219 if (!m_isLeft) { 219 if (!m_isLeft) {
220 codewordRowNumber += 2; 220 codewordRowNumber += 2;
221 } 221 }
222 switch (codewordRowNumber % 3) { 222 switch (codewordRowNumber % 3) {
223 case 0: 223 case 0:
224 if (rowIndicatorValue * 3 + 1 != barcodeMetadata.getRowCountUppe rPart()) { 224 if (rowIndicatorValue * 3 + 1 != barcodeMetadata.getRowCountUppe rPart()) {
225 codewords->SetAt(codewordRow, NULL); 225 codewords->SetAt(codewordRow, NULL);
226 } 226 }
227 break; 227 break;
228 case 1: 228 case 1:
229 if (rowIndicatorValue / 3 != barcodeMetadata.getErrorCorrectionL evel() || 229 if (rowIndicatorValue / 3 != barcodeMetadata.getErrorCorrectionL evel() ||
230 rowIndicatorValue % 3 != barcodeMetadata.getRowCountLowe rPart()) { 230 rowIndicatorValue % 3 != barcodeMetadata.getRowCountLowe rPart()) {
231 codewords->SetAt(codewordRow, NULL); 231 codewords->SetAt(codewordRow, NULL);
232 } 232 }
233 break; 233 break;
234 case 2: 234 case 2:
235 if (rowIndicatorValue + 1 != barcodeMetadata.getColumnCount()) { 235 if (rowIndicatorValue + 1 != barcodeMetadata.getColumnCount()) {
236 codewords->SetAt(codewordRow, NULL); 236 codewords->SetAt(codewordRow, NULL);
237 } 237 }
238 break; 238 break;
239 } 239 }
240 } 240 }
241 } 241 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/pdf417/BC_PDF417DetectionResultRowIndicatorColumn.h ('k') | xfa/src/fxbarcode/pdf417/BC_PDF417Detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698