Table of Contents
QccENTGolombEncode, QccENTGolombDecode - Golomb encoding and decoding
for binary sequence
#include "libQccPack.h"
int QccENTGolombEncode(QccBitBuffer
*output_buffer, const int *symbols, int num_symbols, const float *p, const
int *m);
int QccENTGolombDecode(QccBitBuffer *input_buffer, int *symbols,
int num_symbols);
QccENTGolombEncode() performs Golomb coding
of the symbol stream in symbols, outputting the binary codewords to output_buffer.
num_symbols indicates how many symbols are in the symbol stream (which
can be as short as one symbol). Since Golomb coding is a binary entropy
coder, the symbol stream, symbols, can consist of only zeros and ones.
p specifies the probability of the favorable event. m is the integer that
satisfies p^m = 1/2. output_buffer must be a QccBitBuffer that has been
opened for writing prior to calling QccENTGolombEncode(). After calling
QccENTGolombEncode(), QccBitBufferFlush(3)
must be called to ensure that
the last few bits of the bitstream are actually written to the output
file.
QccENTGolombDecode() performs Golomb decoding of the bits in the
bitstream input_buffer, producing an output stream of symbols that are
stored in symbols. The symbols array must be allocated with space sufficient
for holding num_symbols integers; this allocation must be done prior
to calling QccENTGolombDecode(). Additionally, input_buffer must be opened
for reading prior to calling QccENTGolombDecode().
QccBitBufferFlush(3)
must be called after the call to QccENTGolombEncode() to ensure that the
last few bits of the concatenated bitstream are actually written to the
output file.
QccENTGolombEncode() will fail if it encounters an invalid
symbol (i.e., a symbol that is neither 0 or 1).
Obviously, p and m cannot
be specified independently since p^m = 1/2. Both can be NULL, in which
case the probability will be estimated by QccENTGolombEncode() itself.
Both routines return 0 on success, and 1 on failure.
QccENTGolombEncodeChannel(3)
, QccENTGolombDecodeChannel(3)
, QccPackENT(3)
,
QccPack(3)
S. W. Golomb, "Run-Length Encodings," IEEE Transactions on Information
Theory, vol. 12, pp. 399-401, July 1966.
Written by Yufei Yuan <yuanyufei@hotmail.com>
Copyright (C) 1997-2021 James E. Fowler
Table of Contents