Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef _RAR_GETBITS_ |
2 | | #define _RAR_GETBITS_ |
3 | | |
4 | | class BitInput |
5 | | { |
6 | | public: |
7 | | enum BufferSize {MAX_SIZE=0x8000}; // Size of input buffer. |
8 | | |
9 | | int InAddr; // Curent byte position in the buffer. |
10 | | int InBit; // Current bit position in the current byte. |
11 | | |
12 | | bool ExternalBuffer; |
13 | | public: |
14 | | BitInput(bool AllocBuffer); |
15 | | ~BitInput(); |
16 | | |
17 | | byte *InBuf; // Dynamically allocated input buffer. |
18 | | |
19 | | void InitBitInput() |
20 | 2 | { |
21 | 2 | InAddr=InBit=0; |
22 | 2 | } |
23 | | |
24 | | // Move forward by 'Bits' bits. |
25 | | void addbits(uint Bits) |
26 | 0 | { |
27 | 0 | Bits+=InBit; |
28 | 0 | InAddr+=Bits>>3; |
29 | 0 | InBit=Bits&7; |
30 | 0 | } |
31 | | |
32 | | // Return 16 bits from current position in the buffer. |
33 | | // Bit at (InAddr,InBit) has the highest position in returning data. |
34 | | uint getbits() |
35 | 0 | { |
36 | 0 | uint BitField=(uint)InBuf[InAddr] << 16; |
37 | 0 | BitField|=(uint)InBuf[InAddr+1] << 8; |
38 | 0 | BitField|=(uint)InBuf[InAddr+2]; |
39 | 0 | BitField >>= (8-InBit); |
40 | 0 | return BitField & 0xffff; |
41 | 0 | } |
42 | | |
43 | | // Return 32 bits from current position in the buffer. |
44 | | // Bit at (InAddr,InBit) has the highest position in returning data. |
45 | | uint getbits32() |
46 | 0 | { |
47 | 0 | uint BitField=(uint)InBuf[InAddr] << 24; |
48 | 0 | BitField|=(uint)InBuf[InAddr+1] << 16; |
49 | 0 | BitField|=(uint)InBuf[InAddr+2] << 8; |
50 | 0 | BitField|=(uint)InBuf[InAddr+3]; |
51 | 0 | BitField <<= InBit; |
52 | 0 | BitField|=(uint)InBuf[InAddr+4] >> (8-InBit); |
53 | 0 | return BitField & 0xffffffff; |
54 | 0 | } |
55 | | |
56 | | void faddbits(uint Bits); |
57 | | uint fgetbits(); |
58 | | |
59 | | // Check if buffer has enough space for IncPtr bytes. Returns 'true' |
60 | | // if buffer will be overflown. |
61 | | bool Overflow(uint IncPtr) |
62 | 0 | { |
63 | 0 | return InAddr+IncPtr>=MAX_SIZE; |
64 | 0 | } |
65 | | |
66 | | void SetExternalBuffer(byte *Buf); |
67 | | }; |
68 | | #endif |