Class PaletteBuilder
java.lang.Object
com.github.jaiimageio.impl.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 class
The node of color tree. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected int
protected static final int
maximum of tree depthprotected int
protected int
protected PaletteBuilder.ColorNode[]
protected PaletteBuilder.ColorNode[]
protected int
protected PaletteBuilder.ColorNode
protected RenderedImage
protected ColorModel
protected Raster
protected PaletteBuilder.ColorNode
protected int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
static boolean
canCreatePalette
(RenderedImage image) Returnstrue
if PaletteBuilder is able to create palette for given rendered image.static boolean
Returnstrue
if PaletteBuilder is able to create palette for given image type.static IndexColorModel
Creates an palette representing colors from given imageimg
.static RenderedImage
Creates an image representing given imagesrc
usingIndexColorModel
.
protected int
findColorIndex
(PaletteBuilder.ColorNode aNode, Color aColor) protected int
findPaletteEntry
(PaletteBuilder.ColorNode aNode, int index, byte[] red, byte[] green, byte[] blue) protected PaletteBuilder.ColorNode
freeTree
(PaletteBuilder.ColorNode aNode) protected int
getBranchIndex
(Color aColor, int aLevel) protected IndexColorModel
protected RenderedImage
private Color
getSrcColor
(int x, int y) protected PaletteBuilder.ColorNode
insertNode
(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 imagesrc
usingIndexColorModel
. 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
- ifsrc
isnull
.UnsupportedOperationException
- if implemented method is unable to create approximation ofsrc
andcanCreatePalette
returnsfalse
.- 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
- ifimg
isnull
.UnsupportedOperationException
- if implemented method is unable to create approximation ofimg
andcanCreatePalette
returnsfalse
.- See Also:
-
canCreatePalette
Returnstrue
if PaletteBuilder is able to create palette for given image type.- Parameters:
type
- an instance ofImageTypeSpecifier
to be indexed.- Returns:
true
if thePaletteBuilder
is likely to be able to create palette for this image type.- Throws:
IllegalArgumentException
- iftype
isnull
.
-
canCreatePalette
Returnstrue
if PaletteBuilder is able to create palette for given rendered image.- Parameters:
image
- an instance ofRenderedImage
to be indexed.- Returns:
true
if thePaletteBuilder
is likely to be able to create palette for this image type.- Throws:
IllegalArgumentException
- ifimage
isnull
.
-
getIndexedImage
-
getSrcColor
-
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
-