Commit 35523430 authored by Mans Rullgard's avatar Mans Rullgard

bits: add put_byte() function

parent fea8a45b
......@@ -37,6 +37,30 @@
#define array_size(a) (sizeof(a) / sizeof(a[0]))
#define min(a, b) ((a) < (b) ? (a) : (b))
void put_byte(struct bitreader *b, int v)
{
int w = b->bitend >> 5;
int p = b->bitend & 31;
uint32_t d;
d = b->bitbuf[w];
d &= ~(255 << p);
d |= v << p;
b->bitbuf[w] = d;
if (p > 24) {
w++;
p = 32 - p;
d = b->bitbuf[w];
d &= ~(255 >> p);
d |= v >> p;
b->bitbuf[w] = d;
}
b->bitend += 8;
}
static void fill_bits(struct bitreader *b, int n)
{
if (b->bitpos) {
......
......@@ -45,6 +45,7 @@ uint64_t get_ubits(struct bitreader *b, int n);
int64_t get_sbits(struct bitreader *b, int n);
uint32_t peek_bits(struct bitreader *b, unsigned n, unsigned offs);
uint64_t peek_bits64(struct bitreader *b, unsigned n, unsigned offs);
void put_byte(struct bitreader *b, int v);
struct bitfield {
int size;
......
......@@ -105,25 +105,13 @@ static const struct frame frame_types[256] = {
static uint32_t crc;
static void put_byte(uint32_t *buf, int pos, int v)
{
uint32_t d = buf[pos >> 5];
int b = pos & 31;
d &= ~(255 << b);
d |= v << b;
buf[pos >> 5] = d;
}
static void fill_bits_mqb(struct bitreader *b, int n)
{
int bits;
while (b->bitend < b->bitpos + n) {
bits = get_ubits(&br, 8);
put_byte(b->bitbuf, b->bitend, bits);
b->bitend += 8;
put_byte(b, bits);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment