| 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 2007 ZXing authors | 8 * Copyright 2007 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 26 matching lines...) Expand all Loading... |
| 37 { | 37 { |
| 38 m_rsDecoder = FX_NEW CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256::DataMatrix
Field); | 38 m_rsDecoder = FX_NEW CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256::DataMatrix
Field); |
| 39 } | 39 } |
| 40 CBC_DataMatrixDecoder::~CBC_DataMatrixDecoder() | 40 CBC_DataMatrixDecoder::~CBC_DataMatrixDecoder() |
| 41 { | 41 { |
| 42 if(m_rsDecoder != NULL) { | 42 if(m_rsDecoder != NULL) { |
| 43 delete m_rsDecoder; | 43 delete m_rsDecoder; |
| 44 } | 44 } |
| 45 m_rsDecoder = NULL; | 45 m_rsDecoder = NULL; |
| 46 } | 46 } |
| 47 CBC_CommonDecoderResult *CBC_DataMatrixDecoder::Decode(CBC_CommonBitMatrix *bits
, FX_INT32 &e) | 47 CBC_CommonDecoderResult *CBC_DataMatrixDecoder::Decode(CBC_CommonBitMatrix *bits
, int32_t &e) |
| 48 { | 48 { |
| 49 CBC_DataMatrixBitMatrixParser parser; | 49 CBC_DataMatrixBitMatrixParser parser; |
| 50 parser.Init(bits, e); | 50 parser.Init(bits, e); |
| 51 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 51 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 52 CBC_DataMatrixVersion *version = parser.GetVersion(); | 52 CBC_DataMatrixVersion *version = parser.GetVersion(); |
| 53 CFX_ByteArray* byteTemp = parser.ReadCodewords(e); | 53 CFX_ByteArray* byteTemp = parser.ReadCodewords(e); |
| 54 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 54 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 55 CBC_AutoPtr<CFX_ByteArray> codewords(byteTemp); | 55 CBC_AutoPtr<CFX_ByteArray> codewords(byteTemp); |
| 56 CFX_PtrArray *dataBlocks = CBC_DataMatrixDataBlock::GetDataBlocks(codewords.
get(), version, e); | 56 CFX_PtrArray *dataBlocks = CBC_DataMatrixDataBlock::GetDataBlocks(codewords.
get(), version, e); |
| 57 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 57 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 58 FX_INT32 dataBlocksCount = dataBlocks->GetSize(); | 58 int32_t dataBlocksCount = dataBlocks->GetSize(); |
| 59 FX_INT32 totalBytes = 0; | 59 int32_t totalBytes = 0; |
| 60 FX_INT32 i, j; | 60 int32_t i, j; |
| 61 for (i = 0; i < dataBlocksCount; i++) { | 61 for (i = 0; i < dataBlocksCount; i++) { |
| 62 totalBytes += ((CBC_DataMatrixDataBlock*)(*dataBlocks)[i])->GetNumDataCo
dewords(); | 62 totalBytes += ((CBC_DataMatrixDataBlock*)(*dataBlocks)[i])->GetNumDataCo
dewords(); |
| 63 } | 63 } |
| 64 CFX_ByteArray resultBytes; | 64 CFX_ByteArray resultBytes; |
| 65 resultBytes.SetSize(totalBytes); | 65 resultBytes.SetSize(totalBytes); |
| 66 for (j = 0; j < dataBlocksCount; j++) { | 66 for (j = 0; j < dataBlocksCount; j++) { |
| 67 CFX_ByteArray *codewordBytes = ((CBC_DataMatrixDataBlock*)(*dataBlocks)[
j])->GetCodewords(); | 67 CFX_ByteArray *codewordBytes = ((CBC_DataMatrixDataBlock*)(*dataBlocks)[
j])->GetCodewords(); |
| 68 FX_INT32 numDataCodewords = ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])
->GetNumDataCodewords(); | 68 int32_t numDataCodewords = ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])-
>GetNumDataCodewords(); |
| 69 CorrectErrors(*codewordBytes, numDataCodewords, e); | 69 CorrectErrors(*codewordBytes, numDataCodewords, e); |
| 70 if (e != BCExceptionNO) { | 70 if (e != BCExceptionNO) { |
| 71 for(FX_INT32 i = 0; i < dataBlocks->GetSize(); i++) { | 71 for(int32_t i = 0; i < dataBlocks->GetSize(); i++) { |
| 72 delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i]; | 72 delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i]; |
| 73 } | 73 } |
| 74 delete dataBlocks; | 74 delete dataBlocks; |
| 75 dataBlocks = NULL; | 75 dataBlocks = NULL; |
| 76 return NULL; | 76 return NULL; |
| 77 } | 77 } |
| 78 FX_INT32 i; | 78 int32_t i; |
| 79 for (i = 0; i < numDataCodewords; i++) { | 79 for (i = 0; i < numDataCodewords; i++) { |
| 80 resultBytes[i * dataBlocksCount + j] = (*codewordBytes)[i]; | 80 resultBytes[i * dataBlocksCount + j] = (*codewordBytes)[i]; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 for(i = 0; i < (dataBlocks->GetSize()); i++) { | 83 for(i = 0; i < (dataBlocks->GetSize()); i++) { |
| 84 delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i]; | 84 delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i]; |
| 85 } | 85 } |
| 86 delete dataBlocks; | 86 delete dataBlocks; |
| 87 dataBlocks = NULL; | 87 dataBlocks = NULL; |
| 88 CBC_CommonDecoderResult *resultR = CBC_DataMatrixDecodedBitStreamParser::Dec
ode(resultBytes, e); | 88 CBC_CommonDecoderResult *resultR = CBC_DataMatrixDecodedBitStreamParser::Dec
ode(resultBytes, e); |
| 89 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 89 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 90 return resultR; | 90 return resultR; |
| 91 } | 91 } |
| 92 void CBC_DataMatrixDecoder::CorrectErrors(CFX_ByteArray &codewordBytes, FX_INT32
numDataCodewords, FX_INT32 &e) | 92 void CBC_DataMatrixDecoder::CorrectErrors(CFX_ByteArray &codewordBytes, int32_t
numDataCodewords, int32_t &e) |
| 93 { | 93 { |
| 94 FX_INT32 numCodewords = codewordBytes.GetSize(); | 94 int32_t numCodewords = codewordBytes.GetSize(); |
| 95 CFX_Int32Array codewordsInts; | 95 CFX_Int32Array codewordsInts; |
| 96 codewordsInts.SetSize(numCodewords); | 96 codewordsInts.SetSize(numCodewords); |
| 97 FX_INT32 i; | 97 int32_t i; |
| 98 for (i = 0; i < numCodewords; i++) { | 98 for (i = 0; i < numCodewords; i++) { |
| 99 codewordsInts[i] = codewordBytes[i] & 0xFF; | 99 codewordsInts[i] = codewordBytes[i] & 0xFF; |
| 100 } | 100 } |
| 101 FX_INT32 numECCodewords = codewordBytes.GetSize() - numDataCodewords; | 101 int32_t numECCodewords = codewordBytes.GetSize() - numDataCodewords; |
| 102 m_rsDecoder->Decode(&codewordsInts, numECCodewords, e); | 102 m_rsDecoder->Decode(&codewordsInts, numECCodewords, e); |
| 103 if (e != BCExceptionNO) { | 103 if (e != BCExceptionNO) { |
| 104 e = BCExceptionChecksumException; | 104 e = BCExceptionChecksumException; |
| 105 return ; | 105 return ; |
| 106 } | 106 } |
| 107 for (i = 0; i < numDataCodewords; i++) { | 107 for (i = 0; i < numDataCodewords; i++) { |
| 108 codewordBytes[i] = (FX_BYTE) codewordsInts[i]; | 108 codewordBytes[i] = (uint8_t) codewordsInts[i]; |
| 109 } | 109 } |
| 110 } | 110 } |
| OLD | NEW |