Arithmetic coding tutorial code  1
AC
Public Member Functions | Data Fields
AC::Encoder Class Reference

#include <arith_code.hh>

Inheritance diagram for AC::Encoder:
Inheritance graph
[legend]
Collaboration diagram for AC::Encoder:
Collaboration graph
[legend]

Public Member Functions

 Encoder (output_callback_t output_callback_=NULL)
 initialize, with a callback function that will output bits ; if output_callback_ is NULL then the code should 'poll' the encoder by calling output_bit() More...
 
void input_symbol (int symb, const F_t *cum_freq=NULL)
 insert a symbol; if output_callback() was provided, send it all available bits More...
 
void flush ()
 
- Public Member Functions inherited from AC::Base
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...
 

Data Fields

output_callback_t output_callback
 callback when the encoder encodes a symbo More...
 
- Data Fields inherited from AC::Base
const char * prefix
 name of the class, for printing More...
 
FILE * verbose_stream = stdout
 
F_tcumulative_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_tfrequencies = 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
 

Additional Inherited Members

- Protected Member Functions inherited from AC::Base
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 ()
 
- Protected Attributes inherited from AC::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 Protected Attributes inherited from AC::Base
static const int n_symbols_flush = 8
 how many symbols in the special cumulative table used for flushing More...
 

Constructor & Destructor Documentation

◆ Encoder()

AC::Encoder::Encoder ( output_callback_t  output_callback_ = NULL)

initialize, with a callback function that will output bits ; if output_callback_ is NULL then the code should 'poll' the encoder by calling output_bit()

Parameters
output_callback_callback that will receive the encoded bits

Member Function Documentation

◆ flush()

void AC::Encoder::flush ( )

flush the encoder (if you are not using callbacks, be sure to pull all bits out of the encoder before and after flushing, or underflow may occour). The method for flushing is described in doc/on_deflushing.pdf

◆ input_symbol()

void AC::Encoder::input_symbol ( int  symb,
const F_t cum_freq = NULL 
)

insert a symbol; if output_callback() was provided, send it all available bits

Parameters
symbsymbol to add to the state!
cum_freqcumulative frequencies (if not provided, use the internally stored ones

Field Documentation

◆ output_callback

output_callback_t AC::Encoder::output_callback

callback when the encoder encodes a symbo


The documentation for this class was generated from the following files: