Class ArithmeticCoder
- java.lang.Object
-
- it.unimi.di.big.mg4j.io.ArithmeticCoder
-
public final class ArithmeticCoder extends Object
An arithmetic coder.This class provides an arithmetic coder. The output of the coder goes to an
OutputBitStream
. You must first create a coder specifying the number of input symbols, then callencode(int, OutputBitStream)
for all symbols to be coded, and finallyflush(OutputBitStream)
. This last operation will output some bits so that the last symbol is encoded nonambiguously.The code is inspired by the arithmetic coder 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:
ArithmeticDecoder
-
-
Field Summary
Fields Modifier and Type Field Description static int
BITS
Number of bits used by the coder.
-
Constructor Summary
Constructors Constructor Description ArithmeticCoder(int n)
Creates a new coder.
-
Method Summary
Modifier and Type Method Description int
encode(int x, OutputBitStream obs)
Encodes a symbol.int
flush(OutputBitStream obs)
Flushes the last bits.
-
-
-
Field Detail
-
BITS
public static final int BITS
Number of bits used by the coder.- See Also:
- Constant Field Values
-
-
Method Detail
-
encode
public int encode(int x, OutputBitStream obs) throws IOException
Encodes a symbol.- Parameters:
x
- a bit.obs
- the output stream.- Returns:
- the number of bits written (note that it can be 0, as arithmetic compression can encode a symbol in a fraction of a bit).
- Throws:
IOException
- ifobs
does.
-
flush
public int flush(OutputBitStream obs) throws IOException
Flushes the last bits.This method must be called when coding is over. It guarantees that enough bits are output to make the decoding of the last symbol nonambiguous, whichever bits follow in the stream.
- Parameters:
obs
- the output stream.- Returns:
- the number of bits written.
- Throws:
IOException
- ifobs
does.
-
-