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"); |
11 * you may not use this file except in compliance with the License. | 11 * you may not use this file except in compliance with the License. |
12 * You may obtain a copy of the License at | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
23 #include "../barcode.h" | 23 #include "../barcode.h" |
24 #include "BC_QRCoderECBlocks.h" | 24 #include "BC_QRCoderECBlocks.h" |
25 #include "BC_QRCoderECB.h" | 25 #include "BC_QRCoderECB.h" |
26 #include "BC_QRDataBlock.h" | 26 #include "BC_QRDataBlock.h" |
27 #include "BC_QRCoderVersion.h" | 27 #include "BC_QRCoderVersion.h" |
28 CBC_QRDataBlock::CBC_QRDataBlock(FX_INT32 numDataCodewords, CFX_ByteArray *codew
ords) | 28 CBC_QRDataBlock::CBC_QRDataBlock(int32_t numDataCodewords, CFX_ByteArray *codewo
rds) |
29 : m_numDataCodewords(numDataCodewords) | 29 : m_numDataCodewords(numDataCodewords) |
30 , m_codewords(codewords) | 30 , m_codewords(codewords) |
31 { | 31 { |
32 } | 32 } |
33 CBC_QRDataBlock::~CBC_QRDataBlock() | 33 CBC_QRDataBlock::~CBC_QRDataBlock() |
34 { | 34 { |
35 if(m_codewords != NULL) { | 35 if(m_codewords != NULL) { |
36 delete m_codewords; | 36 delete m_codewords; |
37 m_codewords = NULL; | 37 m_codewords = NULL; |
38 } | 38 } |
39 } | 39 } |
40 FX_INT32 CBC_QRDataBlock::GetNumDataCodewords() | 40 int32_t CBC_QRDataBlock::GetNumDataCodewords() |
41 { | 41 { |
42 return m_numDataCodewords; | 42 return m_numDataCodewords; |
43 } | 43 } |
44 CFX_ByteArray *CBC_QRDataBlock::GetCodewords() | 44 CFX_ByteArray *CBC_QRDataBlock::GetCodewords() |
45 { | 45 { |
46 return m_codewords; | 46 return m_codewords; |
47 } | 47 } |
48 CFX_PtrArray *CBC_QRDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, CBC_QR
CoderVersion *version, CBC_QRCoderErrorCorrectionLevel* ecLevel, FX_INT32 &e) | 48 CFX_PtrArray *CBC_QRDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, CBC_QR
CoderVersion *version, CBC_QRCoderErrorCorrectionLevel* ecLevel, int32_t &e) |
49 { | 49 { |
50 if(rawCodewords->GetSize() != version->GetTotalCodeWords()) { | 50 if(rawCodewords->GetSize() != version->GetTotalCodeWords()) { |
51 e = BCExceptionIllegalArgument; | 51 e = BCExceptionIllegalArgument; |
52 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 52 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
53 } | 53 } |
54 CBC_QRCoderECBlocks *ecBlocks = version->GetECBlocksForLevel(ecLevel); | 54 CBC_QRCoderECBlocks *ecBlocks = version->GetECBlocksForLevel(ecLevel); |
55 FX_INT32 totalBlocks = 0; | 55 int32_t totalBlocks = 0; |
56 CFX_PtrArray* ecBlockArray = ecBlocks->GetECBlocks(); | 56 CFX_PtrArray* ecBlockArray = ecBlocks->GetECBlocks(); |
57 FX_INT32 i = 0; | 57 int32_t i = 0; |
58 for(i = 0; i < ecBlockArray->GetSize(); i++) { | 58 for(i = 0; i < ecBlockArray->GetSize(); i++) { |
59 totalBlocks += ((CBC_QRCoderECB*)(*ecBlockArray)[i])->GetCount(); | 59 totalBlocks += ((CBC_QRCoderECB*)(*ecBlockArray)[i])->GetCount(); |
60 } | 60 } |
61 CFX_PtrArray *datablock = FX_NEW CFX_PtrArray(); | 61 CFX_PtrArray *datablock = FX_NEW CFX_PtrArray(); |
62 datablock->SetSize(totalBlocks); | 62 datablock->SetSize(totalBlocks); |
63 CBC_AutoPtr<CFX_PtrArray > result(datablock); | 63 CBC_AutoPtr<CFX_PtrArray > result(datablock); |
64 FX_INT32 numResultBlocks = 0; | 64 int32_t numResultBlocks = 0; |
65 for(FX_INT32 j = 0; j < ecBlockArray->GetSize(); j++) { | 65 for(int32_t j = 0; j < ecBlockArray->GetSize(); j++) { |
66 CBC_QRCoderECB *ecBlock = (CBC_QRCoderECB*)(*ecBlockArray)[j]; | 66 CBC_QRCoderECB *ecBlock = (CBC_QRCoderECB*)(*ecBlockArray)[j]; |
67 for(FX_INT32 k = 0; k < ecBlock->GetCount(); k++) { | 67 for(int32_t k = 0; k < ecBlock->GetCount(); k++) { |
68 FX_INT32 numDataCodewords = ecBlock->GetDataCodeWords(); | 68 int32_t numDataCodewords = ecBlock->GetDataCodeWords(); |
69 FX_INT32 numBlockCodewords = ecBlocks->GetECCodeWordsPerBlock() + nu
mDataCodewords; | 69 int32_t numBlockCodewords = ecBlocks->GetECCodeWordsPerBlock() + num
DataCodewords; |
70 CFX_ByteArray *bytearray = FX_NEW CFX_ByteArray(); | 70 CFX_ByteArray *bytearray = FX_NEW CFX_ByteArray(); |
71 bytearray->SetSize(numBlockCodewords); | 71 bytearray->SetSize(numBlockCodewords); |
72 (*result)[numResultBlocks++] = FX_NEW CBC_QRDataBlock(numDataCodewor
ds, bytearray); | 72 (*result)[numResultBlocks++] = FX_NEW CBC_QRDataBlock(numDataCodewor
ds, bytearray); |
73 } | 73 } |
74 } | 74 } |
75 FX_INT32 shorterBlocksTotalCodewords = ((CBC_QRDataBlock*)(*result)[0])->m_c
odewords->GetSize(); | 75 int32_t shorterBlocksTotalCodewords = ((CBC_QRDataBlock*)(*result)[0])->m_co
dewords->GetSize(); |
76 FX_INT32 longerBlocksStartAt = result->GetSize() - 1; | 76 int32_t longerBlocksStartAt = result->GetSize() - 1; |
77 while(longerBlocksStartAt >= 0) { | 77 while(longerBlocksStartAt >= 0) { |
78 FX_INT32 numCodewords = ((CBC_QRDataBlock*)(*result)[longerBlocksStartAt
])->m_codewords->GetSize(); | 78 int32_t numCodewords = ((CBC_QRDataBlock*)(*result)[longerBlocksStartAt]
)->m_codewords->GetSize(); |
79 if(numCodewords == shorterBlocksTotalCodewords) { | 79 if(numCodewords == shorterBlocksTotalCodewords) { |
80 break; | 80 break; |
81 } | 81 } |
82 longerBlocksStartAt--; | 82 longerBlocksStartAt--; |
83 } | 83 } |
84 longerBlocksStartAt++; | 84 longerBlocksStartAt++; |
85 FX_INT32 shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlo
cks->GetECCodeWordsPerBlock(); | 85 int32_t shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBloc
ks->GetECCodeWordsPerBlock(); |
86 FX_INT32 rawCodewordsOffset = 0; | 86 int32_t rawCodewordsOffset = 0; |
87 FX_INT32 x = 0; | 87 int32_t x = 0; |
88 for(FX_INT32 k = 0; k < shorterBlocksNumDataCodewords; k++) { | 88 for(int32_t k = 0; k < shorterBlocksNumDataCodewords; k++) { |
89 for(x = 0; x < numResultBlocks; x++) { | 89 for(x = 0; x < numResultBlocks; x++) { |
90 (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[k] = (*rawCodewor
ds)[rawCodewordsOffset++]; | 90 (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[k] = (*rawCodewor
ds)[rawCodewordsOffset++]; |
91 } | 91 } |
92 } | 92 } |
93 for(x = longerBlocksStartAt; x < numResultBlocks; x++) { | 93 for(x = longerBlocksStartAt; x < numResultBlocks; x++) { |
94 (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[shorterBlocksNumDataC
odewords] = (*rawCodewords)[rawCodewordsOffset++]; | 94 (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[shorterBlocksNumDataC
odewords] = (*rawCodewords)[rawCodewordsOffset++]; |
95 } | 95 } |
96 FX_INT32 max = ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize(); | 96 int32_t max = ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize(); |
97 for(i = shorterBlocksNumDataCodewords; i < max; i++) { | 97 for(i = shorterBlocksNumDataCodewords; i < max; i++) { |
98 for(FX_INT32 y = 0; y < numResultBlocks; y++) { | 98 for(int32_t y = 0; y < numResultBlocks; y++) { |
99 FX_INT32 iOffset = y < longerBlocksStartAt ? i : i + 1; | 99 int32_t iOffset = y < longerBlocksStartAt ? i : i + 1; |
100 (*(((CBC_QRDataBlock*)(*result)[y])->m_codewords))[iOffset] = (*rawC
odewords)[rawCodewordsOffset++]; | 100 (*(((CBC_QRDataBlock*)(*result)[y])->m_codewords))[iOffset] = (*rawC
odewords)[rawCodewordsOffset++]; |
101 } | 101 } |
102 } | 102 } |
103 return result.release(); | 103 return result.release(); |
104 } | 104 } |
OLD | NEW |