Slim numerical data compression 1.0
|
Input bit stream. More...
Public Member Functions | |
ibitstream (FILE *file, int buffersize=DEFAULT_IOBUFFER_SIZE) | |
Start ibitstream using a FILE ptr to an open file. | |
ibitstream (const char *filename, int buffersize=DEFAULT_IOBUFFER_SIZE) | |
Start inputbitstream by filename. | |
ibitstream (int fd, int buffersize=DEFAULT_IOBUFFER_SIZE) | |
Start inputbitstream by file descriptor. | |
~ibitstream () | |
Destructor only uses base class destructor. | |
virtual void | close () |
Close the IO file. | |
virtual bool | is_open () const |
Is the IO file closed? | |
void | setupstream () |
Allocate a buffer and set up all pointers, then fill buffer. | |
void | windup () |
Put the current word to the buffer with upper 0 bits as needed. | |
virtual void | print () const |
Print buffer contents. | |
virtual int | get_bytes_used () |
Return the number of bytes used so far in this stream. | |
Word_t | readbits (int nbits) |
Read data from the buffer as unsigned ints. | |
int32_t | readbits_int (int nbits) |
Read data from the buffer as (signed) ints. | |
Word_t | read_unary () |
Read a single unary-coded value. | |
int | readstring (char *s, int count=-1) |
Read a null-terminated string of 8-bit characters from the bit stream. | |
![]() | |
bitstream () | |
Dummy default constructor. | |
bitstream (const char *filename, int buffersize=DEFAULT_IOBUFFER_SIZE) | |
Start bitstream by filename. | |
virtual | ~bitstream () |
Destructor deletes output buffer, closes file. | |
int | get_bitptr () |
Get the position of the bitptr. | |
Protected Attributes | ||
FILE * | fp | |
![]() | ||
size_t | bufsize | |
Size of I/O buffer (bytes) | ||
size_t | buf_used | |
Byte_t * | buffer_base | |
Pointer to the buffer. | ||
Byte_t * | beyondbuffer | |
Pointer just beyond buffer (convenience). | ||
union { | ||
Byte_t * Bptr | ||
Pointer to the current word (as Byte_t *). | ||
Word_t * Dptr | ||
Pointer to the current word (as Word_t *). | ||
} | buffptr | |
Pointer to the current word. | ||
int | bitptr | |
Pointer to the current bits. | ||
Private Member Functions | |
void | next_word () |
Move to next word in buffer, refilling it if needed. | |
int | fill () |
Fill the read buffer and reset for more data. | |
Private Attributes | |
Word_t | partial_word |
int | partial_word_bitptr |
Additional Inherited Members | |
![]() | |
enum | { DEFAULT_IOBUFFER_SIZE =1024*1024 } |
Make *Dptr always point to same place as Bptr. More... | |
enum | { MAX_BITSTREAM_BUFSIZE =16*1024*1024 } |
![]() | |
static const int | Bits_per_word = 8*sizeof(Word_t) |
Bits per buffer word. | |
Input bit stream.
Allows you to read data N bits at a time with buffered reading.
|
virtual |
|
private |
Fill the read buffer and reset for more data.
References bitstream::beyondbuffer, bitstream::bitptr, bitstream::buf_used, bitstream::buffer_base, bitstream::buffptr, and bitstream::bufsize.
Referenced by next_word(), and setupstream().
|
virtual |
Return the number of bytes used so far in this stream.
Reimplemented from bitstream.
References bitstream::beyondbuffer, bitstream::bitptr, bitstream::buf_used, and bitstream::buffptr.
|
virtual |
Is the IO file closed?
Implements bitstream.
|
virtual |
Print buffer contents.
Implements bitstream.
References bitstream::bitptr, bitstream::buffer_base, and bitstream::buffptr.
Word_t ibitstream::read_unary | ( | ) |
Read a single unary-coded value.
References readbits().
Referenced by mexp_golomb_read_u32().
Word_t ibitstream::readbits | ( | int | n_bits | ) |
Read data from the buffer as unsigned ints.
n_bits | Number of bits to use |
References bitstream::bitptr, bitstream::Bits_per_word, bitstream::buffptr, and next_word().
Referenced by mexp_golomb_read_u32(), read_unary(), readbits_int(), readstring(), and windup().
int ibitstream::readbits_int | ( | int | n_bits | ) |
Read data from the buffer as (signed) ints.
n_bits | Number of bits to read. |
References readbits().
int ibitstream::readstring | ( | char * | s, |
int | count = -1 ) |
Read a null-terminated string of 8-bit characters from the bit stream.
s | Pointer to the string (must be available memory). |
count | Maximum size of the string. |
References readbits().
|
virtual |
Allocate a buffer and set up all pointers, then fill buffer.
Reimplemented from bitstream.
References bitstream::bufsize, fill(), and bitstream::setupstream().
Referenced by ibitstream(), ibitstream(), and ibitstream().
|
virtual |
Put the current word to the buffer with upper 0 bits as needed.
Implements bitstream.
References bitstream::bitptr, and readbits().