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

Side by Side Diff: xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp

Issue 2048983002: Get rid of NULLs in xfa/fxbarcode/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 4 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
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRDetector.cpp ('k') | xfa/fxbarcode/qrcode/BC_QRGridSampler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (confirmed) { 159 if (confirmed) {
160 iSkip = stateCount[0]; 160 iSkip = stateCount[0];
161 if (m_hasSkipped) { 161 if (m_hasSkipped) {
162 done = HaveMultiplyConfirmedCenters(); 162 done = HaveMultiplyConfirmedCenters();
163 } 163 }
164 } 164 }
165 } 165 }
166 } 166 }
167 std::unique_ptr<CFX_ArrayTemplate<CBC_QRFinderPattern*>> patternInfo( 167 std::unique_ptr<CFX_ArrayTemplate<CBC_QRFinderPattern*>> patternInfo(
168 SelectBestpatterns(e)); 168 SelectBestpatterns(e));
169 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 169 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
170 OrderBestPatterns(patternInfo.get()); 170 OrderBestPatterns(patternInfo.get());
171 return new CBC_QRFinderPatternInfo(patternInfo.get()); 171 return new CBC_QRFinderPatternInfo(patternInfo.get());
172 } 172 }
173 void CBC_QRFinderPatternFinder::OrderBestPatterns( 173 void CBC_QRFinderPatternFinder::OrderBestPatterns(
174 CFX_ArrayTemplate<CBC_QRFinderPattern*>* patterns) { 174 CFX_ArrayTemplate<CBC_QRFinderPattern*>* patterns) {
175 FX_FLOAT abDistance = Distance((*patterns)[0], (*patterns)[1]); 175 FX_FLOAT abDistance = Distance((*patterns)[0], (*patterns)[1]);
176 FX_FLOAT bcDistance = Distance((*patterns)[1], (*patterns)[2]); 176 FX_FLOAT bcDistance = Distance((*patterns)[1], (*patterns)[2]);
177 FX_FLOAT acDistance = Distance((*patterns)[0], (*patterns)[2]); 177 FX_FLOAT acDistance = Distance((*patterns)[0], (*patterns)[2]);
178 CBC_QRFinderPattern* topLeft; 178 CBC_QRFinderPattern* topLeft;
179 CBC_QRFinderPattern* topRight; 179 CBC_QRFinderPattern* topRight;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 return TRUE; 393 return TRUE;
394 } 394 }
395 } 395 }
396 return FALSE; 396 return FALSE;
397 } 397 }
398 int32_t CBC_QRFinderPatternFinder::FindRowSkip() { 398 int32_t CBC_QRFinderPatternFinder::FindRowSkip() {
399 int32_t max = m_possibleCenters.GetSize(); 399 int32_t max = m_possibleCenters.GetSize();
400 if (max <= 1) { 400 if (max <= 1) {
401 return 0; 401 return 0;
402 } 402 }
403 FinderPattern* firstConfirmedCenter = NULL; 403 FinderPattern* firstConfirmedCenter = nullptr;
404 for (int32_t i = 0; i < max; i++) { 404 for (int32_t i = 0; i < max; i++) {
405 CBC_QRFinderPattern* center = m_possibleCenters[i]; 405 CBC_QRFinderPattern* center = m_possibleCenters[i];
406 if (center->GetCount() >= CENTER_QUORUM) { 406 if (center->GetCount() >= CENTER_QUORUM) {
407 if (firstConfirmedCenter == NULL) { 407 if (firstConfirmedCenter) {
408 firstConfirmedCenter = center;
409 } else {
410 m_hasSkipped = TRUE; 408 m_hasSkipped = TRUE;
411 return (int32_t)((fabs(firstConfirmedCenter->GetX() - center->GetX()) - 409 return (int32_t)((fabs(firstConfirmedCenter->GetX() - center->GetX()) -
412 fabs(firstConfirmedCenter->GetY() - center->GetY())) / 410 fabs(firstConfirmedCenter->GetY() - center->GetY())) /
413 2); 411 2);
414 } 412 }
413 firstConfirmedCenter = center;
415 } 414 }
416 } 415 }
417 return 0; 416 return 0;
418 } 417 }
419 FX_BOOL CBC_QRFinderPatternFinder::HaveMultiplyConfirmedCenters() { 418 FX_BOOL CBC_QRFinderPatternFinder::HaveMultiplyConfirmedCenters() {
420 int32_t confirmedCount = 0; 419 int32_t confirmedCount = 0;
421 FX_FLOAT totalModuleSize = 0.0f; 420 FX_FLOAT totalModuleSize = 0.0f;
422 int32_t max = m_possibleCenters.GetSize(); 421 int32_t max = m_possibleCenters.GetSize();
423 int32_t i; 422 int32_t i;
424 for (i = 0; i < max; i++) { 423 for (i = 0; i < max; i++) {
(...skipping 13 matching lines...) Expand all
438 totalDeviation += fabs(pattern->GetEstimatedModuleSize() - average); 437 totalDeviation += fabs(pattern->GetEstimatedModuleSize() - average);
439 } 438 }
440 return totalDeviation <= 0.05f * totalModuleSize; 439 return totalDeviation <= 0.05f * totalModuleSize;
441 } 440 }
442 441
443 CFX_ArrayTemplate<CBC_QRFinderPattern*>* 442 CFX_ArrayTemplate<CBC_QRFinderPattern*>*
444 CBC_QRFinderPatternFinder::SelectBestpatterns(int32_t& e) { 443 CBC_QRFinderPatternFinder::SelectBestpatterns(int32_t& e) {
445 int32_t startSize = m_possibleCenters.GetSize(); 444 int32_t startSize = m_possibleCenters.GetSize();
446 if (m_possibleCenters.GetSize() < 3) { 445 if (m_possibleCenters.GetSize() < 3) {
447 e = BCExceptionRead; 446 e = BCExceptionRead;
448 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 447 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
449 } 448 }
450 FX_FLOAT average = 0.0f; 449 FX_FLOAT average = 0.0f;
451 if (startSize > 3) { 450 if (startSize > 3) {
452 FX_FLOAT totalModuleSize = 0.0f; 451 FX_FLOAT totalModuleSize = 0.0f;
453 for (int32_t i = 0; i < startSize; i++) 452 for (int32_t i = 0; i < startSize; i++)
454 totalModuleSize += m_possibleCenters[i]->GetEstimatedModuleSize(); 453 totalModuleSize += m_possibleCenters[i]->GetEstimatedModuleSize();
455 454
456 average = totalModuleSize / (FX_FLOAT)startSize; 455 average = totalModuleSize / (FX_FLOAT)startSize;
457 for (int32_t j = 0; 456 for (int32_t j = 0;
458 j < m_possibleCenters.GetSize() && m_possibleCenters.GetSize() > 3; 457 j < m_possibleCenters.GetSize() && m_possibleCenters.GetSize() > 3;
(...skipping 14 matching lines...) Expand all
473 }); 472 });
474 } 473 }
475 CFX_ArrayTemplate<CBC_QRFinderPattern*>* vec = 474 CFX_ArrayTemplate<CBC_QRFinderPattern*>* vec =
476 new CFX_ArrayTemplate<CBC_QRFinderPattern*>(); 475 new CFX_ArrayTemplate<CBC_QRFinderPattern*>();
477 vec->SetSize(3); 476 vec->SetSize(3);
478 (*vec)[0] = m_possibleCenters[0]->Clone(); 477 (*vec)[0] = m_possibleCenters[0]->Clone();
479 (*vec)[1] = m_possibleCenters[1]->Clone(); 478 (*vec)[1] = m_possibleCenters[1]->Clone();
480 (*vec)[2] = m_possibleCenters[2]->Clone(); 479 (*vec)[2] = m_possibleCenters[2]->Clone();
481 return vec; 480 return vec;
482 } 481 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRDetector.cpp ('k') | xfa/fxbarcode/qrcode/BC_QRGridSampler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698