comparison mupdf-source/thirdparty/zxing-cpp/core/src/BitArray.cpp @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 * Copyright 2016 Nu-book Inc.
3 * Copyright 2016 ZXing authors
4 */
5 // SPDX-License-Identifier: Apache-2.0
6
7 #include "BitArray.h"
8
9 #include "ByteArray.h"
10
11 #include <cstddef>
12 #include <stdexcept>
13
14 namespace ZXing {
15
16 void
17 BitArray::bitwiseXOR(const BitArray& other)
18 {
19 if (size() != other.size()) {
20 throw std::invalid_argument("BitArray::xor(): Sizes don't match");
21 }
22 for (size_t i = 0; i < _bits.size(); i++) {
23 // The last int could be incomplete (i.e. not have 32 bits in
24 // it) but there is no problem since 0 XOR 0 == 0.
25 _bits[i] ^= other._bits[i];
26 }
27 }
28
29 ByteArray BitArray::toBytes(int bitOffset, int numBytes) const
30 {
31 ByteArray res(numBytes == -1 ? (size() - bitOffset + 7) / 8 : numBytes);
32 for (int i = 0; i < Size(res); i++)
33 for (int j = 0; j < 8; j++)
34 AppendBit(res[i], (numBytes != -1 || bitOffset < size()) ? get(bitOffset++) : 0);
35 return res;
36 }
37
38 } // ZXing