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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h" | 27 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h" |
28 #include "xfa/fxbarcode/utils.h" | 28 #include "xfa/fxbarcode/utils.h" |
29 | 29 |
30 CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock() {} | 30 CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock() {} |
31 CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords, | 31 CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords, |
32 CFX_ByteArray* codewords) { | 32 CFX_ByteArray* codewords) { |
33 m_codewords.Copy(*codewords); | 33 m_codewords.Copy(*codewords); |
34 m_numDataCodewords = numDataCodewords; | 34 m_numDataCodewords = numDataCodewords; |
35 } | 35 } |
36 CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks( | 36 CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>* |
37 CFX_ByteArray* rawCodewords, | 37 CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, |
38 CBC_DataMatrixVersion* version, | 38 CBC_DataMatrixVersion* version, |
39 int32_t& e) { | 39 int32_t& e) { |
40 ECBlocks* ecBlocks = version->GetECBlocks(); | 40 ECBlocks* ecBlocks = version->GetECBlocks(); |
41 int32_t totalBlocks = 0; | 41 int32_t totalBlocks = 0; |
42 const CFX_ArrayTemplate<ECB*>& ecBlockArray = ecBlocks->GetECBlocks(); | 42 const CFX_ArrayTemplate<ECB*>& ecBlockArray = ecBlocks->GetECBlocks(); |
43 int32_t i; | 43 int32_t i; |
44 for (i = 0; i < ecBlockArray.GetSize(); i++) { | 44 for (i = 0; i < ecBlockArray.GetSize(); i++) { |
45 totalBlocks += ecBlockArray[i]->GetCount(); | 45 totalBlocks += ecBlockArray[i]->GetCount(); |
46 } | 46 } |
47 std::unique_ptr<CFX_PtrArray> result(new CFX_PtrArray()); | 47 std::unique_ptr<CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>> result( |
| 48 new CFX_ArrayTemplate<CBC_DataMatrixDataBlock*>()); |
48 result->SetSize(totalBlocks); | 49 result->SetSize(totalBlocks); |
49 int32_t numResultBlocks = 0; | 50 int32_t numResultBlocks = 0; |
50 int32_t j; | 51 int32_t j; |
51 for (j = 0; j < ecBlockArray.GetSize(); j++) { | 52 for (j = 0; j < ecBlockArray.GetSize(); j++) { |
52 for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) { | 53 for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) { |
53 int32_t numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords(); | 54 int32_t numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords(); |
54 int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords; | 55 int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords; |
55 CFX_ByteArray codewords; | 56 CFX_ByteArray codewords; |
56 codewords.SetSize(numBlockCodewords); | 57 codewords.SetSize(numBlockCodewords); |
57 (*result)[numResultBlocks++] = | 58 (*result)[numResultBlocks++] = |
58 new CBC_DataMatrixDataBlock(numDataCodewords, &codewords); | 59 new CBC_DataMatrixDataBlock(numDataCodewords, &codewords); |
59 codewords.SetSize(0); | 60 codewords.SetSize(0); |
60 } | 61 } |
61 } | 62 } |
62 int32_t longerBlocksTotalCodewords = | 63 int32_t longerBlocksTotalCodewords = (*result)[0]->GetCodewords()->GetSize(); |
63 ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize(); | |
64 int32_t longerBlocksNumDataCodewords = | 64 int32_t longerBlocksNumDataCodewords = |
65 longerBlocksTotalCodewords - ecBlocks->GetECCodewords(); | 65 longerBlocksTotalCodewords - ecBlocks->GetECCodewords(); |
66 int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1; | 66 int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1; |
67 int32_t rawCodewordsOffset = 0; | 67 int32_t rawCodewordsOffset = 0; |
68 for (i = 0; i < shorterBlocksNumDataCodewords; i++) { | 68 for (i = 0; i < shorterBlocksNumDataCodewords; i++) { |
69 int32_t j; | 69 int32_t j; |
70 for (j = 0; j < numResultBlocks; j++) { | 70 for (j = 0; j < numResultBlocks; j++) { |
71 if (rawCodewordsOffset < rawCodewords->GetSize()) { | 71 if (rawCodewordsOffset < rawCodewords->GetSize()) { |
72 ((CBC_DataMatrixDataBlock*)(*result)[j]) | 72 (*result)[j]->GetCodewords()->operator[](i) = |
73 ->GetCodewords() | 73 (*rawCodewords)[rawCodewordsOffset++]; |
74 -> | |
75 operator[](i) = (*rawCodewords)[rawCodewordsOffset++]; | |
76 } | 74 } |
77 } | 75 } |
78 } | 76 } |
79 const bool specialVersion = version->GetVersionNumber() == 24; | 77 const bool specialVersion = version->GetVersionNumber() == 24; |
80 int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks; | 78 int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks; |
81 for (j = 0; j < numLongerBlocks; j++) { | 79 for (j = 0; j < numLongerBlocks; j++) { |
82 if (rawCodewordsOffset < rawCodewords->GetSize()) { | 80 if (rawCodewordsOffset < rawCodewords->GetSize()) { |
83 ((CBC_DataMatrixDataBlock*)(*result)[j]) | 81 (*result)[j]->GetCodewords()->operator[](longerBlocksNumDataCodewords - |
84 ->GetCodewords() | 82 1) = |
85 -> | |
86 operator[](longerBlocksNumDataCodewords - 1) = | |
87 (*rawCodewords)[rawCodewordsOffset++]; | 83 (*rawCodewords)[rawCodewordsOffset++]; |
88 } | 84 } |
89 } | 85 } |
90 int32_t max = | 86 int32_t max = (*result)[0]->GetCodewords()->GetSize(); |
91 ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize(); | |
92 for (i = longerBlocksNumDataCodewords; i < max; i++) { | 87 for (i = longerBlocksNumDataCodewords; i < max; i++) { |
93 int32_t j; | 88 int32_t j; |
94 for (j = 0; j < numResultBlocks; j++) { | 89 for (j = 0; j < numResultBlocks; j++) { |
95 int32_t iOffset = specialVersion && j > 7 ? i - 1 : i; | 90 int32_t iOffset = specialVersion && j > 7 ? i - 1 : i; |
96 if (rawCodewordsOffset < rawCodewords->GetSize()) { | 91 if (rawCodewordsOffset < rawCodewords->GetSize()) { |
97 ((CBC_DataMatrixDataBlock*)(*result)[j]) | 92 (*result)[j]->GetCodewords()->operator[](iOffset) = |
98 ->GetCodewords() | 93 (*rawCodewords)[rawCodewordsOffset++]; |
99 -> | |
100 operator[](iOffset) = (*rawCodewords)[rawCodewordsOffset++]; | |
101 } | 94 } |
102 } | 95 } |
103 } | 96 } |
104 if (rawCodewordsOffset != rawCodewords->GetSize()) { | 97 if (rawCodewordsOffset != rawCodewords->GetSize()) { |
105 e = BCExceptionIllegalArgument; | 98 e = BCExceptionIllegalArgument; |
106 return NULL; | 99 return NULL; |
107 } | 100 } |
108 return result.release(); | 101 return result.release(); |
109 } | 102 } |
110 int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords() { | 103 int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords() { |
111 return m_numDataCodewords; | 104 return m_numDataCodewords; |
112 } | 105 } |
113 CFX_ByteArray* CBC_DataMatrixDataBlock::GetCodewords() { | 106 CFX_ByteArray* CBC_DataMatrixDataBlock::GetCodewords() { |
114 return &m_codewords; | 107 return &m_codewords; |
115 } | 108 } |
OLD | NEW |