My implementation for Arithmetic Coding algorithm.
You can view testSample.py code to get an idea about how to use the ArithmaticCoding class.
I have implemented the algorithm from Fundamentals of Multimedia book, the algorithms are Algorithm 7.5, Procedure 7.2, Algorithm 7.6.
BEGIN
low = 0.0; high = 1.0; range = 1.0;
initialize symbol; // so symbol != terminator
while (symbol != terminator)
{
get (symbol);
low = low + range * Range_low(symbol);
high = low + range * Range_high(symbol);
range = high - low;
}
output a code so that low <= code < high;
END
BEGIN
code = 0;
k = 1;
while (value(code) < low)
{
assign 1 to the kth binary fraction bit;
if (value(code) > high)
replace the kth bit by 0;
k = k + 1;
}
END
BEGIN
get binary code and convert to decimal value = value(code);
Do
{
find a symbol s so that
Range_low(s) <= value < Range_high(s);
output s;
low = Rang_low(s);
high = Range_high(s);
range = high - low;
value = [value - low] / range;
}
Until symbol s is a terminator
END
I have not handled any exceptions, just the basic algorithm.
This project is licensed under the MIT License - see the LICENSE.md file for details