Class IndexImage

java.lang.Object
org.apache.batik.ext.awt.image.rendered.IndexImage

public class IndexImage extends Object
This class implements an adaptive palette generator to reduce images to a specified number of colors. Ideally this would also support a better dither option than just the JDK's pattern dither. The algorithm used is the 'Median Cut Algorithm' published by Paul Heckbert in early '80s.
Version:
$Id: IndexImage.java 1804130 2017-08-04 14:41:11Z ssteiner $
  • Constructor Details

    • IndexImage

      public IndexImage()
  • Method Details

    • computeRGB

      static byte[][] computeRGB(int nCubes, IndexImage.Cube[] cubes)
      create an array of rgb-colors from the cubes-array. The color of each cube is computed as the sum of all colors in the cube, where each pixel is weighted according to it's count.
      Parameters:
      nCubes - number of entries to use in cubes
      cubes - contains the Cubes resulting from running the split-algorithm.
      Returns:
      a byte[][] which is arranged as [ r|g|b ][ 0..nCubes-1 ]
    • logRGB

      static void logRGB(byte[] r, byte[] g, byte[] b)
      helper-method to print the complete rgb-arrays.
      Parameters:
      r -
      g -
      b -
    • createColorList

      static List[] createColorList(BufferedImage bi)
      step 1: fill a data-structure with the count of each color in the image.
      Parameters:
      bi - input-image
      Returns:
      a List[] where each slot is a List of Counters (or null)
    • convertColorList

      static IndexImage.Counter[][] convertColorList(List[] colors)
      step 2: convert the result of step 1 to an Cube[][] which is more efficient in the following iterations. All slots in the result are filled with at least an empty array - thus we avoid tests for null.
      Note: the converted slots in colors are no longer needed and removed.
      Parameters:
      colors - the data-structure to convert. Note that it is empty after conversion!
      Returns:
      same data as in colors, but Lists are converted to arrays.
    • getIndexedImage

      public static BufferedImage getIndexedImage(BufferedImage bi, int nColors)
      Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image. Generating an adaptive palette with number of colors specified.
      Parameters:
      bi - the image to be processed.
      nColors - number of colors in the palette