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

Side by Side Diff: xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.cpp

Issue 1734823002: Get rid of CBC_AutoPtr and use std::unique_ptr instead. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 9 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");
11 * you may not use this file except in compliance with the License. 11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at 12 * You may obtain a copy of the License at
13 * 13 *
14 * http://www.apache.org/licenses/LICENSE-2.0 14 * http://www.apache.org/licenses/LICENSE-2.0
15 * 15 *
16 * Unless required by applicable law or agreed to in writing, software 16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, 17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and 19 * See the License for the specific language governing permissions and
20 * limitations under the License. 20 * limitations under the License.
21 */ 21 */
22 22
23 #include "xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h"
24
25 #include <memory>
26
23 #include "xfa/src/fxbarcode/BC_ResultPoint.h" 27 #include "xfa/src/fxbarcode/BC_ResultPoint.h"
24 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" 28 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h"
25 #include "xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h"
26 #include "xfa/src/fxbarcode/utils.h" 29 #include "xfa/src/fxbarcode/utils.h"
27 30
28 const int32_t CBC_WhiteRectangleDetector::INIT_SIZE = 30; 31 const int32_t CBC_WhiteRectangleDetector::INIT_SIZE = 30;
29 const int32_t CBC_WhiteRectangleDetector::CORR = 1; 32 const int32_t CBC_WhiteRectangleDetector::CORR = 1;
30 33
31 CBC_WhiteRectangleDetector::CBC_WhiteRectangleDetector( 34 CBC_WhiteRectangleDetector::CBC_WhiteRectangleDetector(
32 CBC_CommonBitMatrix* image) { 35 CBC_CommonBitMatrix* image) {
33 m_image = image; 36 m_image = image;
34 m_height = image->GetHeight(); 37 m_height = image->GetHeight();
35 m_width = image->GetWidth(); 38 m_width = image->GetWidth();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (up < 0) { 120 if (up < 0) {
118 sizeExceeded = TRUE; 121 sizeExceeded = TRUE;
119 break; 122 break;
120 } 123 }
121 if (aBlackPointFoundOnBorder) { 124 if (aBlackPointFoundOnBorder) {
122 atLeastOneBlackPointFoundOnBorder = TRUE; 125 atLeastOneBlackPointFoundOnBorder = TRUE;
123 } 126 }
124 } 127 }
125 if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) { 128 if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) {
126 int32_t maxSize = right - left; 129 int32_t maxSize = right - left;
127 CBC_AutoPtr<CBC_ResultPoint> z(NULL); 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 = CBC_AutoPtr<CBC_ResultPoint>( 132 z.reset(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(down - i),
130 GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(down - i), 133 (FX_FLOAT)(left + i), (FX_FLOAT)(down)));
131 (FX_FLOAT)(left + i), (FX_FLOAT)(down))); 134 if (z)
132 if (z.get()) {
133 break; 135 break;
134 }
135 } 136 }
136 if (z.get() == NULL) { 137 if (z.get() == NULL) {
137 e = BCExceptionNotFound; 138 e = BCExceptionNotFound;
138 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 139 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
139 } 140 }
140 CBC_AutoPtr<CBC_ResultPoint> t(NULL); 141 std::unique_ptr<CBC_ResultPoint> t;
141 for (int32_t j = 1; j < maxSize; j++) { 142 for (int32_t j = 1; j < maxSize; j++) {
142 t = CBC_AutoPtr<CBC_ResultPoint>( 143 t.reset(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(up + j),
143 GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(up + j), 144 (FX_FLOAT)(left + j), (FX_FLOAT)up));
144 (FX_FLOAT)(left + j), (FX_FLOAT)up)); 145 if (t)
145 if (t.get()) {
146 break; 146 break;
147 }
148 } 147 }
149 if (t.get() == NULL) { 148 if (t.get() == NULL) {
150 e = BCExceptionNotFound; 149 e = BCExceptionNotFound;
151 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 150 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
152 } 151 }
153 CBC_AutoPtr<CBC_ResultPoint> x(NULL); 152 std::unique_ptr<CBC_ResultPoint> x;
154 for (int32_t k = 1; k < maxSize; k++) { 153 for (int32_t k = 1; k < maxSize; k++) {
155 x = CBC_AutoPtr<CBC_ResultPoint>( 154 x.reset(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(up + k),
156 GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(up + k), 155 (FX_FLOAT)(right - k), (FX_FLOAT)up));
157 (FX_FLOAT)(right - k), (FX_FLOAT)up)); 156 if (x)
158 if (x.get()) {
159 break; 157 break;
160 }
161 } 158 }
162 if (x.get() == NULL) { 159 if (x.get() == NULL) {
163 e = BCExceptionNotFound; 160 e = BCExceptionNotFound;
164 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 161 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
165 } 162 }
166 CBC_AutoPtr<CBC_ResultPoint> y(NULL); 163 std::unique_ptr<CBC_ResultPoint> y;
167 for (int32_t m = 1; m < maxSize; m++) { 164 for (int32_t m = 1; m < maxSize; m++) {
168 y = CBC_AutoPtr<CBC_ResultPoint>( 165 y.reset(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(down - m),
169 GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(down - m), 166 (FX_FLOAT)(right - m), (FX_FLOAT)down));
170 (FX_FLOAT)(right - m), (FX_FLOAT)down)); 167 if (y)
171 if (y.get()) {
172 break; 168 break;
173 }
174 } 169 }
175 if (y.get() == NULL) { 170 if (y.get() == NULL) {
176 e = BCExceptionNotFound; 171 e = BCExceptionNotFound;
177 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 172 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
178 } 173 }
179 return CenterEdges(y.get(), z.get(), x.get(), t.get()); 174 return CenterEdges(y.get(), z.get(), x.get(), t.get());
180 } else { 175 } else {
181 e = BCExceptionNotFound; 176 e = BCExceptionNotFound;
182 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 177 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
183 } 178 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 248 }
254 } else { 249 } else {
255 for (int32_t y = a; y <= b; y++) { 250 for (int32_t y = a; y <= b; y++) {
256 if (m_image->Get(fixed, y)) { 251 if (m_image->Get(fixed, y)) {
257 return TRUE; 252 return TRUE;
258 } 253 }
259 } 254 }
260 } 255 }
261 return FALSE; 256 return FALSE;
262 } 257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698