cz.cuni.jagrlib.piece
Class ArithmeticCodec

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.ArithmeticCodec
All Implemented Interfaces:
Breakable, EntropyCodec, Property, Template

public class ArithmeticCodec
extends Piece
implements EntropyCodec

Arithmetic codec.

Since:
0.24
See Also:
ArithmeticCodec.java

Nested Class Summary
protected static class ArithmeticCodec.OpenState
          Codec state: closed/input/output.
 
Field Summary
protected static java.lang.String CATEGORY
          Object category.
static java.lang.String DECIMATION_LIMIT
           
protected  int decimationLimit
          Actual decimation limit.
protected  int defaultCtx
          Default context Id.
protected  int defaultMaxSymbol
          Default alphabet size (for new context creation).
protected  long follow
          Number of center-doublings (unknown bits to write later).
protected  long h
          Arithmetic encoder/decoder range and value.
protected  EntropyHistogram hist
          EntropyHistogram to manage contexts.
protected  int increment
          Increment of frequency for every encoded symbol.
static java.lang.String INCREMENT
           
protected  long l
          Arithmetic encoder/decoder range and value.
protected static int MAX_DECIMATION_LIMIT
          Maximal decimation limit for entropy histograms.
protected  long position
          Actual position in the original (logical) stream in symbols.
protected  long rawBits
          Actual position in the coded stream in bits.
static RegPiece reg
          Static registration instance for this class.
protected  ArithmeticCodec.OpenState state
          Actual codec state.
protected  boolean statistics
          Print summary statistics at the end of encoding?
protected  BitStream stream
          Associated I/O stream.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
protected  long v
          Arithmetic encoder/decoder range and value.
protected static long VAL_1_2
          One half of the maximal interval.
protected static long VAL_1_4
          One quarter of the maximal interval.
protected static long VAL_3_4
          Three quarters of the maximal interval.
protected static int VAL_BITS
          Number of bits for maximum value in interval arithmetic.
protected static long VAL_MAX
          Maximum working arithmetic value.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
ArithmeticCodec()
           
 
Method Summary
 boolean available()
          Are they any input symbols (bits) available?
 void close()
          Codec close.
 long compressed()
          Actual codec compressed position in bits (total amount in all contexts).
 void flush()
          Codec flush.
 int get()
          Decodes one symbol (using the current context).
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 int get(WheelOfFortune wheel)
          Decodes one subinterval from the given WheelOfFortune.
 long getBits(int length)
          Reads the given amount of "raw" bits (by-passes the entropy decoder).
 int getMaxSymbol()
          Retrieves maximal symbol value for the actual context.
 void open(boolean output, int ctx)
          Codec initialization.
 long position()
          Actual codec external position in symbols (total amount in all contexts).
 void put(int s)
          Encodes the given symbol (in the current context).
 void put(WheelOfFortune wheel, int s)
          Encodes one subinterval from the given WheelOfFortune.
 void putBits(long bits, int length)
          Writes the given "raw" bits (by-passes the entropy encoder).
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
 int setContext(int ctx)
          Sets the given context as current.
 void setMaxSymbol(int maxSymbol)
          Sets maximal symbol value for the actual context and all subsequently created ones.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 

Field Detail

state

protected ArithmeticCodec.OpenState state
Actual codec state.


stream

protected BitStream stream
Associated I/O stream. null if the codec is not opened.


hist

protected EntropyHistogram hist
EntropyHistogram to manage contexts.


position

protected long position
Actual position in the original (logical) stream in symbols.


rawBits

protected long rawBits
Actual position in the coded stream in bits.


defaultMaxSymbol

protected int defaultMaxSymbol
Default alphabet size (for new context creation).


defaultCtx

protected int defaultCtx
Default context Id.


increment

protected int increment
Increment of frequency for every encoded symbol.


decimationLimit

protected int decimationLimit
Actual decimation limit.


MAX_DECIMATION_LIMIT

protected static final int MAX_DECIMATION_LIMIT
Maximal decimation limit for entropy histograms.

See Also:
Constant Field Values

VAL_BITS

protected static final int VAL_BITS
Number of bits for maximum value in interval arithmetic. VAL_MAX * decimationLimit must not overflow!

See Also:
Constant Field Values

VAL_1_4

protected static final long VAL_1_4
One quarter of the maximal interval.

See Also:
Constant Field Values

VAL_1_2

protected static final long VAL_1_2
One half of the maximal interval.

See Also:
Constant Field Values

VAL_3_4

protected static final long VAL_3_4
Three quarters of the maximal interval.

See Also:
Constant Field Values

VAL_MAX

protected static final long VAL_MAX
Maximum working arithmetic value.

See Also:
Constant Field Values

follow

protected long follow
Number of center-doublings (unknown bits to write later).


l

protected long l
Arithmetic encoder/decoder range and value.


h

protected long h
Arithmetic encoder/decoder range and value.


v

protected long v
Arithmetic encoder/decoder range and value.


statistics

protected boolean statistics
Print summary statistics at the end of encoding?


INCREMENT

public static final java.lang.String INCREMENT
See Also:
Constant Field Values

DECIMATION_LIMIT

public static final java.lang.String DECIMATION_LIMIT
See Also:
Constant Field Values

TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

ArithmeticCodec

public ArithmeticCodec()
Method Detail

flush

public void flush()
           throws java.io.IOException
Description copied from interface: EntropyCodec
Codec flush.

Specified by:
flush in interface EntropyCodec
Throws:
java.io.IOException
See Also:
EntropyCodec.open(boolean, int), EntropyCodec.close()

put

public void put(int s)
         throws java.io.IOException
Encodes the given symbol (in the current context).

Specified by:
put in interface EntropyCodec
Parameters:
s - Symbol to encode.
Throws:
java.io.IOException
See Also:
putBits(long, int), get()

put

public void put(WheelOfFortune wheel,
                int s)
         throws java.io.IOException
Encodes one subinterval from the given WheelOfFortune. Doesn't use contexts and assigned histograms..

Specified by:
put in interface EntropyCodec
Parameters:
wheel - Set of intervals (wheel of fortune).
s - Index of an interval to encode.
Throws:
java.io.IOException

putBits

public void putBits(long bits,
                    int length)
             throws java.io.IOException
Writes the given "raw" bits (by-passes the entropy encoder).

Specified by:
putBits in interface EntropyCodec
Parameters:
bits - Bits to be written ("MSB first" order).
length - Number of bits to write.
Throws:
java.io.IOException
See Also:
put(int), getBits(int)

get

public int get()
        throws java.io.IOException
Decodes one symbol (using the current context).

Specified by:
get in interface EntropyCodec
Returns:
Read symbol (-1 if no symbol is available).
Throws:
java.io.IOException
See Also:
getBits(int), put(int), available()

get

public int get(WheelOfFortune wheel)
        throws java.io.IOException
Decodes one subinterval from the given WheelOfFortune. Doesn't use contexts and assigned histograms..

Specified by:
get in interface EntropyCodec
Parameters:
wheel - Set of intervals (wheel of fortune).
Returns:
Index of the relevant interval.
Throws:
java.io.IOException

getBits

public long getBits(int length)
             throws java.io.IOException
Reads the given amount of "raw" bits (by-passes the entropy decoder).

Specified by:
getBits in interface EntropyCodec
Parameters:
length - Number of bits to read.
Returns:
Read bits (or -1 if no bits are available).
Throws:
java.io.IOException
See Also:
get(), putBits(long, int), available()

open

public void open(boolean output,
                 int ctx)
          throws java.io.IOException
Description copied from interface: EntropyCodec
Codec initialization.

Specified by:
open in interface EntropyCodec
Parameters:
output - Open for output?
ctx - Initial context.
Throws:
java.io.IOException
See Also:
BitStream, EntropyCodec.setContext(int)

close

public void close()
           throws java.io.IOException
Description copied from interface: EntropyCodec
Codec close.

Specified by:
close in interface EntropyCodec
Throws:
java.io.IOException
See Also:
EntropyCodec.open(boolean, int), EntropyCodec.flush()

setContext

public int setContext(int ctx)
               throws java.io.IOException
Description copied from interface: EntropyCodec
Sets the given context as current.

Specified by:
setContext in interface EntropyCodec
Parameters:
ctx - Id of the new context.
Returns:
The old context's id.
Throws:
java.io.IOException

getMaxSymbol

public int getMaxSymbol()
Description copied from interface: EntropyCodec
Retrieves maximal symbol value for the actual context.

Specified by:
getMaxSymbol in interface EntropyCodec
Returns:
Maximal symbol value.

setMaxSymbol

public void setMaxSymbol(int maxSymbol)
Description copied from interface: EntropyCodec
Sets maximal symbol value for the actual context and all subsequently created ones. Could be called before EntropyCodec.open(boolean, int)!

Specified by:
setMaxSymbol in interface EntropyCodec
Parameters:
maxSymbol - New maximal symbol value.

position

public long position()
              throws java.io.IOException
Description copied from interface: EntropyCodec
Actual codec external position in symbols (total amount in all contexts).

Specified by:
position in interface EntropyCodec
Returns:
Actual codec external position in symbols.
Throws:
java.io.IOException
See Also:
EntropyCodec.compressed()

compressed

public long compressed()
                throws java.io.IOException
Description copied from interface: EntropyCodec
Actual codec compressed position in bits (total amount in all contexts).

Specified by:
compressed in interface EntropyCodec
Returns:
Actual codec compressed position in bits.
Throws:
java.io.IOException
See Also:
EntropyCodec.position()

available

public boolean available()
                  throws java.io.IOException
Description copied from interface: EntropyCodec
Are they any input symbols (bits) available?

Specified by:
available in interface EntropyCodec
Returns:
Any symbols (bits) are ready to read.
Throws:
java.io.IOException
See Also:
EntropyCodec.position(), EntropyCodec.compressed()

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.