Class IndexImage
- java.lang.Object
-
- org.apache.batik.ext.awt.image.rendered.IndexImage
-
public class IndexImage extends java.lang.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 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
IndexImage.Counter
Used to track a color and the number of pixels of that colorsprivate static class
IndexImage.Cube
Used to define a cube of the colorspace.
-
Constructor Summary
Constructors Constructor Description IndexImage()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static byte[][]
computeRGB(int nCubes, IndexImage.Cube[] cubes)
create an array of rgb-colors from the cubes-array.(package private) static IndexImage.Counter[][]
convertColorList(java.util.List[] colors)
step 2: convert the result of step 1 to an Cube[][] which is more efficient in the following iterations.(package private) static java.util.List[]
createColorList(java.awt.image.BufferedImage bi)
step 1: fill a data-structure with the count of each color in the image.static java.awt.image.BufferedImage
getIndexedImage(java.awt.image.BufferedImage bi, int nColors)
Converts the input image (must be TYPE_INT_RGB or TYPE_INT_ARGB) to an indexed image.(package private) static void
logRGB(byte[] r, byte[] g, byte[] b)
helper-method to print the complete rgb-arrays.
-
-
-
Method Detail
-
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 cubescubes
- 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 java.util.List[] createColorList(java.awt.image.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(java.util.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 java.awt.image.BufferedImage getIndexedImage(java.awt.image.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
-
-