| 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"); |
| 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_DataMatrixVersion.h" | 24 #include "BC_DataMatrixVersion.h" |
| 25 #include "BC_DataMatrixDataBlock.h" | 25 #include "BC_DataMatrixDataBlock.h" |
| 26 CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock() | 26 CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock() |
| 27 { | 27 { |
| 28 } | 28 } |
| 29 CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(FX_INT32 numDataCodewords, CFX_
ByteArray *codewords) | 29 CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords, CFX_B
yteArray *codewords) |
| 30 { | 30 { |
| 31 m_codewords.Copy(*codewords); | 31 m_codewords.Copy(*codewords); |
| 32 m_numDataCodewords = numDataCodewords; | 32 m_numDataCodewords = numDataCodewords; |
| 33 } | 33 } |
| 34 CFX_PtrArray *CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords
, CBC_DataMatrixVersion *version, FX_INT32 &e) | 34 CFX_PtrArray *CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords
, CBC_DataMatrixVersion *version, int32_t &e) |
| 35 { | 35 { |
| 36 ECBlocks *ecBlocks = version->GetECBlocks(); | 36 ECBlocks *ecBlocks = version->GetECBlocks(); |
| 37 FX_INT32 totalBlocks = 0; | 37 int32_t totalBlocks = 0; |
| 38 const CFX_PtrArray &ecBlockArray = ecBlocks->GetECBlocks(); | 38 const CFX_PtrArray &ecBlockArray = ecBlocks->GetECBlocks(); |
| 39 FX_INT32 i; | 39 int32_t i; |
| 40 for (i = 0; i < ecBlockArray.GetSize(); i++) { | 40 for (i = 0; i < ecBlockArray.GetSize(); i++) { |
| 41 totalBlocks += ((ECB*)ecBlockArray[i])->GetCount(); | 41 totalBlocks += ((ECB*)ecBlockArray[i])->GetCount(); |
| 42 } | 42 } |
| 43 CBC_AutoPtr<CFX_PtrArray>result(FX_NEW CFX_PtrArray()); | 43 CBC_AutoPtr<CFX_PtrArray>result(FX_NEW CFX_PtrArray()); |
| 44 result->SetSize(totalBlocks); | 44 result->SetSize(totalBlocks); |
| 45 FX_INT32 numResultBlocks = 0; | 45 int32_t numResultBlocks = 0; |
| 46 FX_INT32 j; | 46 int32_t j; |
| 47 for (j = 0; j < ecBlockArray.GetSize(); j++) { | 47 for (j = 0; j < ecBlockArray.GetSize(); j++) { |
| 48 for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) { | 48 for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) { |
| 49 FX_INT32 numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodeword
s(); | 49 int32_t numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords
(); |
| 50 FX_INT32 numBlockCodewords = ecBlocks->GetECCodewords() + numDataCod
ewords; | 50 int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCode
words; |
| 51 CFX_ByteArray codewords; | 51 CFX_ByteArray codewords; |
| 52 codewords.SetSize(numBlockCodewords); | 52 codewords.SetSize(numBlockCodewords); |
| 53 (*result)[numResultBlocks++] = FX_NEW CBC_DataMatrixDataBlock(numDat
aCodewords, &codewords); | 53 (*result)[numResultBlocks++] = FX_NEW CBC_DataMatrixDataBlock(numDat
aCodewords, &codewords); |
| 54 codewords.SetSize(0); | 54 codewords.SetSize(0); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 FX_INT32 longerBlocksTotalCodewords = ((CBC_DataMatrixDataBlock*)(*result)[0
])->GetCodewords()->GetSize(); | 57 int32_t longerBlocksTotalCodewords = ((CBC_DataMatrixDataBlock*)(*result)[0]
)->GetCodewords()->GetSize(); |
| 58 FX_INT32 longerBlocksNumDataCodewords = longerBlocksTotalCodewords - ecBlock
s->GetECCodewords(); | 58 int32_t longerBlocksNumDataCodewords = longerBlocksTotalCodewords - ecBlocks
->GetECCodewords(); |
| 59 FX_INT32 shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1; | 59 int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1; |
| 60 FX_INT32 rawCodewordsOffset = 0; | 60 int32_t rawCodewordsOffset = 0; |
| 61 for (i = 0; i < shorterBlocksNumDataCodewords; i++) { | 61 for (i = 0; i < shorterBlocksNumDataCodewords; i++) { |
| 62 FX_INT32 j; | 62 int32_t j; |
| 63 for (j = 0; j < numResultBlocks; j++) { | 63 for (j = 0; j < numResultBlocks; j++) { |
| 64 if (rawCodewordsOffset < rawCodewords->GetSize()) { | 64 if (rawCodewordsOffset < rawCodewords->GetSize()) { |
| 65 ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operat
or [](i) = (*rawCodewords)[rawCodewordsOffset++]; | 65 ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operat
or [](i) = (*rawCodewords)[rawCodewordsOffset++]; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 FX_BOOL specialVersion = version->GetVersionNumber() == 24; | 69 FX_BOOL specialVersion = version->GetVersionNumber() == 24; |
| 70 FX_INT32 numLongerBlocks = specialVersion ? 8 : numResultBlocks; | 70 int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks; |
| 71 for (j = 0; j < numLongerBlocks; j++) { | 71 for (j = 0; j < numLongerBlocks; j++) { |
| 72 if (rawCodewordsOffset < rawCodewords->GetSize()) { | 72 if (rawCodewordsOffset < rawCodewords->GetSize()) { |
| 73 ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operator [
](longerBlocksNumDataCodewords - 1) = (*rawCodewords)[rawCodewordsOffset++]; | 73 ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operator [
](longerBlocksNumDataCodewords - 1) = (*rawCodewords)[rawCodewordsOffset++]; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 FX_INT32 max = ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->Get
Size(); | 76 int32_t max = ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetS
ize(); |
| 77 for (i = longerBlocksNumDataCodewords; i < max; i++) { | 77 for (i = longerBlocksNumDataCodewords; i < max; i++) { |
| 78 FX_INT32 j; | 78 int32_t j; |
| 79 for (j = 0; j < numResultBlocks; j++) { | 79 for (j = 0; j < numResultBlocks; j++) { |
| 80 FX_INT32 iOffset = specialVersion && j > 7 ? i - 1 : i; | 80 int32_t iOffset = specialVersion && j > 7 ? i - 1 : i; |
| 81 if (rawCodewordsOffset < rawCodewords->GetSize()) { | 81 if (rawCodewordsOffset < rawCodewords->GetSize()) { |
| 82 ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operat
or [](iOffset) = (*rawCodewords)[rawCodewordsOffset++]; | 82 ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operat
or [](iOffset) = (*rawCodewords)[rawCodewordsOffset++]; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 if (rawCodewordsOffset != rawCodewords->GetSize()) { | 86 if (rawCodewordsOffset != rawCodewords->GetSize()) { |
| 87 e = BCExceptionIllegalArgument; | 87 e = BCExceptionIllegalArgument; |
| 88 return NULL; | 88 return NULL; |
| 89 } | 89 } |
| 90 return result.release(); | 90 return result.release(); |
| 91 } | 91 } |
| 92 FX_INT32 CBC_DataMatrixDataBlock::GetNumDataCodewords() | 92 int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords() |
| 93 { | 93 { |
| 94 return m_numDataCodewords; | 94 return m_numDataCodewords; |
| 95 } | 95 } |
| 96 CFX_ByteArray *CBC_DataMatrixDataBlock::GetCodewords() | 96 CFX_ByteArray *CBC_DataMatrixDataBlock::GetCodewords() |
| 97 { | 97 { |
| 98 return &m_codewords; | 98 return &m_codewords; |
| 99 } | 99 } |
| OLD | NEW |