|
FreeRDP
|
20 #ifndef FREERDP_LIB_CODEC_RFX_BITSTREAM_H
21 #define FREERDP_LIB_CODEC_RFX_BITSTREAM_H
23 #include <freerdp/codec/rfx.h>
33 #define rfx_bitstream_attach(bs, _buffer, _nbytes) \
36 bs->buffer = (BYTE*)(_buffer); \
37 bs->nbytes = (_nbytes); \
42 #define rfx_bitstream_get_bits(bs, _nbits, _r) \
48 while (bs->byte_pos < bs->nbytes && nbits > 0) \
51 if (b > bs->bits_left) \
55 n |= (bs->buffer[bs->byte_pos] >> (bs->bits_left - b)) & ((1 << b) - 1); \
58 if (bs->bits_left == 0) \
67 #define rfx_bitstream_put_bits(bs, _bits, _nbits) \
70 UINT16 bits = (_bits); \
71 int nbits = (_nbits); \
73 while (bs->byte_pos < bs->nbytes && nbits > 0) \
76 if (b > bs->bits_left) \
78 bs->buffer[bs->byte_pos] |= ((bits >> (nbits - b)) & ((1 << b) - 1)) \
79 << (bs->bits_left - b); \
82 if (bs->bits_left == 0) \
89 #define rfx_bitstream_flush(bs) \
92 if (bs->bits_left != 8) \
94 int _nbits = 8 - bs->bits_left; \
95 rfx_bitstream_put_bits(bs, 0, _nbits); \
99 #define rfx_bitstream_eos(_bs) ((_bs)->byte_pos >= (_bs)->nbytes)
100 #define rfx_bitstream_left(_bs) \
101 ((_bs)->byte_pos >= (_bs)->nbytes \
103 : ((_bs)->nbytes - (_bs)->byte_pos - 1) * 8 + (_bs)->bits_left)
104 #define rfx_bitstream_get_processed_bytes(_bs) \
105 ((_bs)->bits_left < 8 ? (_bs)->byte_pos + 1 : (_bs)->byte_pos)