Class PaletteFactory
- java.lang.Object
-
- org.apache.commons.imaging.palette.PaletteFactory
-
public class PaletteFactory extends java.lang.Object
Factory for creating palettes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PaletteFactory.DivisionCandidate
-
Field Summary
Fields Modifier and Type Field Description static int
COMPONENTS
private static java.util.logging.Logger
LOGGER
-
Constructor Summary
Constructors Constructor Description PaletteFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
countTransparentColors(java.awt.image.BufferedImage src)
int
countTrasparentColors(int[] rgbs)
private java.util.List<ColorSpaceSubset>
divide(java.util.List<ColorSpaceSubset> v, int desiredCount, int[] table, int precision)
private PaletteFactory.DivisionCandidate
divideSubset2(int[] table, ColorSpaceSubset subset, int precision)
private java.util.List<PaletteFactory.DivisionCandidate>
divideSubset2(int[] table, ColorSpaceSubset subset, int component, int precision)
private PaletteFactory.DivisionCandidate
finishDivision(ColorSpaceSubset subset, int component, int precision, int sum, int slice)
private int
getFrequencyTotal(int[] table, int[] mins, int[] maxs, int precision)
boolean
hasTransparency(java.awt.image.BufferedImage src)
boolean
hasTransparency(java.awt.image.BufferedImage src, int threshold)
boolean
isGrayscale(java.awt.image.BufferedImage src)
Palette
makeExactRgbPaletteFancy(java.awt.image.BufferedImage src)
Builds an exact complete opaque palette containing all the colors insrc
, using an algorithm that is faster than makeExactRgbPaletteSimple(java.awt.image.BufferedImage, int) for large images but uses 2 mebibytes of working memory.SimplePalette
makeExactRgbPaletteSimple(java.awt.image.BufferedImage src, int max)
Builds an exact complete opaque palette containing all the colors insrc
, and fails by returningnull
if there are more thanmax
colors necessary to do this.Palette
makeQuantizedRgbaPalette(java.awt.image.BufferedImage src, boolean transparent, int max)
Builds an inexact possibly translucent palette of at mostmax
colors insrc
using the traditional Median Cut algorithm.Palette
makeQuantizedRgbPalette(java.awt.image.BufferedImage src, int max)
Builds an inexact opaque palette of at mostmax
colors insrc
using a variation of the Median Cut algorithm.private int
pixelToQuantizationTableIndex(int argb, int precision)
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
COMPONENTS
public static final int COMPONENTS
- See Also:
- Constant Field Values
-
-
Method Detail
-
makeExactRgbPaletteFancy
public Palette makeExactRgbPaletteFancy(java.awt.image.BufferedImage src)
Builds an exact complete opaque palette containing all the colors insrc
, using an algorithm that is faster than makeExactRgbPaletteSimple(java.awt.image.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
-
pixelToQuantizationTableIndex
private int pixelToQuantizationTableIndex(int argb, int precision)
-
getFrequencyTotal
private int getFrequencyTotal(int[] table, int[] mins, int[] maxs, int precision)
-
finishDivision
private PaletteFactory.DivisionCandidate finishDivision(ColorSpaceSubset subset, int component, int precision, int sum, int slice)
-
divideSubset2
private java.util.List<PaletteFactory.DivisionCandidate> divideSubset2(int[] table, ColorSpaceSubset subset, int component, int precision)
-
divideSubset2
private PaletteFactory.DivisionCandidate divideSubset2(int[] table, ColorSpaceSubset subset, int precision)
-
divide
private java.util.List<ColorSpaceSubset> divide(java.util.List<ColorSpaceSubset> v, int desiredCount, int[] table, int precision)
-
makeQuantizedRgbPalette
public Palette makeQuantizedRgbPalette(java.awt.image.BufferedImage src, int max)
Builds an inexact opaque palette of at mostmax
colors insrc
using 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
max
colors
-
makeQuantizedRgbaPalette
public Palette makeQuantizedRgbaPalette(java.awt.image.BufferedImage src, boolean transparent, int max) throws ImageWriteException
Builds an inexact possibly translucent palette of at mostmax
colors insrc
using 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
max
colors - Throws:
ImageWriteException
- if it fails to process the palette
-
makeExactRgbPaletteSimple
public SimplePalette makeExactRgbPaletteSimple(java.awt.image.BufferedImage src, int max)
Builds an exact complete opaque palette containing all the colors insrc
, and fails by returningnull
if there are more thanmax
colors 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
max
or less colors, ornull
if more thanmax
colors are necessary
-
isGrayscale
public boolean isGrayscale(java.awt.image.BufferedImage src)
-
hasTransparency
public boolean hasTransparency(java.awt.image.BufferedImage src)
-
hasTransparency
public boolean hasTransparency(java.awt.image.BufferedImage src, int threshold)
-
countTrasparentColors
public int countTrasparentColors(int[] rgbs)
-
countTransparentColors
public int countTransparentColors(java.awt.image.BufferedImage src)
-
-