cz.cuni.jagrlib.piece
Class HuffmanCodec

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

public class HuffmanCodec
extends Piece
implements EntropyCodec

Adaptive Huffman codec.

See Also:
HuffmanCodec.java

Nested Class Summary
protected static class HuffmanCodec.HuffNode
          Node of the Huffman tree.
protected static class HuffmanCodec.HuffTree
          Huffman tree (used as EntropyCodec-context).
 
Field Summary
protected static java.lang.String CATEGORY
          Object category.
protected  HuffmanCodec.HuffTree context
          Current context (accelerator).
protected  IntMap<HuffmanCodec.HuffTree> contexts
          Map of contexts.
protected  int currentContext
          Id of the current context.
protected  int maxSymbol
          Max-symbol used only for creating of new contexts!
protected  boolean output
          Opened for output (encoding)?
protected  long position
          Actual position in original (logical) stream.
static RegPiece reg
          Static registration instance for this class.
protected  BitStream stream
          Associated I/O stream.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
 
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
HuffmanCodec()
           
 
Method Summary
 boolean available()
          Are they any input symbols (bits) available?
protected  void clearContexts()
          Discards all contexts.
 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).
 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.
protected  void initContexts(int ctx)
          [Re-]initializes context set, creates the given solo context.
 void open(boolean output, int dCtx)
          Codec initialization.
 long position()
          Actual codec external position in symbols (total amount in all contexts).
 void put(int symbol)
          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).
 int setContext(int ctx)
          Sets the given context as current.
 void setMaxSymbol(int maxSym)
          Sets maximal symbol value for the actual context.
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, get, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, 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, get, set
 

Field Detail

stream

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


contexts

protected IntMap<HuffmanCodec.HuffTree> contexts
Map of contexts.


currentContext

protected int currentContext
Id of the current context.


context

protected HuffmanCodec.HuffTree context
Current context (accelerator).


maxSymbol

protected int maxSymbol
Max-symbol used only for creating of new contexts!


output

protected boolean output
Opened for output (encoding)?


position

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


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

HuffmanCodec

public HuffmanCodec()
Method Detail

clearContexts

protected void clearContexts()
Discards all contexts.


initContexts

protected void initContexts(int ctx)
[Re-]initializes context set, creates the given solo context.


available

public boolean available()
                  throws java.io.IOException
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:
position, compressed()

close

public void close()
           throws java.io.IOException
Codec close.

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

compressed

public long compressed()
                throws java.io.IOException
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:
position

flush

public void flush()
           throws java.io.IOException
Codec flush.

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

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. Uses the actual context!

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 dCtx)
          throws java.io.IOException
Codec initialization.

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

getMaxSymbol

public int getMaxSymbol()
Retrieves maximal symbol value for the actual context.

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

setMaxSymbol

public void setMaxSymbol(int maxSym)
Sets maximal symbol value for the actual context.

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

position

public long position()
              throws java.io.IOException
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:
compressed()

put

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

Specified by:
put in interface EntropyCodec
Parameters:
symbol - 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. Uses the actual context!

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)

setContext

public int setContext(int ctx)
               throws java.io.IOException
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

setTemplate

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