Arithmetic coding tutorial code
1
AC
|
#include <arith_code.hh>
Public Member Functions | |
Decoder (output_callback_t output_callback_=NULL, input_callback_t read_bit_call_=NULL, output_callback_t bit_callback_=NULL) | |
int | output_symbol (F_t const *cum_freq=NULL, I_t max_symb=-1) |
It returns a symbol (a number from MIN_SYMBOL up), or NO_SYMBOL if no symbol could be identified; or, if the decoder was deflushing, FLUSH_SYMBOL to signal that it deflushed succesfully. More... | |
void | input_bit (int bit) |
Add bit to internal state ; the Decoder will call the callback output_callback() if symbols are decoded. More... | |
void | run () |
Run the decoder. More... | |
void | prepare_for_deflush () |
this must be called when it is known that the encoder was flushed before the next symbol ; if the callback is used for the decoder output, the callback will receive FLUSH_SYMBOL when the deflushing is done; if instead the callback is not used, then the program must call output_symbol() repeatedly until it will receive FLUSH_SYMBOL . More... | |
int | is_deflushing () |
tells if the decoder is deflushing More... | |
![]() | |
unsigned int | number_input_bits () |
number of bits inserted in the state More... | |
unsigned int | number_input_symbols () |
number of symbols inserted in the state More... | |
unsigned int | number_output_bits () |
number of bits extracted from the state More... | |
unsigned int | number_output_symbols () |
number of symbols extracted from the state More... | |
void | print_state () |
print the internal state More... | |
interval_t | S_interval () |
return the S_interval More... | |
interval_t | B_interval () |
return the B_interval More... | |
int | output_bit () |
outputs one bit from the state, if available, else -1 More... | |
void | output_bits (output_callback_t out) |
outputs multiple bits, returns them using a callback (if not null; else they are lost) More... | |
void | frequencies2cumulative_frequencies () |
if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be used; "cumulative_frequencies" may be updated from "frequencies" using this call, that wraps freq2cum_freq() More... | |
Additional Inherited Members | |
![]() | |
const char * | prefix |
name of the class, for printing More... | |
FILE * | verbose_stream = stdout |
F_t * | cumulative_frequencies = NULL |
if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be updated after each symbol is decoded, with the correct frequencies for the next symbol More... | |
I_t | max_symbol = -1 |
if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be updated after each symbol is decoded, with the correct frequencies for the next symbol More... | |
F_t * | frequencies = NULL |
if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be used; these may be derived from a table of frequencies, that may be stored here More... | |
void * | callback_data = NULL |
![]() | |
void | doubleit () |
void | doublehi () |
void | doublelow () |
void | doublecen () |
I_t | separ_low_high (int symb, const F_t *cum_freq) |
divides Slow - Shigh in subintervals : returns the beginning of each interval; note that intervals are in reverse order wrt symbols, that is, symb=0 gives the rightmost subinterval, symb=max_symbols-1 is the leftmost More... | |
int | resize_pull_one_bit () |
returns 0 , 1 or -1 if no bit can be pulled at this moment ; resize S-interval and B-interval accordingly More... | |
I_t | interval_right (int symb, const F_t *cum_freq) |
right extreme of a S-sub-interval ; note that symbols start from 0 here More... | |
I_t | interval_left (int symb, const F_t *cum_freq) |
left extreme of a S-sub-interval More... | |
void | push_symbol (int symb, const F_t *cum_freq) |
put symbol in S-interval by splitting it and choosing a subinterval, proportional to the frequencies More... | |
void | push_bit (int bit) |
put bit in B-interval More... | |
Base () | |
![]() | |
unsigned int | bitsToFollow |
int | virtual_bit |
const I_t | One = 1 |
const I_t | Top = (One << AC_representation_bitsize) |
representation of 1 More... | |
const I_t | Qtr = (One << (AC_representation_bitsize-2)) |
representation of 1/4 More... | |
const I_t | QtrMinus = (One << (AC_representation_bitsize-2)) - One |
representation of point preceding 1/4 More... | |
const I_t | Half = (Qtr*2) |
Representation of 3/4. More... | |
const I_t | ThreeQtr = (Qtr*3) |
representation of 3/4 More... | |
F_t const | cum_freq_uniform8 [9] = { 8 , 7 , 6 , 5, 4 , 3 , 2 , 1 , 0 } |
cumulative tables of 8 equidistributed symbols More... | |
F_t const * | cum_freq_flush = cum_freq_uniform8 |
special cumulative table used for flushing More... | |
I_t | Slow |
S-interval left extreme. More... | |
I_t | Shigh |
S-interval right extreme (included in the interval) More... | |
long_I_t | Srange |
S-interval width. More... | |
I_t | Blow |
B-interval left extreme. More... | |
I_t | Bhigh |
B-interval right extreme. More... | |
unsigned int | significant_bits |
significant bits (used in the decoder) More... | |
unsigned int | n_in_bits |
number of bits inserted in the state More... | |
unsigned int | n_in_symbs |
number of symbols inserted in the state More... | |
unsigned int | n_zooms |
number of zooms More... | |
unsigned int | n_out_bits |
number of bits extracted from the state More... | |
unsigned int | n_out_symbs |
number of symbols extracted from the state More... | |
![]() | |
static const int | n_symbols_flush = 8 |
how many symbols in the special cumulative table used for flushing More... | |
AC::Decoder::Decoder | ( | output_callback_t | output_callback_ = NULL , |
input_callback_t | read_bit_call_ = NULL , |
||
output_callback_t | bit_callback_ = NULL |
||
) |
output_callback_ | callback that will receive the decoded symbols; if it is NULL, then the output_symbol() may be used to get symbols |
read_bit_call_ | call that the Decoder will call when it needs to read bits; if it is NULL, then input_bit() may be used to insert bits |
bit_callback_ | callback for testing the code (mostly unneeded) |
void AC::Decoder::input_bit | ( | int | bit | ) |
int AC::Decoder::is_deflushing | ( | ) |
tells if the decoder is deflushing
It returns a symbol (a number from MIN_SYMBOL up), or NO_SYMBOL if no symbol could be identified; or, if the decoder was deflushing, FLUSH_SYMBOL to signal that it deflushed succesfully.
If the input_callback was provided, it will call it to get the needed bits.
cum_freq | cumulative frequency table; if NULL, stored cumulative_frequencies will be used |
max_symb | number of symbols; if <0 , stored number will be used |
void AC::Decoder::prepare_for_deflush | ( | ) |
this must be called when it is known that the encoder was flushed before the next symbol ; if the callback is used for the decoder output, the callback will receive FLUSH_SYMBOL when the deflushing is done; if instead the callback is not used, then the program must call output_symbol() repeatedly until it will receive FLUSH_SYMBOL .
Calling this twice before FLUSH_SYMBOL is received raises an error.
void AC::Decoder::run | ( | ) |
Run the decoder.
Can only be used when both input and output callbacks are defined. ! Will run until the the input callback returns -1 . ! The output callback must take care of cumulative_frequencies, max_symbol ; ! moreover the callback should call prepare_for_deflush() to deflush (if/when encoder flushed).