Package com.sun.media.imageioimpl.common
Class PaletteBuilder
java.lang.Object
com.sun.media.imageioimpl.common.PaletteBuilder
This class implements the octree quantization method
as it is described in the "Graphics Gems"
(ISBN 0-12-286166-3, Chapter 4, pages 297-293)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThe node of color tree. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected static final intmaximum of tree depthprotected intprotected intprotected PaletteBuilder.ColorNode[]protected PaletteBuilder.ColorNode[]protected intprotected PaletteBuilder.ColorNodeprotected RenderedImageprotected ColorModelprotected Rasterprotected PaletteBuilder.ColorNodeprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidstatic booleancanCreatePalette(RenderedImage image) Returnstrueif PaletteBuilder is able to create palette for given rendered image.static booleanReturnstrueif PaletteBuilder is able to create palette for given image type.static IndexColorModelCreates an palette representing colors from given imageimg.static RenderedImageCreates an image representing given imagesrcusingIndexColorModel.protected intfindColorIndex(PaletteBuilder.ColorNode aNode, Color aColor) protected intfindPaletteEntry(PaletteBuilder.ColorNode aNode, int index, byte[] red, byte[] green, byte[] blue) protected PaletteBuilder.ColorNodefreeTree(PaletteBuilder.ColorNode aNode) protected intgetBranchIndex(Color aColor, int aLevel) protected IndexColorModelprotected RenderedImageprotected PaletteBuilder.ColorNodeinsertNode(PaletteBuilder.ColorNode aNode, Color aColor, int aLevel) protected void
-
Field Details
-
MAXLEVEL
protected static final int MAXLEVELmaximum of tree depth- See Also:
-
src
-
srcColorModel
-
srcRaster
-
requiredSize
protected int requiredSize -
root
-
numNodes
protected int numNodes -
maxNodes
protected int maxNodes -
currLevel
protected int currLevel -
currSize
protected int currSize -
reduceList
-
palette
-
transparency
protected int transparency -
transColor
-
-
Constructor Details
-
PaletteBuilder
-
PaletteBuilder
-
-
Method Details
-
createIndexedImage
Creates an image representing given imagesrcusingIndexColorModel. Lossless conversion is not always possible (e.g. if number of colors in the given image exceeds maximum palette size). Result image then is an approximation constructed by octree quantization method.- Throws:
IllegalArgumentException- ifsrcisnull.UnsupportedOperationException- if implemented method is unable to create approximation ofsrcandcanCreatePalettereturnsfalse.- See Also:
-
createIndexColorModel
Creates an palette representing colors from given imageimg. If number of colors in the given image exceeds maximum palette size closest colors would be merged.- Throws:
IllegalArgumentException- ifimgisnull.UnsupportedOperationException- if implemented method is unable to create approximation ofimgandcanCreatePalettereturnsfalse.- See Also:
-
canCreatePalette
Returnstrueif PaletteBuilder is able to create palette for given image type.- Parameters:
type- an instance ofImageTypeSpecifierto be indexed.- Returns:
trueif thePaletteBuilderis likely to be able to create palette for this image type.- Throws:
IllegalArgumentException- iftypeisnull.
-
canCreatePalette
Returnstrueif PaletteBuilder is able to create palette for given rendered image.- Parameters:
image- an instance ofRenderedImageto be indexed.- Returns:
trueif thePaletteBuilderis likely to be able to create palette for this image type.- Throws:
IllegalArgumentException- ifimageisnull.
-
getIndexedImage
-
findColorIndex
-
buildPalette
protected void buildPalette() -
insertNode
protected PaletteBuilder.ColorNode insertNode(PaletteBuilder.ColorNode aNode, Color aColor, int aLevel) -
getIndexColorModel
-
findPaletteEntry
protected int findPaletteEntry(PaletteBuilder.ColorNode aNode, int index, byte[] red, byte[] green, byte[] blue) -
getBranchIndex
-
reduceTree
protected void reduceTree() -
freeTree
-