*/
int bio_numbytes()
{
- return bio_bp - bio_start;
+ return bio_bp - bio_start;
}
/*
*/
void bio_init_enc(unsigned char *bp, int len)
{
- bio_start = bp;
- bio_end = bp + len;
- bio_bp = bp;
- bio_buf = 0;
- bio_ct = 8;
+ bio_start = bp;
+ bio_end = bp + len;
+ bio_bp = bp;
+ bio_buf = 0;
+ bio_ct = 8;
}
/*
*/
void bio_init_dec(unsigned char *bp, int len)
{
- bio_start = bp;
- bio_end = bp + len;
- bio_bp = bp;
- bio_buf = 0;
- bio_ct = 0;
+ bio_start = bp;
+ bio_end = bp + len;
+ bio_bp = bp;
+ bio_buf = 0;
+ bio_ct = 0;
}
/*
*/
int bio_byteout()
{
- bio_buf = (bio_buf << 8) & 0xffff;
- bio_ct = bio_buf == 0xff00 ? 7 : 8;
- if (bio_bp >= bio_end)
- return 1;
- *bio_bp++ = bio_buf >> 8;
- return 0;
+ bio_buf = (bio_buf << 8) & 0xffff;
+ bio_ct = bio_buf == 0xff00 ? 7 : 8;
+ if (bio_bp >= bio_end)
+ return 1;
+ *bio_bp++ = bio_buf >> 8;
+ return 0;
}
/*
*/
int bio_bytein()
{
- bio_buf = (bio_buf << 8) & 0xffff;
- bio_ct = bio_buf == 0xff00 ? 7 : 8;
- if (bio_bp >= bio_end)
- return 1;
- bio_buf |= *bio_bp++;
- return 0;
+ bio_buf = (bio_buf << 8) & 0xffff;
+ bio_ct = bio_buf == 0xff00 ? 7 : 8;
+ if (bio_bp >= bio_end)
+ return 1;
+ bio_buf |= *bio_bp++;
+ return 0;
}
/*
*/
void bio_putbit(int b)
{
- if (bio_ct == 0) {
- bio_byteout();
- }
- bio_ct--;
- bio_buf |= b << bio_ct;
+ if (bio_ct == 0) {
+ bio_byteout();
+ }
+ bio_ct--;
+ bio_buf |= b << bio_ct;
}
/*
*/
int bio_getbit()
{
- if (bio_ct == 0) {
- bio_bytein();
- }
- bio_ct--;
- return (bio_buf >> bio_ct) & 1;
+ if (bio_ct == 0) {
+ bio_bytein();
+ }
+ bio_ct--;
+ return (bio_buf >> bio_ct) & 1;
}
/*
*/
void bio_write(int v, int n)
{
- int i;
- for (i = n - 1; i >= 0; i--) {
- bio_putbit((v >> i) & 1);
- }
+ int i;
+ for (i = n - 1; i >= 0; i--) {
+ bio_putbit((v >> i) & 1);
+ }
}
/*
*/
int bio_read(int n)
{
- int i, v;
- v = 0;
- for (i = n - 1; i >= 0; i--) {
- v += bio_getbit() << i;
- }
- return v;
+ int i, v;
+ v = 0;
+ for (i = n - 1; i >= 0; i--) {
+ v += bio_getbit() << i;
+ }
+ return v;
}
/*
*/
int bio_flush()
{
+ bio_ct = 0;
+ if (bio_byteout())
+ return 1;
+ if (bio_ct == 7) {
bio_ct = 0;
- if (bio_byteout())
- return 1;
- if (bio_ct == 7) {
- bio_ct = 0;
- if (bio_byteout())
- return 1;
- }
- return 0;
+ if (bio_byteout())
+ return 1;
+ }
+ return 0;
}
/*
*/
int bio_inalign()
{
+ bio_ct = 0;
+ if ((bio_buf & 0xff) == 0xff) {
+ if (bio_bytein())
+ return 1;
bio_ct = 0;
- if ((bio_buf & 0xff) == 0xff) {
- if (bio_bytein())
- return 1;
- bio_ct = 0;
- }
- return 0;
+ }
+ return 0;
}