| 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 2013 ZXing authors | 8 * Copyright 2013 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 16 matching lines...) Expand all Loading... |
| 27 #define Float_MAX_VALUE 2147483647 | 27 #define Float_MAX_VALUE 2147483647 |
| 28 FX_FLOAT CBC_PDF417CodewordDecoder::RATIOS_TABLE[2787][8] = {0}; | 28 FX_FLOAT CBC_PDF417CodewordDecoder::RATIOS_TABLE[2787][8] = {0}; |
| 29 CBC_PDF417CodewordDecoder::CBC_PDF417CodewordDecoder() | 29 CBC_PDF417CodewordDecoder::CBC_PDF417CodewordDecoder() |
| 30 { | 30 { |
| 31 } | 31 } |
| 32 CBC_PDF417CodewordDecoder::~CBC_PDF417CodewordDecoder() | 32 CBC_PDF417CodewordDecoder::~CBC_PDF417CodewordDecoder() |
| 33 { | 33 { |
| 34 } | 34 } |
| 35 void CBC_PDF417CodewordDecoder::Initialize() | 35 void CBC_PDF417CodewordDecoder::Initialize() |
| 36 { | 36 { |
| 37 for (FX_INT32 i = 0; i < SYMBOL_TABLE_Length; i++) { | 37 for (int32_t i = 0; i < SYMBOL_TABLE_Length; i++) { |
| 38 FX_INT32 currentSymbol = CBC_PDF417Common::SYMBOL_TABLE[i]; | 38 int32_t currentSymbol = CBC_PDF417Common::SYMBOL_TABLE[i]; |
| 39 FX_INT32 currentBit = currentSymbol & 0x1; | 39 int32_t currentBit = currentSymbol & 0x1; |
| 40 for (FX_INT32 j = 0; j < CBC_PDF417Common::BARS_IN_MODULE; j++) { | 40 for (int32_t j = 0; j < CBC_PDF417Common::BARS_IN_MODULE; j++) { |
| 41 FX_FLOAT size = 0.0f; | 41 FX_FLOAT size = 0.0f; |
| 42 while ((currentSymbol & 0x1) == currentBit) { | 42 while ((currentSymbol & 0x1) == currentBit) { |
| 43 size += 1.0f; | 43 size += 1.0f; |
| 44 currentSymbol >>= 1; | 44 currentSymbol >>= 1; |
| 45 } | 45 } |
| 46 currentBit = currentSymbol & 0x1; | 46 currentBit = currentSymbol & 0x1; |
| 47 RATIOS_TABLE[i][CBC_PDF417Common::BARS_IN_MODULE - j - 1] = size / C
BC_PDF417Common::MODULES_IN_CODEWORD; | 47 RATIOS_TABLE[i][CBC_PDF417Common::BARS_IN_MODULE - j - 1] = size / C
BC_PDF417Common::MODULES_IN_CODEWORD; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 void CBC_PDF417CodewordDecoder::Finalize() | 51 void CBC_PDF417CodewordDecoder::Finalize() |
| 52 { | 52 { |
| 53 } | 53 } |
| 54 FX_INT32 CBC_PDF417CodewordDecoder::getDecodedValue(CFX_Int32Array& moduleBitCou
nt) | 54 int32_t CBC_PDF417CodewordDecoder::getDecodedValue(CFX_Int32Array& moduleBitCoun
t) |
| 55 { | 55 { |
| 56 CFX_Int32Array* array = sampleBitCounts(moduleBitCount); | 56 CFX_Int32Array* array = sampleBitCounts(moduleBitCount); |
| 57 FX_INT32 decodedValue = getDecodedCodewordValue(*array); | 57 int32_t decodedValue = getDecodedCodewordValue(*array); |
| 58 delete array; | 58 delete array; |
| 59 if (decodedValue != -1) { | 59 if (decodedValue != -1) { |
| 60 return decodedValue; | 60 return decodedValue; |
| 61 } | 61 } |
| 62 return getClosestDecodedValue(moduleBitCount); | 62 return getClosestDecodedValue(moduleBitCount); |
| 63 } | 63 } |
| 64 CFX_Int32Array* CBC_PDF417CodewordDecoder::sampleBitCounts(CFX_Int32Array& modul
eBitCount) | 64 CFX_Int32Array* CBC_PDF417CodewordDecoder::sampleBitCounts(CFX_Int32Array& modul
eBitCount) |
| 65 { | 65 { |
| 66 FX_FLOAT bitCountSum = (FX_FLOAT)CBC_PDF417Common::getBitCountSum(moduleBitC
ount); | 66 FX_FLOAT bitCountSum = (FX_FLOAT)CBC_PDF417Common::getBitCountSum(moduleBitC
ount); |
| 67 CFX_Int32Array* bitCount = FX_NEW CFX_Int32Array(); | 67 CFX_Int32Array* bitCount = FX_NEW CFX_Int32Array(); |
| 68 bitCount->SetSize(CBC_PDF417Common::BARS_IN_MODULE); | 68 bitCount->SetSize(CBC_PDF417Common::BARS_IN_MODULE); |
| 69 FX_INT32 bitCountIndex = 0; | 69 int32_t bitCountIndex = 0; |
| 70 FX_INT32 sumPreviousBits = 0; | 70 int32_t sumPreviousBits = 0; |
| 71 for (FX_INT32 i = 0; i < CBC_PDF417Common::MODULES_IN_CODEWORD; i++) { | 71 for (int32_t i = 0; i < CBC_PDF417Common::MODULES_IN_CODEWORD; i++) { |
| 72 FX_FLOAT sampleIndex = bitCountSum / (2 * CBC_PDF417Common::MODULES_IN_C
ODEWORD) + (i * bitCountSum) / CBC_PDF417Common::MODULES_IN_CODEWORD; | 72 FX_FLOAT sampleIndex = bitCountSum / (2 * CBC_PDF417Common::MODULES_IN_C
ODEWORD) + (i * bitCountSum) / CBC_PDF417Common::MODULES_IN_CODEWORD; |
| 73 if (sumPreviousBits + moduleBitCount.GetAt(bitCountIndex) <= sampleIndex
) { | 73 if (sumPreviousBits + moduleBitCount.GetAt(bitCountIndex) <= sampleIndex
) { |
| 74 sumPreviousBits += moduleBitCount.GetAt(bitCountIndex); | 74 sumPreviousBits += moduleBitCount.GetAt(bitCountIndex); |
| 75 bitCountIndex++; | 75 bitCountIndex++; |
| 76 } | 76 } |
| 77 bitCount->SetAt(bitCountIndex, bitCount->GetAt(bitCountIndex) + 1); | 77 bitCount->SetAt(bitCountIndex, bitCount->GetAt(bitCountIndex) + 1); |
| 78 } | 78 } |
| 79 return bitCount; | 79 return bitCount; |
| 80 } | 80 } |
| 81 FX_INT32 CBC_PDF417CodewordDecoder::getDecodedCodewordValue(CFX_Int32Array& modu
leBitCount) | 81 int32_t CBC_PDF417CodewordDecoder::getDecodedCodewordValue(CFX_Int32Array& modul
eBitCount) |
| 82 { | 82 { |
| 83 FX_INT32 decodedValue = getBitValue(moduleBitCount); | 83 int32_t decodedValue = getBitValue(moduleBitCount); |
| 84 return CBC_PDF417Common::getCodeword(decodedValue) == -1 ? -1 : decodedValue
; | 84 return CBC_PDF417Common::getCodeword(decodedValue) == -1 ? -1 : decodedValue
; |
| 85 } | 85 } |
| 86 FX_INT32 CBC_PDF417CodewordDecoder::getBitValue(CFX_Int32Array& moduleBitCount) | 86 int32_t CBC_PDF417CodewordDecoder::getBitValue(CFX_Int32Array& moduleBitCount) |
| 87 { | 87 { |
| 88 FX_INT64 result = 0; | 88 int64_t result = 0; |
| 89 for (FX_INT32 i = 0; i < moduleBitCount.GetSize(); i++) { | 89 for (int32_t i = 0; i < moduleBitCount.GetSize(); i++) { |
| 90 for (FX_INT32 bit = 0; bit < moduleBitCount.GetAt(i); bit++) { | 90 for (int32_t bit = 0; bit < moduleBitCount.GetAt(i); bit++) { |
| 91 result = (result << 1) | (i % 2 == 0 ? 1 : 0); | 91 result = (result << 1) | (i % 2 == 0 ? 1 : 0); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 return (FX_INT32) result; | 94 return (int32_t) result; |
| 95 } | 95 } |
| 96 FX_INT32 CBC_PDF417CodewordDecoder::getClosestDecodedValue(CFX_Int32Array& modul
eBitCount) | 96 int32_t CBC_PDF417CodewordDecoder::getClosestDecodedValue(CFX_Int32Array& module
BitCount) |
| 97 { | 97 { |
| 98 FX_INT32 bitCountSum = CBC_PDF417Common::getBitCountSum(moduleBitCount); | 98 int32_t bitCountSum = CBC_PDF417Common::getBitCountSum(moduleBitCount); |
| 99 CFX_FloatArray bitCountRatios; | 99 CFX_FloatArray bitCountRatios; |
| 100 bitCountRatios.SetSize(CBC_PDF417Common::BARS_IN_MODULE); | 100 bitCountRatios.SetSize(CBC_PDF417Common::BARS_IN_MODULE); |
| 101 for (FX_INT32 i = 0; i < bitCountRatios.GetSize(); i++) { | 101 for (int32_t i = 0; i < bitCountRatios.GetSize(); i++) { |
| 102 bitCountRatios[i] = moduleBitCount.GetAt(i) / (FX_FLOAT) bitCountSum; | 102 bitCountRatios[i] = moduleBitCount.GetAt(i) / (FX_FLOAT) bitCountSum; |
| 103 } | 103 } |
| 104 FX_FLOAT bestMatchError = (FX_FLOAT)Float_MAX_VALUE; | 104 FX_FLOAT bestMatchError = (FX_FLOAT)Float_MAX_VALUE; |
| 105 FX_INT32 bestMatch = -1; | 105 int32_t bestMatch = -1; |
| 106 for (FX_INT32 j = 0; j < SYMBOL_TABLE_Length; j++) { | 106 for (int32_t j = 0; j < SYMBOL_TABLE_Length; j++) { |
| 107 FX_FLOAT error = 0.0f; | 107 FX_FLOAT error = 0.0f; |
| 108 for (FX_INT32 k = 0; k < CBC_PDF417Common::BARS_IN_MODULE; k++) { | 108 for (int32_t k = 0; k < CBC_PDF417Common::BARS_IN_MODULE; k++) { |
| 109 FX_FLOAT diff = RATIOS_TABLE[j][k] - bitCountRatios[k]; | 109 FX_FLOAT diff = RATIOS_TABLE[j][k] - bitCountRatios[k]; |
| 110 error += diff * diff; | 110 error += diff * diff; |
| 111 } | 111 } |
| 112 if (error < bestMatchError) { | 112 if (error < bestMatchError) { |
| 113 bestMatchError = error; | 113 bestMatchError = error; |
| 114 bestMatch = CBC_PDF417Common::SYMBOL_TABLE[j]; | 114 bestMatch = CBC_PDF417Common::SYMBOL_TABLE[j]; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 return bestMatch; | 117 return bestMatch; |
| 118 } | 118 } |
| OLD | NEW |