Package org.carrot2.util
Class ColorQuantizer
java.lang.Object
org.carrot2.util.ColorQuantizer
A simple utility wrapping the
Quantize class to work on BufferedImages and handle transparency.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIndicates how many distinct colors an image has, whether it has partial transparency (alpha channel). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum number of colors in an indexed image, leaving one for transparency. -
Method Summary
Modifier and TypeMethodDescriptiongetColorReductionInfo(BufferedImage source) Returns aColorQuantizer.ColorReductionInfofor the provided image.static BufferedImagequantize(BufferedImage source) Quantizes the image toMAX_INDEXED_COLORSwith white matte for areas with partial transparency (full transparency will be preserved).static BufferedImagequantize(BufferedImage source, Color matteColor) Quantizes the image toMAX_INDEXED_COLORSwith the provided matteColorfor areas with partial transparency (full transparency will be preserved).static BufferedImagequantize(BufferedImage source, Color matteColor, int maxColors) Quantizes the image to the provided number of colors with the provided matteColorfor areas with partial transparency (full transparency will be preserved).static BufferedImagereduce(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_COLORSwith white matte for areas with partial transparency (full transparency will be preserved).- Parameters:
source- the source- Returns:
BufferedImagewith typeBufferedImage.TYPE_BYTE_INDEXEDand quantized colors
-
quantize
Quantizes the image toMAX_INDEXED_COLORSwith the provided matteColorfor areas with partial transparency (full transparency will be preserved).- Parameters:
source- the sourcematteColor- the matte color- Returns:
BufferedImagewith typeBufferedImage.TYPE_BYTE_INDEXEDand quantized colors
-
quantize
Quantizes the image to the provided number of colors with the provided matteColorfor areas with partial transparency (full transparency will be preserved).- Parameters:
source- the sourcematteColor- the matte colormaxColors- the max colors- Returns:
BufferedImagewith typeBufferedImage.TYPE_BYTE_INDEXEDand 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.ColorReductionInfofor the provided image.- Parameters:
source- the source- Returns:
- the color reduction info
-