blob: 0fe36eae68136dd142a3939c1b5119691dd4c907 [file] [log] [blame]
Yann Colletb1f3f4b2015-10-18 22:18:32 +01001/* ******************************************************************
2 bitstream
Yann Colletae7aa062016-02-03 02:46:46 +01003 Part of FSE library
Yann Colletb1f3f4b2015-10-18 22:18:32 +01004 header file (to include)
Yann Colletae7aa062016-02-03 02:46:46 +01005 Copyright (C) 2013-2016, Yann Collet.
Yann Colletb1f3f4b2015-10-18 22:18:32 +01006
7 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above
16 copyright notice, this list of conditions and the following disclaimer
17 in the documentation and/or other materials provided with the
18 distribution.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 You can contact the author at :
33 - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
Yann Colletb1f3f4b2015-10-18 22:18:32 +010034****************************************************************** */
35#ifndef BITSTREAM_H_MODULE
36#define BITSTREAM_H_MODULE
37
38#if defined (__cplusplus)
39extern "C" {
40#endif
41
42
43/*
Yann Collet01e5b952016-03-19 14:14:31 +010044* This API consists of small unitary functions, which must be inlined for best performance.
Yann Colletb1f3f4b2015-10-18 22:18:32 +010045* Since link-time-optimization is not available for all compilers,
46* these functions are defined into a .h to be included.
47*/
48
Yann Colletae7aa062016-02-03 02:46:46 +010049/*-****************************************
50* Dependencies
Yann Colletb1f3f4b2015-10-18 22:18:32 +010051******************************************/
Yann Collet977f1f32016-01-21 15:38:47 +010052#include "mem.h" /* unaligned access routines */
53#include "error_private.h" /* error codes and messages */
Yann Colletb1f3f4b2015-10-18 22:18:32 +010054
55
Yann Colletae7aa062016-02-03 02:46:46 +010056/*-******************************************
57* bitStream encoding API (write forward)
Yann Colletb1f3f4b2015-10-18 22:18:32 +010058********************************************/
Yann Colletd1d210f2016-03-19 12:12:07 +010059/* bitStream can mix input from multiple sources.
60* A critical property of these streams is that they encode and decode in **reverse** direction.
61* So the first bit sequence you add will be the last to be read, like a LIFO stack.
Yann Colletb1f3f4b2015-10-18 22:18:32 +010062*/
63typedef struct
64{
65 size_t bitContainer;
66 int bitPos;
67 char* startPtr;
68 char* ptr;
69 char* endPtr;
70} BIT_CStream_t;
71
Yann Colletae7aa062016-02-03 02:46:46 +010072MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* dstBuffer, size_t dstCapacity);
Yann Colletb1f3f4b2015-10-18 22:18:32 +010073MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned nbBits);
74MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC);
75MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC);
76
Yann Collet01e5b952016-03-19 14:14:31 +010077/* Start with initCStream, providing the size of buffer to write into.
78* bitStream will never write outside of this buffer.
79* `dstCapacity` must be >= sizeof(size_t), otherwise @return will be an error code.
Yann Colletb1f3f4b2015-10-18 22:18:32 +010080*
Yann Collet01e5b952016-03-19 14:14:31 +010081* bits are first added to a local register.
82* Local register is size_t, hence 64-bits on 64-bits systems, or 32-bits on 32-bits systems.
83* Writing data into memory is an explicit operation, performed by the flushBits function.
84* Hence keep track how many bits are potentially stored into local register to avoid register overflow.
85* After a flushBits, a maximum of 7 bits might still be stored into local register.
Yann Colletb1f3f4b2015-10-18 22:18:32 +010086*
Yann Collet01e5b952016-03-19 14:14:31 +010087* Avoid storing elements of more than 24 bits if you want compatibility with 32-bits bitstream readers.
Yann Colletb1f3f4b2015-10-18 22:18:32 +010088*
Yann Collet01e5b952016-03-19 14:14:31 +010089* Last operation is to close the bitStream.
90* The function returns the final size of CStream in bytes.
91* If data couldn't fit into `dstBuffer`, it will return a 0 ( == not storable)
Yann Colletb1f3f4b2015-10-18 22:18:32 +010092*/
93
94
Yann Colletae7aa062016-02-03 02:46:46 +010095/*-********************************************
96* bitStream decoding API (read backward)
Yann Colletb1f3f4b2015-10-18 22:18:32 +010097**********************************************/
98typedef struct
99{
100 size_t bitContainer;
101 unsigned bitsConsumed;
102 const char* ptr;
103 const char* start;
104} BIT_DStream_t;
105
106typedef enum { BIT_DStream_unfinished = 0,
107 BIT_DStream_endOfBuffer = 1,
108 BIT_DStream_completed = 2,
109 BIT_DStream_overflow = 3 } BIT_DStream_status; /* result of BIT_reloadDStream() */
110 /* 1,2,4,8 would be better for bitmap combinations, but slows down performance a bit ... :( */
111
112MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize);
113MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits);
114MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
115MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
116
117
Yann Collet01e5b952016-03-19 14:14:31 +0100118/* Start by invoking BIT_initDStream().
119* A chunk of the bitStream is then stored into a local register.
120* Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
121* You can then retrieve bitFields stored into the local register, **in reverse order**.
122* Local register is explicitly reloaded from memory by the BIT_reloadDStream() method.
123* A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BIT_DStream_unfinished.
124* Otherwise, it can be less than that, so proceed accordingly.
125* Checking if DStream has reached its end can be performed with BIT_endOfDStream()
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100126*/
127
128
Yann Colletae7aa062016-02-03 02:46:46 +0100129/*-****************************************
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100130* unsafe API
131******************************************/
132MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, size_t value, unsigned nbBits);
133/* faster, but works only if value is "clean", meaning all high bits above nbBits are 0 */
134
135MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC);
136/* unsafe version; does not check buffer overflow */
137
138MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
139/* faster, but works only if nbBits >= 1 */
140
141
142
Yann Colletae7aa062016-02-03 02:46:46 +0100143/*-**************************************************************
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100144* Helper functions
145****************************************************************/
146MEM_STATIC unsigned BIT_highbit32 (register U32 val)
147{
148# if defined(_MSC_VER) /* Visual */
Yann Collet4114f952015-10-30 06:40:22 +0100149 unsigned long r=0;
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100150 _BitScanReverse ( &r, val );
151 return (unsigned) r;
152# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
153 return 31 - __builtin_clz (val);
154# else /* Software version */
155 static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
156 U32 v = val;
157 unsigned r;
158 v |= v >> 1;
159 v |= v >> 2;
160 v |= v >> 4;
161 v |= v >> 8;
162 v |= v >> 16;
163 r = DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27];
164 return r;
165# endif
166}
167
168
Yann Colletae7aa062016-02-03 02:46:46 +0100169/*-**************************************************************
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100170* bitStream encoding
171****************************************************************/
Yann Collet01e5b952016-03-19 14:14:31 +0100172/*! BIT_initCStream() :
173 * `dstCapacity` must be > sizeof(void*)
174 * @return : 0 if success,
175 otherwise an error code (can be tested using ERR_isError() ) */
176MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* startPtr, size_t dstCapacity)
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100177{
178 bitC->bitContainer = 0;
179 bitC->bitPos = 0;
180 bitC->startPtr = (char*)startPtr;
181 bitC->ptr = bitC->startPtr;
Yann Collet01e5b952016-03-19 14:14:31 +0100182 bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->ptr);
183 if (dstCapacity <= sizeof(bitC->ptr)) return ERROR(dstSize_tooSmall);
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100184 return 0;
185}
186
Yann Collet01e5b952016-03-19 14:14:31 +0100187/*! BIT_addBits() :
188 can add up to 26 bits into `bitC`.
189 Does not check for register overflow ! */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100190MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned nbBits)
191{
Yann Collet95cd0c22016-03-08 18:24:21 +0100192 static const unsigned mask[] = { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF }; /* up to 26 bits */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100193 bitC->bitContainer |= (value & mask[nbBits]) << bitC->bitPos;
194 bitC->bitPos += nbBits;
195}
196
Yann Colletd1d210f2016-03-19 12:12:07 +0100197/*! BIT_addBitsFast() :
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100198 * works only if `value` is _clean_, meaning all high bits above nbBits are 0 */
199MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, size_t value, unsigned nbBits)
200{
201 bitC->bitContainer |= value << bitC->bitPos;
202 bitC->bitPos += nbBits;
203}
204
Yann Colletd1d210f2016-03-19 12:12:07 +0100205/*! BIT_flushBitsFast() :
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100206 * unsafe version; does not check buffer overflow */
207MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC)
208{
Yann Colletd64f4352016-03-21 00:07:42 +0100209 size_t const nbBytes = bitC->bitPos >> 3;
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100210 MEM_writeLEST(bitC->ptr, bitC->bitContainer);
211 bitC->ptr += nbBytes;
212 bitC->bitPos &= 7;
Yann Collet00fd7a22015-11-28 16:03:22 +0100213 bitC->bitContainer >>= nbBytes*8; /* if bitPos >= sizeof(bitContainer)*8 --> undefined behavior */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100214}
215
Yann Collet01e5b952016-03-19 14:14:31 +0100216/*! BIT_flushBits() :
217 * safe version; check for buffer overflow, and prevents it.
218 * note : does not signal buffer overflow. This will be revealed later on using BIT_closeCStream() */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100219MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC)
220{
Yann Colletd64f4352016-03-21 00:07:42 +0100221 size_t const nbBytes = bitC->bitPos >> 3;
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100222 MEM_writeLEST(bitC->ptr, bitC->bitContainer);
223 bitC->ptr += nbBytes;
224 if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
225 bitC->bitPos &= 7;
Yann Collet00fd7a22015-11-28 16:03:22 +0100226 bitC->bitContainer >>= nbBytes*8; /* if bitPos >= sizeof(bitContainer)*8 --> undefined behavior */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100227}
228
Yann Colletd1d210f2016-03-19 12:12:07 +0100229/*! BIT_closeCStream() :
Yann Collet01e5b952016-03-19 14:14:31 +0100230 * @return : size of CStream, in bytes,
231 or 0 if it could not fit into dstBuffer */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100232MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC)
233{
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100234 BIT_addBitsFast(bitC, 1, 1); /* endMark */
235 BIT_flushBits(bitC);
236
Yann Collet01e5b952016-03-19 14:14:31 +0100237 if (bitC->ptr >= bitC->endPtr) return 0; /* doesn't fit within authorized budget : cancel */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100238
Yann Collet01e5b952016-03-19 14:14:31 +0100239 return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100240}
241
242
Yann Colletae7aa062016-02-03 02:46:46 +0100243/*-********************************************************
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100244* bitStream decoding
245**********************************************************/
Yann Collet01e5b952016-03-19 14:14:31 +0100246/*! BIT_initDStream() :
247* Initialize a BIT_DStream_t.
248* `bitD` : a pointer to an already allocated BIT_DStream_t structure.
249* `srcBuffer` must point at the beginning of a bitStream.
250* `srcSize` must be the exact size of the bitStream, in bytes.
251* @return : size of stream (== srcSize) or an errorCode if a problem is detected
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100252*/
253MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize)
254{
255 if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
256
Yann Colletae7aa062016-02-03 02:46:46 +0100257 if (srcSize >= sizeof(size_t)) { /* normal case */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100258 U32 contain32;
259 bitD->start = (const char*)srcBuffer;
260 bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(size_t);
261 bitD->bitContainer = MEM_readLEST(bitD->ptr);
262 contain32 = ((const BYTE*)srcBuffer)[srcSize-1];
263 if (contain32 == 0) return ERROR(GENERIC); /* endMark not present */
264 bitD->bitsConsumed = 8 - BIT_highbit32(contain32);
Yann Colletae7aa062016-02-03 02:46:46 +0100265 } else {
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100266 U32 contain32;
267 bitD->start = (const char*)srcBuffer;
268 bitD->ptr = bitD->start;
269 bitD->bitContainer = *(const BYTE*)(bitD->start);
270 switch(srcSize)
271 {
272 case 7: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[6]) << (sizeof(size_t)*8 - 16);
273 case 6: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[5]) << (sizeof(size_t)*8 - 24);
274 case 5: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[4]) << (sizeof(size_t)*8 - 32);
275 case 4: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[3]) << 24;
276 case 3: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[2]) << 16;
277 case 2: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[1]) << 8;
278 default:;
279 }
280 contain32 = ((const BYTE*)srcBuffer)[srcSize-1];
281 if (contain32 == 0) return ERROR(GENERIC); /* endMark not present */
282 bitD->bitsConsumed = 8 - BIT_highbit32(contain32);
283 bitD->bitsConsumed += (U32)(sizeof(size_t) - srcSize)*8;
284 }
285
286 return srcSize;
287}
288
Yann Collet01e5b952016-03-19 14:14:31 +0100289/*! BIT_lookBits() :
290 * Provides next n bits from local register.
291 * local register is not modified (bits are still present for next read/look).
292 * On 32-bits, maxNbBits==24.
293 * On 64-bits, maxNbBits==56.
294 * @return : value extracted
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100295 */
296MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
297{
Yann Colletd1d210f2016-03-19 12:12:07 +0100298 U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1;
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100299 return ((bitD->bitContainer << (bitD->bitsConsumed & bitMask)) >> 1) >> ((bitMask-nbBits) & bitMask);
300}
301
Yann Collet01e5b952016-03-19 14:14:31 +0100302/*! BIT_lookBitsFast() :
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100303* unsafe version; only works only if nbBits >= 1 */
304MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
305{
Yann Colletd1d210f2016-03-19 12:12:07 +0100306 U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1;
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100307 return (bitD->bitContainer << (bitD->bitsConsumed & bitMask)) >> (((bitMask+1)-nbBits) & bitMask);
308}
309
310MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
311{
312 bitD->bitsConsumed += nbBits;
313}
314
Yann Collet01e5b952016-03-19 14:14:31 +0100315/*! BIT_readBits() :
316 * Read next n bits from local register.
317 * pay attention to not read more than nbBits contained into local register.
318 * @return : extracted value.
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100319 */
320MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
321{
322 size_t value = BIT_lookBits(bitD, nbBits);
323 BIT_skipBits(bitD, nbBits);
324 return value;
325}
326
Yann Collet01e5b952016-03-19 14:14:31 +0100327/*! BIT_readBitsFast() :
328* unsafe version; only works only if nbBits >= 1 */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100329MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
330{
331 size_t value = BIT_lookBitsFast(bitD, nbBits);
332 BIT_skipBits(bitD, nbBits);
333 return value;
334}
335
Yann Collet01e5b952016-03-19 14:14:31 +0100336/*! BIT_reloadDStream() :
337* Refill `BIT_DStream_t` from src buffer previously defined (see BIT_initDStream() ).
338* This function is safe, it guarantees it will not read beyond src buffer.
339* @return : status of `BIT_DStream_t` internal register.
340 if status == unfinished, internal register is filled with >= (sizeof(size_t)*8 - 7) bits */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100341MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
342{
343 if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should never happen */
344 return BIT_DStream_overflow;
345
Yann Colletae7aa062016-02-03 02:46:46 +0100346 if (bitD->ptr >= bitD->start + sizeof(bitD->bitContainer)) {
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100347 bitD->ptr -= bitD->bitsConsumed >> 3;
348 bitD->bitsConsumed &= 7;
349 bitD->bitContainer = MEM_readLEST(bitD->ptr);
350 return BIT_DStream_unfinished;
351 }
Yann Colletae7aa062016-02-03 02:46:46 +0100352 if (bitD->ptr == bitD->start) {
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100353 if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
354 return BIT_DStream_completed;
355 }
Yann Collet01e5b952016-03-19 14:14:31 +0100356 { U32 nbBytes = bitD->bitsConsumed >> 3;
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100357 BIT_DStream_status result = BIT_DStream_unfinished;
Yann Colletae7aa062016-02-03 02:46:46 +0100358 if (bitD->ptr - nbBytes < bitD->start) {
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100359 nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */
360 result = BIT_DStream_endOfBuffer;
361 }
362 bitD->ptr -= nbBytes;
363 bitD->bitsConsumed -= nbBytes*8;
364 bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD) */
365 return result;
366 }
367}
368
Yann Colletd1d210f2016-03-19 12:12:07 +0100369/*! BIT_endOfDStream() :
Yann Collet01e5b952016-03-19 14:14:31 +0100370* @return Tells if DStream has exactly reached its end (all bits consumed).
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100371*/
372MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
373{
374 return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
375}
376
377#if defined (__cplusplus)
378}
379#endif
380
381#endif /* BITSTREAM_H_MODULE */