uvg266/src/bitstream.h
Ari Koivula 627762dcd8 Refactor: Fix include guards.
- Remove _ from the beginning of include guards because that prefix is
  for the implementation.
- Move include guards to the beginning of file.
- Unify the syntax.
2013-09-19 10:36:24 +03:00

69 lines
2.3 KiB
C

#ifndef BITSTREAM_H_
#define BITSTREAM_H_
/**
* \file
* \brief Bitstream can be written to one or several bits at a time.
*
* \author Marko Viitanen ( fador@iki.fi ),
* Tampere University of Technology,
* Department of Pervasive Computing.
* \author Ari Koivula ( ari@koivu.la ),
* Tampere University of Technology,
* Department of Pervasive Computing.
*/
#include "global.h"
typedef struct
{
uint32_t data[32];
uint8_t cur_byte;
uint8_t cur_bit;
FILE* output;
uint8_t* buffer;
uint32_t buffer_pos;
uint32_t bufferlen;
} bitstream;
typedef struct
{
uint8_t len;
uint32_t value;
} bit_table;
extern bit_table *g_exp_table;
int floor_log2(unsigned int n);
void bitstream_alloc(bitstream* stream, uint32_t alloc);
void bitstream_clear_buffer(bitstream* stream);
void bitstream_init(bitstream* stream);
void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits);
/* Use macros to force inlining */
#define bitstream_put_ue(stream, data) { bitstream_put(stream,g_exp_table[data].value,g_exp_table[data].len); }
#define bitstream_put_se(stream, data) { uint32_t index=(uint32_t)(((data)<=0)?(-(data))<<1:((data)<<1)-1); \
bitstream_put(stream,g_exp_table[index].value,g_exp_table[index].len); }
void bitstream_align(bitstream* stream);
void bitstream_align_zero(bitstream* stream);
void bitstream_flush(bitstream* stream);
void init_exp_golomb(uint32_t len);
/* In debug mode print out some extra info */
#ifdef NOTDEFINED//_DEBUG
/* Counter to keep up with bits written */
static int WRITE_VALUE = 0;
#define WRITE_U(stream, data, bits, name) { printf("%8d %-40s u(%d) : %d\n",WRITE_VALUE, name,bits,data); bitstream_put(stream,data,bits); WRITE_VALUE++;}
#define WRITE_UE(stream, data, name) { printf("%8d %-40s ue(v): %d\n",WRITE_VALUE, name,data); bitstream_put_ue(stream,data); WRITE_VALUE++;}
#define WRITE_SE(stream, data, name) { printf("%8d %-40s se(v): %d\n",WRITE_VALUE, name,data); bitstream_put_se(stream,(data)); WRITE_VALUE++;}
#else
#define WRITE_U(stream, data, bits, name) { bitstream_put(stream,data,bits); }
#define WRITE_UE(stream, data, name) { bitstream_put_ue(stream,data); }
#define WRITE_SE(stream, data, name) { bitstream_put_se(stream,data); }
#endif
#endif