1 #ifndef __BIT_SOURCE_H__
2 #define __BIT_SOURCE_H__
8 * Created by Christian Brunschen on 09/05/2008.
9 * Copyright 2008 Google UK. All rights reserved.
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
24 #include <zxing/common/Array.h>
28 * <p>This provides an easy abstraction to read bits at a time from a sequence of bytes, where the
29 * number of bits read is not often a multiple of 8.</p>
31 * <p>This class is not thread-safe.</p>
33 * @author srowen@google.com (Sean Owen)
34 * @author christian.brunschen@gmail.com (Christian Brunschen)
36 class BitSource : public Counted {
37 typedef unsigned char byte;
39 ArrayRef<byte> bytes_;
44 * @param bytes bytes from which this will read bits. Bits will be read from the first byte first.
45 * Bits are read within a byte from most-significant to least-significant bit.
47 BitSource(ArrayRef<byte> &bytes) :
48 bytes_(bytes), byteOffset_(0), bitOffset_(0) {
53 * @param numBits number of bits to read
54 * @return int representing the bits read. The bits will appear as the least-significant
56 * @throws IllegalArgumentException if numBits isn't in [1,32]
58 int readBits(int numBits);
61 * @return number of bits that can be read successfully
68 #endif // __BIT_SOURCE_H__