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

Side by Side Diff: xfa/src/fxbarcode/oned/BC_OneDReader.cpp

Issue 1726373002: Remove foo != NULL checks in xfa/src/fxbarcode. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 10 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");
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 <algorithm> 23 #include <algorithm>
24 #include <memory>
24 25
25 #include "xfa/src/fxbarcode/BC_BinaryBitmap.h" 26 #include "xfa/src/fxbarcode/BC_BinaryBitmap.h"
26 #include "xfa/src/fxbarcode/BC_Reader.h" 27 #include "xfa/src/fxbarcode/BC_Reader.h"
27 #include "xfa/src/fxbarcode/barcode.h" 28 #include "xfa/src/fxbarcode/barcode.h"
28 #include "xfa/src/fxbarcode/common/BC_CommonBitArray.h" 29 #include "xfa/src/fxbarcode/common/BC_CommonBitArray.h"
29 #include "xfa/src/fxbarcode/oned/BC_OneDReader.h" 30 #include "xfa/src/fxbarcode/oned/BC_OneDReader.h"
30 const int32_t CBC_OneDReader::INTEGER_MATH_SHIFT = 8; 31 const int32_t CBC_OneDReader::INTEGER_MATH_SHIFT = 8;
31 const int32_t CBC_OneDReader::PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << 8; 32 const int32_t CBC_OneDReader::PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << 8;
32 CBC_OneDReader::CBC_OneDReader() {} 33 CBC_OneDReader::CBC_OneDReader() {}
33 CBC_OneDReader::~CBC_OneDReader() {} 34 CBC_OneDReader::~CBC_OneDReader() {}
34 CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image, int32_t& e) { 35 CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image, int32_t& e) {
35 CFX_ByteString strtemp = Decode(image, 0, e); 36 CFX_ByteString strtemp = Decode(image, 0, e);
36 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 37 BC_EXCEPTION_CHECK_ReturnValue(e, "");
37 return strtemp; 38 return strtemp;
38 } 39 }
39 CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image, 40 CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image,
40 int32_t hints, 41 int32_t hints,
41 int32_t& e) { 42 int32_t& e) {
42 CFX_ByteString strtemp = DeDecode(image, hints, e); 43 CFX_ByteString strtemp = DeDecode(image, hints, e);
43 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 44 BC_EXCEPTION_CHECK_ReturnValue(e, "");
44 return strtemp; 45 return strtemp;
45 } 46 }
46 CFX_ByteString CBC_OneDReader::DeDecode(CBC_BinaryBitmap* image, 47 CFX_ByteString CBC_OneDReader::DeDecode(CBC_BinaryBitmap* image,
47 int32_t hints, 48 int32_t hints,
48 int32_t& e) { 49 int32_t& e) {
49 int32_t height = image->GetHeight(); 50 int32_t height = image->GetHeight();
50 CBC_CommonBitArray* row = NULL;
51 int32_t middle = height >> 1; 51 int32_t middle = height >> 1;
52 FX_BOOL tryHarder = FALSE; 52 FX_BOOL tryHarder = FALSE;
53 int32_t rowStep = std::max(1, height >> (tryHarder ? 8 : 5)); 53 int32_t rowStep = std::max(1, height >> (tryHarder ? 8 : 5));
54 int32_t maxLines; 54 int32_t maxLines;
55 if (tryHarder) { 55 if (tryHarder) {
56 maxLines = height; 56 maxLines = height;
57 } else { 57 } else {
58 maxLines = 15; 58 maxLines = 15;
59 } 59 }
60 for (int32_t x = 0; x < maxLines; x++) { 60 for (int32_t x = 0; x < maxLines; x++) {
61 int32_t rowStepsAboveOrBelow = (x + 1) >> 1; 61 int32_t rowStepsAboveOrBelow = (x + 1) >> 1;
62 FX_BOOL isAbove = (x & 0x01) == 0; 62 FX_BOOL isAbove = (x & 0x01) == 0;
63 int32_t rowNumber = 63 int32_t rowNumber =
64 middle + 64 middle +
65 rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow); 65 rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
66 if (rowNumber < 0 || rowNumber >= height) { 66 if (rowNumber < 0 || rowNumber >= height) {
67 break; 67 break;
68 } 68 }
69 row = image->GetBlackRow(rowNumber, NULL, e); 69 std::unique_ptr<CBC_CommonBitArray> row(
70 image->GetBlackRow(rowNumber, nullptr, e));
70 if (e != BCExceptionNO) { 71 if (e != BCExceptionNO) {
71 e = BCExceptionNO; 72 e = BCExceptionNO;
72 if (row != NULL) {
73 delete row;
74 row = NULL;
75 }
76 continue; 73 continue;
77 } 74 }
78 for (int32_t attempt = 0; attempt < 2; attempt++) { 75 for (int32_t attempt = 0; attempt < 2; attempt++) {
79 if (attempt == 1) { 76 if (attempt == 1) {
80 row->Reverse(); 77 row->Reverse();
81 } 78 }
82 CFX_ByteString result = DecodeRow(rowNumber, row, hints, e); 79 CFX_ByteString result = DecodeRow(rowNumber, row.get(), hints, e);
83 if (e != BCExceptionNO) { 80 if (e != BCExceptionNO) {
84 e = BCExceptionNO; 81 e = BCExceptionNO;
85 continue; 82 continue;
86 } 83 }
87 if (row != NULL) {
88 delete row;
89 row = NULL;
90 }
91 return result; 84 return result;
92 } 85 }
93 if (row != NULL) {
94 delete row;
95 row = NULL;
96 }
97 } 86 }
98 e = BCExceptionNotFound; 87 e = BCExceptionNotFound;
99 return ""; 88 return "";
100 } 89 }
101 void CBC_OneDReader::RecordPattern(CBC_CommonBitArray* row, 90 void CBC_OneDReader::RecordPattern(CBC_CommonBitArray* row,
102 int32_t start, 91 int32_t start,
103 CFX_Int32Array* counters, 92 CFX_Int32Array* counters,
104 int32_t& e) { 93 int32_t& e) {
105 int32_t numCounters = counters->GetSize(); 94 int32_t numCounters = counters->GetSize();
106 for (int32_t i = 0; i < numCounters; i++) { 95 for (int32_t i = 0; i < numCounters; i++) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 int32_t variance = counter > scaledPattern ? counter - scaledPattern 167 int32_t variance = counter > scaledPattern ? counter - scaledPattern
179 : scaledPattern - counter; 168 : scaledPattern - counter;
180 if (variance > maxIndividualVariance) { 169 if (variance > maxIndividualVariance) {
181 #undef max 170 #undef max
182 return FXSYS_IntMax; 171 return FXSYS_IntMax;
183 } 172 }
184 totalVariance += variance; 173 totalVariance += variance;
185 } 174 }
186 return totalVariance / total; 175 return totalVariance / total;
187 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698