Package com.sun.media.imageioimpl.common
Class PaletteBuilder
- java.lang.Object
-
- com.sun.media.imageioimpl.common.PaletteBuilder
-
public class PaletteBuilder extends Object
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 Classes Modifier and Type Class Description protected class
PaletteBuilder.ColorNode
The node of color tree.
-
Field Summary
Fields Modifier and Type Field Description protected int
currLevel
protected int
currSize
protected static int
MAXLEVEL
maximum of tree depthprotected int
maxNodes
protected int
numNodes
protected PaletteBuilder.ColorNode[]
palette
protected PaletteBuilder.ColorNode[]
reduceList
protected int
requiredSize
protected PaletteBuilder.ColorNode
root
protected RenderedImage
src
protected ColorModel
srcColorModel
protected Raster
srcRaster
protected PaletteBuilder.ColorNode
transColor
protected int
transparency
-
Constructor Summary
Constructors Modifier Constructor Description protected
PaletteBuilder(RenderedImage src)
protected
PaletteBuilder(RenderedImage src, int size)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
buildPalette()
static boolean
canCreatePalette(RenderedImage image)
Returnstrue
if PaletteBuilder is able to create palette for given rendered image.static boolean
canCreatePalette(ImageTypeSpecifier type)
Returnstrue
if PaletteBuilder is able to create palette for given image type.static IndexColorModel
createIndexColorModel(RenderedImage img)
Creates an palette representing colors from given imageimg
.static RenderedImage
createIndexedImage(RenderedImage src)
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
getIndexColorModel()
protected RenderedImage
getIndexedImage()
protected PaletteBuilder.ColorNode
insertNode(PaletteBuilder.ColorNode aNode, Color aColor, int aLevel)
protected void
reduceTree()
-
-
-
Field Detail
-
MAXLEVEL
protected static final int MAXLEVEL
maximum of tree depth- See Also:
- Constant Field Values
-
src
protected RenderedImage src
-
srcColorModel
protected ColorModel srcColorModel
-
srcRaster
protected Raster srcRaster
-
requiredSize
protected int requiredSize
-
root
protected PaletteBuilder.ColorNode root
-
numNodes
protected int numNodes
-
maxNodes
protected int maxNodes
-
currLevel
protected int currLevel
-
currSize
protected int currSize
-
reduceList
protected PaletteBuilder.ColorNode[] reduceList
-
palette
protected PaletteBuilder.ColorNode[] palette
-
transparency
protected int transparency
-
transColor
protected PaletteBuilder.ColorNode transColor
-
-
Constructor Detail
-
PaletteBuilder
protected PaletteBuilder(RenderedImage src)
-
PaletteBuilder
protected PaletteBuilder(RenderedImage src, int size)
-
-
Method Detail
-
createIndexedImage
public static RenderedImage createIndexedImage(RenderedImage src)
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(RenderedImage)
,canCreatePalette(RenderedImage)
-
createIndexColorModel
public static IndexColorModel createIndexColorModel(RenderedImage img)
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:
createIndexedImage(RenderedImage)
,canCreatePalette(RenderedImage)
-
canCreatePalette
public static boolean canCreatePalette(ImageTypeSpecifier type)
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
public static boolean canCreatePalette(RenderedImage image)
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
protected RenderedImage getIndexedImage()
-
findColorIndex
protected int findColorIndex(PaletteBuilder.ColorNode aNode, Color aColor)
-
buildPalette
protected void buildPalette()
-
insertNode
protected PaletteBuilder.ColorNode insertNode(PaletteBuilder.ColorNode aNode, Color aColor, int aLevel)
-
getIndexColorModel
protected IndexColorModel getIndexColorModel()
-
findPaletteEntry
protected int findPaletteEntry(PaletteBuilder.ColorNode aNode, int index, byte[] red, byte[] green, byte[] blue)
-
getBranchIndex
protected int getBranchIndex(Color aColor, int aLevel)
-
reduceTree
protected void reduceTree()
-
freeTree
protected PaletteBuilder.ColorNode freeTree(PaletteBuilder.ColorNode aNode)
-
-