public final class ArithmeticCoder extends Object
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 call encode(int, OutputBitStream) for
all symbols to be coded, and finally flush(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).
ArithmeticDecoder| Modifier and Type | Field and Description |
|---|---|
static int |
BITS
Number of bits used by the coder.
|
| Constructor and Description |
|---|
ArithmeticCoder(int n)
Creates a new coder.
|
| Modifier and Type | Method and Description |
|---|---|
int |
encode(int x,
OutputBitStream obs)
Encodes a symbol.
|
int |
flush(OutputBitStream obs)
Flushes the last bits.
|
public static final int BITS
public ArithmeticCoder(int n)
n - number of symbols used by the coder.public int encode(int x,
OutputBitStream obs)
throws IOException
x - a bit.obs - the output stream.IOException - if obs does.public int flush(OutputBitStream obs) throws IOException
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.
obs - the output stream.IOException - if obs does.