Top Description Inners Fields Constructors Methods
com.sun.imageio.plugins.common

public Class PaletteBuilder

extends Object
Class Inheritance
Imports
java.awt.Transparency, .Color, java.awt.image.BufferedImage, .RenderedImage, .ColorModel, .IndexColorModel, .Raster, .WritableRaster, javax.imageio.ImageTypeSpecifier

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 and Inner Type Summary

Modifier and TypeClass and Description
protected class
PaletteBuilder.ColorNode

The node of color tree.

Field Summary

Modifier and TypeField and Description
protected int
protected int
protected static final int
MAXLEVEL

maximum of tree depth

protected 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

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
protected void
public static boolean

Returns:

true if the PaletteBuilder is likely to be able to create palette for this image type.
canCreatePalette
(ImageTypeSpecifier
an instance of ImageTypeSpecifier to be indexed.
type
)

Returns true if PaletteBuilder is able to create palette for given image type.

public static boolean

Returns:

true if the PaletteBuilder is likely to be able to create palette for this image type.
canCreatePalette
(RenderedImage
an instance of RenderedImage to be indexed.
image
)

Returns true if PaletteBuilder is able to create palette for given rendered image.

public static IndexColorModel
createIndexColorModel(RenderedImage img)

Creates an palette representing colors from given image img.

public static RenderedImage
createIndexedImage(RenderedImage src)

Creates an image representing given image src using IndexColorModel.

protected int
protected int
findPaletteEntry(PaletteBuilder.ColorNode aNode, int index, byte[] red, byte[] green, byte[] blue)

protected PaletteBuilder.ColorNode
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
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currLevelback to summary
protected int currLevel
currSizeback to summary
protected int currSize
MAXLEVELback to summary
protected static final int MAXLEVEL

maximum of tree depth

maxNodesback to summary
protected int maxNodes
numNodesback to summary
protected int numNodes
paletteback to summary
protected PaletteBuilder.ColorNode[] palette
reduceListback to summary
protected PaletteBuilder.ColorNode[] reduceList
requiredSizeback to summary
protected int requiredSize
rootback to summary
protected PaletteBuilder.ColorNode root
srcback to summary
protected RenderedImage src
srcColorModelback to summary
protected ColorModel srcColorModel
srcRasterback to summary
protected Raster srcRaster
transColorback to summary
protected PaletteBuilder.ColorNode transColor
transparencyback to summary
protected int transparency

Constructor Detail

PaletteBuilderback to summary
protected PaletteBuilder(RenderedImage src)
PaletteBuilderback to summary
protected PaletteBuilder(RenderedImage src, int size)

Method Detail

buildPaletteback to summary
protected void buildPalette()
canCreatePaletteback to summary
public static boolean canCreatePalette(ImageTypeSpecifier type)

Returns true if PaletteBuilder is able to create palette for given image type.

Parameters
type:ImageTypeSpecifier

an instance of ImageTypeSpecifier to be indexed.

Returns:boolean

true if the PaletteBuilder is likely to be able to create palette for this image type.

Exceptions
IllegalArgumentException:
if type is null.
canCreatePaletteback to summary
public static boolean canCreatePalette(RenderedImage image)

Returns true if PaletteBuilder is able to create palette for given rendered image.

Parameters
image:RenderedImage

an instance of RenderedImage to be indexed.

Returns:boolean

true if the PaletteBuilder is likely to be able to create palette for this image type.

Exceptions
IllegalArgumentException:
if image is null.
createIndexColorModelback to summary
public static IndexColorModel createIndexColorModel(RenderedImage img)

Creates an palette representing colors from given image img. If number of colors in the given image exceeds maximum palette size closest colors would be merged.

Exceptions
IllegalArgumentException:
if img is null.
UnsupportedOperationException:
if implemented method is unable to create approximation of img and canCreatePalette returns false.
See Also
createIndexedImage, canCreatePalette
createIndexedImageback to summary
public static RenderedImage createIndexedImage(RenderedImage src)

Creates an image representing given image src using IndexColorModel. 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.

Exceptions
IllegalArgumentException:
if src is null.
UnsupportedOperationException:
if implemented method is unable to create approximation of src and canCreatePalette returns false.
See Also
createIndexColorModel, canCreatePalette
findColorIndexback to summary
protected int findColorIndex(PaletteBuilder.ColorNode aNode, Color aColor)
findPaletteEntryback to summary
protected int findPaletteEntry(PaletteBuilder.ColorNode aNode, int index, byte[] red, byte[] green, byte[] blue)
freeTreeback to summary
protected PaletteBuilder.ColorNode freeTree(PaletteBuilder.ColorNode aNode)
getBranchIndexback to summary
protected int getBranchIndex(Color aColor, int aLevel)
getIndexColorModelback to summary
protected IndexColorModel getIndexColorModel()
getIndexedImageback to summary
protected RenderedImage getIndexedImage()
getSrcColorback to summary
private Color getSrcColor(int x, int y)
insertNodeback to summary
protected PaletteBuilder.ColorNode insertNode(PaletteBuilder.ColorNode aNode, Color aColor, int aLevel)
reduceTreeback to summary
protected void reduceTree()
com.sun.imageio.plugins.common back to summary

protected Class PaletteBuilder.ColorNode

extends Object
Class Inheritance

The node of color tree.

Field Summary

Modifier and TypeField and Description
public long
public int
pack-priv PaletteBuilder.ColorNode[]
public int
public long
public boolean
public int
pack-priv PaletteBuilder.ColorNode
public int
public long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blueback to summary
public long blue
childCountback to summary
public int childCount
childrenback to summary
pack-priv PaletteBuilder.ColorNode[] children
colorCountback to summary
public int colorCount
greenback to summary
public long green
isLeafback to summary
public boolean isLeaf
levelback to summary
public int level
nextReducibleback to summary
pack-priv PaletteBuilder.ColorNode nextReducible
paletteIndexback to summary
public int paletteIndex
redback to summary
public long red

Constructor Detail

ColorNodeback to summary
public ColorNode()

Method Detail

getLeafChildCountback to summary
public int getLeafChildCount()
getRGBback to summary
public int getRGB()