Class 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 Detail

    • 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.