• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 2007 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 "fxbarcode/common/BC_CommonBitArray.h"
24 
25 #include <utility>
26 
27 #include "fxbarcode/utils.h"
28 
CBC_CommonBitArray(CBC_CommonBitArray * array)29 CBC_CommonBitArray::CBC_CommonBitArray(CBC_CommonBitArray* array) {
30   m_size = array->GetSize();
31   m_bits = array->GetBits();
32 }
33 
CBC_CommonBitArray()34 CBC_CommonBitArray::CBC_CommonBitArray() {
35   m_bits.resize(1);
36   m_size = 0;
37 }
38 
CBC_CommonBitArray(int32_t size)39 CBC_CommonBitArray::CBC_CommonBitArray(int32_t size) {
40   m_bits.resize((size + 31) >> 5);
41   m_size = size;
42 }
43 
~CBC_CommonBitArray()44 CBC_CommonBitArray::~CBC_CommonBitArray() {}
45 
GetSize()46 size_t CBC_CommonBitArray::GetSize() {
47   return m_size;
48 }
49 
GetBits()50 std::vector<int32_t>& CBC_CommonBitArray::GetBits() {
51   return m_bits;
52 }
53 
GetSizeInBytes()54 size_t CBC_CommonBitArray::GetSizeInBytes() {
55   return (m_size + 7) >> 3;
56 }
57 
Get(size_t i)58 bool CBC_CommonBitArray::Get(size_t i) {
59   return (m_bits[i >> 5] & (1 << (i & 0x1f))) != 0;
60 }
61 
Set(size_t i)62 void CBC_CommonBitArray::Set(size_t i) {
63   m_bits[i >> 5] |= 1 << (i & 0x1F);
64 }
65 
Flip(size_t i)66 void CBC_CommonBitArray::Flip(size_t i) {
67   m_bits[i >> 5] ^= 1 << (i & 0x1F);
68 }
69 
SetBulk(size_t i,int32_t newBits)70 void CBC_CommonBitArray::SetBulk(size_t i, int32_t newBits) {
71   m_bits[i >> 5] = newBits;
72 }
73 
Clear()74 void CBC_CommonBitArray::Clear() {
75   for (auto& value : m_bits)
76     value = 0;
77 }
78 
GetBitArray()79 int32_t* CBC_CommonBitArray::GetBitArray() {
80   return m_bits.data();
81 }
82 
Reverse()83 void CBC_CommonBitArray::Reverse() {
84   std::vector<int32_t> newBits(m_bits.size());
85   for (size_t i = 0; i < m_size; i++) {
86     if (Get(m_size - i - 1))
87       newBits[i >> 5] |= 1 << (i & 0x1F);
88   }
89   m_bits = std::move(newBits);
90 }
91