Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Side by Side Diff: xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 2008 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 "xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h"
24
25 #include <memory>
26
27 #include "xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.h"
28 #include "xfa/src/fxbarcode/utils.h"
29
30 CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock() {}
31 CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords,
32 CFX_ByteArray* codewords) {
33 m_codewords.Copy(*codewords);
34 m_numDataCodewords = numDataCodewords;
35 }
36 CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks(
37 CFX_ByteArray* rawCodewords,
38 CBC_DataMatrixVersion* version,
39 int32_t& e) {
40 ECBlocks* ecBlocks = version->GetECBlocks();
41 int32_t totalBlocks = 0;
42 const CFX_PtrArray& ecBlockArray = ecBlocks->GetECBlocks();
43 int32_t i;
44 for (i = 0; i < ecBlockArray.GetSize(); i++) {
45 totalBlocks += ((ECB*)ecBlockArray[i])->GetCount();
46 }
47 std::unique_ptr<CFX_PtrArray> result(new CFX_PtrArray());
48 result->SetSize(totalBlocks);
49 int32_t numResultBlocks = 0;
50 int32_t j;
51 for (j = 0; j < ecBlockArray.GetSize(); j++) {
52 for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) {
53 int32_t numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords();
54 int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords;
55 CFX_ByteArray codewords;
56 codewords.SetSize(numBlockCodewords);
57 (*result)[numResultBlocks++] =
58 new CBC_DataMatrixDataBlock(numDataCodewords, &codewords);
59 codewords.SetSize(0);
60 }
61 }
62 int32_t longerBlocksTotalCodewords =
63 ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
64 int32_t longerBlocksNumDataCodewords =
65 longerBlocksTotalCodewords - ecBlocks->GetECCodewords();
66 int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1;
67 int32_t rawCodewordsOffset = 0;
68 for (i = 0; i < shorterBlocksNumDataCodewords; i++) {
69 int32_t j;
70 for (j = 0; j < numResultBlocks; j++) {
71 if (rawCodewordsOffset < rawCodewords->GetSize()) {
72 ((CBC_DataMatrixDataBlock*)(*result)[j])
73 ->GetCodewords()
74 ->
75 operator[](i) = (*rawCodewords)[rawCodewordsOffset++];
76 }
77 }
78 }
79 const bool specialVersion = version->GetVersionNumber() == 24;
80 int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks;
81 for (j = 0; j < numLongerBlocks; j++) {
82 if (rawCodewordsOffset < rawCodewords->GetSize()) {
83 ((CBC_DataMatrixDataBlock*)(*result)[j])
84 ->GetCodewords()
85 ->
86 operator[](longerBlocksNumDataCodewords - 1) =
87 (*rawCodewords)[rawCodewordsOffset++];
88 }
89 }
90 int32_t max =
91 ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
92 for (i = longerBlocksNumDataCodewords; i < max; i++) {
93 int32_t j;
94 for (j = 0; j < numResultBlocks; j++) {
95 int32_t iOffset = specialVersion && j > 7 ? i - 1 : i;
96 if (rawCodewordsOffset < rawCodewords->GetSize()) {
97 ((CBC_DataMatrixDataBlock*)(*result)[j])
98 ->GetCodewords()
99 ->
100 operator[](iOffset) = (*rawCodewords)[rawCodewordsOffset++];
101 }
102 }
103 }
104 if (rawCodewordsOffset != rawCodewords->GetSize()) {
105 e = BCExceptionIllegalArgument;
106 return NULL;
107 }
108 return result.release();
109 }
110 int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords() {
111 return m_numDataCodewords;
112 }
113 CFX_ByteArray* CBC_DataMatrixDataBlock::GetCodewords() {
114 return &m_codewords;
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698