it.unimi.di.mg4j.io
Class ArithmeticDecoder

java.lang.Object
  extended by it.unimi.di.mg4j.io.ArithmeticDecoder

public final class ArithmeticDecoder
extends Object

An arithmetic decoder.

This class provides an arithmetic decoder. The input of the coder is an InputBitStream. You must first create a decoder specifying the number of input symbols, then call decode(InputBitStream) for all symbols to be decoded, and finally flush(InputBitStream). This last operation reads the bits flushed by ArithmeticCoder.flush(OutputBitStream). Thereafter, exactly BITS excess bits will be present in the current window of the decoder. You can get them using getWindow().

The code is inspired by the arithmetic decoder by John Carpinelli, Radford M. Neal, Wayne Salamonsen and Lang Stuiver, which is in turn based on Arithmetic Coding Revisited, by Alistair Moffat, Radford M. Neal and Ian H. Witten (Proc. IEEE Data Compression Conference, Snowbird, Utah, March 1995).

Since:
0.1
Author:
Sebastiano Vigna
See Also:
ArithmeticCoder

Field Summary
static int BITS
          Number of bits used by the decoder.
 
Constructor Summary
ArithmeticDecoder(int n)
          Creates a new decoder.
 
Method Summary
 int decode(InputBitStream ibs)
          Decodes a symbol.
 void flush(InputBitStream ibs)
          Flushes (reads) the disambiguating bits.
 long getWindow()
          Returns the current bit stream window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BITS

public static final int BITS
Number of bits used by the decoder.

See Also:
Constant Field Values
Constructor Detail

ArithmeticDecoder

public ArithmeticDecoder(int n)
Creates a new decoder.

Parameters:
n - number of symbols used by the decoder.
Method Detail

decode

public int decode(InputBitStream ibs)
           throws IOException
Decodes a symbol.

Parameters:
ibs - the input stream.
Returns:
the next symbol encoded.
Throws:
IOException - if ibs does.

flush

public void flush(InputBitStream ibs)
           throws IOException
Flushes (reads) the disambiguating bits.

This method must be called when all symbols have been decoded. After the call, exactly BITS excess bits will be present in the current window of the decoder. You can get them using getWindow(); usually you will then unget them to the bit stream.

Parameters:
ibs - the input stream.
Throws:
IOException - if ibs does.

getWindow

public long getWindow()
Returns the current bit stream window.

Returns:
the current bit stream window in the lower BITS bits.