|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.davisor.graphics.OctreeColorReducer.ColorTree
ColorTree implements a color octree that orginizes colors into a
hierarchy of similar colors. The color tree is made of OctreeColorReducer.ColorNode nodes, each having up to 8 children
nodes. Each node represents a RGB color value. If the node has
children, the node color value represents also the weighed
average of all the children color values.
All nodes at the same tree depth are also arranged into one-directional linked lists. The head nodes of these lists are always known to the color tree. These lists area allow very fast access to nodes at spesific depth.
This implementation uses a speed optimization strategy that keeps the color tree size down to given maximum size AT ALL TIMES. In particular, the color tree is reduced immediately back to the maximum size each time after a new color has been added to the tree. This produces less optimal but much faster results than a strategy that would first add all colors to the tree, and only then reduce it.
The 8 children represent all the combinations a 3 bit bit -patterns can take. These bit patterns are formed by taking the corresponding bits from the 3 RGB component values. RGB component values are expected to be 8 bit values, so the maximum color tree depth is also 8.
addColor(int),
reduce()| Field Summary | |
static int |
ALPHA_THRESHOLD
BITMAP trasparency threshold (0x80). |
protected int |
M_leafCount
Current total number of color leafs. |
protected int |
M_maxColors
Maximum allowed number of color leafs. |
protected OctreeColorReducer.ColorNode[] |
M_nodesAtDepth
Color node list heads, indexed and sorted by node depth. |
protected OctreeColorReducer.ColorNode |
M_root
The color tree root node. |
protected boolean |
M_transparent
Indicates the presense or absense of a special transparent color. |
static int |
MAX_DEPTH
Maximum color tree depth (8). |
| Constructor Summary | |
protected |
OctreeColorReducer.ColorTree(int maxColors)
Creates a new color tree, with potential to grow to contain up to given maximum number of different colors. |
| Method Summary | |
protected void |
addColor(int argb)
Adds a ARGB color into the tree. |
protected int |
getColor(int argb)
Gets the replacement color value for the given color. |
protected int[] |
getColors()
Traverses through the tree is depth-first order and stores the found color sRGB values into the returned array. |
protected int |
getIndex(int argb)
Gets the replacement color index for the given color. |
protected void |
reduce()
Reduces the tree size size by collapsing one of the less significant color nodes. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int ALPHA_THRESHOLD
public static final int MAX_DEPTH
protected int M_leafCount
protected int M_maxColors
protected OctreeColorReducer.ColorNode[] M_nodesAtDepth
protected OctreeColorReducer.ColorNode M_root
protected boolean M_transparent
| Constructor Detail |
protected OctreeColorReducer.ColorTree(int maxColors)
maxColors - maximum number of colors this tree may contain| Method Detail |
protected void addColor(int argb)
argb - standard 32 bit ARGB color value to add to the treegetColor(int),
getIndex(int),
reduce()protected int[] getColors()
protected int getColor(int argb)
Color palettes provide typically only limited set of transparent colors, as typical color palette contains only fully opaque colors, and only one fully transparent color, if even that. The transparency component of the returned palette color may therefore be significantly different that of the source color.
argb - standard sRGB color value (with alpha)
addColor(int),
getIndex(int),
OctreeColorReducer.ColorNode.getColor()protected int getIndex(int argb)
OctreeColorReducer.getPalette() method.
Color palettes provide typically only limited set of transparent colors, as typical color palette contains only fully opaque colors, and only one fully transparent color, if even that. The transparency component of the returned palette color may therefore be significantly different that of the source color.
argb - standard sRGB color value (with alpha)
java.lang.IllegalStateException - if the color tree has not been
assosiated with any color paletteaddColor(int),
getColor(int),
OctreeColorReducer.ColorNode.getIndex(int, int, int, int)
protected void reduce()
throws com.davisor.core.NotFoundException
If the tree has been reduced down to just the root node, it will not be collapsed, as this would result a tree with just one color. Instead, the least referenced root child is removed, and the root color is changed to the average between the original root color, and the color of the removed child.
If the tree has been reduced so small that even the root node has no children, no node to be collapsed can be found, and an exception is thrown.
This implementation optimizes the less significant color node search by just taking the latest added node from the deepest possible tree hierarchy level. An optimal but much slower solution would search the whole tree for the least reference color.
com.davisor.core.NotFoundException - if not even one reductable node was found
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||