| 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"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2}, | 38 {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2}, |
| 39 {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}, | 39 {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}, |
| 40 {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1}, | 40 {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1}, |
| 41 {1, 3, 2, 1}, {4, 1, 1, 1}, {2, 1, 3, 1}, {3, 1, 2, 1}, {2, 1, 1, 3}}; | 41 {1, 3, 2, 1}, {4, 1, 1, 1}, {2, 1, 3, 1}, {3, 1, 2, 1}, {2, 1, 1, 3}}; |
| 42 | 42 |
| 43 CBC_OneDimReader::CBC_OneDimReader() {} | 43 CBC_OneDimReader::CBC_OneDimReader() {} |
| 44 CBC_OneDimReader::~CBC_OneDimReader() {} | 44 CBC_OneDimReader::~CBC_OneDimReader() {} |
| 45 CFX_Int32Array* CBC_OneDimReader::FindStartGuardPattern(CBC_CommonBitArray* row, | 45 CFX_Int32Array* CBC_OneDimReader::FindStartGuardPattern(CBC_CommonBitArray* row, |
| 46 int32_t& e) { | 46 int32_t& e) { |
| 47 FX_BOOL foundStart = FALSE; | 47 FX_BOOL foundStart = FALSE; |
| 48 CFX_Int32Array* startRange = NULL; | 48 CFX_Int32Array* startRange = nullptr; |
| 49 CFX_Int32Array startEndPattern; | 49 CFX_Int32Array startEndPattern; |
| 50 startEndPattern.SetSize(3); | 50 startEndPattern.SetSize(3); |
| 51 startEndPattern[0] = START_END_PATTERN[0]; | 51 startEndPattern[0] = START_END_PATTERN[0]; |
| 52 startEndPattern[1] = START_END_PATTERN[1]; | 52 startEndPattern[1] = START_END_PATTERN[1]; |
| 53 startEndPattern[2] = START_END_PATTERN[2]; | 53 startEndPattern[2] = START_END_PATTERN[2]; |
| 54 int32_t nextStart = 0; | 54 int32_t nextStart = 0; |
| 55 while (!foundStart) { | 55 while (!foundStart) { |
| 56 delete startRange; | 56 delete startRange; |
| 57 startRange = FindGuardPattern(row, nextStart, FALSE, &startEndPattern, e); | 57 startRange = FindGuardPattern(row, nextStart, FALSE, &startEndPattern, e); |
| 58 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 58 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 59 int32_t start = (*startRange)[0]; | 59 int32_t start = (*startRange)[0]; |
| 60 nextStart = (*startRange)[1]; | 60 nextStart = (*startRange)[1]; |
| 61 if (start <= 1) { | 61 if (start <= 1) { |
| 62 break; | 62 break; |
| 63 } | 63 } |
| 64 int32_t quietStart = start - (nextStart - start); | 64 int32_t quietStart = start - (nextStart - start); |
| 65 if (quietStart >= 0) { | 65 if (quietStart >= 0) { |
| 66 FX_BOOL booT = row->IsRange(quietStart, start, FALSE, e); | 66 FX_BOOL booT = row->IsRange(quietStart, start, FALSE, e); |
| 67 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 67 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 68 foundStart = booT; | 68 foundStart = booT; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 return startRange; | 71 return startRange; |
| 72 } | 72 } |
| 73 CFX_ByteString CBC_OneDimReader::DecodeRow(int32_t rowNumber, | 73 CFX_ByteString CBC_OneDimReader::DecodeRow(int32_t rowNumber, |
| 74 CBC_CommonBitArray* row, | 74 CBC_CommonBitArray* row, |
| 75 int32_t hints, | 75 int32_t hints, |
| 76 int32_t& e) { | 76 int32_t& e) { |
| 77 std::unique_ptr<CFX_Int32Array> result(FindStartGuardPattern(row, e)); | 77 std::unique_ptr<CFX_Int32Array> result(FindStartGuardPattern(row, e)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 CFX_Int32Array* CBC_OneDimReader::DecodeEnd(CBC_CommonBitArray* row, | 130 CFX_Int32Array* CBC_OneDimReader::DecodeEnd(CBC_CommonBitArray* row, |
| 131 int32_t endStart, | 131 int32_t endStart, |
| 132 int32_t& e) { | 132 int32_t& e) { |
| 133 CFX_Int32Array startEndPattern; | 133 CFX_Int32Array startEndPattern; |
| 134 startEndPattern.Add(START_END_PATTERN[0]); | 134 startEndPattern.Add(START_END_PATTERN[0]); |
| 135 startEndPattern.Add(START_END_PATTERN[1]); | 135 startEndPattern.Add(START_END_PATTERN[1]); |
| 136 startEndPattern.Add(START_END_PATTERN[2]); | 136 startEndPattern.Add(START_END_PATTERN[2]); |
| 137 CFX_Int32Array* FindGuard = | 137 CFX_Int32Array* FindGuard = |
| 138 FindGuardPattern(row, endStart, FALSE, &startEndPattern, e); | 138 FindGuardPattern(row, endStart, FALSE, &startEndPattern, e); |
| 139 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 139 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 140 return FindGuard; | 140 return FindGuard; |
| 141 } | 141 } |
| 142 CFX_Int32Array* CBC_OneDimReader::FindGuardPattern(CBC_CommonBitArray* row, | 142 CFX_Int32Array* CBC_OneDimReader::FindGuardPattern(CBC_CommonBitArray* row, |
| 143 int32_t rowOffset, | 143 int32_t rowOffset, |
| 144 FX_BOOL whiteFirst, | 144 FX_BOOL whiteFirst, |
| 145 CFX_Int32Array* pattern, | 145 CFX_Int32Array* pattern, |
| 146 int32_t& e) { | 146 int32_t& e) { |
| 147 int32_t patternLength = pattern->GetSize(); | 147 int32_t patternLength = pattern->GetSize(); |
| 148 CFX_Int32Array counters; | 148 CFX_Int32Array counters; |
| 149 counters.SetSize(patternLength); | 149 counters.SetSize(patternLength); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 180 counters[patternLength - 1] = 0; | 180 counters[patternLength - 1] = 0; |
| 181 counterPosition--; | 181 counterPosition--; |
| 182 } else { | 182 } else { |
| 183 counterPosition++; | 183 counterPosition++; |
| 184 } | 184 } |
| 185 counters[counterPosition] = 1; | 185 counters[counterPosition] = 1; |
| 186 isWhite = !isWhite; | 186 isWhite = !isWhite; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 e = BCExceptionNotFound; | 189 e = BCExceptionNotFound; |
| 190 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 190 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 191 return NULL; | 191 return nullptr; |
| 192 } | 192 } |
| 193 int32_t CBC_OneDimReader::DecodeDigit(CBC_CommonBitArray* row, | 193 int32_t CBC_OneDimReader::DecodeDigit(CBC_CommonBitArray* row, |
| 194 CFX_Int32Array* counters, | 194 CFX_Int32Array* counters, |
| 195 int32_t rowOffset, | 195 int32_t rowOffset, |
| 196 const int32_t* patterns, | 196 const int32_t* patterns, |
| 197 int32_t patternLength, | 197 int32_t patternLength, |
| 198 int32_t& e) { | 198 int32_t& e) { |
| 199 RecordPattern(row, rowOffset, counters, e); | 199 RecordPattern(row, rowOffset, counters, e); |
| 200 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 200 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
| 201 int32_t bestVariance = MAX_AVG_VARIANCE; | 201 int32_t bestVariance = MAX_AVG_VARIANCE; |
| 202 int32_t bestMatch = -1; | 202 int32_t bestMatch = -1; |
| 203 int32_t max = patternLength; | 203 int32_t max = patternLength; |
| 204 for (int32_t i = 0; i < max; i++) { | 204 for (int32_t i = 0; i < max; i++) { |
| 205 int32_t variance = PatternMatchVariance(counters, &patterns[i * 4], | 205 int32_t variance = PatternMatchVariance(counters, &patterns[i * 4], |
| 206 MAX_INDIVIDUAL_VARIANCE); | 206 MAX_INDIVIDUAL_VARIANCE); |
| 207 if (variance < bestVariance) { | 207 if (variance < bestVariance) { |
| 208 bestVariance = variance; | 208 bestVariance = variance; |
| 209 bestMatch = i; | 209 bestMatch = i; |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 if (bestMatch >= 0) { | 212 if (bestMatch >= 0) { |
| 213 return bestMatch; | 213 return bestMatch; |
| 214 } | 214 } |
| 215 e = BCExceptionNotFound; | 215 e = BCExceptionNotFound; |
| 216 return 0; | 216 return 0; |
| 217 } | 217 } |
| OLD | NEW |