xref: /aosp_15_r20/external/pdfium/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2014 The PDFium Authors
2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file.
4*3ac0a46fSAndroid Build Coastguard Worker 
5*3ac0a46fSAndroid Build Coastguard Worker // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6*3ac0a46fSAndroid Build Coastguard Worker // Original code is licensed as follows:
7*3ac0a46fSAndroid Build Coastguard Worker /*
8*3ac0a46fSAndroid Build Coastguard Worker  * Copyright 2011 ZXing authors
9*3ac0a46fSAndroid Build Coastguard Worker  *
10*3ac0a46fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
11*3ac0a46fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
12*3ac0a46fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
13*3ac0a46fSAndroid Build Coastguard Worker  *
14*3ac0a46fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
15*3ac0a46fSAndroid Build Coastguard Worker  *
16*3ac0a46fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
17*3ac0a46fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
18*3ac0a46fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19*3ac0a46fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
20*3ac0a46fSAndroid Build Coastguard Worker  * limitations under the License.
21*3ac0a46fSAndroid Build Coastguard Worker  */
22*3ac0a46fSAndroid Build Coastguard Worker 
23*3ac0a46fSAndroid Build Coastguard Worker #include "fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h"
24*3ac0a46fSAndroid Build Coastguard Worker 
25*3ac0a46fSAndroid Build Coastguard Worker #include <stdint.h>
26*3ac0a46fSAndroid Build Coastguard Worker 
27*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/data_vector.h"
28*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/span_util.h"
29*3ac0a46fSAndroid Build Coastguard Worker #include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h"
30*3ac0a46fSAndroid Build Coastguard Worker 
CBC_BarcodeMatrix(size_t width,size_t height)31*3ac0a46fSAndroid Build Coastguard Worker CBC_BarcodeMatrix::CBC_BarcodeMatrix(size_t width, size_t height)
32*3ac0a46fSAndroid Build Coastguard Worker     : m_width((width + 4) * 17 + 1), m_height(height) {
33*3ac0a46fSAndroid Build Coastguard Worker   m_matrix.resize(m_height);
34*3ac0a46fSAndroid Build Coastguard Worker   for (size_t i = 0; i < m_height; ++i)
35*3ac0a46fSAndroid Build Coastguard Worker     m_matrix[i] = std::make_unique<CBC_BarcodeRow>(m_width);
36*3ac0a46fSAndroid Build Coastguard Worker }
37*3ac0a46fSAndroid Build Coastguard Worker 
38*3ac0a46fSAndroid Build Coastguard Worker CBC_BarcodeMatrix::~CBC_BarcodeMatrix() = default;
39*3ac0a46fSAndroid Build Coastguard Worker 
toBitArray()40*3ac0a46fSAndroid Build Coastguard Worker DataVector<uint8_t> CBC_BarcodeMatrix::toBitArray() {
41*3ac0a46fSAndroid Build Coastguard Worker   DataVector<uint8_t> bit_array(m_width * m_height);
42*3ac0a46fSAndroid Build Coastguard Worker   pdfium::span<uint8_t> bit_array_span(bit_array);
43*3ac0a46fSAndroid Build Coastguard Worker   for (size_t i = 0; i < m_height; ++i)
44*3ac0a46fSAndroid Build Coastguard Worker     fxcrt::spancpy(bit_array_span.subspan(i * m_width), m_matrix[i]->GetRow());
45*3ac0a46fSAndroid Build Coastguard Worker   return bit_array;
46*3ac0a46fSAndroid Build Coastguard Worker }
47