com.davisor.graphics
Class FloydSteinbergImageFilter

java.lang.Object
  extended byjava.awt.image.ImageFilter
      extended byjava.awt.image.RGBImageFilter
          extended bycom.davisor.graphics.FloydSteinbergImageFilter
All Implemented Interfaces:
java.lang.Cloneable, java.awt.image.ImageConsumer

public class FloydSteinbergImageFilter
extends java.awt.image.RGBImageFilter

Reduces colors and dithers image using Octree image reducer. First color reduction is done, after wchich dithering takes place.


Field Summary
protected  OctreeColorReducer M_octree
          The octree
 
Fields inherited from class java.awt.image.RGBImageFilter
canFilterIndexColorModel, newmodel, origmodel
 
Fields inherited from class java.awt.image.ImageFilter
consumer
 
Fields inherited from interface java.awt.image.ImageConsumer
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT
 
Constructor Summary
FloydSteinbergImageFilter(java.awt.image.RenderedImage image, int maxNumOfColors)
          This constructor prepares octree color reduction.
 
Method Summary
protected  int addRGBErrors(int originalRGB, int redError, int greenError, int blueError)
          Helper method for adding to a RGB values color components given individualy.
protected  int blueError(int firstRGB, int secondRGB)
          Helper method for defining red error Error is integer between -255 and 255.
protected  void ditherImage(java.awt.image.RenderedImage image)
          This is the main loop, responsible for dithering the image.
 int filterRGB(int x, int y, int rgb)
          Return filtered RGB value In case of invalid index will return black (0).
protected  int findNearestColor(int currentColor)
          This method will find the nearest color from the octree color palette as seen usnig squared error.
 int[][] getAllRGBValues()
          Returns all the RGB values for the whole dithered image
protected  int greenError(int firstRGB, int secondRGB)
          Helper method for defining red error Error is integer between -255 and 255.
protected  int[][] prepareRGBArray(java.awt.image.RenderedImage image)
          This helper method can be used to cnovert RenderedImage to int array containing RGB values of the corresponding pixels.
protected  int redError(int firstRGB, int secondRGB)
          Helper method for defining red error Error is integer between -255 and 255.
 
Methods inherited from class java.awt.image.RGBImageFilter
filterIndexColorModel, filterRGBPixels, setColorModel, setPixels, setPixels, substituteColorModel
 
Methods inherited from class java.awt.image.ImageFilter
clone, getFilterInstance, imageComplete, resendTopDownLeftRight, setDimensions, setHints, setProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

M_octree

protected OctreeColorReducer M_octree
The octree

Constructor Detail

FloydSteinbergImageFilter

public FloydSteinbergImageFilter(java.awt.image.RenderedImage image,
                                 int maxNumOfColors)
This constructor prepares octree color reduction. In addition the image is scanne through and dithered RGB values are prepared.

Method Detail

filterRGB

public int filterRGB(int x,
                     int y,
                     int rgb)
Return filtered RGB value In case of invalid index will return black (0).


prepareRGBArray

protected int[][] prepareRGBArray(java.awt.image.RenderedImage image)
This helper method can be used to cnovert RenderedImage to int array containing RGB values of the corresponding pixels.

Parameters:
image - from which RGB values should be extracted
Returns:
integer array containing RGB values

getAllRGBValues

public int[][] getAllRGBValues()
Returns all the RGB values for the whole dithered image

Returns:
integer array containing RGB values for dithered image

ditherImage

protected void ditherImage(java.awt.image.RenderedImage image)
This is the main loop, responsible for dithering the image.

Error propagation is done using the standard mask:

 0 * 7
 3 5 1
 


redError

protected int redError(int firstRGB,
                       int secondRGB)
Helper method for defining red error Error is integer between -255 and 255.


greenError

protected int greenError(int firstRGB,
                         int secondRGB)
Helper method for defining red error Error is integer between -255 and 255.


blueError

protected int blueError(int firstRGB,
                        int secondRGB)
Helper method for defining red error Error is integer between -255 and 255.


addRGBErrors

protected int addRGBErrors(int originalRGB,
                           int redError,
                           int greenError,
                           int blueError)
Helper method for adding to a RGB values color components given individualy. This method ensures that colors cannot exceed their minimum and maximum values (0 and 255). The alfa channel in return value is set to 0x00.

Parameters:
originalRGB - to which rgb components are to be added
redError - between 0 and 255
greenError - between 0 and 255
blueError - between 0 and 255
Returns:
summed up color

findNearestColor

protected int findNearestColor(int currentColor)
This method will find the nearest color from the octree color palette as seen usnig squared error.



Copyright © 2001-2004 Davisor Oy. All Rights Reserved.