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

Side by Side Diff: xfa/src/fxbarcode/pdf417/BC_PDF417Detector.cpp

Issue 1726373002: Remove foo != NULL checks in xfa/src/fxbarcode. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 9 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 2009 ZXing authors 8 * Copyright 2009 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (vertices) { 117 if (vertices) {
118 delete (vertices); 118 delete (vertices);
119 } 119 }
120 break; 120 break;
121 } 121 }
122 foundBarcodeInRow = FALSE; 122 foundBarcodeInRow = FALSE;
123 column = 0; 123 column = 0;
124 for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) { 124 for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) {
125 CFX_PtrArray* barcodeCoordinate = 125 CFX_PtrArray* barcodeCoordinate =
126 (CFX_PtrArray*)barcodeCoordinates->GetAt(i); 126 (CFX_PtrArray*)barcodeCoordinates->GetAt(i);
127 if (barcodeCoordinate->GetAt(1) != NULL) { 127 if (barcodeCoordinate->GetAt(1)) {
128 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(1))->GetY(); 128 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(1))->GetY();
129 } 129 }
130 if (barcodeCoordinate->GetAt(3) != NULL) { 130 if (barcodeCoordinate->GetAt(3)) {
131 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(3))->GetY(); 131 row = row > ((CBC_ResultPoint*)barcodeCoordinate->GetAt(3))->GetY();
132 } 132 }
133 } 133 }
134 row += ROW_STEP; 134 row += ROW_STEP;
135 if (vertices) { 135 if (vertices) {
136 delete (vertices); 136 delete (vertices);
137 } 137 }
138 continue; 138 continue;
139 } 139 }
140 foundBarcodeInRow = TRUE; 140 foundBarcodeInRow = TRUE;
141 barcodeCoordinates->Add(vertices); 141 barcodeCoordinates->Add(vertices);
142 if (!multiple) { 142 if (!multiple) {
143 break; 143 break;
144 } 144 }
145 if (vertices->GetAt(2) != NULL) { 145 if (vertices->GetAt(2)) {
146 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetX(); 146 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetX();
147 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetY(); 147 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(2))->GetY();
148 } else { 148 } else {
149 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetX(); 149 column = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetX();
150 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetY(); 150 row = (int32_t)((CBC_ResultPoint*)vertices->GetAt(4))->GetY();
151 } 151 }
152 } 152 }
153 return barcodeCoordinates; 153 return barcodeCoordinates;
154 } 154 }
155 CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix, 155 CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix,
156 int32_t startRow, 156 int32_t startRow,
157 int32_t startColumn) { 157 int32_t startColumn) {
158 int32_t height = matrix->GetHeight(); 158 int32_t height = matrix->GetHeight();
159 int32_t width = matrix->GetWidth(); 159 int32_t width = matrix->GetWidth();
160 CFX_PtrArray* result = new CFX_PtrArray; 160 CFX_PtrArray* result = new CFX_PtrArray;
161 result->SetSize(8); 161 result->SetSize(8);
162 CFX_PtrArray* startptr = findRowsWithPattern( 162 CFX_PtrArray* startptr = findRowsWithPattern(
163 matrix, height, width, startRow, startColumn, START_PATTERN, 163 matrix, height, width, startRow, startColumn, START_PATTERN,
164 sizeof(START_PATTERN) / sizeof(START_PATTERN[0])); 164 sizeof(START_PATTERN) / sizeof(START_PATTERN[0]));
165 copyToResult( 165 copyToResult(
166 result, startptr, INDEXES_START_PATTERN, 166 result, startptr, INDEXES_START_PATTERN,
167 sizeof(INDEXES_START_PATTERN) / sizeof(INDEXES_START_PATTERN[0])); 167 sizeof(INDEXES_START_PATTERN) / sizeof(INDEXES_START_PATTERN[0]));
168 startptr->RemoveAll(); 168 startptr->RemoveAll();
169 delete startptr; 169 delete startptr;
170 if (result->GetAt(4) != NULL) { 170 if (result->GetAt(4)) {
171 startColumn = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetX(); 171 startColumn = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetX();
172 startRow = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetY(); 172 startRow = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetY();
173 } 173 }
174 CFX_PtrArray* stopptr = findRowsWithPattern( 174 CFX_PtrArray* stopptr = findRowsWithPattern(
175 matrix, height, width, startRow, startColumn, STOP_PATTERN, 175 matrix, height, width, startRow, startColumn, STOP_PATTERN,
176 sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0])); 176 sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0]));
177 copyToResult(result, stopptr, INDEXES_STOP_PATTERN, 177 copyToResult(result, stopptr, INDEXES_STOP_PATTERN,
178 sizeof(INDEXES_STOP_PATTERN) / sizeof(INDEXES_STOP_PATTERN[0])); 178 sizeof(INDEXES_STOP_PATTERN) / sizeof(INDEXES_STOP_PATTERN[0]));
179 stopptr->RemoveAll(); 179 stopptr->RemoveAll();
180 delete stopptr; 180 delete stopptr;
(...skipping 16 matching lines...) Expand all
197 int32_t patternLength) { 197 int32_t patternLength) {
198 CFX_PtrArray* result = new CFX_PtrArray; 198 CFX_PtrArray* result = new CFX_PtrArray;
199 result->SetSize(4); 199 result->SetSize(4);
200 FX_BOOL found = FALSE; 200 FX_BOOL found = FALSE;
201 CFX_Int32Array counters; 201 CFX_Int32Array counters;
202 counters.SetSize(patternLength); 202 counters.SetSize(patternLength);
203 for (; startRow < height; startRow += ROW_STEP) { 203 for (; startRow < height; startRow += ROW_STEP) {
204 CFX_Int32Array* loc = 204 CFX_Int32Array* loc =
205 findGuardPattern(matrix, startColumn, startRow, width, FALSE, pattern, 205 findGuardPattern(matrix, startColumn, startRow, width, FALSE, pattern,
206 patternLength, counters); 206 patternLength, counters);
207 if (loc != NULL) { 207 if (loc) {
208 while (startRow > 0) { 208 while (startRow > 0) {
209 CFX_Int32Array* previousRowLoc = 209 CFX_Int32Array* previousRowLoc =
210 findGuardPattern(matrix, startColumn, --startRow, width, FALSE, 210 findGuardPattern(matrix, startColumn, --startRow, width, FALSE,
211 pattern, patternLength, counters); 211 pattern, patternLength, counters);
212 if (previousRowLoc != NULL) { 212 if (previousRowLoc) {
213 delete loc; 213 delete loc;
214 loc = previousRowLoc; 214 loc = previousRowLoc;
215 } else { 215 } else {
216 startRow++; 216 startRow++;
217 break; 217 break;
218 } 218 }
219 } 219 }
220 result->SetAt( 220 result->SetAt(
221 0, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(0), (FX_FLOAT)startRow)); 221 0, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(0), (FX_FLOAT)startRow));
222 result->SetAt( 222 result->SetAt(
223 1, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(1), (FX_FLOAT)startRow)); 223 1, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(1), (FX_FLOAT)startRow));
224 found = TRUE; 224 found = TRUE;
225 delete loc; 225 delete loc;
226 break; 226 break;
227 } 227 }
228 } 228 }
229 int32_t stopRow = startRow + 1; 229 int32_t stopRow = startRow + 1;
230 if (found) { 230 if (found) {
231 int32_t skippedRowCount = 0; 231 int32_t skippedRowCount = 0;
232 CFX_Int32Array previousRowLoc; 232 CFX_Int32Array previousRowLoc;
233 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(0))->GetX()); 233 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(0))->GetX());
234 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(1))->GetX()); 234 previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(1))->GetX());
235 for (; stopRow < height; stopRow++) { 235 for (; stopRow < height; stopRow++) {
236 CFX_Int32Array* loc = 236 CFX_Int32Array* loc =
237 findGuardPattern(matrix, previousRowLoc[0], stopRow, width, FALSE, 237 findGuardPattern(matrix, previousRowLoc[0], stopRow, width, FALSE,
238 pattern, patternLength, counters); 238 pattern, patternLength, counters);
239 if (loc != NULL && 239 if (loc && abs(previousRowLoc[0] - loc->GetAt(0)) < MAX_PATTERN_DRIFT &&
240 abs(previousRowLoc[0] - loc->GetAt(0)) < MAX_PATTERN_DRIFT &&
241 abs(previousRowLoc[1] - loc->GetAt(1)) < MAX_PATTERN_DRIFT) { 240 abs(previousRowLoc[1] - loc->GetAt(1)) < MAX_PATTERN_DRIFT) {
242 previousRowLoc.Copy(*loc); 241 previousRowLoc.Copy(*loc);
243 skippedRowCount = 0; 242 skippedRowCount = 0;
244 } else { 243 } else {
245 if (skippedRowCount > SKIPPED_ROW_COUNT_MAX) { 244 if (skippedRowCount > SKIPPED_ROW_COUNT_MAX) {
246 delete loc; 245 delete loc;
247 break; 246 break;
248 } else { 247 } else {
249 skippedRowCount++; 248 skippedRowCount++;
250 } 249 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 int32_t scaledPattern = pattern[x] * unitBarWidth; 343 int32_t scaledPattern = pattern[x] * unitBarWidth;
345 int32_t variance = counter > scaledPattern ? counter - scaledPattern 344 int32_t variance = counter > scaledPattern ? counter - scaledPattern
346 : scaledPattern - counter; 345 : scaledPattern - counter;
347 if (variance > maxIndividualVariance) { 346 if (variance > maxIndividualVariance) {
348 return INTEGER_MAX; 347 return INTEGER_MAX;
349 } 348 }
350 totalVariance += variance; 349 totalVariance += variance;
351 } 350 }
352 return totalVariance / total; 351 return totalVariance / total;
353 } 352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698