Class IndexImage
java.lang.Object
org.apache.batik.ext.awt.image.rendered.IndexImage
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 ClassesModifier and TypeClassDescriptionprivate static class
Used to track a color and the number of pixels of that colorsprivate static class
Used to define a cube of the colorspace. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(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
(List[] colors) step 2: convert the result of step 1 to an Cube[][] which is more efficient in the following iterations.(package private) static List[]
step 1: fill a data-structure with the count of each color in the image.static BufferedImage
getIndexedImage
(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.
-
Constructor Details
-
IndexImage
public IndexImage()
-
-
Method Details
-
computeRGB
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
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
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
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
-