Package org.carrot2.util
Class ColorQuantizer
java.lang.Object
org.carrot2.util.ColorQuantizer
A simple utility wrapping the
Quantize
class to work on BufferedImage
s and handle transparency.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Indicates how many distinct colors an image has, whether it has partial transparency (alpha channel). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Maximum number of colors in an indexed image, leaving one for transparency. -
Method Summary
Modifier and TypeMethodDescriptiongetColorReductionInfo
(BufferedImage source) Returns aColorQuantizer.ColorReductionInfo
for the provided image.static BufferedImage
quantize
(BufferedImage source) Quantizes the image toMAX_INDEXED_COLORS
with white matte for areas with partial transparency (full transparency will be preserved).static BufferedImage
quantize
(BufferedImage source, Color matteColor) Quantizes the image toMAX_INDEXED_COLORS
with the provided matteColor
for areas with partial transparency (full transparency will be preserved).static BufferedImage
quantize
(BufferedImage source, Color matteColor, int maxColors) Quantizes the image to the provided number of colors with the provided matteColor
for areas with partial transparency (full transparency will be preserved).static BufferedImage
reduce
(BufferedImage source) Reduces a direct color buffered image to an indexed color one without quality loss.
-
Field Details
-
MAX_INDEXED_COLORS
public static final int MAX_INDEXED_COLORSMaximum number of colors in an indexed image, leaving one for transparency.- See Also:
-
-
Method Details
-
quantize
Quantizes the image toMAX_INDEXED_COLORS
with white matte for areas with partial transparency (full transparency will be preserved).- Parameters:
source
- the source- Returns:
BufferedImage
with typeBufferedImage.TYPE_BYTE_INDEXED
and quantized colors
-
quantize
Quantizes the image toMAX_INDEXED_COLORS
with the provided matteColor
for areas with partial transparency (full transparency will be preserved).- Parameters:
source
- the sourcematteColor
- the matte color- Returns:
BufferedImage
with typeBufferedImage.TYPE_BYTE_INDEXED
and quantized colors
-
quantize
Quantizes the image to the provided number of colors with the provided matteColor
for areas with partial transparency (full transparency will be preserved).- Parameters:
source
- the sourcematteColor
- the matte colormaxColors
- the max colors- Returns:
BufferedImage
with typeBufferedImage.TYPE_BYTE_INDEXED
and quantized colors
-
reduce
Reduces a direct color buffered image to an indexed color one without quality loss. To make sure no quality loss will occur, check the results of thegetColorReductionInfo(BufferedImage)
method call.- Parameters:
source
- the source- Returns:
- the buffered image
- Throws:
IllegalArgumentException
- if the application of this method would result in image quality loss
-
getColorReductionInfo
Returns aColorQuantizer.ColorReductionInfo
for the provided image.- Parameters:
source
- the source- Returns:
- the color reduction info
-