Class OctreeNode
- java.lang.Object
-
- net.sourceforge.jiu.color.quantization.OctreeNode
-
- All Implemented Interfaces:
RGBIndex,ComparatorInterface
public class OctreeNode extends Object implements ComparatorInterface, RGBIndex
A single node in an octree.- Since:
- 0.6.0
- Author:
- Marco Schmidt
- See Also:
OctreeColorQuantizer
-
-
Field Summary
Fields Modifier and Type Field Description private intblueprivate intblueSumprivate OctreeNode[]childrenprivate intgreenprivate intgreenSumprivate intpaletteIndexprivate intpixelCountprivate intredprivate intredSum-
Fields inherited from interface net.sourceforge.jiu.data.RGBIndex
INDEX_BLUE, INDEX_GREEN, INDEX_RED
-
-
Constructor Summary
Constructors Constructor Description OctreeNode()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanadd(OctreeNode root, int red, int green, int blue, int bitsPerSample)Add a color red-green-blue to the octree, given by its root node.intcompare(Object o1, Object o2)Compares the two argument objects and returns their relation.private static intcomputeIndex(int red, int green, int blue, int shift)voidcopyChildSums()Adds the sums for red, green and blue values and the pixel count values of all child nodes and stores the results in this node.voiddetermineRepresentativeColor()intgetBlue()OctreeNode[]getChildren()intgetGreen()intgetNumChildren()intgetPaletteIndex()intgetRed()booleanisLeaf()intmap(int[] origRgb, int[] quantizedRgb)Returns the index of the best match for origRgb in the palette or -1 if the best match could not be determined.private intmap(int r, int g, int b, int shift, int[] quantizedRgb)voidsetChildren(OctreeNode[] newChildren)voidsetPaletteIndex(int index)private voidupdate(int red, int green, int blue)
-
-
-
Field Detail
-
paletteIndex
private int paletteIndex
-
pixelCount
private int pixelCount
-
redSum
private int redSum
-
greenSum
private int greenSum
-
blueSum
private int blueSum
-
red
private int red
-
green
private int green
-
blue
private int blue
-
children
private OctreeNode[] children
-
-
Method Detail
-
add
public static boolean add(OctreeNode root, int red, int green, int blue, int bitsPerSample)
Add a color red-green-blue to the octree, given by its root node. This methods follows the octree down to the bitsPerSample'th level, creating nodes as necessary. Increases the pixelCount of a leaf node (if the node already exists) or initializes a newly-created leaf.- Parameters:
root- root node of the octreered- the red intensity value of the color to be addedgreen- the green intensity value of the color to be addedblue- the blue intensity value of the color to be addedbitsPerSample-
-
compare
public int compare(Object o1, Object o2)
Description copied from interface:ComparatorInterfaceCompares the two argument objects and returns their relation. Returns- a value < 0 if
o1is smaller thano2, - 0 if
o1is equal too2and - a value > 0 if
o1is greater thano2.
- Specified by:
comparein interfaceComparatorInterface
- a value < 0 if
-
computeIndex
private static int computeIndex(int red, int green, int blue, int shift)
-
copyChildSums
public void copyChildSums()
Adds the sums for red, green and blue values and the pixel count values of all child nodes and stores the results in this node. Does nothing if this is a leaf. Otherwise, recursively calls itself with all non-null child nodes and adds their sums for red, green and blue and the number of pixel values. Then stores these values in this node. They will be used when the octree is pruned to have a certain number of leaves.
-
determineRepresentativeColor
public void determineRepresentativeColor()
-
getBlue
public int getBlue()
-
getChildren
public OctreeNode[] getChildren()
-
getGreen
public int getGreen()
-
getNumChildren
public int getNumChildren()
-
getPaletteIndex
public int getPaletteIndex()
-
getRed
public int getRed()
-
isLeaf
public boolean isLeaf()
-
map
public int map(int[] origRgb, int[] quantizedRgb)Returns the index of the best match for origRgb in the palette or -1 if the best match could not be determined. If there was a best match, quantizedRgb is filled with the quantized color's RGB values.
-
map
private final int map(int r, int g, int b, int shift, int[] quantizedRgb)
-
setChildren
public void setChildren(OctreeNode[] newChildren)
-
setPaletteIndex
public void setPaletteIndex(int index)
-
update
private void update(int red, int green, int blue)
-
-