2 * Copyright (C) 2009, 2010 by Nils Faerber <nils.faerber@kernelconcepts.de>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
15 #include "bitstream.h"
17 static unsigned char *_BITBUF;
18 static unsigned int _BITPOS;
19 static unsigned int _BUFLEN;
21 void printbits(unsigned int val)
26 if (val & (1<<(31-i++)))
33 void printbuf_head(unsigned char *buf)
35 //printbits(buf[3]<<24 | buf[2]<<16 | buf[1]<<8 | buf[0]);
36 printbits(buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]);
39 unsigned int bitstream_get_bits(unsigned char *data, unsigned int bitOffset, unsigned int numBits)
42 unsigned int mask = (1 << numBits) - 1;
44 data += ((bitOffset / 8) -3);
46 // printf("0x%08x ", val);
48 val = val << (bitOffset % 8);
49 // printf("0x%08x ", val);
51 val = val >> (32-numBits);
52 // printf("0x%08x %d ", val, (32-numBits));
55 // printf("0x%08x\n", val);
60 int bitstream_bits_remaining(void)
62 return (_BUFLEN - _BITPOS);
65 unsigned int bitstream_get_next_bits(unsigned int nbits)
69 res = bitstream_get_bits(_BITBUF, _BITPOS, nbits);
75 void bitstream_start(unsigned char *buf, unsigned int len)