xref: /aosp_15_r20/external/pdfium/fxbarcode/common/BC_CommonBitMatrix.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 2007 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/common/BC_CommonBitMatrix.h"
24*3ac0a46fSAndroid Build Coastguard Worker 
25*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/fixed_zeroed_data_vector.h"
26*3ac0a46fSAndroid Build Coastguard Worker #include "third_party/base/check_op.h"
27*3ac0a46fSAndroid Build Coastguard Worker 
CBC_CommonBitMatrix(size_t width,size_t height)28*3ac0a46fSAndroid Build Coastguard Worker CBC_CommonBitMatrix::CBC_CommonBitMatrix(size_t width, size_t height)
29*3ac0a46fSAndroid Build Coastguard Worker     : m_height(height), m_rowSize((width + 31) >> 5) {
30*3ac0a46fSAndroid Build Coastguard Worker   static constexpr int32_t kMaxBits = 1024 * 1024 * 1024;  // 1 Gb.
31*3ac0a46fSAndroid Build Coastguard Worker   CHECK_LT(m_rowSize, kMaxBits / m_height);
32*3ac0a46fSAndroid Build Coastguard Worker   m_bits = FixedZeroedDataVector<uint32_t>(m_rowSize * m_height);
33*3ac0a46fSAndroid Build Coastguard Worker }
34*3ac0a46fSAndroid Build Coastguard Worker 
35*3ac0a46fSAndroid Build Coastguard Worker CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default;
36*3ac0a46fSAndroid Build Coastguard Worker 
Get(size_t x,size_t y) const37*3ac0a46fSAndroid Build Coastguard Worker bool CBC_CommonBitMatrix::Get(size_t x, size_t y) const {
38*3ac0a46fSAndroid Build Coastguard Worker   size_t offset = y * m_rowSize + (x >> 5);
39*3ac0a46fSAndroid Build Coastguard Worker   return ((m_bits.span()[offset] >> (x & 0x1f)) & 1) != 0;
40*3ac0a46fSAndroid Build Coastguard Worker }
41*3ac0a46fSAndroid Build Coastguard Worker 
Set(size_t x,size_t y)42*3ac0a46fSAndroid Build Coastguard Worker void CBC_CommonBitMatrix::Set(size_t x, size_t y) {
43*3ac0a46fSAndroid Build Coastguard Worker   size_t offset = y * m_rowSize + (x >> 5);
44*3ac0a46fSAndroid Build Coastguard Worker   m_bits.writable_span()[offset] |= 1u << (x & 0x1f);
45*3ac0a46fSAndroid Build Coastguard Worker }
46