OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 // Original code is licensed as follows: | |
7 /* | |
8 * Copyright 2007 ZXing authors | |
9 * | |
10 * Licensed under the Apache License, Version 2.0 (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 | |
13 * | |
14 * http://www.apache.org/licenses/LICENSE-2.0 | |
15 * | |
16 * Unless required by applicable law or agreed to in writing, software | |
17 * distributed under the License is distributed on an "AS IS" BASIS, | |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
19 * See the License for the specific language governing permissions and | |
20 * limitations under the License. | |
21 */ | |
22 | |
23 #include "barcode.h" | |
24 #include "include/BC_QRCoderECBlocks.h" | |
25 #include "include/BC_QRCoderECB.h" | |
26 #include "include/BC_QRDataBlock.h" | |
27 #include "include/BC_QRCoderVersion.h" | |
28 CBC_QRDataBlock::CBC_QRDataBlock(FX_INT32 numDataCodewords, CFX_ByteArray *codew
ords) | |
29 : m_numDataCodewords(numDataCodewords) | |
30 , m_codewords(codewords) | |
31 { | |
32 } | |
33 CBC_QRDataBlock::~CBC_QRDataBlock() | |
34 { | |
35 if(m_codewords != NULL) { | |
36 delete m_codewords; | |
37 m_codewords = NULL; | |
38 } | |
39 } | |
40 FX_INT32 CBC_QRDataBlock::GetNumDataCodewords() | |
41 { | |
42 return m_numDataCodewords; | |
43 } | |
44 CFX_ByteArray *CBC_QRDataBlock::GetCodewords() | |
45 { | |
46 return m_codewords; | |
47 } | |
48 CFX_PtrArray *CBC_QRDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, CBC_QR
CoderVersion *version, CBC_QRCoderErrorCorrectionLevel* ecLevel, FX_INT32 &e) | |
49 { | |
50 if(rawCodewords->GetSize() != version->GetTotalCodeWords()) { | |
51 e = BCExceptionIllegalArgument; | |
52 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
53 } | |
54 CBC_QRCoderECBlocks *ecBlocks = version->GetECBlocksForLevel(ecLevel); | |
55 FX_INT32 totalBlocks = 0; | |
56 CFX_PtrArray* ecBlockArray = ecBlocks->GetECBlocks(); | |
57 FX_INT32 i = 0; | |
58 for(i = 0; i < ecBlockArray->GetSize(); i++) { | |
59 totalBlocks += ((CBC_QRCoderECB*)(*ecBlockArray)[i])->GetCount(); | |
60 } | |
61 CFX_PtrArray *datablock = FX_NEW CFX_PtrArray(); | |
62 datablock->SetSize(totalBlocks); | |
63 CBC_AutoPtr<CFX_PtrArray > result(datablock); | |
64 FX_INT32 numResultBlocks = 0; | |
65 for(FX_INT32 j = 0; j < ecBlockArray->GetSize(); j++) { | |
66 CBC_QRCoderECB *ecBlock = (CBC_QRCoderECB*)(*ecBlockArray)[j]; | |
67 for(FX_INT32 k = 0; k < ecBlock->GetCount(); k++) { | |
68 FX_INT32 numDataCodewords = ecBlock->GetDataCodeWords(); | |
69 FX_INT32 numBlockCodewords = ecBlocks->GetECCodeWordsPerBlock() + nu
mDataCodewords; | |
70 CFX_ByteArray *bytearray = FX_NEW CFX_ByteArray(); | |
71 bytearray->SetSize(numBlockCodewords); | |
72 (*result)[numResultBlocks++] = FX_NEW CBC_QRDataBlock(numDataCodewor
ds, bytearray); | |
73 } | |
74 } | |
75 FX_INT32 shorterBlocksTotalCodewords = ((CBC_QRDataBlock*)(*result)[0])->m_c
odewords->GetSize(); | |
76 FX_INT32 longerBlocksStartAt = result->GetSize() - 1; | |
77 while(longerBlocksStartAt >= 0) { | |
78 FX_INT32 numCodewords = ((CBC_QRDataBlock*)(*result)[longerBlocksStartAt
])->m_codewords->GetSize(); | |
79 if(numCodewords == shorterBlocksTotalCodewords) { | |
80 break; | |
81 } | |
82 longerBlocksStartAt--; | |
83 } | |
84 longerBlocksStartAt++; | |
85 FX_INT32 shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlo
cks->GetECCodeWordsPerBlock(); | |
86 FX_INT32 rawCodewordsOffset = 0; | |
87 FX_INT32 x = 0; | |
88 for(FX_INT32 k = 0; k < shorterBlocksNumDataCodewords; k++) { | |
89 for(x = 0; x < numResultBlocks; x++) { | |
90 (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[k] = (*rawCodewor
ds)[rawCodewordsOffset++]; | |
91 } | |
92 } | |
93 for(x = longerBlocksStartAt; x < numResultBlocks; x++) { | |
94 (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[shorterBlocksNumDataC
odewords] = (*rawCodewords)[rawCodewordsOffset++]; | |
95 } | |
96 FX_INT32 max = ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize(); | |
97 for(i = shorterBlocksNumDataCodewords; i < max; i++) { | |
98 for(FX_INT32 y = 0; y < numResultBlocks; y++) { | |
99 FX_INT32 iOffset = y < longerBlocksStartAt ? i : i + 1; | |
100 (*(((CBC_QRDataBlock*)(*result)[y])->m_codewords))[iOffset] = (*rawC
odewords)[rawCodewordsOffset++]; | |
101 } | |
102 } | |
103 return result.release(); | |
104 } | |
OLD | NEW |