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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 std::unique_ptr<CFX_ByteArray> codewords(parser.ReadCodewords(e)); | 75 std::unique_ptr<CFX_ByteArray> codewords(parser.ReadCodewords(e)); |
76 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 76 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
77 CFX_PtrArray* dataBlocks = | 77 CFX_ArrayTemplate<CBC_QRDataBlock*>* dataBlocks = |
78 CBC_QRDataBlock::GetDataBlocks(codewords.get(), version, ecLevel, e); | 78 CBC_QRDataBlock::GetDataBlocks(codewords.get(), version, ecLevel, e); |
79 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 79 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
80 int32_t totalBytes = 0; | 80 int32_t totalBytes = 0; |
81 for (int32_t i = 0; i < dataBlocks->GetSize(); i++) { | 81 for (int32_t i = 0; i < dataBlocks->GetSize(); i++) { |
82 totalBytes += ((CBC_QRDataBlock*)((*dataBlocks)[i]))->GetNumDataCodewords(); | 82 totalBytes += (*dataBlocks)[i]->GetNumDataCodewords(); |
83 } | 83 } |
84 CFX_ByteArray resultBytes; | 84 CFX_ByteArray resultBytes; |
85 for (int32_t j = 0; j < dataBlocks->GetSize(); j++) { | 85 for (int32_t j = 0; j < dataBlocks->GetSize(); j++) { |
86 CBC_QRDataBlock* dataBlock = (CBC_QRDataBlock*)((*dataBlocks)[j]); | 86 CBC_QRDataBlock* dataBlock = (*dataBlocks)[j]; |
87 CFX_ByteArray* codewordBytes = dataBlock->GetCodewords(); | 87 CFX_ByteArray* codewordBytes = dataBlock->GetCodewords(); |
88 int32_t numDataCodewords = dataBlock->GetNumDataCodewords(); | 88 int32_t numDataCodewords = dataBlock->GetNumDataCodewords(); |
89 CorrectErrors(codewordBytes, numDataCodewords, e); | 89 CorrectErrors(codewordBytes, numDataCodewords, e); |
90 if (e != BCExceptionNO) { | 90 if (e != BCExceptionNO) { |
91 for (int32_t k = 0; k < dataBlocks->GetSize(); k++) { | 91 for (int32_t k = 0; k < dataBlocks->GetSize(); k++) { |
92 delete (CBC_QRDataBlock*)(*dataBlocks)[k]; | 92 delete (*dataBlocks)[k]; |
93 } | 93 } |
94 dataBlocks->RemoveAll(); | |
95 delete dataBlocks; | 94 delete dataBlocks; |
96 dataBlocks = NULL; | |
97 return NULL; | 95 return NULL; |
98 } | 96 } |
99 for (int32_t i = 0; i < numDataCodewords; i++) { | 97 for (int32_t i = 0; i < numDataCodewords; i++) { |
100 resultBytes.Add((*codewordBytes)[i]); | 98 resultBytes.Add((*codewordBytes)[i]); |
101 } | 99 } |
102 } | 100 } |
103 for (int32_t k = 0; k < dataBlocks->GetSize(); k++) { | 101 for (int32_t k = 0; k < dataBlocks->GetSize(); k++) { |
104 delete (CBC_QRDataBlock*)(*dataBlocks)[k]; | 102 delete (*dataBlocks)[k]; |
105 } | 103 } |
106 dataBlocks->RemoveAll(); | |
107 delete dataBlocks; | 104 delete dataBlocks; |
108 dataBlocks = NULL; | |
109 CBC_CommonDecoderResult* cdr = CBC_QRDecodedBitStreamParser::Decode( | 105 CBC_CommonDecoderResult* cdr = CBC_QRDecodedBitStreamParser::Decode( |
110 &resultBytes, version, ecLevel, byteModeDecode, e); | 106 &resultBytes, version, ecLevel, byteModeDecode, e); |
111 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 107 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
112 return cdr; | 108 return cdr; |
113 } | 109 } |
114 void CBC_QRCoderDecoder::CorrectErrors(CFX_ByteArray* codewordBytes, | 110 void CBC_QRCoderDecoder::CorrectErrors(CFX_ByteArray* codewordBytes, |
115 int32_t numDataCodewords, | 111 int32_t numDataCodewords, |
116 int32_t& e) { | 112 int32_t& e) { |
117 int32_t numCodewords = codewordBytes->GetSize(); | 113 int32_t numCodewords = codewordBytes->GetSize(); |
118 CFX_Int32Array codewordsInts; | 114 CFX_Int32Array codewordsInts; |
119 codewordsInts.SetSize(numCodewords); | 115 codewordsInts.SetSize(numCodewords); |
120 for (int32_t i = 0; i < numCodewords; i++) { | 116 for (int32_t i = 0; i < numCodewords; i++) { |
121 codewordsInts[i] = (int32_t)((*codewordBytes)[i] & 0xff); | 117 codewordsInts[i] = (int32_t)((*codewordBytes)[i] & 0xff); |
122 } | 118 } |
123 int32_t numECCodewords = codewordBytes->GetSize() - numDataCodewords; | 119 int32_t numECCodewords = codewordBytes->GetSize() - numDataCodewords; |
124 m_rsDecoder->Decode(&codewordsInts, numECCodewords, e); | 120 m_rsDecoder->Decode(&codewordsInts, numECCodewords, e); |
125 BC_EXCEPTION_CHECK_ReturnVoid(e); | 121 BC_EXCEPTION_CHECK_ReturnVoid(e); |
126 for (int32_t k = 0; k < numDataCodewords; k++) { | 122 for (int32_t k = 0; k < numDataCodewords; k++) { |
127 (*codewordBytes)[k] = (uint8_t)codewordsInts[k]; | 123 (*codewordBytes)[k] = (uint8_t)codewordsInts[k]; |
128 } | 124 } |
129 } | 125 } |
OLD | NEW |