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

Side by Side Diff: xfa/fxbarcode/common/BC_WhiteRectangleDetector.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 2010 ZXing authors 8 * Copyright 2010 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 int32_t y) { 52 int32_t y) {
53 m_image = image; 53 m_image = image;
54 m_height = image->GetHeight(); 54 m_height = image->GetHeight();
55 m_width = image->GetWidth(); 55 m_width = image->GetWidth();
56 int32_t halfsize = initSize >> 1; 56 int32_t halfsize = initSize >> 1;
57 m_leftInit = x - halfsize; 57 m_leftInit = x - halfsize;
58 m_rightInit = x + halfsize; 58 m_rightInit = x + halfsize;
59 m_upInit = y - halfsize; 59 m_upInit = y - halfsize;
60 m_downInit = y + halfsize; 60 m_downInit = y + halfsize;
61 } 61 }
62
62 CBC_WhiteRectangleDetector::~CBC_WhiteRectangleDetector() {} 63 CBC_WhiteRectangleDetector::~CBC_WhiteRectangleDetector() {}
63 CFX_PtrArray* CBC_WhiteRectangleDetector::Detect(int32_t& e) { 64
65 CFX_ArrayTemplate<CBC_ResultPoint*>* CBC_WhiteRectangleDetector::Detect(
66 int32_t& e) {
64 int32_t left = m_leftInit; 67 int32_t left = m_leftInit;
65 int32_t right = m_rightInit; 68 int32_t right = m_rightInit;
66 int32_t up = m_upInit; 69 int32_t up = m_upInit;
67 int32_t down = m_downInit; 70 int32_t down = m_downInit;
68 FX_BOOL sizeExceeded = FALSE; 71 FX_BOOL sizeExceeded = FALSE;
69 FX_BOOL aBlackPointFoundOnBorder = TRUE; 72 FX_BOOL aBlackPointFoundOnBorder = TRUE;
70 FX_BOOL atLeastOneBlackPointFoundOnBorder = FALSE; 73 FX_BOOL atLeastOneBlackPointFoundOnBorder = FALSE;
71 while (aBlackPointFoundOnBorder) { 74 while (aBlackPointFoundOnBorder) {
72 aBlackPointFoundOnBorder = FALSE; 75 aBlackPointFoundOnBorder = FALSE;
73 FX_BOOL rightBorderNotWhite = TRUE; 76 FX_BOOL rightBorderNotWhite = TRUE;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 127 }
125 if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) { 128 if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) {
126 int32_t maxSize = right - left; 129 int32_t maxSize = right - left;
127 std::unique_ptr<CBC_ResultPoint> z; 130 std::unique_ptr<CBC_ResultPoint> z;
128 for (int32_t i = 1; i < maxSize; i++) { 131 for (int32_t i = 1; i < maxSize; i++) {
129 z.reset(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(down - i), 132 z.reset(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(down - i),
130 (FX_FLOAT)(left + i), (FX_FLOAT)(down))); 133 (FX_FLOAT)(left + i), (FX_FLOAT)(down)));
131 if (z) 134 if (z)
132 break; 135 break;
133 } 136 }
134 if (z.get() == NULL) { 137 if (!z.get()) {
135 e = BCExceptionNotFound; 138 e = BCExceptionNotFound;
136 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 139 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
137 } 140 }
138 std::unique_ptr<CBC_ResultPoint> t; 141 std::unique_ptr<CBC_ResultPoint> t;
139 for (int32_t j = 1; j < maxSize; j++) { 142 for (int32_t j = 1; j < maxSize; j++) {
140 t.reset(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(up + j), 143 t.reset(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(up + j),
141 (FX_FLOAT)(left + j), (FX_FLOAT)up)); 144 (FX_FLOAT)(left + j), (FX_FLOAT)up));
142 if (t) 145 if (t)
143 break; 146 break;
144 } 147 }
145 if (t.get() == NULL) { 148 if (!t.get()) {
146 e = BCExceptionNotFound; 149 e = BCExceptionNotFound;
147 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 150 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
148 } 151 }
149 std::unique_ptr<CBC_ResultPoint> x; 152 std::unique_ptr<CBC_ResultPoint> x;
150 for (int32_t k = 1; k < maxSize; k++) { 153 for (int32_t k = 1; k < maxSize; k++) {
151 x.reset(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(up + k), 154 x.reset(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(up + k),
152 (FX_FLOAT)(right - k), (FX_FLOAT)up)); 155 (FX_FLOAT)(right - k), (FX_FLOAT)up));
153 if (x) 156 if (x)
154 break; 157 break;
155 } 158 }
156 if (x.get() == NULL) { 159 if (!x.get()) {
157 e = BCExceptionNotFound; 160 e = BCExceptionNotFound;
158 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 161 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
159 } 162 }
160 std::unique_ptr<CBC_ResultPoint> y; 163 std::unique_ptr<CBC_ResultPoint> y;
161 for (int32_t m = 1; m < maxSize; m++) { 164 for (int32_t m = 1; m < maxSize; m++) {
162 y.reset(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(down - m), 165 y.reset(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(down - m),
163 (FX_FLOAT)(right - m), (FX_FLOAT)down)); 166 (FX_FLOAT)(right - m), (FX_FLOAT)down));
164 if (y) 167 if (y)
165 break; 168 break;
166 } 169 }
167 if (y.get() == NULL) { 170 if (!y.get()) {
168 e = BCExceptionNotFound; 171 e = BCExceptionNotFound;
169 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 172 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
170 } 173 }
171 return CenterEdges(y.get(), z.get(), x.get(), t.get()); 174 return CenterEdges(y.get(), z.get(), x.get(), t.get());
172 } else {
173 e = BCExceptionNotFound;
174 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
175 } 175 }
176 return NULL; 176
177 e = BCExceptionNotFound;
178 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
179 return nullptr;
177 } 180 }
181
178 int32_t CBC_WhiteRectangleDetector::Round(FX_FLOAT d) { 182 int32_t CBC_WhiteRectangleDetector::Round(FX_FLOAT d) {
179 return (int32_t)(d + 0.5f); 183 return (int32_t)(d + 0.5f);
180 } 184 }
181 CBC_ResultPoint* CBC_WhiteRectangleDetector::GetBlackPointOnSegment( 185 CBC_ResultPoint* CBC_WhiteRectangleDetector::GetBlackPointOnSegment(
182 FX_FLOAT aX, 186 FX_FLOAT aX,
183 FX_FLOAT aY, 187 FX_FLOAT aY,
184 FX_FLOAT bX, 188 FX_FLOAT bX,
185 FX_FLOAT bY) { 189 FX_FLOAT bY) {
186 int32_t dist = DistanceL2(aX, aY, bX, bY); 190 int32_t dist = DistanceL2(aX, aY, bX, bY);
187 float xStep = (bX - aX) / dist; 191 float xStep = (bX - aX) / dist;
188 float yStep = (bY - aY) / dist; 192 float yStep = (bY - aY) / dist;
189 for (int32_t i = 0; i < dist; i++) { 193 for (int32_t i = 0; i < dist; i++) {
190 int32_t x = Round(aX + i * xStep); 194 int32_t x = Round(aX + i * xStep);
191 int32_t y = Round(aY + i * yStep); 195 int32_t y = Round(aY + i * yStep);
192 if (m_image->Get(x, y)) { 196 if (m_image->Get(x, y)) {
193 return new CBC_ResultPoint((FX_FLOAT)x, (FX_FLOAT)y); 197 return new CBC_ResultPoint((FX_FLOAT)x, (FX_FLOAT)y);
194 } 198 }
195 } 199 }
196 return NULL; 200 return NULL;
197 } 201 }
198 int32_t CBC_WhiteRectangleDetector::DistanceL2(FX_FLOAT aX, 202 int32_t CBC_WhiteRectangleDetector::DistanceL2(FX_FLOAT aX,
199 FX_FLOAT aY, 203 FX_FLOAT aY,
200 FX_FLOAT bX, 204 FX_FLOAT bX,
201 FX_FLOAT bY) { 205 FX_FLOAT bY) {
202 float xDiff = aX - bX; 206 float xDiff = aX - bX;
203 float yDiff = aY - bY; 207 float yDiff = aY - bY;
204 return Round((float)sqrt(xDiff * xDiff + yDiff * yDiff)); 208 return Round((float)sqrt(xDiff * xDiff + yDiff * yDiff));
205 } 209 }
206 CFX_PtrArray* CBC_WhiteRectangleDetector::CenterEdges(CBC_ResultPoint* y, 210
207 CBC_ResultPoint* z, 211 CFX_ArrayTemplate<CBC_ResultPoint*>* CBC_WhiteRectangleDetector::CenterEdges(
208 CBC_ResultPoint* x, 212 CBC_ResultPoint* y,
209 CBC_ResultPoint* t) { 213 CBC_ResultPoint* z,
214 CBC_ResultPoint* x,
215 CBC_ResultPoint* t) const {
216 CFX_ArrayTemplate<CBC_ResultPoint*>* result =
217 new CFX_ArrayTemplate<CBC_ResultPoint*>();
218 result->SetSize(4);
219
210 float yi = y->GetX(); 220 float yi = y->GetX();
211 float yj = y->GetY(); 221 float yj = y->GetY();
212 float zi = z->GetX(); 222 float zi = z->GetX();
213 float zj = z->GetY(); 223 float zj = z->GetY();
214 float xi = x->GetX(); 224 float xi = x->GetX();
215 float xj = x->GetY(); 225 float xj = x->GetY();
216 float ti = t->GetX(); 226 float ti = t->GetX();
217 float tj = t->GetY(); 227 float tj = t->GetY();
228
218 if (yi < m_width / 2) { 229 if (yi < m_width / 2) {
219 CFX_PtrArray* result = new CFX_PtrArray;
220 result->SetSize(4);
221 (*result)[0] = new CBC_ResultPoint(ti - CORR, tj + CORR); 230 (*result)[0] = new CBC_ResultPoint(ti - CORR, tj + CORR);
222 (*result)[1] = new CBC_ResultPoint(zi + CORR, zj + CORR); 231 (*result)[1] = new CBC_ResultPoint(zi + CORR, zj + CORR);
223 (*result)[2] = new CBC_ResultPoint(xi - CORR, xj - CORR); 232 (*result)[2] = new CBC_ResultPoint(xi - CORR, xj - CORR);
224 (*result)[3] = new CBC_ResultPoint(yi + CORR, yj - CORR); 233 (*result)[3] = new CBC_ResultPoint(yi + CORR, yj - CORR);
225 return result; 234 return result;
226 } else {
227 CFX_PtrArray* result = new CFX_PtrArray;
228 result->SetSize(4);
229 (*result)[0] = new CBC_ResultPoint(ti + CORR, tj + CORR);
230 (*result)[1] = new CBC_ResultPoint(zi + CORR, zj - CORR);
231 (*result)[2] = new CBC_ResultPoint(xi - CORR, xj + CORR);
232 (*result)[3] = new CBC_ResultPoint(yi - CORR, yj - CORR);
233 return result;
234 } 235 }
236
237 (*result)[0] = new CBC_ResultPoint(ti + CORR, tj + CORR);
238 (*result)[1] = new CBC_ResultPoint(zi + CORR, zj - CORR);
239 (*result)[2] = new CBC_ResultPoint(xi - CORR, xj + CORR);
240 (*result)[3] = new CBC_ResultPoint(yi - CORR, yj - CORR);
241 return result;
235 } 242 }
243
236 FX_BOOL CBC_WhiteRectangleDetector::ContainsBlackPoint(int32_t a, 244 FX_BOOL CBC_WhiteRectangleDetector::ContainsBlackPoint(int32_t a,
237 int32_t b, 245 int32_t b,
238 int32_t fixed, 246 int32_t fixed,
239 FX_BOOL horizontal) { 247 FX_BOOL horizontal) {
240 if (horizontal) { 248 if (horizontal) {
241 for (int32_t x = a; x <= b; x++) { 249 for (int32_t x = a; x <= b; x++) {
242 if (m_image->Get(x, fixed)) { 250 if (m_image->Get(x, fixed)) {
243 return TRUE; 251 return TRUE;
244 } 252 }
245 } 253 }
246 } else { 254 } else {
247 for (int32_t y = a; y <= b; y++) { 255 for (int32_t y = a; y <= b; y++) {
248 if (m_image->Get(fixed, y)) { 256 if (m_image->Get(fixed, y)) {
249 return TRUE; 257 return TRUE;
250 } 258 }
251 } 259 }
252 } 260 }
253 return FALSE; 261 return FALSE;
254 } 262 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/common/BC_WhiteRectangleDetector.h ('k') | xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698