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

Side by Side Diff: xfa/fxbarcode/qrcode/BC_QRDetector.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
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 23 matching lines...) Expand all
34 #include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h" 34 #include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h"
35 #include "xfa/fxbarcode/qrcode/BC_QRFinderPattern.h" 35 #include "xfa/fxbarcode/qrcode/BC_QRFinderPattern.h"
36 #include "xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.h" 36 #include "xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.h"
37 #include "xfa/fxbarcode/qrcode/BC_QRGridSampler.h" 37 #include "xfa/fxbarcode/qrcode/BC_QRGridSampler.h"
38 38
39 CBC_QRDetector::CBC_QRDetector(CBC_CommonBitMatrix* image) : m_image(image) {} 39 CBC_QRDetector::CBC_QRDetector(CBC_CommonBitMatrix* image) : m_image(image) {}
40 CBC_QRDetector::~CBC_QRDetector() {} 40 CBC_QRDetector::~CBC_QRDetector() {}
41 CBC_QRDetectorResult* CBC_QRDetector::Detect(int32_t hints, int32_t& e) { 41 CBC_QRDetectorResult* CBC_QRDetector::Detect(int32_t hints, int32_t& e) {
42 CBC_QRFinderPatternFinder finder(m_image); 42 CBC_QRFinderPatternFinder finder(m_image);
43 std::unique_ptr<CBC_QRFinderPatternInfo> info(finder.Find(hints, e)); 43 std::unique_ptr<CBC_QRFinderPatternInfo> info(finder.Find(hints, e));
44 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 44 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
45 CBC_QRDetectorResult* qdr = ProcessFinderPatternInfo(info.get(), e); 45 CBC_QRDetectorResult* qdr = ProcessFinderPatternInfo(info.get(), e);
46 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 46 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
47 return qdr; 47 return qdr;
48 } 48 }
49 CBC_QRDetectorResult* CBC_QRDetector::ProcessFinderPatternInfo( 49 CBC_QRDetectorResult* CBC_QRDetector::ProcessFinderPatternInfo(
50 CBC_QRFinderPatternInfo* info, 50 CBC_QRFinderPatternInfo* info,
51 int32_t& e) { 51 int32_t& e) {
52 std::unique_ptr<CBC_QRFinderPattern> topLeft(info->GetTopLeft()); 52 std::unique_ptr<CBC_QRFinderPattern> topLeft(info->GetTopLeft());
53 std::unique_ptr<CBC_QRFinderPattern> topRight(info->GetTopRight()); 53 std::unique_ptr<CBC_QRFinderPattern> topRight(info->GetTopRight());
54 std::unique_ptr<CBC_QRFinderPattern> bottomLeft(info->GetBottomLeft()); 54 std::unique_ptr<CBC_QRFinderPattern> bottomLeft(info->GetBottomLeft());
55 FX_FLOAT moduleSize = 55 FX_FLOAT moduleSize =
56 CalculateModuleSize(topLeft.get(), topRight.get(), bottomLeft.get()); 56 CalculateModuleSize(topLeft.get(), topRight.get(), bottomLeft.get());
(...skipping 28 matching lines...) Expand all
85 moduleSize, estAlignmentX, estAlignmentY, (FX_FLOAT)i, e); 85 moduleSize, estAlignmentX, estAlignmentY, (FX_FLOAT)i, e);
86 if (temp) { 86 if (temp) {
87 alignmentPattern = temp; 87 alignmentPattern = temp;
88 break; 88 break;
89 } 89 }
90 } 90 }
91 } 91 }
92 CBC_CommonBitMatrix* bits = 92 CBC_CommonBitMatrix* bits =
93 SampleGrid(m_image, topLeft.get(), topRight.get(), bottomLeft.get(), 93 SampleGrid(m_image, topLeft.get(), topRight.get(), bottomLeft.get(),
94 (CBC_ResultPoint*)(alignmentPattern), dimension, e); 94 (CBC_ResultPoint*)(alignmentPattern), dimension, e);
95 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 95 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
96 96
97 CFX_ArrayTemplate<CBC_ResultPoint*>* points = 97 CFX_ArrayTemplate<CBC_ResultPoint*>* points =
98 new CFX_ArrayTemplate<CBC_ResultPoint*>(); 98 new CFX_ArrayTemplate<CBC_ResultPoint*>();
99 points->Add(bottomLeft.release()); 99 points->Add(bottomLeft.release());
100 points->Add(topLeft.release()); 100 points->Add(topLeft.release());
101 points->Add(topRight.release()); 101 points->Add(topRight.release());
102 if (alignmentPattern) 102 if (alignmentPattern)
103 points->Add(alignmentPattern); 103 points->Add(alignmentPattern);
104 return new CBC_QRDetectorResult(bits, points); 104 return new CBC_QRDetectorResult(bits, points);
105 } 105 }
(...skipping 18 matching lines...) Expand all
124 bottomRightX = (topRight->GetX() - topLeft->GetX()) + bottomLeft->GetX(); 124 bottomRightX = (topRight->GetX() - topLeft->GetX()) + bottomLeft->GetX();
125 bottomRightY = (topRight->GetY() - topLeft->GetY()) + bottomLeft->GetY(); 125 bottomRightY = (topRight->GetY() - topLeft->GetY()) + bottomLeft->GetY();
126 sourceBottomRightX = sourceBottomRightY = dimMinusThree; 126 sourceBottomRightX = sourceBottomRightY = dimMinusThree;
127 } 127 }
128 CBC_QRGridSampler& sampler = CBC_QRGridSampler::GetInstance(); 128 CBC_QRGridSampler& sampler = CBC_QRGridSampler::GetInstance();
129 CBC_CommonBitMatrix* cbm = sampler.SampleGrid( 129 CBC_CommonBitMatrix* cbm = sampler.SampleGrid(
130 image, dimension, dimension, 3.5f, 3.5f, dimMinusThree, 3.5f, 130 image, dimension, dimension, 3.5f, 3.5f, dimMinusThree, 3.5f,
131 sourceBottomRightX, sourceBottomRightY, 3.5f, dimMinusThree, 131 sourceBottomRightX, sourceBottomRightY, 3.5f, dimMinusThree,
132 topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(), 132 topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(),
133 bottomRightX, bottomRightY, bottomLeft->GetX(), bottomLeft->GetY(), e); 133 bottomRightX, bottomRightY, bottomLeft->GetX(), bottomLeft->GetY(), e);
134 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 134 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
135 return cbm; 135 return cbm;
136 } 136 }
137 int32_t CBC_QRDetector::ComputeDimension(CBC_ResultPoint* topLeft, 137 int32_t CBC_QRDetector::ComputeDimension(CBC_ResultPoint* topLeft,
138 CBC_ResultPoint* topRight, 138 CBC_ResultPoint* topRight,
139 CBC_ResultPoint* bottomLeft, 139 CBC_ResultPoint* bottomLeft,
140 FX_FLOAT moduleSize, 140 FX_FLOAT moduleSize,
141 int32_t& e) { 141 int32_t& e) {
142 int32_t tltrCentersDimension = Round( 142 int32_t tltrCentersDimension = Round(
143 CBC_QRFinderPatternFinder::Distance(topLeft, topRight) / moduleSize); 143 CBC_QRFinderPatternFinder::Distance(topLeft, topRight) / moduleSize);
144 int32_t tlblCentersDimension = Round( 144 int32_t tlblCentersDimension = Round(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 int32_t estAlignmentX, 256 int32_t estAlignmentX,
257 int32_t estAlignmentY, 257 int32_t estAlignmentY,
258 FX_FLOAT allowanceFactor, 258 FX_FLOAT allowanceFactor,
259 int32_t& e) { 259 int32_t& e) {
260 int32_t allowance = (int32_t)(allowanceFactor * overallEstModuleSize); 260 int32_t allowance = (int32_t)(allowanceFactor * overallEstModuleSize);
261 int32_t alignmentAreaLeftX = std::max(0, estAlignmentX - allowance); 261 int32_t alignmentAreaLeftX = std::max(0, estAlignmentX - allowance);
262 int32_t alignmentAreaRightX = 262 int32_t alignmentAreaRightX =
263 std::min(m_image->GetWidth() - 1, estAlignmentX + allowance); 263 std::min(m_image->GetWidth() - 1, estAlignmentX + allowance);
264 if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) { 264 if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) {
265 e = BCExceptionRead; 265 e = BCExceptionRead;
266 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 266 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
267 } 267 }
268 int32_t alignmentAreaTopY = std::max(0, estAlignmentY - allowance); 268 int32_t alignmentAreaTopY = std::max(0, estAlignmentY - allowance);
269 int32_t alignmentAreaBottomY = 269 int32_t alignmentAreaBottomY =
270 std::min(m_image->GetHeight() - 1, estAlignmentY + allowance); 270 std::min(m_image->GetHeight() - 1, estAlignmentY + allowance);
271 CBC_QRAlignmentPatternFinder alignmentFinder( 271 CBC_QRAlignmentPatternFinder alignmentFinder(
272 m_image, alignmentAreaLeftX, alignmentAreaTopY, 272 m_image, alignmentAreaLeftX, alignmentAreaTopY,
273 alignmentAreaRightX - alignmentAreaLeftX, 273 alignmentAreaRightX - alignmentAreaLeftX,
274 alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize); 274 alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize);
275 CBC_QRAlignmentPattern* qap = alignmentFinder.Find(e); 275 CBC_QRAlignmentPattern* qap = alignmentFinder.Find(e);
276 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 276 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
277 return qap; 277 return qap;
278 } 278 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRDecodedBitStreamParser.cpp ('k') | xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698