public class

PaletteBuilder

extends Object
java.lang.Object
   ↳ com.sun.imageio.plugins.common.PaletteBuilder

Class Overview

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)

Summary

Nested Classes
class PaletteBuilder.ColorNode The node of color tree. 
Constants
int MAXLEVEL maximum of tree depth
Fields
protected int currLevel
protected int currSize
protected int maxNodes
protected int numNodes
protected ColorNode[] palette
protected 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
Protected Constructors
PaletteBuilder(RenderedImage src)
PaletteBuilder(RenderedImage src, int size)
Public Methods
static boolean canCreatePalette(RenderedImage image)
Returns true if PaletteBuilder is able to create palette for given rendered image.
static boolean canCreatePalette(ImageTypeSpecifier type)
Returns true if PaletteBuilder is able to create palette for given image type.
static IndexColorModel createIndexColorModel(RenderedImage img)
Creates an palette representing colors from given image img.
static RenderedImage createIndexedImage(RenderedImage src)
Creates an image representing given image src using IndexColorModel.
Protected Methods
void buildPalette()
int findColorIndex(PaletteBuilder.ColorNode aNode, Color aColor)
int findPaletteEntry(PaletteBuilder.ColorNode aNode, int index, byte[] red, byte[] green, byte[] blue)
PaletteBuilder.ColorNode freeTree(PaletteBuilder.ColorNode aNode)
int getBranchIndex(Color aColor, int aLevel)
IndexColorModel getIndexColorModel()
RenderedImage getIndexedImage()
PaletteBuilder.ColorNode insertNode(PaletteBuilder.ColorNode aNode, Color aColor, int aLevel)
void reduceTree()
[Expand]
Inherited Methods
From class java.lang.Object

Constants

protected static final int MAXLEVEL

maximum of tree depth

Constant Value: 8 (0x00000008)

Fields

protected int currLevel

protected int currSize

protected int maxNodes

protected int numNodes

protected ColorNode[] palette

protected 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

Protected Constructors

protected PaletteBuilder (RenderedImage src)

protected PaletteBuilder (RenderedImage src, int size)

Public Methods

public static boolean canCreatePalette (RenderedImage image)

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

Parameters
image an instance of RenderedImage to be indexed.
Returns
  • true if the PaletteBuilder is likely to be able to create palette for this image type.
Throws
IllegalArgumentException if image is null.

public static boolean canCreatePalette (ImageTypeSpecifier type)

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

Parameters
type an instance of ImageTypeSpecifier to be indexed.
Returns
  • true if the PaletteBuilder is likely to be able to create palette for this image type.
Throws
IllegalArgumentException if type is null.

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.

Throws
IllegalArgumentException if img is null.
UnsupportedOperationException if implemented method is unable to create approximation of img and canCreatePalette returns false.
See Also
  • createIndexedImage
  • canCreatePalette

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.

Throws
IllegalArgumentException if src is null.
UnsupportedOperationException if implemented method is unable to create approximation of src and canCreatePalette returns false.
See Also
  • createIndexColorModel
  • canCreatePalette

Protected Methods

protected void buildPalette ()

protected int findColorIndex (PaletteBuilder.ColorNode aNode, Color aColor)

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

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 ()