Package com.day.image
Class DitherOp
java.lang.Object
com.day.image.AbstractBufferedImageOp
com.day.image.DitherOp
- All Implemented Interfaces:
BufferedImageOp
The
DitherOp 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:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DitherOp.DitherAlgorithmIndicate the use of the simple bit width color reduction algorithm with no further dithering effects.static final DitherOp.DitherAlgorithmIndicate the use of the simple bit width color reduction algorithm plus using the simple error correction algorithm. -
Constructor Summary
ConstructorsConstructorDescriptionDitherOp(int nCol, Color transparency, Color bgcolor, DitherOp.DitherAlgorithm algorithm, RenderingHints hints) Creates a newDitherOpinstance to reduce colors of an image to the given number of colors. -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageconvertToIndexed(BufferedImage src, int nCol, Color transparency, Color bgcolor, RenderingHints hints) Converts the source image to an image with IndexColorModel and with a maximal number of colors.filter(BufferedImage src, BufferedImage dst) Performs the operation on a BufferedImage.Methods inherited from class com.day.image.AbstractBufferedImageOp
createCompatibleDestImage, getBounds2D, getPoint2D, getRenderingHints
-
Field Details
-
DITHER_NONE
Indicate the use of the simple bit width color reduction algorithm with no further dithering effects. -
DITHER_SIMPLE_ERROR_CORRECTION
Indicate the use of the simple bit width color reduction algorithm plus using the simple error correction algorithm.
-
-
Constructor Details
-
DitherOp
public DitherOp(int nCol, Color transparency, Color bgcolor, DitherOp.DitherAlgorithm algorithm, RenderingHints hints) Creates a newDitherOpinstance 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- TheColorof the color to be considered as transparent. This will be one of the nCol colors if notnull.bgcolor- TheColorof 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 benulland is not currently used.- Throws:
NullPointerException- if algorithm isnull.IllegalArgumentException- if nCol is less than 2.
-
-
Method Details
-
convertToIndexed
public static BufferedImage convertToIndexed(BufferedImage src, int nCol, Color transparency, Color bgcolor, 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- TheColorof the color to be considered as transparent. This will be one of the nCol colors if notnull.bgcolor- TheColorof 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 benulland is not currently used.- Returns:
- An image with the
IndexColorModelcolor model. If the source image already has theIndexColorModeland the number of colors are less than or equal tonColthe source image is returned else a new image according to the parameters is returned. - Throws:
NullPointerException- if the source image isnull.NullPointerException- if algorithm isnull.IllegalArgumentException- if nCol is less than 2.
-
filter
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:
filterin interfaceBufferedImageOp- Overrides:
filterin classAbstractBufferedImageOp- Parameters:
src- The src image to be resized.dst- The dest image into which to place the resized image. This may benullin 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:
IllegalArgumentException- if the dest image is the same as the src image.NullPointerException- if the src image isnull.
-