bitio.c File Reference

#include <sys/types.h>
#include "globals.h"
#include "endian.h"
#include "bitio.h"

Functions


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:
stream The file buffer to close.
Returns:
Always returns true.

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:
stream The 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:
filename Name of file to open
type File-open mode string: "w" or "r" accepted
bf Buffer 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:
data Pointer to the location for the read bit data.
nbits Number of bits to read.
stream The 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:
data Pointer to the location for the read bit data.
nbits Number of bits to read.
stream The 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:
data The data to write.
nbits The number of bits to write from data.
stream The 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:
data The data to write.
nbits Number of bits to write.
stream The 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:
stream The stream buffer to close.
Returns:
Always returns true.

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

Referenced by ClosePositionStream(), get_id_at_position(), and get_positions().

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:
stream The 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:
base Pointer to the stream
type Mode-string: "w" or "r" accepted
bf Buffer 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 get_id_at_position(), get_positions(), and OpenPositionStream().

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:
data Pointer to the location for the read bit data.
nbits Number of bits to read.
stream The 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 get_id_at_position(), 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:
stream The stream whose position marker is changed.
offset The desired new offset.
Returns:
Always true.

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

Referenced by get_id_at_position(), get_positions(), and OpenPositionStream().

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:
data The data to write.
nbits The number of bits to write from data.
stream The 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.


Generated on Sun Feb 28 18:08:03 2010 for CWB by  doxygen 1.6.1