1 #ifndef __BIT_SOURCE_H__
2 #define __BIT_SOURCE_H__
8 * Copyright 2010 ZXing authors All rights reserved.
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <zxing/common/Array.h>
27 * <p>This provides an easy abstraction to read bits at a time from a sequence of bytes, where the
28 * number of bits read is not often a multiple of 8.</p>
30 * <p>This class is not thread-safe.</p>
32 * @author srowen@google.com (Sean Owen)
33 * @author christian.brunschen@gmail.com (Christian Brunschen)
35 class BitSource : public Counted {
36 typedef unsigned char byte;
38 ArrayRef<byte> bytes_;
43 * @param bytes bytes from which this will read bits. Bits will be read from the first byte first.
44 * Bits are read within a byte from most-significant to least-significant bit.
46 BitSource(ArrayRef<byte> &bytes) :
47 bytes_(bytes), byteOffset_(0), bitOffset_(0) {
52 * @param numBits number of bits to read
53 * @return int representing the bits read. The bits will appear as the least-significant
55 * @throws IllegalArgumentException if numBits isn't in [1,32]
57 int readBits(int numBits);
60 * @return number of bits that can be read successfully
67 #endif // __BIT_SOURCE_H__