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