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

Side by Side Diff: xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp

Issue 1937513002: Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 8 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Flip if/else. Created 4 years, 7 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 2008 ZXing authors 8 * Copyright 2008 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 17 matching lines...) Expand all
28 #include "xfa/fxbarcode/BC_ResultPoint.h" 28 #include "xfa/fxbarcode/BC_ResultPoint.h"
29 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" 29 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
30 #include "xfa/fxbarcode/common/BC_WhiteRectangleDetector.h" 30 #include "xfa/fxbarcode/common/BC_WhiteRectangleDetector.h"
31 #include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h" 31 #include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h"
32 #include "xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.h" 32 #include "xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.h"
33 #include "xfa/fxbarcode/qrcode/BC_QRGridSampler.h" 33 #include "xfa/fxbarcode/qrcode/BC_QRGridSampler.h"
34 #include "xfa/fxbarcode/utils.h" 34 #include "xfa/fxbarcode/utils.h"
35 35
36 const int32_t CBC_DataMatrixDetector::INTEGERS[5] = {0, 1, 2, 3, 4}; 36 const int32_t CBC_DataMatrixDetector::INTEGERS[5] = {0, 1, 2, 3, 4};
37 CBC_DataMatrixDetector::CBC_DataMatrixDetector(CBC_CommonBitMatrix* image) 37 CBC_DataMatrixDetector::CBC_DataMatrixDetector(CBC_CommonBitMatrix* image)
38 : m_image(image), m_rectangleDetector(NULL) {} 38 : m_image(image), m_rectangleDetector(nullptr) {}
39 void CBC_DataMatrixDetector::Init(int32_t& e) { 39 void CBC_DataMatrixDetector::Init(int32_t& e) {
40 m_rectangleDetector = new CBC_WhiteRectangleDetector(m_image); 40 m_rectangleDetector = new CBC_WhiteRectangleDetector(m_image);
41 m_rectangleDetector->Init(e); 41 m_rectangleDetector->Init(e);
42 BC_EXCEPTION_CHECK_ReturnVoid(e); 42 BC_EXCEPTION_CHECK_ReturnVoid(e);
43 } 43 }
44 CBC_DataMatrixDetector::~CBC_DataMatrixDetector() { 44 CBC_DataMatrixDetector::~CBC_DataMatrixDetector() {
45 delete m_rectangleDetector; 45 delete m_rectangleDetector;
46 } 46 }
47 inline FX_BOOL ResultPointsAndTransitionsComparator(void* a, void* b) { 47
48 return ((CBC_ResultPointsAndTransitions*)b)->GetTransitions() >
49 ((CBC_ResultPointsAndTransitions*)a)->GetTransitions();
50 }
51 CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) { 48 CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
52 CFX_PtrArray* cornerPoints = m_rectangleDetector->Detect(e); 49 CFX_ArrayTemplate<CBC_ResultPoint*>* cornerPoints =
53 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 50 m_rectangleDetector->Detect(e);
54 CBC_ResultPoint* pointA = (CBC_ResultPoint*)(*cornerPoints)[0]; 51 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
55 CBC_ResultPoint* pointB = (CBC_ResultPoint*)(*cornerPoints)[1]; 52 CBC_ResultPoint* pointA = (*cornerPoints)[0];
56 CBC_ResultPoint* pointC = (CBC_ResultPoint*)(*cornerPoints)[2]; 53 CBC_ResultPoint* pointB = (*cornerPoints)[1];
57 CBC_ResultPoint* pointD = (CBC_ResultPoint*)(*cornerPoints)[3]; 54 CBC_ResultPoint* pointC = (*cornerPoints)[2];
55 CBC_ResultPoint* pointD = (*cornerPoints)[3];
58 delete cornerPoints; 56 delete cornerPoints;
59 cornerPoints = NULL; 57
60 CFX_PtrArray transitions; 58 CFX_ArrayTemplate<CBC_ResultPointsAndTransitions*> transitions;
61 transitions.Add(TransitionsBetween(pointA, pointB)); 59 transitions.Add(TransitionsBetween(pointA, pointB));
62 transitions.Add(TransitionsBetween(pointA, pointC)); 60 transitions.Add(TransitionsBetween(pointA, pointC));
63 transitions.Add(TransitionsBetween(pointB, pointD)); 61 transitions.Add(TransitionsBetween(pointB, pointD));
64 transitions.Add(TransitionsBetween(pointC, pointD)); 62 transitions.Add(TransitionsBetween(pointC, pointD));
65 BC_FX_PtrArray_Sort(transitions, &ResultPointsAndTransitionsComparator); 63 std::sort(transitions.GetData(),
66 delete ((CBC_ResultPointsAndTransitions*)transitions[2]); 64 transitions.GetData() + transitions.GetSize(),
67 delete ((CBC_ResultPointsAndTransitions*)transitions[3]); 65 [](const CBC_ResultPointsAndTransitions* a,
68 CBC_ResultPointsAndTransitions* lSideOne = 66 const CBC_ResultPointsAndTransitions* b) {
69 (CBC_ResultPointsAndTransitions*)transitions[0]; 67 return a->GetTransitions() < b->GetTransitions();
70 CBC_ResultPointsAndTransitions* lSideTwo = 68 });
71 (CBC_ResultPointsAndTransitions*)transitions[1]; 69 delete transitions[2];
70 delete transitions[3];
71
72 CBC_ResultPointsAndTransitions* lSideOne = transitions[0];
73 CBC_ResultPointsAndTransitions* lSideTwo = transitions[1];
72 CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> pointCount; 74 CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> pointCount;
73 Increment(pointCount, lSideOne->GetFrom()); 75 Increment(pointCount, lSideOne->GetFrom());
74 Increment(pointCount, lSideOne->GetTo()); 76 Increment(pointCount, lSideOne->GetTo());
75 Increment(pointCount, lSideTwo->GetFrom()); 77 Increment(pointCount, lSideTwo->GetFrom());
76 Increment(pointCount, lSideTwo->GetTo()); 78 Increment(pointCount, lSideTwo->GetTo());
77 delete ((CBC_ResultPointsAndTransitions*)transitions[1]); 79 delete transitions[1];
78 delete ((CBC_ResultPointsAndTransitions*)transitions[0]); 80 delete transitions[0];
79 transitions.RemoveAll(); 81 transitions.RemoveAll();
80 CBC_ResultPoint* maybeTopLeft = NULL; 82 CBC_ResultPoint* maybeTopLeft = nullptr;
81 CBC_ResultPoint* bottomLeft = NULL; 83 CBC_ResultPoint* bottomLeft = nullptr;
82 CBC_ResultPoint* maybeBottomRight = NULL; 84 CBC_ResultPoint* maybeBottomRight = nullptr;
83 FX_POSITION itBegin = pointCount.GetStartPosition(); 85 FX_POSITION itBegin = pointCount.GetStartPosition();
84 while (itBegin) { 86 while (itBegin) {
85 CBC_ResultPoint* key = 0; 87 CBC_ResultPoint* key = 0;
86 int32_t value = 0; 88 int32_t value = 0;
87 pointCount.GetNextAssoc(itBegin, key, value); 89 pointCount.GetNextAssoc(itBegin, key, value);
88 if (value == 2) { 90 if (value == 2) {
89 bottomLeft = key; 91 bottomLeft = key;
90 } else { 92 } else {
91 if (maybeBottomRight == NULL) { 93 if (maybeBottomRight) {
94 maybeTopLeft = key;
95 } else {
92 maybeBottomRight = key; 96 maybeBottomRight = key;
93 } else {
94 maybeTopLeft = key;
95 } 97 }
96 } 98 }
97 } 99 }
98 if (maybeTopLeft == NULL || bottomLeft == NULL || maybeBottomRight == NULL) { 100 if (!maybeTopLeft || !bottomLeft || !maybeBottomRight) {
99 delete pointA; 101 delete pointA;
100 delete pointB; 102 delete pointB;
101 delete pointC; 103 delete pointC;
102 delete pointD; 104 delete pointD;
103 e = BCExceptionNotFound; 105 e = BCExceptionNotFound;
104 return NULL; 106 return nullptr;
105 } 107 }
106 CFX_PtrArray corners; 108 CFX_ArrayTemplate<CBC_ResultPoint*> corners;
107 corners.SetSize(3); 109 corners.SetSize(3);
108 corners[0] = maybeTopLeft; 110 corners[0] = maybeTopLeft;
109 corners[1] = bottomLeft; 111 corners[1] = bottomLeft;
110 corners[2] = maybeBottomRight; 112 corners[2] = maybeBottomRight;
111 OrderBestPatterns(&corners); 113 OrderBestPatterns(&corners);
112 CBC_ResultPoint* bottomRight = (CBC_ResultPoint*)corners[0]; 114 CBC_ResultPoint* bottomRight = corners[0];
113 bottomLeft = (CBC_ResultPoint*)corners[1]; 115 bottomLeft = corners[1];
114 CBC_ResultPoint* topLeft = (CBC_ResultPoint*)corners[2]; 116 CBC_ResultPoint* topLeft = corners[2];
115 CBC_ResultPoint* topRight = NULL; 117 CBC_ResultPoint* topRight = nullptr;
116 int32_t value; 118 int32_t value;
117 if (!pointCount.Lookup(pointA, value)) { 119 if (!pointCount.Lookup(pointA, value)) {
118 topRight = pointA; 120 topRight = pointA;
119 } else if (!pointCount.Lookup(pointB, value)) { 121 } else if (!pointCount.Lookup(pointB, value)) {
120 topRight = pointB; 122 topRight = pointB;
121 } else if (!pointCount.Lookup(pointC, value)) { 123 } else if (!pointCount.Lookup(pointC, value)) {
122 topRight = pointC; 124 topRight = pointC;
123 } else { 125 } else {
124 topRight = pointD; 126 topRight = pointD;
125 } 127 }
(...skipping 11 matching lines...) Expand all
137 dimensionRight++; 139 dimensionRight++;
138 } 140 }
139 dimensionRight += 2; 141 dimensionRight += 2;
140 std::unique_ptr<CBC_CommonBitMatrix> bits; 142 std::unique_ptr<CBC_CommonBitMatrix> bits;
141 std::unique_ptr<CBC_ResultPoint> correctedTopRight; 143 std::unique_ptr<CBC_ResultPoint> correctedTopRight;
142 if (4 * dimensionTop >= 7 * dimensionRight || 144 if (4 * dimensionTop >= 7 * dimensionRight ||
143 4 * dimensionRight >= 7 * dimensionTop) { 145 4 * dimensionRight >= 7 * dimensionTop) {
144 correctedTopRight.reset( 146 correctedTopRight.reset(
145 CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, 147 CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight,
146 dimensionTop, dimensionRight)); 148 dimensionTop, dimensionRight));
147 if (correctedTopRight.get() == NULL) { 149 if (!correctedTopRight.get()) {
148 correctedTopRight.reset(topRight); 150 correctedTopRight.reset(topRight);
149 } else { 151 } else {
150 delete topRight; 152 delete topRight;
151 topRight = NULL; 153 topRight = nullptr;
152 } 154 }
153 dimensionTop = std::unique_ptr<CBC_ResultPointsAndTransitions>( 155 dimensionTop = std::unique_ptr<CBC_ResultPointsAndTransitions>(
154 TransitionsBetween(topLeft, correctedTopRight.get())) 156 TransitionsBetween(topLeft, correctedTopRight.get()))
155 ->GetTransitions(); 157 ->GetTransitions();
156 dimensionRight = 158 dimensionRight =
157 std::unique_ptr<CBC_ResultPointsAndTransitions>( 159 std::unique_ptr<CBC_ResultPointsAndTransitions>(
158 TransitionsBetween(bottomRight, correctedTopRight.get())) 160 TransitionsBetween(bottomRight, correctedTopRight.get()))
159 ->GetTransitions(); 161 ->GetTransitions();
160 if ((dimensionTop & 0x01) == 1) { 162 if ((dimensionTop & 0x01) == 1) {
161 dimensionTop++; 163 dimensionTop++;
162 } 164 }
163 if ((dimensionRight & 0x01) == 1) { 165 if ((dimensionRight & 0x01) == 1) {
164 dimensionRight++; 166 dimensionRight++;
165 } 167 }
166 bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight, 168 bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight,
167 correctedTopRight.get(), dimensionTop, dimensionRight, 169 correctedTopRight.get(), dimensionTop, dimensionRight,
168 e)); 170 e));
169 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 171 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
170 } else { 172 } else {
171 int32_t dimension = std::min(dimensionRight, dimensionTop); 173 int32_t dimension = std::min(dimensionRight, dimensionTop);
172 correctedTopRight.reset( 174 correctedTopRight.reset(
173 CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension)); 175 CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension));
174 if (correctedTopRight.get() == NULL) { 176 if (!correctedTopRight.get()) {
175 correctedTopRight.reset(topRight); 177 correctedTopRight.reset(topRight);
176 } else { 178 } else {
177 delete topRight; 179 delete topRight;
178 topRight = NULL; 180 topRight = nullptr;
179 } 181 }
180 int32_t dimensionCorrected = 182 int32_t dimensionCorrected =
181 std::max(std::unique_ptr<CBC_ResultPointsAndTransitions>( 183 std::max(std::unique_ptr<CBC_ResultPointsAndTransitions>(
182 TransitionsBetween(topLeft, correctedTopRight.get())) 184 TransitionsBetween(topLeft, correctedTopRight.get()))
183 ->GetTransitions(), 185 ->GetTransitions(),
184 std::unique_ptr<CBC_ResultPointsAndTransitions>( 186 std::unique_ptr<CBC_ResultPointsAndTransitions>(
185 TransitionsBetween(bottomRight, correctedTopRight.get())) 187 TransitionsBetween(bottomRight, correctedTopRight.get()))
186 ->GetTransitions()); 188 ->GetTransitions());
187 dimensionCorrected++; 189 dimensionCorrected++;
188 if ((dimensionCorrected & 0x01) == 1) { 190 if ((dimensionCorrected & 0x01) == 1) {
189 dimensionCorrected++; 191 dimensionCorrected++;
190 } 192 }
191 bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight, 193 bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight,
192 correctedTopRight.get(), dimensionCorrected, 194 correctedTopRight.get(), dimensionCorrected,
193 dimensionCorrected, e)); 195 dimensionCorrected, e));
194 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 196 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
195 } 197 }
196 CFX_PtrArray* result = new CFX_PtrArray; 198 CFX_PtrArray* result = new CFX_PtrArray;
197 result->SetSize(4); 199 result->SetSize(4);
198 result->Add(topLeft); 200 result->Add(topLeft);
199 result->Add(bottomLeft); 201 result->Add(bottomLeft);
200 result->Add(bottomRight); 202 result->Add(bottomRight);
201 result->Add(correctedTopRight.release()); 203 result->Add(correctedTopRight.release());
202 return new CBC_QRDetectorResult(bits.release(), result); 204 return new CBC_QRDetectorResult(bits.release(), result);
203 } 205 }
204 CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular( 206 CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular(
(...skipping 12 matching lines...) Expand all
217 corr = Distance(bottomLeft, topLeft) / (FX_FLOAT)dimensionRight; 219 corr = Distance(bottomLeft, topLeft) / (FX_FLOAT)dimensionRight;
218 norm = Distance(bottomRight, topRight); 220 norm = Distance(bottomRight, topRight);
219 cos = (topRight->GetX() - bottomRight->GetX()) / norm; 221 cos = (topRight->GetX() - bottomRight->GetX()) / norm;
220 sin = (topRight->GetY() - bottomRight->GetY()) / norm; 222 sin = (topRight->GetY() - bottomRight->GetY()) / norm;
221 std::unique_ptr<CBC_ResultPoint> c2(new CBC_ResultPoint( 223 std::unique_ptr<CBC_ResultPoint> c2(new CBC_ResultPoint(
222 topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); 224 topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
223 if (!IsValid(c1.get())) { 225 if (!IsValid(c1.get())) {
224 if (IsValid(c2.get())) { 226 if (IsValid(c2.get())) {
225 return c2.release(); 227 return c2.release();
226 } 228 }
227 return NULL; 229 return nullptr;
228 } else if (!IsValid(c2.get())) { 230 } else if (!IsValid(c2.get())) {
229 return c1.release(); 231 return c1.release();
230 } 232 }
231 int32_t l1 = FXSYS_abs(dimensionTop - 233 int32_t l1 = FXSYS_abs(dimensionTop -
232 std::unique_ptr<CBC_ResultPointsAndTransitions>( 234 std::unique_ptr<CBC_ResultPointsAndTransitions>(
233 TransitionsBetween(topLeft, c1.get())) 235 TransitionsBetween(topLeft, c1.get()))
234 ->GetTransitions()) + 236 ->GetTransitions()) +
235 FXSYS_abs(dimensionRight - 237 FXSYS_abs(dimensionRight -
236 std::unique_ptr<CBC_ResultPointsAndTransitions>( 238 std::unique_ptr<CBC_ResultPointsAndTransitions>(
237 TransitionsBetween(bottomRight, c1.get())) 239 TransitionsBetween(bottomRight, c1.get()))
(...skipping 26 matching lines...) Expand all
264 corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimension; 266 corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimension;
265 norm = Distance(bottomRight, topRight); 267 norm = Distance(bottomRight, topRight);
266 cos = (topRight->GetX() - bottomRight->GetX()) / norm; 268 cos = (topRight->GetX() - bottomRight->GetX()) / norm;
267 sin = (topRight->GetY() - bottomRight->GetY()) / norm; 269 sin = (topRight->GetY() - bottomRight->GetY()) / norm;
268 std::unique_ptr<CBC_ResultPoint> c2(new CBC_ResultPoint( 270 std::unique_ptr<CBC_ResultPoint> c2(new CBC_ResultPoint(
269 topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); 271 topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
270 if (!IsValid(c1.get())) { 272 if (!IsValid(c1.get())) {
271 if (IsValid(c2.get())) { 273 if (IsValid(c2.get())) {
272 return c2.release(); 274 return c2.release();
273 } 275 }
274 return NULL; 276 return nullptr;
275 } else if (!IsValid(c2.get())) { 277 } else if (!IsValid(c2.get())) {
276 return c1.release(); 278 return c1.release();
277 } 279 }
278 int32_t l1 = FXSYS_abs(std::unique_ptr<CBC_ResultPointsAndTransitions>( 280 int32_t l1 = FXSYS_abs(std::unique_ptr<CBC_ResultPointsAndTransitions>(
279 TransitionsBetween(topLeft, c1.get())) 281 TransitionsBetween(topLeft, c1.get()))
280 ->GetTransitions() - 282 ->GetTransitions() -
281 std::unique_ptr<CBC_ResultPointsAndTransitions>( 283 std::unique_ptr<CBC_ResultPointsAndTransitions>(
282 TransitionsBetween(bottomRight, c1.get())) 284 TransitionsBetween(bottomRight, c1.get()))
283 ->GetTransitions()); 285 ->GetTransitions());
284 int32_t l2 = FXSYS_abs(std::unique_ptr<CBC_ResultPointsAndTransitions>( 286 int32_t l2 = FXSYS_abs(std::unique_ptr<CBC_ResultPointsAndTransitions>(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 int32_t dimensionX, 323 int32_t dimensionX,
322 int32_t dimensionY, 324 int32_t dimensionY,
323 int32_t& e) { 325 int32_t& e) {
324 CBC_QRGridSampler& sampler = CBC_QRGridSampler::GetInstance(); 326 CBC_QRGridSampler& sampler = CBC_QRGridSampler::GetInstance();
325 CBC_CommonBitMatrix* cbm = sampler.SampleGrid( 327 CBC_CommonBitMatrix* cbm = sampler.SampleGrid(
326 image, dimensionX, dimensionY, 0.5f, 0.5f, dimensionX - 0.5f, 0.5f, 328 image, dimensionX, dimensionY, 0.5f, 0.5f, dimensionX - 0.5f, 0.5f,
327 dimensionX - 0.5f, dimensionY - 0.5f, 0.5f, dimensionY - 0.5f, 329 dimensionX - 0.5f, dimensionY - 0.5f, 0.5f, dimensionY - 0.5f,
328 topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(), 330 topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(),
329 bottomRight->GetX(), bottomRight->GetY(), bottomLeft->GetX(), 331 bottomRight->GetX(), bottomRight->GetY(), bottomLeft->GetX(),
330 bottomLeft->GetY(), e); 332 bottomLeft->GetY(), e);
331 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 333 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
332 return cbm; 334 return cbm;
333 } 335 }
334 CBC_ResultPointsAndTransitions* CBC_DataMatrixDetector::TransitionsBetween( 336 CBC_ResultPointsAndTransitions* CBC_DataMatrixDetector::TransitionsBetween(
335 CBC_ResultPoint* from, 337 CBC_ResultPoint* from,
336 CBC_ResultPoint* to) { 338 CBC_ResultPoint* to) {
337 int32_t fromX = (int32_t)from->GetX(); 339 int32_t fromX = (int32_t)from->GetX();
338 int32_t fromY = (int32_t)from->GetY(); 340 int32_t fromY = (int32_t)from->GetY();
339 int32_t toX = (int32_t)to->GetX(); 341 int32_t toX = (int32_t)to->GetX();
340 int32_t toY = (int32_t)to->GetY(); 342 int32_t toY = (int32_t)to->GetY();
341 FX_BOOL steep = FXSYS_abs(toY - fromY) > FXSYS_abs(toX - fromX); 343 FX_BOOL steep = FXSYS_abs(toY - fromY) > FXSYS_abs(toX - fromX);
(...skipping 22 matching lines...) Expand all
364 if (error > 0) { 366 if (error > 0) {
365 if (y == toY) { 367 if (y == toY) {
366 break; 368 break;
367 } 369 }
368 y += ystep; 370 y += ystep;
369 error -= dx; 371 error -= dx;
370 } 372 }
371 } 373 }
372 return new CBC_ResultPointsAndTransitions(from, to, transitions); 374 return new CBC_ResultPointsAndTransitions(from, to, transitions);
373 } 375 }
374 void CBC_DataMatrixDetector::OrderBestPatterns(CFX_PtrArray* patterns) { 376 void CBC_DataMatrixDetector::OrderBestPatterns(
375 FX_FLOAT abDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0], 377 CFX_ArrayTemplate<CBC_ResultPoint*>* patterns) {
376 (CBC_ResultPoint*)(*patterns)[1]); 378 FX_FLOAT abDistance = (FX_FLOAT)Distance((*patterns)[0], (*patterns)[1]);
377 FX_FLOAT bcDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[1], 379 FX_FLOAT bcDistance = (FX_FLOAT)Distance((*patterns)[1], (*patterns)[2]);
378 (CBC_ResultPoint*)(*patterns)[2]); 380 FX_FLOAT acDistance = (FX_FLOAT)Distance((*patterns)[0], (*patterns)[2]);
379 FX_FLOAT acDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0],
380 (CBC_ResultPoint*)(*patterns)[2]);
381 CBC_ResultPoint *topLeft, *topRight, *bottomLeft; 381 CBC_ResultPoint *topLeft, *topRight, *bottomLeft;
382 if (bcDistance >= abDistance && bcDistance >= acDistance) { 382 if (bcDistance >= abDistance && bcDistance >= acDistance) {
383 topLeft = (CBC_ResultPoint*)(*patterns)[0]; 383 topLeft = (*patterns)[0];
384 topRight = (CBC_ResultPoint*)(*patterns)[1]; 384 topRight = (*patterns)[1];
385 bottomLeft = (CBC_ResultPoint*)(*patterns)[2]; 385 bottomLeft = (*patterns)[2];
386 } else if (acDistance >= bcDistance && acDistance >= abDistance) { 386 } else if (acDistance >= bcDistance && acDistance >= abDistance) {
387 topLeft = (CBC_ResultPoint*)(*patterns)[1]; 387 topLeft = (*patterns)[1];
388 topRight = (CBC_ResultPoint*)(*patterns)[0]; 388 topRight = (*patterns)[0];
389 bottomLeft = (CBC_ResultPoint*)(*patterns)[2]; 389 bottomLeft = (*patterns)[2];
390 } else { 390 } else {
391 topLeft = (CBC_ResultPoint*)(*patterns)[2]; 391 topLeft = (*patterns)[2];
392 topRight = (CBC_ResultPoint*)(*patterns)[0]; 392 topRight = (*patterns)[0];
393 bottomLeft = (CBC_ResultPoint*)(*patterns)[1]; 393 bottomLeft = (*patterns)[1];
394 } 394 }
395 if ((bottomLeft->GetY() - topLeft->GetY()) * 395 if ((bottomLeft->GetY() - topLeft->GetY()) *
396 (topRight->GetX() - topLeft->GetX()) < 396 (topRight->GetX() - topLeft->GetX()) <
397 (bottomLeft->GetX() - topLeft->GetX()) * 397 (bottomLeft->GetX() - topLeft->GetX()) *
398 (topRight->GetY() - topLeft->GetY())) { 398 (topRight->GetY() - topLeft->GetY())) {
399 CBC_ResultPoint* temp = topRight; 399 CBC_ResultPoint* temp = topRight;
400 topRight = bottomLeft; 400 topRight = bottomLeft;
401 bottomLeft = temp; 401 bottomLeft = temp;
402 } 402 }
403 (*patterns)[0] = bottomLeft; 403 (*patterns)[0] = bottomLeft;
404 (*patterns)[1] = topLeft; 404 (*patterns)[1] = topLeft;
405 (*patterns)[2] = topRight; 405 (*patterns)[2] = topRight;
406 } 406 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h ('k') | xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698