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