Package bdsup2sub.tools
Class OctTreeQuantizer
java.lang.Object
bdsup2sub.tools.OctTreeQuantizer
An image Quantizer based on the Octree algorithm. This is a very basic implementation
at present and could be much improved by picking the nodes to reduce more carefully
(i.e. not completely at random).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classAn Octtree node. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Vector[]private intprivate static final intThe greatest depth the tree is allowed to reachprivate intprivate intprivate OctTreeQuantizer.OctTreeNode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPixels(int[] pixels, int offset, int count) Add pixels to the quantizer.int[]Build the color table.voidbuildColorTable(int[] pixels, int[] table) A quick way to use the quantizer.private intbuildColorTable(OctTreeQuantizer.OctTreeNode node, int[] table, int index) Build color tableintgetIndexForColor(int argb) Get the color table index for a color.private voidinsertColor(int rgb) private voidreduceTree(int numColors) voidsetup(int numColors) Initialize the quantizer.
-
Field Details
-
MAX_LEVEL
private static final int MAX_LEVELThe greatest depth the tree is allowed to reach- See Also:
-
root
-
reduceColors
private int reduceColors -
maximumColors
private int maximumColors -
colors
private int colors -
colorList
-
-
Constructor Details
-
OctTreeQuantizer
public OctTreeQuantizer()
-
-
Method Details
-
setup
public void setup(int numColors) Initialize the quantizer. This should be called before adding any pixels.- Parameters:
numColors- Number of colors we're quantizing to.
-
addPixels
public void addPixels(int[] pixels, int offset, int count) Add pixels to the quantizer.- Parameters:
pixels- Array of ARGB pixelsoffset- Offset into the arraycount- Count of pixels
-
getIndexForColor
public int getIndexForColor(int argb) Get the color table index for a color.- Parameters:
argb- Color in ARGB format- Returns:
- Index of color in table
-
insertColor
private void insertColor(int rgb) -
reduceTree
private void reduceTree(int numColors) -
buildColorTable
public int[] buildColorTable()Build the color table.- Returns:
- Color table
-
buildColorTable
public void buildColorTable(int[] pixels, int[] table) A quick way to use the quantizer. Just create a table the right size and pass in the pixels.- Parameters:
pixels- Integer array containing the pixelstable- Output color table
-
buildColorTable
Build color table- Parameters:
node- Octree nodetable- Color tableindex- Index- Returns:
- Index
-