29 #ifndef PGF_BITSTREAM_H
30 #define PGF_BITSTREAM_H
37 static const UINT32 Filled = 0xFFFFFFFF;
40 #define MAKEU64(a, b) ((UINT64) (((UINT32) (a)) | ((UINT64) ((UINT32) (b))) << 32))
48 inline void SetBit(UINT32* stream, UINT32 pos) {
56 inline void ClearBit(UINT32* stream, UINT32 pos) {
65 inline bool GetBit(UINT32* stream, UINT32 pos) {
79 const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog;
80 ASSERT(iLoInt <= iHiInt);
81 const UINT32 mask = (Filled >> (
WordWidth - k));
83 if (iLoInt == iHiInt) {
87 return (stream[iLoInt] & val) == val;
90 UINT64 v1 =
MAKEU64(stream[iLoInt], stream[iHiInt]);
91 UINT64 v2 = UINT64(val & mask) << (pos%
WordWidth);
92 return (v1 & v2) == v2;
102 inline void SetValueBlock(UINT32* stream, UINT32 pos, UINT32 val, UINT32 k) {
105 const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog;
106 ASSERT(iLoInt <= iHiInt);
107 const UINT32 loMask = Filled << offset;
110 if (iLoInt == iHiInt) {
112 stream[iLoInt] &= ~(loMask & hiMask);
113 stream[iLoInt] |= val << offset;
116 stream[iLoInt] &= ~loMask;
117 stream[iLoInt] |= val << offset;
118 stream[iHiInt] &= ~hiMask;
119 stream[iHiInt] |= val >> (
WordWidth - offset);
129 UINT32 count, hiCount;
131 const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog;
132 const UINT32 loMask = Filled << (pos%
WordWidth);
135 if (iLoInt == iHiInt) {
137 count = stream[iLoInt] & (loMask & hiMask);
141 count = stream[iLoInt] & loMask;
143 hiCount = stream[iHiInt] & hiMask;
158 const UINT32 iLastInt = (pos + len - 1) >> WordWidthLog;
160 const UINT32 startMask = Filled << (pos%
WordWidth);
163 if (iFirstInt == iLastInt) {
164 stream[iFirstInt] &= ~(startMask );
166 stream[iFirstInt] &= ~startMask;
167 for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) {
183 const UINT32 iLastInt = (pos + len - 1) >> WordWidthLog;
185 const UINT32 startMask = Filled << (pos%
WordWidth);
188 if (iFirstInt == iLastInt) {
189 stream[iFirstInt] |= (startMask );
191 stream[iFirstInt] |= startMask;
192 for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) {
211 while (((*word & testMask) == 0) && (count < len)) {
215 word++; testMask = 1;
218 while ((count +
WordWidth <= len) && (*word == 0)) {
240 while (((*word & testMask) != 0) && (count < len)) {
244 word++; testMask = 1;
247 while ((count +
WordWidth <= len) && (*word == Filled)) {
272 #endif //PGF_BITSTREAM_H
void SetValueBlock(UINT32 *stream, UINT32 pos, UINT32 val, UINT32 k)
Definition: BitStream.h:102
UINT32 AlignWordPos(UINT32 pos)
Definition: BitStream.h:260
void SetBitBlock(UINT32 *stream, UINT32 pos, UINT32 len)
Definition: BitStream.h:179
UINT32 SeekBitRange(UINT32 *stream, UINT32 pos, UINT32 len)
Definition: BitStream.h:206
void ClearBit(UINT32 *stream, UINT32 pos)
Definition: BitStream.h:56
void ClearBitBlock(UINT32 *stream, UINT32 pos, UINT32 len)
Definition: BitStream.h:155
bool GetBit(UINT32 *stream, UINT32 pos)
Definition: BitStream.h:65
UINT32 NumberOfWords(UINT32 pos)
Definition: BitStream.h:269
UINT32 SeekBit1Range(UINT32 *stream, UINT32 pos, UINT32 len)
Definition: BitStream.h:235
#define MAKEU64(a, b)
Make 64 bit unsigned integer from two 32 bit unsigned integers.
Definition: BitStream.h:40
bool CompareBitBlock(UINT32 *stream, UINT32 pos, UINT32 k, UINT32 val)
Definition: BitStream.h:77
void SetBit(UINT32 *stream, UINT32 pos)
Definition: BitStream.h:48
UINT32 GetValueBlock(UINT32 *stream, UINT32 pos, UINT32 k)
Definition: BitStream.h:128