Class PaletteFactory
- java.lang.Object
-
- org.apache.commons.imaging.palette.PaletteFactory
-
public class PaletteFactory extends Object
Factory for creating palettes.
-
-
Field Summary
Fields Modifier and Type Field Description static intCOMPONENTS
-
Constructor Summary
Constructors Constructor Description PaletteFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcountTransparentColors(BufferedImage src)intcountTrasparentColors(int[] rgbs)booleanhasTransparency(BufferedImage src)booleanhasTransparency(BufferedImage src, int threshold)booleanisGrayscale(BufferedImage src)PalettemakeExactRgbPaletteFancy(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.SimplePalettemakeExactRgbPaletteSimple(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.PalettemakeQuantizedRgbaPalette(BufferedImage src, boolean transparent, int max)Builds an inexact possibly translucent palette of at mostmaxcolors insrcusing the traditional Median Cut algorithm.PalettemakeQuantizedRgbPalette(BufferedImage src, int max)Builds an inexact opaque palette of at mostmaxcolors insrcusing a variation of the Median Cut algorithm.
-
-
-
Field Detail
-
COMPONENTS
public static final int COMPONENTS
- See Also:
- Constant Field Values
-
-
Method Detail
-
makeExactRgbPaletteFancy
public Palette makeExactRgbPaletteFancy(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
-
makeQuantizedRgbPalette
public Palette makeQuantizedRgbPalette(BufferedImage src, int max)
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
-
makeQuantizedRgbaPalette
public Palette makeQuantizedRgbaPalette(BufferedImage src, boolean transparent, int max) throws ImageWriteException
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:
ImageWriteException- if it fails to process the palette
-
makeExactRgbPaletteSimple
public SimplePalette 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.- 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
-
isGrayscale
public boolean isGrayscale(BufferedImage src)
-
hasTransparency
public boolean hasTransparency(BufferedImage src)
-
hasTransparency
public boolean hasTransparency(BufferedImage src, int threshold)
-
countTrasparentColors
public int countTrasparentColors(int[] rgbs)
-
countTransparentColors
public int countTransparentColors(BufferedImage src)
-
-