comparison mupdf-source/thirdparty/zxing-cpp/core/src/BitArray.cpp @ 3:2c135c81b16c

MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:44:09 +0200
parents b50eed0cc0ef
children
comparison
equal deleted inserted replaced
0:6015a75abc2d 3:2c135c81b16c
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