Class IndexImage
Support for the default JVM (ordered/pattern) dither, Floyd-Steinberg like
error-diffusion and no dither, controlled by the hints
DITHER_DIFFUSION
,
DITHER_NONE
and
DITHER_DEFAULT
.
Color selection speed/accuracy can be controlled using the hints
COLOR_SELECTION_FAST
,
COLOR_SELECTION_QUALITY
and
COLOR_SELECTION_DEFAULT
.
Transparency support can be controlled using the hints
TRANSPARENCY_OPAQUE
,
TRANSPARENCY_BITMASK
and
TRANSPARENCY_TRANSLUCENT
.
This product includes software developed by the Apache Software Foundation. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see http://www.apache.org/
- Version:
- $Id: IndexImage.java#1 $
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Used to track a color and the number of pixels of that colorsprivate static class
Used to define a cube of the color space. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default color selectionstatic final int
Prioritize speedprotected static final int
Color Selection maskstatic final int
Prioritize qualitystatic final int
Java default ditherstatic final int
Error diffusion ditherstatic final int
Error diffusion dither with alternating scansprotected static final int
Dither maskstatic final int
No ditherstatic final int
Convert alpha to bitmaskstatic final int
Default transparency (none)protected static final int
Transparency maskstatic final int
Discard any alpha informationprotected static final int
Keep original alpha (not supported yet) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
applyAlpha
(BufferedImage pImage, BufferedImage pAlpha) Applies the alpha-component of the alpha image to the given image.private static IndexColorModel
createIndexColorModel
(BufferedImage pImage, int pNumberOfColors, int pHints) Creates anIndexColorModel
from the given image, using an adaptive palette.private static BufferedImage
createSolid
(BufferedImage pOriginal, Color pBackground) Creates a copy of the given image, with a solid backgroundstatic IndexColorModel
getIndexColorModel
(Image pImage, int pNumberOfColors, boolean pFast) Deprecated.static IndexColorModel
getIndexColorModel
(Image pImage, int pNumberOfColors, int pHints) Gets anIndexColorModel
from the given image.static BufferedImage
getIndexedImage
(BufferedImage pImage) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image.static BufferedImage
getIndexedImage
(BufferedImage pImage, int pNumberOfColors, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image.static BufferedImage
getIndexedImage
(BufferedImage pImage, int pNumberOfColors, Color pMatte, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image.static BufferedImage
getIndexedImage
(BufferedImage pImage, IndexColorModel pColors, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image.static BufferedImage
getIndexedImage
(BufferedImage pImage, IndexColorModel pColors, Color pMatte, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image.static BufferedImage
getIndexedImage
(BufferedImage pImage, Image pPalette, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image.static BufferedImage
getIndexedImage
(BufferedImage pImage, Image pPalette, Color pMatte, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image.private static boolean
isFast
(int pHints) Tests if the hintCOLOR_SELECTION_QUALITY
is not set.(package private) static boolean
isTransparent
(int pHints) Tests if the hintTRANSPARENCY_BITMASK
orTRANSPARENCY_TRANSLUCENT
is set.static void
-
Field Details
-
DITHER_MASK
protected static final int DITHER_MASKDither mask- See Also:
-
DITHER_DEFAULT
public static final int DITHER_DEFAULTJava default dither- See Also:
-
DITHER_NONE
public static final int DITHER_NONENo dither- See Also:
-
DITHER_DIFFUSION
public static final int DITHER_DIFFUSIONError diffusion dither- See Also:
-
DITHER_DIFFUSION_ALTSCANS
public static final int DITHER_DIFFUSION_ALTSCANSError diffusion dither with alternating scans- See Also:
-
COLOR_SELECTION_MASK
protected static final int COLOR_SELECTION_MASKColor Selection mask- See Also:
-
COLOR_SELECTION_DEFAULT
public static final int COLOR_SELECTION_DEFAULTDefault color selection- See Also:
-
COLOR_SELECTION_FAST
public static final int COLOR_SELECTION_FASTPrioritize speed- See Also:
-
COLOR_SELECTION_QUALITY
public static final int COLOR_SELECTION_QUALITYPrioritize quality- See Also:
-
TRANSPARENCY_MASK
protected static final int TRANSPARENCY_MASKTransparency mask- See Also:
-
TRANSPARENCY_DEFAULT
public static final int TRANSPARENCY_DEFAULTDefault transparency (none)- See Also:
-
TRANSPARENCY_OPAQUE
public static final int TRANSPARENCY_OPAQUEDiscard any alpha information- See Also:
-
TRANSPARENCY_BITMASK
public static final int TRANSPARENCY_BITMASKConvert alpha to bitmask- See Also:
-
TRANSPARENCY_TRANSLUCENT
protected static final int TRANSPARENCY_TRANSLUCENTKeep original alpha (not supported yet)- See Also:
-
-
Constructor Details
-
IndexImage
private IndexImage()You cannot create this
-
-
Method Details
-
getIndexColorModel
@Deprecated public static IndexColorModel getIndexColorModel(Image pImage, int pNumberOfColors, boolean pFast) Deprecated.UsegetIndexColorModel(Image,int,int)
instead! This version will be removed in a later version of the API.- Parameters:
pImage
- the image to getIndexColorModel
frompNumberOfColors
- the number of colors for theIndexColorModel
pFast
-true
if fast- Returns:
- an
IndexColorModel
- See Also:
-
getIndexColorModel
public static IndexColorModel getIndexColorModel(Image pImage, int pNumberOfColors, int pHints) throws ImageConversionException Gets anIndexColorModel
from the given image. If the image has anIndexColorModel
, this will be returned. Otherwise, anIndexColorModel
is created, using an adaptive palette.- Parameters:
pImage
- the image to getIndexColorModel
frompNumberOfColors
- the number of colors for theIndexColorModel
pHints
- one ofCOLOR_SELECTION_FAST
,COLOR_SELECTION_QUALITY
orCOLOR_SELECTION_DEFAULT
.- Returns:
- The
IndexColorModel
from the given image, or a newly createdIndexColorModel
using an adaptive palette. - Throws:
ImageConversionException
- if an exception occurred during color model extraction.
-
createIndexColorModel
private static IndexColorModel createIndexColorModel(BufferedImage pImage, int pNumberOfColors, int pHints) Creates anIndexColorModel
from the given image, using an adaptive palette.- Parameters:
pImage
- the image to getIndexColorModel
frompNumberOfColors
- the number of colors for theIndexColorModel
pHints
- use fast mode if possible (might give slightly lower quality)- Returns:
- a new
IndexColorModel
created from the given image
-
getIndexedImage
Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image. Generating an adaptive palette (8 bit) from the color data in the image, and uses default dither.The image returned is a new image, the input image is not modified.
- Parameters:
pImage
- the BufferedImage to index and get color information from.- Returns:
- the indexed BufferedImage. The image will be of type
BufferedImage.TYPE_BYTE_INDEXED
, and use anIndexColorModel
. - See Also:
-
isFast
private static boolean isFast(int pHints) Tests if the hintCOLOR_SELECTION_QUALITY
is not set.- Parameters:
pHints
- hints- Returns:
- true if the hint
COLOR_SELECTION_QUALITY
is not set.
-
isTransparent
static boolean isTransparent(int pHints) Tests if the hintTRANSPARENCY_BITMASK
orTRANSPARENCY_TRANSLUCENT
is set.- Parameters:
pHints
- hints- Returns:
- true if the hint
TRANSPARENCY_BITMASK
orTRANSPARENCY_TRANSLUCENT
is set.
-
getIndexedImage
public static BufferedImage getIndexedImage(BufferedImage pImage, Image pPalette, Color pMatte, int pHints) throws ImageConversionException Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image. If the palette image uses anIndexColorModel
, this will be used. Otherwise, generating an adaptive palette (8 bit) from the given palette image. Dithering, transparency and color selection is controlled with thepHints
parameter.The image returned is a new image, the input image is not modified.
- Parameters:
pImage
- the BufferedImage to indexpPalette
- the Image to read color information frompMatte
- the background color, used where the original image was transparentpHints
- hints that control output quality and speed.- Returns:
- the indexed BufferedImage. The image will be of type
BufferedImage.TYPE_BYTE_INDEXED
orBufferedImage.TYPE_BYTE_BINARY
, and use anIndexColorModel
. - Throws:
ImageConversionException
- if an exception occurred during color model extraction.- See Also:
-
getIndexedImage
public static BufferedImage getIndexedImage(BufferedImage pImage, int pNumberOfColors, Color pMatte, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image. Generating an adaptive palette with the given number of colors. Dithering, transparency and color selection is controlled with thepHints
parameter.The image returned is a new image, the input image is not modified.
- Parameters:
pImage
- the BufferedImage to indexpNumberOfColors
- the number of colors for the imagepMatte
- the background color, used where the original image was transparentpHints
- hints that control output quality and speed.- Returns:
- the indexed BufferedImage. The image will be of type
BufferedImage.TYPE_BYTE_INDEXED
orBufferedImage.TYPE_BYTE_BINARY
, and use anIndexColorModel
. - See Also:
-
getIndexedImage
public static BufferedImage getIndexedImage(BufferedImage pImage, IndexColorModel pColors, Color pMatte, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image. Using the suppliedIndexColorModel
's palette. Dithering, transparency and color selection is controlled with thepHints
parameter.The image returned is a new image, the input image is not modified.
- Parameters:
pImage
- the BufferedImage to indexpColors
- anIndexColorModel
containing the color informationpMatte
- the background color, used where the original image was transparent. Also note that any transparent antialias will be rendered against this color.pHints
- RenderingHints that control output quality and speed.- Returns:
- the indexed BufferedImage. The image will be of type
BufferedImage.TYPE_BYTE_INDEXED
orBufferedImage.TYPE_BYTE_BINARY
, and use anIndexColorModel
. - See Also:
-
getIndexedImage
Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image. Generating an adaptive palette with the given number of colors. Dithering, transparency and color selection is controlled with thepHints
parameter.The image returned is a new image, the input image is not modified.
- Parameters:
pImage
- the BufferedImage to indexpNumberOfColors
- the number of colors for the imagepHints
- hints that control output quality and speed.- Returns:
- the indexed BufferedImage. The image will be of type
BufferedImage.TYPE_BYTE_INDEXED
orBufferedImage.TYPE_BYTE_BINARY
, and use anIndexColorModel
. - See Also:
-
getIndexedImage
public static BufferedImage getIndexedImage(BufferedImage pImage, IndexColorModel pColors, int pHints) Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image. Using the suppliedIndexColorModel
's palette. Dithering, transparency and color selection is controlled with thepHints
parameter.The image returned is a new image, the input image is not modified.
- Parameters:
pImage
- the BufferedImage to indexpColors
- anIndexColorModel
containing the color informationpHints
- RenderingHints that control output quality and speed.- Returns:
- the indexed BufferedImage. The image will be of type
BufferedImage.TYPE_BYTE_INDEXED
orBufferedImage.TYPE_BYTE_BINARY
, and use anIndexColorModel
. - See Also:
-
getIndexedImage
Converts the input image (must beTYPE_INT_RGB
orTYPE_INT_ARGB
) to an indexed image. If the palette image uses anIndexColorModel
, this will be used. Otherwise, generating an adaptive palette (8 bit) from the given palette image. Dithering, transparency and color selection is controlled with thepHints
parameter.The image returned is a new image, the input image is not modified.
- Parameters:
pImage
- the BufferedImage to indexpPalette
- the Image to read color information frompHints
- hints that control output quality and speed.- Returns:
- the indexed BufferedImage. The image will be of type
BufferedImage.TYPE_BYTE_INDEXED
orBufferedImage.TYPE_BYTE_BINARY
, and use anIndexColorModel
. - See Also:
-
createSolid
Creates a copy of the given image, with a solid background- Parameters:
pOriginal
- the original imagepBackground
- the background color- Returns:
- a new
BufferedImage
-
applyAlpha
Applies the alpha-component of the alpha image to the given image. The given image is modified in place.- Parameters:
pImage
- the image to apply alpha topAlpha
- the image containing the alpha
-
main
-
getIndexColorModel(Image,int,int)
instead! This version will be removed in a later version of the API.