Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
BC_QRCoderBitVector.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
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/qrcode/BC_QRCoderBitVector.h"
24
25#include "core/fxcrt/fx_system.h"
26#include "third_party/base/check.h"
27
29
31
32int32_t CBC_QRCoderBitVector::At(size_t index) const {
33 CHECK(index < m_sizeInBits);
34 int32_t value = m_array[index >> 3] & 0xff;
35 return (value >> (7 - (index & 0x7))) & 1;
36}
37
39 return (m_sizeInBits + 7) >> 3;
40}
41
43 return m_sizeInBits;
44}
45
46void CBC_QRCoderBitVector::AppendBit(int32_t bit) {
47 DCHECK(bit == 0 || bit == 1);
48 int32_t numBitsInLastByte = m_sizeInBits & 0x7;
49 if (numBitsInLastByte == 0) {
50 AppendByte(0);
51 m_sizeInBits -= 8;
52 }
53 m_array[m_sizeInBits >> 3] |= (bit << (7 - numBitsInLastByte));
54 ++m_sizeInBits;
55}
56
57void CBC_QRCoderBitVector::AppendBits(int32_t value, int32_t numBits) {
58 DCHECK(numBits > 0);
59 DCHECK(numBits <= 32);
60
61 int32_t numBitsLeft = numBits;
62 while (numBitsLeft > 0) {
63 if ((m_sizeInBits & 0x7) == 0 && numBitsLeft >= 8) {
64 AppendByte(static_cast<int8_t>((value >> (numBitsLeft - 8)) & 0xff));
65 numBitsLeft -= 8;
66 } else {
67 AppendBit((value >> (numBitsLeft - 1)) & 1);
68 --numBitsLeft;
69 }
70 }
71}
72
74 for (size_t i = 0; i < bits->Size(); i++)
75 AppendBit(bits->At(i));
76}
77
79 if (m_sizeInBits != other->Size())
80 return false;
81
82 pdfium::span<const uint8_t> other_span = other->GetArray();
83 for (size_t i = 0; i < sizeInBytes(); ++i)
84 m_array[i] ^= other_span[i];
85 return true;
86}
87
88pdfium::span<const uint8_t> CBC_QRCoderBitVector::GetArray() const {
89 return m_array;
90}
91
92void CBC_QRCoderBitVector::AppendByte(int8_t value) {
93 if ((m_sizeInBits >> 3) == m_array.size())
94 m_array.push_back(0);
95 m_array[m_sizeInBits >> 3] = value;
96 m_sizeInBits += 8;
97}
void AppendBits(int32_t value, int32_t numBits)
int32_t At(size_t index) const
void AppendBitVector(const CBC_QRCoderBitVector *bits)
bool XOR(const CBC_QRCoderBitVector *other)
void AppendBit(int32_t bit)
pdfium::span< const uint8_t > GetArray() const
#define CHECK(cvref)