xref: /aosp_15_r20/external/pdfium/fxbarcode/common/BC_CommonByteMatrix.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 2008 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 #include "fxbarcode/common/BC_CommonByteMatrix.h"
23*3ac0a46fSAndroid Build Coastguard Worker 
24*3ac0a46fSAndroid Build Coastguard Worker #include <algorithm>
25*3ac0a46fSAndroid Build Coastguard Worker #include <iterator>
26*3ac0a46fSAndroid Build Coastguard Worker #include <utility>
27*3ac0a46fSAndroid Build Coastguard Worker 
28*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/data_vector.h"
29*3ac0a46fSAndroid Build Coastguard Worker #include "third_party/base/check_op.h"
30*3ac0a46fSAndroid Build Coastguard Worker 
CBC_CommonByteMatrix(size_t width,size_t height)31*3ac0a46fSAndroid Build Coastguard Worker CBC_CommonByteMatrix::CBC_CommonByteMatrix(size_t width, size_t height)
32*3ac0a46fSAndroid Build Coastguard Worker     : m_width(width), m_height(height) {
33*3ac0a46fSAndroid Build Coastguard Worker   static constexpr size_t kMaxBytes = 256 * 1024 * 1024;  // 256 MB.
34*3ac0a46fSAndroid Build Coastguard Worker   static constexpr uint8_t kDefaultFill = 0xff;
35*3ac0a46fSAndroid Build Coastguard Worker   CHECK_LT(m_width, kMaxBytes / m_height);
36*3ac0a46fSAndroid Build Coastguard Worker   m_bytes.resize(m_width * m_height, kDefaultFill);
37*3ac0a46fSAndroid Build Coastguard Worker }
38*3ac0a46fSAndroid Build Coastguard Worker 
39*3ac0a46fSAndroid Build Coastguard Worker CBC_CommonByteMatrix::~CBC_CommonByteMatrix() = default;
40*3ac0a46fSAndroid Build Coastguard Worker 
TakeArray()41*3ac0a46fSAndroid Build Coastguard Worker DataVector<uint8_t> CBC_CommonByteMatrix::TakeArray() {
42*3ac0a46fSAndroid Build Coastguard Worker   return std::move(m_bytes);
43*3ac0a46fSAndroid Build Coastguard Worker }
44*3ac0a46fSAndroid Build Coastguard Worker 
Get(size_t x,size_t y) const45*3ac0a46fSAndroid Build Coastguard Worker uint8_t CBC_CommonByteMatrix::Get(size_t x, size_t y) const {
46*3ac0a46fSAndroid Build Coastguard Worker   const size_t offset = y * m_width + x;
47*3ac0a46fSAndroid Build Coastguard Worker   CHECK_LT(offset, m_bytes.size());
48*3ac0a46fSAndroid Build Coastguard Worker   return m_bytes[offset];
49*3ac0a46fSAndroid Build Coastguard Worker }
50*3ac0a46fSAndroid Build Coastguard Worker 
Set(size_t x,size_t y,uint8_t value)51*3ac0a46fSAndroid Build Coastguard Worker void CBC_CommonByteMatrix::Set(size_t x, size_t y, uint8_t value) {
52*3ac0a46fSAndroid Build Coastguard Worker   const size_t offset = y * m_width + x;
53*3ac0a46fSAndroid Build Coastguard Worker   CHECK_LT(offset, m_bytes.size());
54*3ac0a46fSAndroid Build Coastguard Worker   m_bytes[offset] = value;
55*3ac0a46fSAndroid Build Coastguard Worker }
56*3ac0a46fSAndroid Build Coastguard Worker 
Fill(uint8_t value)57*3ac0a46fSAndroid Build Coastguard Worker void CBC_CommonByteMatrix::Fill(uint8_t value) {
58*3ac0a46fSAndroid Build Coastguard Worker   std::fill(std::begin(m_bytes), std::end(m_bytes), value);
59*3ac0a46fSAndroid Build Coastguard Worker }
60