Class PaletteBuilder


  • public class PaletteBuilder
    extends java.lang.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)
    • Field Detail

      • src

        protected java.awt.image.RenderedImage src
      • srcColorModel

        protected java.awt.image.ColorModel srcColorModel
      • srcRaster

        protected java.awt.image.Raster srcRaster
      • requiredSize

        protected int requiredSize
      • numNodes

        protected int numNodes
      • maxNodes

        protected int maxNodes
      • currLevel

        protected int currLevel
      • currSize

        protected int currSize
      • transparency

        protected int transparency
    • Constructor Detail

      • PaletteBuilder

        protected PaletteBuilder​(java.awt.image.RenderedImage src)
      • PaletteBuilder

        protected PaletteBuilder​(java.awt.image.RenderedImage src,
                                 int size)
    • Method Detail

      • createIndexedImage

        public static java.awt.image.RenderedImage createIndexedImage​(java.awt.image.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:
        java.lang.IllegalArgumentException - if src is null.
        java.lang.UnsupportedOperationException - if implemented method is unable to create approximation of src and canCreatePalette returns false.
        See Also:
        createIndexColorModel(RenderedImage), canCreatePalette(RenderedImage)
      • createIndexColorModel

        public static java.awt.image.IndexColorModel createIndexColorModel​(java.awt.image.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:
        java.lang.IllegalArgumentException - if img is null.
        java.lang.UnsupportedOperationException - if implemented method is unable to create approximation of img and canCreatePalette returns false.
        See Also:
        createIndexedImage(RenderedImage), canCreatePalette(RenderedImage)
      • canCreatePalette

        public static boolean canCreatePalette​(javax.imageio.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:
        java.lang.IllegalArgumentException - if type is null.
      • canCreatePalette

        public static boolean canCreatePalette​(java.awt.image.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:
        java.lang.IllegalArgumentException - if image is null.
      • getIndexedImage

        protected java.awt.image.RenderedImage getIndexedImage()
      • getSrcColor

        private java.awt.Color getSrcColor​(int x,
                                           int y)
      • buildPalette

        protected void buildPalette()
      • getIndexColorModel

        protected java.awt.image.IndexColorModel getIndexColorModel()
      • findPaletteEntry

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

        protected int getBranchIndex​(java.awt.Color aColor,
                                     int aLevel)
      • reduceTree

        protected void reduceTree()