railo.runtime.img.filter
Class QuantizeFilter

java.lang.Object
  extended by railo.runtime.img.filter.AbstractBufferedImageOp
      extended by railo.runtime.img.filter.WholeImageFilter
          extended by railo.runtime.img.filter.QuantizeFilter
All Implemented Interfaces:
BufferedImageOp, Cloneable, DynFiltering

public class QuantizeFilter
extends WholeImageFilter
implements DynFiltering

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.


Constructor Summary
QuantizeFilter()
           
 
Method Summary
 BufferedImage filter(BufferedImage src, Struct parameters)
           
 boolean getDither()
          Return the dithering setting
 int getNumColors()
          Get the number of colors to quantize to.
 boolean getSerpentine()
          Return the serpentine setting
 void quantize(int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine)
           
 void setDither(boolean dither)
          Set whether to use dithering or not.
 void setNumColors(int numColors)
          Set the number of colors to quantize to.
 void setSerpentine(boolean serpentine)
          Set whether to use a serpentine pattern for return or not.
 String toString()
           
 
Methods inherited from class railo.runtime.img.filter.WholeImageFilter
filter
 
Methods inherited from class railo.runtime.img.filter.AbstractBufferedImageOp
clone, createCompatibleDestImage, getBounds2D, getPoint2D, getRenderingHints, getRGB, setRGB
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QuantizeFilter

public QuantizeFilter()
Method Detail

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)

toString

public String toString()
Overrides:
toString in class Object

filter

public BufferedImage filter(BufferedImage src,
                            Struct parameters)
                     throws PageException
Specified by:
filter in interface DynFiltering
Overrides:
filter in class WholeImageFilter
Throws:
PageException


Copyright © 2012 Railo