Class QuantizeFilter
java.lang.Object
org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.AbstractBufferedImageOp
org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.WholeImageFilter
org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.QuantizeFilter
- All Implemented Interfaces:
BufferedImageOp,Cloneable
A filter which quantizes an image to a set number of colors - useful for producing
images which are to be encoded using an index color model. The filter can perform
Floyd-Steinberg error-diffusion dithering if required. At present, the quantization
is done using an octtree algorithm but I eventually hope to add more quantization
methods such as median cut. Note: at present, the filter produces an image which
uses the RGB color model (because the application it was written for required it).
I hope to extend it to produce an IndexColorModel by request.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int[]Floyd-Steinberg dithering matrix.Fields inherited from class org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.WholeImageFilter
originalSpace, transformedSpace -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int[]filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) Actually filter the pixels.booleanReturn the dithering setting.intGet the number of colors to quantize to.booleanReturn the serpentine setting.voidquantize(int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine) voidsetDither(boolean dither) Set whether to use dithering or not.voidsetNumColors(int numColors) Set the number of colors to quantize to.voidsetSerpentine(boolean serpentine) Set whether to use a serpentine pattern for return or not.toString()Methods inherited from class org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.WholeImageFilter
filter, transformSpaceMethods inherited from class org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.AbstractBufferedImageOp
clone, createCompatibleDestImage, getBounds2D, getPoint2D, getRenderingHints, getRGB, setRGB
-
Field Details
-
matrix
protected static final int[] matrixFloyd-Steinberg dithering matrix.
-
-
Constructor Details
-
QuantizeFilter
public QuantizeFilter()
-
-
Method Details
-
setNumColors
public void setNumColors(int numColors) Set the number of colors to quantize to.- Parameters:
numColors- the number of colors. The default is 256.
-
getNumColors
public int getNumColors()Get the number of colors to quantize to.- Returns:
- the number of colors.
-
setDither
public void setDither(boolean dither) Set whether to use dithering or not. If not, the image is posterized.- Parameters:
dither- true to use dithering
-
getDither
public boolean getDither()Return the dithering setting.- Returns:
- the current setting
-
setSerpentine
public void setSerpentine(boolean serpentine) Set whether to use a serpentine pattern for return or not. This can reduce 'avalanche' artifacts in the output.- Parameters:
serpentine- true to use serpentine pattern
-
getSerpentine
public boolean getSerpentine()Return the serpentine setting.- Returns:
- the current setting
-
quantize
public void quantize(int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine) -
filterPixels
Description copied from class:WholeImageFilterActually filter the pixels.- Specified by:
filterPixelsin classWholeImageFilter- Parameters:
width- the image widthheight- the image heightinPixels- the image pixelstransformedSpace- the output bounds- Returns:
- the output pixels
-
toString
-