| 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 29 matching lines...) Expand all Loading... |
| 40 { | 40 { |
| 41 m_rsDecoder = FX_NEW CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256::QRCodeFild
); | 41 m_rsDecoder = FX_NEW CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256::QRCodeFild
); |
| 42 } | 42 } |
| 43 CBC_QRCoderDecoder::~CBC_QRCoderDecoder() | 43 CBC_QRCoderDecoder::~CBC_QRCoderDecoder() |
| 44 { | 44 { |
| 45 if(m_rsDecoder != NULL) { | 45 if(m_rsDecoder != NULL) { |
| 46 delete m_rsDecoder; | 46 delete m_rsDecoder; |
| 47 } | 47 } |
| 48 m_rsDecoder = NULL; | 48 m_rsDecoder = NULL; |
| 49 } | 49 } |
| 50 CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(FX_BOOL* image, FX_INT32 wid
th, FX_INT32 height, FX_INT32 &e) | 50 CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(FX_BOOL* image, int32_t widt
h, int32_t height, int32_t &e) |
| 51 { | 51 { |
| 52 CBC_CommonBitMatrix bits; | 52 CBC_CommonBitMatrix bits; |
| 53 bits.Init(width); | 53 bits.Init(width); |
| 54 for(FX_INT32 i = 0; i < width; i++) { | 54 for(int32_t i = 0; i < width; i++) { |
| 55 for(FX_INT32 j = 0; j < height; j++) { | 55 for(int32_t j = 0; j < height; j++) { |
| 56 if(image[i * width + j]) { | 56 if(image[i * width + j]) { |
| 57 bits.Set(j, i); | 57 bits.Set(j, i); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 CBC_CommonDecoderResult* cdr = Decode(&bits, height, e); | 61 CBC_CommonDecoderResult* cdr = Decode(&bits, height, e); |
| 62 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 62 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 63 return cdr; | 63 return cdr; |
| 64 } | 64 } |
| 65 CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(CBC_CommonBitMatrix* bits, F
X_INT32 byteModeDecode, FX_INT32 &e) | 65 CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(CBC_CommonBitMatrix* bits, i
nt32_t byteModeDecode, int32_t &e) |
| 66 { | 66 { |
| 67 CBC_QRBitMatrixParser parser; | 67 CBC_QRBitMatrixParser parser; |
| 68 parser.Init(bits, e); | 68 parser.Init(bits, e); |
| 69 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 69 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 70 CBC_QRCoderVersion *version = parser.ReadVersion(e); | 70 CBC_QRCoderVersion *version = parser.ReadVersion(e); |
| 71 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 71 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 72 CBC_QRCoderFormatInformation* temp = parser.ReadFormatInformation(e); | 72 CBC_QRCoderFormatInformation* temp = parser.ReadFormatInformation(e); |
| 73 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 73 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 74 CBC_QRCoderErrorCorrectionLevel* ecLevel = temp->GetErrorCorrectionLevel(); | 74 CBC_QRCoderErrorCorrectionLevel* ecLevel = temp->GetErrorCorrectionLevel(); |
| 75 CFX_ByteArray* ba = parser.ReadCodewords(e); | 75 CFX_ByteArray* ba = parser.ReadCodewords(e); |
| 76 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 76 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 77 CBC_AutoPtr<CFX_ByteArray > codewords(ba); | 77 CBC_AutoPtr<CFX_ByteArray > codewords(ba); |
| 78 CFX_PtrArray *dataBlocks = CBC_QRDataBlock::GetDataBlocks(codewords.get(), v
ersion, ecLevel, e); | 78 CFX_PtrArray *dataBlocks = CBC_QRDataBlock::GetDataBlocks(codewords.get(), v
ersion, ecLevel, e); |
| 79 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 79 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 80 FX_INT32 totalBytes = 0; | 80 int32_t totalBytes = 0; |
| 81 for (FX_INT32 i = 0; i < dataBlocks->GetSize(); i++) { | 81 for (int32_t i = 0; i < dataBlocks->GetSize(); i++) { |
| 82 totalBytes += ((CBC_QRDataBlock*) ((*dataBlocks)[i]))->GetNumDataCodewor
ds(); | 82 totalBytes += ((CBC_QRDataBlock*) ((*dataBlocks)[i]))->GetNumDataCodewor
ds(); |
| 83 } | 83 } |
| 84 CFX_ByteArray resultBytes; | 84 CFX_ByteArray resultBytes; |
| 85 FX_INT32 resultOffset = 0; | 85 int32_t resultOffset = 0; |
| 86 for (FX_INT32 j = 0; j < dataBlocks->GetSize(); j++) { | 86 for (int32_t j = 0; j < dataBlocks->GetSize(); j++) { |
| 87 CBC_QRDataBlock *dataBlock = (CBC_QRDataBlock *)((*dataBlocks)[j]); | 87 CBC_QRDataBlock *dataBlock = (CBC_QRDataBlock *)((*dataBlocks)[j]); |
| 88 CFX_ByteArray* codewordBytes = dataBlock->GetCodewords(); | 88 CFX_ByteArray* codewordBytes = dataBlock->GetCodewords(); |
| 89 FX_INT32 numDataCodewords = dataBlock->GetNumDataCodewords(); | 89 int32_t numDataCodewords = dataBlock->GetNumDataCodewords(); |
| 90 CorrectErrors(codewordBytes, numDataCodewords, e); | 90 CorrectErrors(codewordBytes, numDataCodewords, e); |
| 91 if (e != BCExceptionNO) { | 91 if (e != BCExceptionNO) { |
| 92 for(FX_INT32 k = 0; k < dataBlocks->GetSize(); k++) { | 92 for(int32_t k = 0; k < dataBlocks->GetSize(); k++) { |
| 93 delete (CBC_QRDataBlock*)(*dataBlocks)[k]; | 93 delete (CBC_QRDataBlock*)(*dataBlocks)[k]; |
| 94 } | 94 } |
| 95 dataBlocks->RemoveAll(); | 95 dataBlocks->RemoveAll(); |
| 96 delete dataBlocks; | 96 delete dataBlocks; |
| 97 dataBlocks = NULL; | 97 dataBlocks = NULL; |
| 98 return NULL; | 98 return NULL; |
| 99 } | 99 } |
| 100 for(FX_INT32 i = 0; i < numDataCodewords; i++) { | 100 for(int32_t i = 0; i < numDataCodewords; i++) { |
| 101 resultBytes.Add((*codewordBytes)[i]); | 101 resultBytes.Add((*codewordBytes)[i]); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 for(FX_INT32 k = 0; k < dataBlocks->GetSize(); k++) { | 104 for(int32_t k = 0; k < dataBlocks->GetSize(); k++) { |
| 105 delete (CBC_QRDataBlock*)(*dataBlocks)[k] ; | 105 delete (CBC_QRDataBlock*)(*dataBlocks)[k] ; |
| 106 } | 106 } |
| 107 dataBlocks->RemoveAll(); | 107 dataBlocks->RemoveAll(); |
| 108 delete dataBlocks; | 108 delete dataBlocks; |
| 109 dataBlocks = NULL; | 109 dataBlocks = NULL; |
| 110 CBC_CommonDecoderResult* cdr = CBC_QRDecodedBitStreamParser::Decode(&resultB
ytes, version, ecLevel, byteModeDecode, e); | 110 CBC_CommonDecoderResult* cdr = CBC_QRDecodedBitStreamParser::Decode(&resultB
ytes, version, ecLevel, byteModeDecode, e); |
| 111 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 111 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 112 return cdr; | 112 return cdr; |
| 113 } | 113 } |
| 114 void CBC_QRCoderDecoder::CorrectErrors(CFX_ByteArray* codewordBytes, FX_INT32 nu
mDataCodewords, FX_INT32 &e) | 114 void CBC_QRCoderDecoder::CorrectErrors(CFX_ByteArray* codewordBytes, int32_t num
DataCodewords, int32_t &e) |
| 115 { | 115 { |
| 116 FX_INT32 numCodewords = codewordBytes->GetSize(); | 116 int32_t numCodewords = codewordBytes->GetSize(); |
| 117 CFX_Int32Array codewordsInts; | 117 CFX_Int32Array codewordsInts; |
| 118 codewordsInts.SetSize(numCodewords); | 118 codewordsInts.SetSize(numCodewords); |
| 119 for(FX_INT32 i = 0; i < numCodewords; i++) { | 119 for(int32_t i = 0; i < numCodewords; i++) { |
| 120 codewordsInts[i] = (FX_INT32)((*codewordBytes)[i] & 0xff); | 120 codewordsInts[i] = (int32_t)((*codewordBytes)[i] & 0xff); |
| 121 } | 121 } |
| 122 FX_INT32 numECCodewords = codewordBytes->GetSize() - numDataCodewords; | 122 int32_t numECCodewords = codewordBytes->GetSize() - numDataCodewords; |
| 123 m_rsDecoder->Decode(&codewordsInts, numECCodewords, e); | 123 m_rsDecoder->Decode(&codewordsInts, numECCodewords, e); |
| 124 BC_EXCEPTION_CHECK_ReturnVoid(e); | 124 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 125 for(FX_INT32 k = 0; k < numDataCodewords; k++) { | 125 for(int32_t k = 0; k < numDataCodewords; k++) { |
| 126 (*codewordBytes)[k] = (FX_BYTE) codewordsInts[k]; | 126 (*codewordBytes)[k] = (uint8_t) codewordsInts[k]; |
| 127 } | 127 } |
| 128 } | 128 } |
| OLD | NEW |