cz.cuni.jagrlib.piece
Class LZWCodec

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

public class LZWCodec
extends Piece
implements EntropyCodec

LZW codec.

Since:
0.24
See Also:
LZWCodec.java

Nested Class Summary
protected static class LZWCodec.InsertResult
           
protected  class LZWCodec.LZWTrie
          Dictionary implemented by trie-like structure (represented by binary tree - first son is son, second one is brother) each entry holds only one character.
 
Field Summary
protected  int actualCtx
          Id of the actual context.
protected static java.lang.String CATEGORY
          Object category.
protected  LZWCodec.LZWTrie ctx
          Working context (= dictionary).
protected  int defaultMaxSymbol
          Default alphabet size (for new context creation).
static java.lang.String MAX_CODE_SIZE
           
protected  int maxCodeSize
          Maximal codeword size in bits.
protected  boolean output
          Opened for output (encoding)?
protected  long position
          Actual position in original (logical) stream.
protected  long rawBits
          Actual position in compressed (binary) 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.
static java.lang.String VARIABLE_CODE
           
protected  boolean variableCode
          Use variable-code implementation?
 
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
LZWCodec()
           
 
Method Summary
 boolean available()
          Are they any input symbols (bits) available?
 void close()
          Close stream, clean statistics, write out the EOD code..
 long compressed()
          Actual codec compressed position in bits (total amount in all contexts).
 void flush()
          Codec flush.
 int get()
          Get the next character from compressed stream.
 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 dCtx)
          Codec initialization.
 long position()
          Actual codec external position in symbols (total amount in all contexts).
 void put(int symbol)
          Puts the given symbol into the stream.
 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 ctxId)
          Sets the given context as current.
 void setMaxSymbol(int maxSymbol)
          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, 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

stream

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


output

protected boolean output
Opened for output (encoding)?


actualCtx

protected int actualCtx
Id of the actual context.


ctx

protected LZWCodec.LZWTrie ctx
Working context (= dictionary).


variableCode

protected boolean variableCode
Use variable-code implementation?


maxCodeSize

protected int maxCodeSize
Maximal codeword size in bits.


position

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


rawBits

protected long rawBits
Actual position in compressed (binary) stream.


defaultMaxSymbol

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


VARIABLE_CODE

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

MAX_CODE_SIZE

public static final java.lang.String MAX_CODE_SIZE
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

LZWCodec

public LZWCodec()
Method Detail

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()

close

public void close()
           throws java.io.IOException
Close stream, clean statistics, write out the EOD code..

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

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()

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()

get

public int get()
        throws java.io.IOException
Get the next character from compressed stream.

Specified by:
get in interface EntropyCodec
Returns:
Read symbol (-1 if no symbol is available).
Throws:
java.io.IOException
See Also:
EntropyCodec.getBits(int), EntropyCodec.put(int), EntropyCodec.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
Description copied from interface: EntropyCodec
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:
EntropyCodec.get(), EntropyCodec.putBits(long, int), EntropyCodec.available()

open

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

Specified by:
open in interface EntropyCodec
Parameters:
output - Open for output?
dCtx - Initial context.
Throws:
java.io.IOException
See Also:
BitStream, EntropyCodec.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 maxSymbol)
Sets maximal symbol value for the actual context.

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()

put

public void put(int symbol)
         throws java.io.IOException
Puts the given symbol into the stream.

Specified by:
put in interface EntropyCodec
Parameters:
symbol - Symbol to encode.
Throws:
java.io.IOException
See Also:
EntropyCodec.putBits(long, int), EntropyCodec.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
Description copied from interface: EntropyCodec
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:
EntropyCodec.put(int), EntropyCodec.getBits(int)

setContext

public int setContext(int ctxId)
Description copied from interface: EntropyCodec
Sets the given context as current.

Specified by:
setContext in interface EntropyCodec
Parameters:
ctxId - Id of the new context.
Returns:
The old context's id.

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.