Class PaletteFactory
java.lang.Object
org.apache.commons.imaging.palette.PaletteFactory
Factory for creating palettes.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintintcountTrasparentColors(int[] rgbs) private voiddivide(List<ColorSpaceSubset> v, int desiredCount, int[] table, int precision) private PaletteFactory.DivisionCandidatedivideSubset2(int[] table, ColorSpaceSubset subset, int precision) private List<PaletteFactory.DivisionCandidate> divideSubset2(int[] table, ColorSpaceSubset subset, int component, int precision) private PaletteFactory.DivisionCandidatefinishDivision(ColorSpaceSubset subset, int component, int precision, int sum, int slice) private intgetFrequencyTotal(int[] table, int[] mins, int[] maxs, int precision) booleanbooleanhasTransparency(BufferedImage src, int threshold) booleanisGrayscale(BufferedImage src) Builds an exact complete opaque palette containing all the colors insrc, using an algorithm that is faster than makeExactRgbPaletteSimple(BufferedImage, int) for large images but uses 2 mebibytes of working memory.makeExactRgbPaletteSimple(BufferedImage src, int max) Builds an exact complete opaque palette containing all the colors insrc, and fails by returningnullif there are more thanmaxcolors necessary to do this.makeQuantizedRgbaPalette(BufferedImage src, boolean transparent, int max) Builds an inexact possibly translucent palette of at mostmaxcolors insrcusing the traditional Median Cut algorithm.makeQuantizedRgbPalette(BufferedImage src, int max) Builds an inexact opaque palette of at mostmaxcolors insrcusing a variation of the Median Cut algorithm.private intpixelToQuantizationTableIndex(int argb, int precision)
-
Field Details
-
LOGGER
-
COMPONENTS
public static final int COMPONENTS- See Also:
-
-
Constructor Details
-
PaletteFactory
public PaletteFactory()
-
-
Method Details
-
countTransparentColors
-
countTrasparentColors
public int countTrasparentColors(int[] rgbs) -
divide
-
divideSubset2
private PaletteFactory.DivisionCandidate divideSubset2(int[] table, ColorSpaceSubset subset, int precision) -
divideSubset2
private List<PaletteFactory.DivisionCandidate> divideSubset2(int[] table, ColorSpaceSubset subset, int component, int precision) -
finishDivision
private PaletteFactory.DivisionCandidate finishDivision(ColorSpaceSubset subset, int component, int precision, int sum, int slice) -
getFrequencyTotal
private int getFrequencyTotal(int[] table, int[] mins, int[] maxs, int precision) -
hasTransparency
-
hasTransparency
-
isGrayscale
-
makeExactRgbPaletteFancy
Builds an exact complete opaque palette containing all the colors insrc, using an algorithm that is faster than makeExactRgbPaletteSimple(BufferedImage, int) for large images but uses 2 mebibytes of working memory. Treats all the colors as opaque.- Parameters:
src- the image whose palette to build- Returns:
- the palette
-
makeExactRgbPaletteSimple
Builds an exact complete opaque palette containing all the colors insrc, and fails by returningnullif there are more thanmaxcolors necessary to do this.- Parameters:
src- the image whose palette to buildmax- the maximum number of colors the palette can contain- Returns:
- the complete palette of
maxor less colors, ornullif more thanmaxcolors are necessary
-
makeQuantizedRgbaPalette
public Palette makeQuantizedRgbaPalette(BufferedImage src, boolean transparent, int max) throws ImagingException Builds an inexact possibly translucent palette of at mostmaxcolors insrcusing the traditional Median Cut algorithm. Color bounding boxes are split along the longest axis, with each step splitting the box. All bits in each component are used. The Algorithm is slower and seems exact than makeQuantizedRgbPalette(BufferedImage, int).- Parameters:
src- the image whose palette to buildtransparent- whether to consider the alpha valuesmax- the maximum number of colors the palette can contain- Returns:
- the palette of at most
maxcolors - Throws:
ImagingException- if it fails to process the palette
-
makeQuantizedRgbPalette
Builds an inexact opaque palette of at mostmaxcolors insrcusing a variation of the Median Cut algorithm. Accurate to 6 bits per component, and works by splitting the color bounding box most heavily populated by colors along the component which splits the colors in that box most evenly.- Parameters:
src- the image whose palette to buildmax- the maximum number of colors the palette can contain- Returns:
- the palette of at most
maxcolors
-
pixelToQuantizationTableIndex
private int pixelToQuantizationTableIndex(int argb, int precision)
-