Package com.day.image
Class DitherOp
- java.lang.Object
-
- com.day.image.AbstractBufferedImageOp
-
- com.day.image.DitherOp
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
public class DitherOp extends AbstractBufferedImageOp
TheDitherOp
provides the dithering capability for reducing colors of an image to any number of colors. The real number of colors at the end of color reduction depends on the color profile of the image under reduction.Currently the following two dithering algorithm's are supported :
- Simple reduction by reducing the bit width of the color components
- Reduction by reducing the bit width and doing some rudimentary error correction on neighbouring pixels.
- Since:
- coati
- See Also:
- Implementation of Image Dithering/Color Reduction
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DitherOp.DitherAlgorithm
-
Field Summary
Fields Modifier and Type Field Description static DitherOp.DitherAlgorithm
DITHER_NONE
Indicate the use of the simple bit width color reduction algorithm with no further dithering effects.static DitherOp.DitherAlgorithm
DITHER_SIMPLE_ERROR_CORRECTION
Indicate the use of the simple bit width color reduction algorithm plus using the simple error correction algorithm.
-
Constructor Summary
Constructors Constructor Description DitherOp(int nCol, java.awt.Color transparency, java.awt.Color bgcolor, DitherOp.DitherAlgorithm algorithm, java.awt.RenderingHints hints)
Creates a newDitherOp
instance to reduce colors of an image to the given number of colors.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.awt.image.BufferedImage
convertToIndexed(java.awt.image.BufferedImage src, int nCol, java.awt.Color transparency, java.awt.Color bgcolor, java.awt.RenderingHints hints)
Converts the source image to an image with IndexColorModel and with a maximal number of colors.java.awt.image.BufferedImage
filter(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dst)
Performs the operation on a BufferedImage.-
Methods inherited from class com.day.image.AbstractBufferedImageOp
createCompatibleDestImage, getBounds2D, getPoint2D, getRenderingHints
-
-
-
-
Field Detail
-
DITHER_NONE
public static final DitherOp.DitherAlgorithm DITHER_NONE
Indicate the use of the simple bit width color reduction algorithm with no further dithering effects.
-
DITHER_SIMPLE_ERROR_CORRECTION
public static final DitherOp.DitherAlgorithm DITHER_SIMPLE_ERROR_CORRECTION
Indicate the use of the simple bit width color reduction algorithm plus using the simple error correction algorithm.
-
-
Constructor Detail
-
DitherOp
public DitherOp(int nCol, java.awt.Color transparency, java.awt.Color bgcolor, DitherOp.DitherAlgorithm algorithm, java.awt.RenderingHints hints)
Creates a newDitherOp
instance to reduce colors of an image to the given number of colors.- Parameters:
nCol
- The maximum number of colors to reduce the image to. This must be higher than 2.transparency
- TheColor
of the color to be considered as transparent. This will be one of the nCol colors if notnull
.bgcolor
- TheColor
of the color to be considered as the background. This will be one of the nCol colors if notnull
.algorithm
- The dithering algorithm to be used.hints
- The RenderingHints for the filter operation. This parameter may benull
and is not currently used.- Throws:
java.lang.NullPointerException
- if algorithm isnull
.java.lang.IllegalArgumentException
- if nCol is less than 2.
-
-
Method Detail
-
convertToIndexed
public static java.awt.image.BufferedImage convertToIndexed(java.awt.image.BufferedImage src, int nCol, java.awt.Color transparency, java.awt.Color bgcolor, java.awt.RenderingHints hints)
Converts the source image to an image with IndexColorModel and with a maximal number of colors. If the source image already has an IndexColorModel and the map size of the that color model instance (src.getColorModel().getMapSize()
) is less than or equal to the number of colors desired, the source image is returned. Else a new image is returned.- Parameters:
src
- The source image to convert to theIndexColorModel
.nCol
- The maximum number of colors to reduce the image to. This must be higher than 2.transparency
- TheColor
of the color to be considered as transparent. This will be one of the nCol colors if notnull
.bgcolor
- TheColor
of the color to be considered as the background. This will be one of the nCol colors if notnull
.hints
- The RenderingHints for the filter operation. This parameter may benull
and is not currently used.- Returns:
- An image with the
IndexColorModel
color model. If the source image already has theIndexColorModel
and the number of colors are less than or equal tonCol
the source image is returned else a new image according to the parameters is returned. - Throws:
java.lang.NullPointerException
- if the source image isnull
.java.lang.NullPointerException
- if algorithm isnull
.java.lang.IllegalArgumentException
- if nCol is less than 2.
-
filter
public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dst)
Performs the operation on a BufferedImage. This implementation only cares to make the images compatible and calls thedoFilter(BufferedImage, BufferedImage)
to do the actual filtering operation.If the color models for the two images do not match, a color conversion into the destination color model will be performed. If the destination image is null, a BufferedImage with an appropriate ColorModel will be created.
Note: The dest image might be clipped if it is not big enough to take the complete resized image.
This method is overwritten to make sure the pixel data is premultiplied with the alpha value to take the real alpha value into account.
- Specified by:
filter
in interfacejava.awt.image.BufferedImageOp
- Overrides:
filter
in classAbstractBufferedImageOp
- Parameters:
src
- The src image to be resized.dst
- The dest image into which to place the resized image. This may benull
in which case a new image with the correct size will be created.- Returns:
- The newly created image (if dest was
null
) or dest into which the resized src image has been drawn. - Throws:
java.lang.IllegalArgumentException
- if the dest image is the same as the src image.java.lang.NullPointerException
- if the src image isnull
.
-
-