2 * FreeRDP: A Remote Desktop Protocol client.
3 * RemoteFX Codec Library - Bit Stream
5 * Copyright 2011 Vic Lee
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #ifndef __RFX_BITSTREAM_H
21 #define __RFX_BITSTREAM_H
23 #include <freerdp/codec/rfx.h>
32 typedef struct _RFX_BITSTREAM RFX_BITSTREAM;
34 #define rfx_bitstream_attach(bs, _buffer, _nbytes) do { \
35 bs->buffer = (uint8*) (_buffer); \
36 bs->nbytes = (_nbytes); \
38 bs->bits_left = 8; } while (0)
40 #define rfx_bitstream_get_bits(bs, _nbits, _r) do { \
44 while (bs->byte_pos < bs->nbytes && nbits > 0) \
47 if (b > bs->bits_left) \
51 n |= (bs->buffer[bs->byte_pos] >> (bs->bits_left - b)) & ((1 << b) - 1); \
54 if (bs->bits_left == 0) \
62 #define rfx_bitstream_put_bits(bs, _bits, _nbits) do { \
63 uint16 bits = (_bits); \
64 int nbits = (_nbits); \
66 while (bs->byte_pos < bs->nbytes && nbits > 0) \
69 if (b > bs->bits_left) \
71 bs->buffer[bs->byte_pos] &= ~(((1 << b) - 1) << (bs->bits_left - b)); \
72 bs->buffer[bs->byte_pos] |= ((bits >> (nbits - b)) & ((1 << b) - 1)) << (bs->bits_left - b); \
75 if (bs->bits_left == 0) \
82 #define rfx_bitstream_eos(_bs) ((_bs)->byte_pos >= (_bs)->nbytes)
83 #define rfx_bitstream_left(_bs) ((_bs)->byte_pos >= (_bs)->nbytes ? 0 : ((_bs)->nbytes - (_bs)->byte_pos - 1) * 8 + (_bs)->bits_left)
84 #define rfx_bitstream_get_processed_bytes(_bs) ((_bs)->bits_left < 8 ? (_bs)->byte_pos + 1 : (_bs)->byte_pos)
86 #endif /* __RFX_BITSTREAM_H */