cz.cuni.jagrlib.piece
Class FractalCompressionQtree

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.DefaultFileFormat
              extended by cz.cuni.jagrlib.DefaultRasterFileFormat
                  extended by cz.cuni.jagrlib.piece.FractalCompressionQtree
All Implemented Interfaces:
Breakable, DataFileFormat, Property, Template

public class FractalCompressionQtree
extends DefaultRasterFileFormat

Fractal image compression module. Uses adaptive Quad-tree partitioning.

See Also:
FractalCompressionQtree.java

Nested Class Summary
protected  class FractalCompressionQtree.ImageBlock
          Decoded image block, acts as Q-tree node as well.
 
Field Summary
protected  HDRImage actIm
          Target image for fractal transform (PIFS).
protected  int bands
          Number of image bands (1 for RasterGraphics.MODE_GRAY).
protected  boolean bestCodeOnly
          Encode the best blocks only (non-redundant code)?
protected  double[] bingo
          Global array for block-search results.
protected  int blockOrderBits
          Number of bits to encode block order# (for progressive [= redundant] mode only).
protected  EntropyCodec codec
          Accelerator: entropy codec.
protected static int CTRL_FAIL
          Control alphabet: failed leaf node.
protected static int CTRL_NODE
          Control alphabet: inner node (with block data).
protected static int CTRL_ORI0
          Control alphabet: 1st code assigned for orientation (marking the leaf node).
protected static int CTRL_REC
          Control alphabet: recursion (inner node w/o block data).
protected static int CTX_COORD
          Entropy-codec context: coordinates.
protected static int CTX_CTRL
          Entropy-codec context: control, orientation.
protected static int CTX_O
          Entropy-codec context: o-coefficient.
protected static int CTX_S
          Entropy-codec context: s-coefficient.
static java.lang.String ERROR_LIMIT
           
protected  double errorLimit
          RMSE error limit for Q-tree adaptive subdivision.
protected  java.util.TreeSet<FractalCompressionQtree.ImageBlock> heap
          Heap of unfinished Q-tree nodes (encoder only).
protected  int height
          Image height in pixels.
protected  RasterGraphics log
          Log-image.
protected static double[][] LOG_COLOR
          Log-image frame colors.
protected  boolean logging
          Log intermediate results?
static java.lang.String LOGGING
           
static int MAGIC
          16-bit magic number (used at the file beginning).
static java.lang.String MAX_BLOCK_SIZE
           
protected static int MAX_ITERATIONS
          Maximal number of transforms steps in image reconstruction.
protected  int maxBlockSize
          Maximal block size in pixels.
static java.lang.String MIN_BLOCK_SIZE
           
protected  int minBlockSize
          Minimal block size in pixels.
protected  int minNodeOrder
          Reconstruction: only nodes with order == 0 or order >= minNodeOrder.
static java.lang.String O_VALUES
           
static java.lang.String ONLY_BEST
           
protected  int oValues
          Number of quantized values of o.
protected  HDRImage prevIm
          Source image for fractal transform (PIFS).
protected  ScalarQuantizer qO
          Accelerator: [linear] quantizer for 'o'.
protected  ScalarQuantizer qS
          Accelerator: [dead-zone] quantizer for 's'.
static RegPiece reg
          Static registration instance for this class.
static java.lang.String S_MAX
           
static java.lang.String S_VALUES
           
protected  RasterSearch search
          Accelerator: searchable object.
protected  double sMax
          Maximal amplitude of s.
protected  int sValues
          Number of quantized values of s.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
protected  int totalSize
          Size of the smallest rectangle containing the whole image.
protected  int width
          Image width in pixels.
 
Fields inherited from class cz.cuni.jagrlib.DefaultRasterFileFormat
CATEGORY
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.DataFileFormat
DOUBLE_STREAM
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
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
FractalCompressionQtree()
           
 
Method Summary
protected  FractalCompressionQtree.ImageBlock buildInitialTree(RasterGraphics g, int x0, int y0, int size)
          Builds one branch of a Q-tree, returns its root.
protected  void commonLoad(BitStream stream, RasterGraphics g)
          Common load code.
protected  void commonSave(BitStream stream, RasterGraphics g)
          Common save code.
 java.lang.String[] fileNameMasks()
          Returns file-name masks associated with the file-format type.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 int headerLength()
          Length of file-format header (number of bytes which is necessary for file-format matching).
protected  FractalCompressionQtree.ImageBlock loadTree(int x0, int y0, int size)
          Loads Q-tree from attached EntropyCodec, returns its root.
 double match(byte[] header, java.lang.String fileName)
          File-format match test.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 
Methods inherited from class cz.cuni.jagrlib.DefaultRasterFileFormat
loadFile, loadFile, saveFile, saveFile
 
Methods inherited from class cz.cuni.jagrlib.DefaultFileFormat
closeFile, init, readFloat, readLine, readParameters, readToken, readUnsigned16, readUnsigned16, readUnsigned32, writeFloat, writeLine, writeParameters, writeUnsigned16, writeUnsigned16, writeUnsigned32
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, 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
 
Methods inherited from interface cz.cuni.jagrlib.Breakable
setProgressListener, stop
 

Field Detail

heap

protected java.util.TreeSet<FractalCompressionQtree.ImageBlock> heap
Heap of unfinished Q-tree nodes (encoder only).


maxBlockSize

protected int maxBlockSize
Maximal block size in pixels.


minBlockSize

protected int minBlockSize
Minimal block size in pixels.


errorLimit

protected double errorLimit
RMSE error limit for Q-tree adaptive subdivision.


bestCodeOnly

protected boolean bestCodeOnly
Encode the best blocks only (non-redundant code)?


logging

protected boolean logging
Log intermediate results?


sValues

protected int sValues
Number of quantized values of s.


oValues

protected int oValues
Number of quantized values of o.


sMax

protected double sMax
Maximal amplitude of s.


blockOrderBits

protected int blockOrderBits
Number of bits to encode block order# (for progressive [= redundant] mode only).


CTX_CTRL

protected static final int CTX_CTRL
Entropy-codec context: control, orientation.

See Also:
Constant Field Values

CTX_COORD

protected static final int CTX_COORD
Entropy-codec context: coordinates.

See Also:
Constant Field Values

CTX_S

protected static final int CTX_S
Entropy-codec context: s-coefficient.

See Also:
Constant Field Values

CTX_O

protected static final int CTX_O
Entropy-codec context: o-coefficient.

See Also:
Constant Field Values

CTRL_REC

protected static final int CTRL_REC
Control alphabet: recursion (inner node w/o block data).

See Also:
Constant Field Values

CTRL_NODE

protected static final int CTRL_NODE
Control alphabet: inner node (with block data).

See Also:
Constant Field Values

CTRL_FAIL

protected static final int CTRL_FAIL
Control alphabet: failed leaf node.

See Also:
Constant Field Values

CTRL_ORI0

protected static final int CTRL_ORI0
Control alphabet: 1st code assigned for orientation (marking the leaf node).

See Also:
Constant Field Values

MAX_ITERATIONS

protected static final int MAX_ITERATIONS
Maximal number of transforms steps in image reconstruction.

See Also:
Constant Field Values

search

protected RasterSearch search
Accelerator: searchable object.


codec

protected EntropyCodec codec
Accelerator: entropy codec.


qS

protected ScalarQuantizer qS
Accelerator: [dead-zone] quantizer for 's'.


qO

protected ScalarQuantizer qO
Accelerator: [linear] quantizer for 'o'.


width

protected int width
Image width in pixels.


height

protected int height
Image height in pixels.


totalSize

protected int totalSize
Size of the smallest rectangle containing the whole image.


bands

protected int bands
Number of image bands (1 for RasterGraphics.MODE_GRAY).


minNodeOrder

protected int minNodeOrder
Reconstruction: only nodes with order == 0 or order >= minNodeOrder.


actIm

protected HDRImage actIm
Target image for fractal transform (PIFS).


prevIm

protected HDRImage prevIm
Source image for fractal transform (PIFS).


bingo

protected double[] bingo
Global array for block-search results.


LOG_COLOR

protected static final double[][] LOG_COLOR
Log-image frame colors.


log

protected RasterGraphics log
Log-image.


MAGIC

public static final int MAGIC
16-bit magic number (used at the file beginning).

See Also:
Constant Field Values

MAX_BLOCK_SIZE

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

MIN_BLOCK_SIZE

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

ERROR_LIMIT

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

S_VALUES

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

S_MAX

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

O_VALUES

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

ONLY_BEST

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

LOGGING

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

TEMPLATE_NAME

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

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

FractalCompressionQtree

public FractalCompressionQtree()
Method Detail

buildInitialTree

protected FractalCompressionQtree.ImageBlock buildInitialTree(RasterGraphics g,
                                                              int x0,
                                                              int y0,
                                                              int size)
Builds one branch of a Q-tree, returns its root. Blocks with size at most maxBlockSize will go to the heap.


loadTree

protected FractalCompressionQtree.ImageBlock loadTree(int x0,
                                                      int y0,
                                                      int size)
                                               throws java.io.IOException
Loads Q-tree from attached EntropyCodec, returns its root.

Throws:
java.io.IOException

commonLoad

protected void commonLoad(BitStream stream,
                          RasterGraphics g)
                   throws java.io.IOException
Common load code.

Overrides:
commonLoad in class DefaultRasterFileFormat
Parameters:
stream - Opened input bit-stream.
g - Checked raster-graphics object.
Throws:
java.io.IOException

commonSave

protected void commonSave(BitStream stream,
                          RasterGraphics g)
                   throws java.io.IOException
Common save code.

Overrides:
commonSave in class DefaultRasterFileFormat
Parameters:
stream - Opened output bit-stream.
g - Checked raster-graphics object.
Throws:
java.io.IOException

headerLength

public int headerLength()
Length of file-format header (number of bytes which is necessary for file-format matching).

Specified by:
headerLength in interface DataFileFormat
Specified by:
headerLength in class DefaultFileFormat
Returns:
Number of bytes from beginning of a file which are enough for file-format match test.
See Also:
match(byte[], java.lang.String)

match

public double match(byte[] header,
                    java.lang.String fileName)
File-format match test. Guesses whether the binary file-header (and file-name) can belong to this file-format type.

Specified by:
match in interface DataFileFormat
Specified by:
match in class DefaultFileFormat
Parameters:
header - Bytes from beginning of the file.
fileName - Optional file-name string.
Returns:
Probability of being my file-format type (0.0 .. no way, 0.5 .. maybe, 0.9 .. almost sure, 1.0 .. absolutely - no need to check another formats).
See Also:
headerLength(), fileNameMasks()

fileNameMasks

public java.lang.String[] fileNameMasks()
Returns file-name masks associated with the file-format type. Needs not be implemented in systems where "file-name -> file-type" mapping is irrelevant.

Specified by:
fileNameMasks in interface DataFileFormat
Specified by:
fileNameMasks in class DefaultFileFormat
Returns:
Array of wild-card file-name masks (e.g. ["*.png"]) or null.
See Also:
match(byte[], java.lang.String)

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.