CWB
Data Structures | Typedefs | Functions
bitio.h File Reference
#include <sys/types.h>
#include "globals.h"

Data Structures

struct  _bfilebuf
 File buffer for bit input / output. More...
 
struct  _bstreambuf
 Stream buffer for bit input / output. More...
 

Typedefs

typedef struct _bfilebuf BFile
 File buffer for bit input / output. More...
 
typedef struct _bstreambuf BStream
 Stream buffer for bit input / output. More...
 

Functions

int BFopen (char *filename, char *type, BFile *bf)
 Opens a file for bit input / output. More...
 
int BFclose (BFile *stream)
 Closes a bit input / output file buffer. More...
 
int BSopen (unsigned char *base, char *type, BStream *bf)
 Creates a stream buffer for bit input / output. More...
 
int BSclose (BStream *stream)
 Closes a bit input / output stream buffer. More...
 
int BFflush (BFile *stream)
 Flushes a bit input / output file buffer. More...
 
int BSflush (BStream *stream)
 Flushes a bit input / output stream buffer. More...
 
int BFwrite (unsigned char data, int nbits, BFile *stream)
 Writes bit data to file via a BFile buffer. More...
 
int BSwrite (unsigned char data, int nbits, BStream *stream)
 Writes bit data to a character stream via a BStream buffer. More...
 
int BFread (unsigned char *data, int nbits, BFile *stream)
 Read bit data from a file via a BFile buffer. More...
 
int BSread (unsigned char *data, int nbits, BStream *stream)
 Read bit data from a stream via a BStream buffer. More...
 
int BFwriteWord (unsigned int data, int nbits, BFile *stream)
 Writes bit data to a file from an unsigned int. More...
 
int BFreadWord (unsigned int *data, int nbits, BFile *stream)
 Reads bit data from a file into an unsigned int. More...
 
int BFposition (BFile *stream)
 Gets the stream position of a BFile. More...
 
int BSposition (BStream *stream)
 Gets the stream position of a BStream. More...
 
int BSseek (BStream *stream, off_t offset)
 Moves the position marker of a BStream (clearing the bit buffer in the process) More...
 

Typedef Documentation

typedef struct _bfilebuf BFile

File buffer for bit input / output.

typedef struct _bstreambuf BStream

Stream buffer for bit input / output.

Function Documentation

int BFclose ( BFile stream)

Closes a bit input / output file buffer.

If this is an output buffer, it is flushed before closing.

Parameters
streamThe file buffer to close.
Returns
Returns true iff the file was closed successfully.

References BFflush(), _bfilebuf::fd, and _bfilebuf::mode.

Referenced by compress_reversed_index(), compute_code_lengths(), decode_check_huff(), and decompress_check_reversed_index().

int BFflush ( BFile stream)

Flushes a bit input / output file buffer.

In the case of an output file buffer, the buffer is flushed, even an incomplete byte (so the next one begins at a new byte). In the case of an input file buffer, the buffer skips to the next input byte.

Parameters
streamThe file buffer to flush.
Returns
Boolean: 1 for all OK, 0 for a problem.

References _bfilebuf::bits_in_buf, _bfilebuf::buf, _bfilebuf::fd, _bfilebuf::mode, and _bfilebuf::position.

Referenced by BFclose(), compress_reversed_index(), compute_code_lengths(), decode_check_huff(), and decompress_check_reversed_index().

int BFopen ( char *  filename,
char *  type,
BFile bf 
)

Opens a file for bit input / output.

Sets up a bit input/output file buffer (BF)

Parameters
filenameName of file to open
typeFile-open mode string: "w" or "r" accepted
bfBuffer in which to set up the opened BF
Returns
1 on success, 0 on failure (not like fopen/fclose)

References _bfilebuf::bits_in_buf, _bfilebuf::buf, _bfilebuf::fd, _bfilebuf::mode, and _bfilebuf::position.

Referenced by compress_reversed_index(), compute_code_lengths(), decode_check_huff(), and decompress_check_reversed_index().

int BFposition ( BFile stream)

Gets the stream position of a BFile.

References _bfilebuf::position.

Referenced by compress_reversed_index(), compute_code_lengths(), and decode_check_huff().

int BFread ( unsigned char *  data,
int  nbits,
BFile stream 
)

Read bit data from a file via a BFile buffer.

NOTE: be sure that you read the data into an unsigned char!

Parameters
dataPointer to the location for the read bit data.
nbitsNumber of bits to read.
streamThe BFile buffer to use.
Returns
Boolean: 1 for all OK, 0 for a problem.

References _bfilebuf::bits_in_buf, _bfilebuf::buf, _bfilebuf::fd, and _bfilebuf::position.

Referenced by BFreadWord(), decode_check_huff(), and read_golomb_code_bf().

int BFreadWord ( unsigned int *  data,
int  nbits,
BFile stream 
)

Reads bit data from a file into an unsigned int.

This function reads nbits into an unsigned int, padded to the right.

Parameters
dataPointer to the location for the read bit data.
nbitsNumber of bits to read.
streamThe BFile buffer to use.
Returns
Boolean: 1 for all OK, 0 for a problem.

References BFread(), and bytes.

int BFwrite ( unsigned char  data,
int  nbits,
BFile stream 
)

Writes bit data to file via a BFile buffer.

Bits accumulate in the buffer till there are 8 of them. Then a byte is written to file (as an unsigned char).

Parameters
dataThe data to write.
nbitsThe number of bits to write from data.
streamThe buffer to write via.
Returns
Boolean: 1 for all OK, 0 for a problem.

References _bfilebuf::bits_in_buf, _bfilebuf::buf, _bfilebuf::fd, and _bfilebuf::position.

Referenced by BFwriteWord(), and write_golomb_code().

int BFwriteWord ( unsigned int  data,
int  nbits,
BFile stream 
)

Writes bit data to a file from an unsigned int.

This function writes nbits from an unsigned int, padded to the right.

Parameters
dataThe data to write.
nbitsNumber of bits to write.
streamThe BFile buffer to use.
Returns
Boolean: 1 for all OK, 0 for a problem.

References BFwrite(), and bytes.

Referenced by compute_code_lengths(), and write_golomb_code().

int BSclose ( BStream stream)

Closes a bit input / output stream buffer.

If this is an output buffer, it is flushed before closing.

Parameters
streamThe stream buffer to close.
Returns
Always returns true.

References _bstreambuf::base, BSflush(), and _bstreambuf::mode.

Referenced by cl_cpos2id(), cl_delete_stream(), and cl_id2cpos_oldstyle().

int BSflush ( BStream stream)

Flushes a bit input / output stream buffer.

In the case of an output stream, the stream is flushed, even an incomplete byte (so the next one begins at a new byte). In the case of an input stream, the stream skips to the next input byte.

Parameters
streamThe stream to flush.
Returns
Boolean: 1 for all OK, 0 for a problem.

References _bstreambuf::base, _bstreambuf::bits_in_buf, _bstreambuf::buf, _bstreambuf::mode, and _bstreambuf::position.

Referenced by BSclose().

int BSopen ( unsigned char *  base,
char *  type,
BStream bf 
)

Creates a stream buffer for bit input / output.

Sets up a bit input/output stream buffer (BS)

Parameters
basePointer to the stream
typeMode-string: "w" or "r" accepted
bfBuffer in which to set up the opened BS
Returns
boolean: 1 on success, 0 on failure (not like fopen/fclose)

References _bstreambuf::base, _bstreambuf::bits_in_buf, _bstreambuf::buf, _bstreambuf::mode, and _bstreambuf::position.

Referenced by cl_cpos2id(), cl_id2cpos_oldstyle(), and cl_new_stream().

int BSposition ( BStream stream)

Gets the stream position of a BStream.

References _bstreambuf::position.

int BSread ( unsigned char *  data,
int  nbits,
BStream stream 
)

Read bit data from a stream via a BStream buffer.

NOTE: be sure that you read the data into an unsigned char!

Parameters
dataPointer to the location for the read bit data.
nbitsNumber of bits to read.
streamThe BStream buffer to use.
Returns
Boolean: 1 for all OK, 0 for a problem.

References _bstreambuf::base, _bstreambuf::bits_in_buf, _bstreambuf::buf, and _bstreambuf::position.

Referenced by cl_cpos2id(), and read_golomb_code_bs().

int BSseek ( BStream stream,
off_t  offset 
)

Moves the position marker of a BStream (clearing the bit buffer in the process)

Parameters
streamThe stream whose position marker is changed.
offsetThe desired new offset.
Returns
Always true.

References _bstreambuf::bits_in_buf, _bstreambuf::buf, and _bstreambuf::position.

Referenced by cl_cpos2id(), cl_id2cpos_oldstyle(), and cl_new_stream().

int BSwrite ( unsigned char  data,
int  nbits,
BStream stream 
)

Writes bit data to a character stream via a BStream buffer.

Bits accumulate in the buffer till there are 8 of them. Then a byte is written to the stream (as an unsigned char).

Parameters
dataThe data to write.
nbitsThe number of bits to write from data.
streamThe buffer to write via.
Returns
Boolean: 1 for all OK, 0 for a problem.

References _bstreambuf::base, _bstreambuf::bits_in_buf, _bstreambuf::buf, and _bstreambuf::position.