| 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 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 int32_t CBC_Detector::BARCODE_MIN_HEIGHT = 10; | 50 int32_t CBC_Detector::BARCODE_MIN_HEIGHT = 10; |
| 51 | 51 |
| 52 CBC_Detector::CBC_Detector() {} | 52 CBC_Detector::CBC_Detector() {} |
| 53 CBC_Detector::~CBC_Detector() {} | 53 CBC_Detector::~CBC_Detector() {} |
| 54 | 54 |
| 55 CBC_PDF417DetectorResult* CBC_Detector::detect(CBC_BinaryBitmap* image, | 55 CBC_PDF417DetectorResult* CBC_Detector::detect(CBC_BinaryBitmap* image, |
| 56 int32_t hints, | 56 int32_t hints, |
| 57 FX_BOOL multiple, | 57 FX_BOOL multiple, |
| 58 int32_t& e) { | 58 int32_t& e) { |
| 59 CBC_CommonBitMatrix* bitMatrix = image->GetBlackMatrix(e); | 59 CBC_CommonBitMatrix* bitMatrix = image->GetBlackMatrix(e); |
| 60 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 60 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 61 CBC_ResultPointArrayArray* barcodeCoordinates = detect(multiple, bitMatrix); | 61 CBC_ResultPointArrayArray* barcodeCoordinates = detect(multiple, bitMatrix); |
| 62 if (barcodeCoordinates->GetSize() == 0) { | 62 if (barcodeCoordinates->GetSize() == 0) { |
| 63 rotate180(bitMatrix); | 63 rotate180(bitMatrix); |
| 64 barcodeCoordinates = detect(multiple, bitMatrix); | 64 barcodeCoordinates = detect(multiple, bitMatrix); |
| 65 } | 65 } |
| 66 if (barcodeCoordinates->GetSize() == 0) { | 66 if (barcodeCoordinates->GetSize() == 0) { |
| 67 e = BCExceptionUnSupportedBarcode; | 67 e = BCExceptionUnSupportedBarcode; |
| 68 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 68 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 69 } | 69 } |
| 70 return new CBC_PDF417DetectorResult(bitMatrix, barcodeCoordinates); | 70 return new CBC_PDF417DetectorResult(bitMatrix, barcodeCoordinates); |
| 71 } | 71 } |
| 72 void CBC_Detector::rotate180(CBC_CommonBitMatrix* bitMatrix) { | 72 void CBC_Detector::rotate180(CBC_CommonBitMatrix* bitMatrix) { |
| 73 int32_t width = bitMatrix->GetWidth(); | 73 int32_t width = bitMatrix->GetWidth(); |
| 74 int32_t height = bitMatrix->GetHeight(); | 74 int32_t height = bitMatrix->GetHeight(); |
| 75 CBC_CommonBitArray* firstRowBitArray = new CBC_CommonBitArray(width); | 75 CBC_CommonBitArray* firstRowBitArray = new CBC_CommonBitArray(width); |
| 76 CBC_CommonBitArray* secondRowBitArray = new CBC_CommonBitArray(width); | 76 CBC_CommonBitArray* secondRowBitArray = new CBC_CommonBitArray(width); |
| 77 CBC_CommonBitArray* tmpBitArray = new CBC_CommonBitArray(width); | 77 CBC_CommonBitArray* tmpBitArray = new CBC_CommonBitArray(width); |
| 78 for (int32_t y = 0; y<(height + 1)>> 1; y++) { | 78 for (int32_t y = 0; y<(height + 1)>> 1; y++) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 108 | 108 |
| 109 CBC_ResultPointArrayArray* CBC_Detector::detect( | 109 CBC_ResultPointArrayArray* CBC_Detector::detect( |
| 110 FX_BOOL multiple, | 110 FX_BOOL multiple, |
| 111 CBC_CommonBitMatrix* bitMatrix) { | 111 CBC_CommonBitMatrix* bitMatrix) { |
| 112 CBC_ResultPointArrayArray* barcodeCoordinates = new CBC_ResultPointArrayArray; | 112 CBC_ResultPointArrayArray* barcodeCoordinates = new CBC_ResultPointArrayArray; |
| 113 int32_t row = 0; | 113 int32_t row = 0; |
| 114 int32_t column = 0; | 114 int32_t column = 0; |
| 115 FX_BOOL foundBarcodeInRow = FALSE; | 115 FX_BOOL foundBarcodeInRow = FALSE; |
| 116 while (row < bitMatrix->GetHeight()) { | 116 while (row < bitMatrix->GetHeight()) { |
| 117 CBC_ResultPointArray* vertices = findVertices(bitMatrix, row, column); | 117 CBC_ResultPointArray* vertices = findVertices(bitMatrix, row, column); |
| 118 if (vertices->GetAt(0) == NULL && vertices->GetAt(3) == NULL) { | 118 if (!vertices->GetAt(0) && !vertices->GetAt(3)) { |
| 119 if (!foundBarcodeInRow) { | 119 if (!foundBarcodeInRow) { |
| 120 delete vertices; | 120 delete vertices; |
| 121 break; | 121 break; |
| 122 } | 122 } |
| 123 foundBarcodeInRow = FALSE; | 123 foundBarcodeInRow = FALSE; |
| 124 column = 0; | 124 column = 0; |
| 125 for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) { | 125 for (int32_t i = 0; i < barcodeCoordinates->GetSize(); i++) { |
| 126 CBC_ResultPointArray* barcodeCoordinate = barcodeCoordinates->GetAt(i); | 126 CBC_ResultPointArray* barcodeCoordinate = barcodeCoordinates->GetAt(i); |
| 127 if (barcodeCoordinate->GetAt(1)) { | 127 if (barcodeCoordinate->GetAt(1)) { |
| 128 row = row > barcodeCoordinate->GetAt(1)->GetY(); | 128 row = row > barcodeCoordinate->GetAt(1)->GetY(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 delete loc; | 248 delete loc; |
| 249 } | 249 } |
| 250 stopRow -= skippedRowCount + 1; | 250 stopRow -= skippedRowCount + 1; |
| 251 result->SetAt(2, new CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(0), | 251 result->SetAt(2, new CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(0), |
| 252 (FX_FLOAT)stopRow)); | 252 (FX_FLOAT)stopRow)); |
| 253 result->SetAt(3, new CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(1), | 253 result->SetAt(3, new CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(1), |
| 254 (FX_FLOAT)stopRow)); | 254 (FX_FLOAT)stopRow)); |
| 255 } | 255 } |
| 256 if (stopRow - startRow < BARCODE_MIN_HEIGHT) { | 256 if (stopRow - startRow < BARCODE_MIN_HEIGHT) { |
| 257 for (int32_t i = 0; i < result->GetSize(); i++) { | 257 for (int32_t i = 0; i < result->GetSize(); i++) { |
| 258 result->SetAt(i, NULL); | 258 result->SetAt(i, nullptr); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 return result; | 261 return result; |
| 262 } | 262 } |
| 263 CFX_Int32Array* CBC_Detector::findGuardPattern(CBC_CommonBitMatrix* matrix, | 263 CFX_Int32Array* CBC_Detector::findGuardPattern(CBC_CommonBitMatrix* matrix, |
| 264 int32_t column, | 264 int32_t column, |
| 265 int32_t row, | 265 int32_t row, |
| 266 int32_t width, | 266 int32_t width, |
| 267 FX_BOOL whiteFirst, | 267 FX_BOOL whiteFirst, |
| 268 int32_t* pattern, | 268 int32_t* pattern, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 309 } |
| 310 if (counterPosition == patternLength - 1) { | 310 if (counterPosition == patternLength - 1) { |
| 311 if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < | 311 if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < |
| 312 MAX_AVG_VARIANCE) { | 312 MAX_AVG_VARIANCE) { |
| 313 intarray->Add(patternStart); | 313 intarray->Add(patternStart); |
| 314 intarray->Add(x - 1); | 314 intarray->Add(x - 1); |
| 315 return intarray; | 315 return intarray; |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 delete intarray; | 318 delete intarray; |
| 319 return NULL; | 319 return nullptr; |
| 320 } | 320 } |
| 321 int32_t CBC_Detector::patternMatchVariance(CFX_Int32Array& counters, | 321 int32_t CBC_Detector::patternMatchVariance(CFX_Int32Array& counters, |
| 322 int32_t* pattern, | 322 int32_t* pattern, |
| 323 int32_t maxIndividualVariance) { | 323 int32_t maxIndividualVariance) { |
| 324 int32_t numCounters = counters.GetSize(); | 324 int32_t numCounters = counters.GetSize(); |
| 325 int32_t total = 0; | 325 int32_t total = 0; |
| 326 int32_t patternLength = 0; | 326 int32_t patternLength = 0; |
| 327 for (int32_t i = 0; i < numCounters; i++) { | 327 for (int32_t i = 0; i < numCounters; i++) { |
| 328 total += counters[i]; | 328 total += counters[i]; |
| 329 patternLength += pattern[i]; | 329 patternLength += pattern[i]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 340 int32_t scaledPattern = pattern[x] * unitBarWidth; | 340 int32_t scaledPattern = pattern[x] * unitBarWidth; |
| 341 int32_t variance = counter > scaledPattern ? counter - scaledPattern | 341 int32_t variance = counter > scaledPattern ? counter - scaledPattern |
| 342 : scaledPattern - counter; | 342 : scaledPattern - counter; |
| 343 if (variance > maxIndividualVariance) { | 343 if (variance > maxIndividualVariance) { |
| 344 return INTEGER_MAX; | 344 return INTEGER_MAX; |
| 345 } | 345 } |
| 346 totalVariance += variance; | 346 totalVariance += variance; |
| 347 } | 347 } |
| 348 return totalVariance / total; | 348 return totalVariance / total; |
| 349 } | 349 } |
| OLD | NEW |