Class ArithmeticDecoder
- java.lang.Object
-
- it.unimi.di.big.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 calldecode(InputBitStream)
for all symbols to be decoded, and finallyflush(InputBitStream)
. This last operation reads the bits flushed byArithmeticCoder.flush(OutputBitStream)
. Thereafter, exactlyBITS
excess bits will be present in the current window of the decoder. You can get them usinggetWindow()
.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
Fields Modifier and Type Field Description static int
BITS
Number of bits used by the decoder.
-
Constructor Summary
Constructors Constructor Description ArithmeticDecoder(int n)
Creates a new decoder.
-
Method Summary
Modifier and Type Method Description int
decode(InputBitStream ibs)
Decodes a symbol.void
flush(InputBitStream ibs)
Flushes (reads) the disambiguating bits.long
getWindow()
Returns the current bit stream window.
-
-
-
Field Detail
-
BITS
public static final int BITS
Number of bits used by the decoder.- See Also:
- Constant Field Values
-
-
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
- ifibs
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 usinggetWindow()
; usually you will then unget them to the bit stream.- Parameters:
ibs
- the input stream.- Throws:
IOException
- ifibs
does.
-
getWindow
public long getWindow()
Returns the current bit stream window.- Returns:
- the current bit stream window in the lower
BITS
bits.
-
-