com.sun.jimi.core.util
Class ColorOctree

java.lang.Object
  |
  +--com.sun.jimi.core.util.ColorOctree

public final class ColorOctree
extends java.lang.Object
implements com.sun.jimi.core.util.OctreeCallback

This class implements a color reduction octree algorithm as discussed in the following article. "A simple method for color quantization: Octree quantization" by Michael Gervautz, Werner Purgathofer in book "Graphics Gems" Once the number of color representations exceeds the maximum [generally max will be 256] then a pair of Octree nodes which each represent a color and have the minimum color difference between them will be located and merged. For minimum color distance these nodes will both be at deepest level of the octree tree.


Field Summary
protected  boolean alpha
          Set to true if alpha-data is being used.
 ExpandableArray cachedONodes
          cache of ONodex
static int MAXCACHE
          no point in caching more nodes than this.
 
Constructor Summary
ColorOctree(int maxColors)
           
 
Method Summary
 void addColor(int color)
           
 void addColor(int[] color)
           
 void cacheONode(OctreeNode on)
          Called with an OctreeNode that is no longer required this method() caches the node if there are insufficient nodes cached.
 OctreeNode getONode(com.sun.jimi.core.util.OctreeCallback oc, int level)
          Return an appropriately initialised OctreeNode object.
 OctreeNode getReducible()
          Part of OctreeCallback interface.
 boolean hasAlpha()
          Returns true if the last color in the palette has been reserved for a transparent color.
 void markReducible(OctreeNode on)
          Part of OctreeCallback interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

alpha

protected boolean alpha
Set to true if alpha-data is being used. If so, the last index in the color map will be reserved for a transparent color.

cachedONodes

public ExpandableArray cachedONodes
cache of ONodex

MAXCACHE

public static final int MAXCACHE
no point in caching more nodes than this.
Constructor Detail

ColorOctree

public ColorOctree(int maxColors)
Method Detail

addColor

public void addColor(int color)

addColor

public void addColor(int[] color)

hasAlpha

public boolean hasAlpha()
Returns true if the last color in the palette has been reserved for a transparent color.

markReducible

public void markReducible(OctreeNode on)
Part of OctreeCallback interface.
Specified by:
markReducible in interface com.sun.jimi.core.util.OctreeCallback

getReducible

public OctreeNode getReducible()
Part of OctreeCallback interface. This implementation searches for the depeest registered reducible node with the most number of pixels recorded for it. J * This would benefit from an ordered data structure.. [ fiX LATER ]
Specified by:
getReducible in interface com.sun.jimi.core.util.OctreeCallback
Returns:
OctreeNode which is the "best" candidate for reducing current number of leaf nodes in the Octree back down to max colors allowed.

getONode

public OctreeNode getONode(com.sun.jimi.core.util.OctreeCallback oc,
                           int level)
Return an appropriately initialised OctreeNode object. It attempts to return a cached node if theres one available if none available it creates a new node.
Specified by:
getONode in interface com.sun.jimi.core.util.OctreeCallback

cacheONode

public void cacheONode(OctreeNode on)
Called with an OctreeNode that is no longer required this method() caches the node if there are insufficient nodes cached.
Specified by:
cacheONode in interface com.sun.jimi.core.util.OctreeCallback