jwo.utils.gifutils
Class ImageQuant

java.lang.Object
  extended byjwo.utils.gifutils.ImageQuant

public class ImageQuant
extends Object

Class to quantize an RGB image into fewer colours. Suitable for convertion of a 24 bit to 8 bit colour image. Based on the 'Greedy Orthogonal Bipartition algorithm' by Xiaolin Wu. See Graphics Gems vol. II, pp.126-133.

Version:
2.1, 10th August, 2004.
Author:
Xiaolin Wu, converted into Java by Jo Wood.

Constructor Summary
ImageQuant(Image inputImage, int maxColours, int width, int height)
          Converts the given image into its quantised equivalent.
 
Method Summary
static byte[] getAlpha(int[] argbArray)
          Extracts the alpha component from an ARGB image array.
static byte[] getBlue(int[] argbArray)
          Extracts the blue component from an ARGB image array.
 String getErrorMessage()
          Reports the current error message or an empty string if none.
static byte[] getGreen(int[] argbArray)
          Extracts the green component from an ARGB image array.
 int[] getQuantImageArray()
          Returns the quantized image as an RGB array.
static byte[] getRed(int[] argbArray)
          Extracts the red component from an ARGB image array.
 boolean hasErrors()
          Reports whether conversion has any errors.
static int[] imageToArray(Image img, int numRows, int numCols)
          Converts a Java Image into an array holding ARGB values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageQuant

public ImageQuant(Image inputImage,
                  int maxColours,
                  int width,
                  int height)
Converts the given image into its quantised equivalent.

Parameters:
inputImage - Original Image to convert.
maxColours - Maximum number of colours to quantize.
width - Width of quantized image.
height - Height of quantized image.
Method Detail

getQuantImageArray

public int[] getQuantImageArray()
Returns the quantized image as an RGB array.

Returns:
1d array containing quantized colours in RGB order.

hasErrors

public boolean hasErrors()
Reports whether conversion has any errors.

Returns:
True if conversion has any errors.

getErrorMessage

public String getErrorMessage()
Reports the current error message or an empty string if none.

Returns:
Error message or blank if no errors.

imageToArray

public static int[] imageToArray(Image img,
                                 int numRows,
                                 int numCols)
Converts a Java Image into an array holding ARGB values. Can resize the image to an arbitrary width and height. Each item in the array is a 32 bit integer containing 8 bits each for ARGB.

Parameters:
img - Image to convert.
numRows - Number of rows for new image.
numCols - Number of columns for new image.
Returns:
Array holding ARGB values.

getAlpha

public static byte[] getAlpha(int[] argbArray)
Extracts the alpha component from an ARGB image array. Note that since the results are stored in a signed byte array, treating values as integers will result in -ve numbers if value >128. Convert value by adding 256 to -ve numbers.

Parameters:
argbArray - Array containing ARGB values.
Returns:
Array holding alpha component of image.

getRed

public static byte[] getRed(int[] argbArray)
Extracts the red component from an ARGB image array. Note that since the results are stored in a signed byte array, treating values as integers will result in -ve numbers if value >128. Convert value by adding 256 to -ve numbers.

Parameters:
argbArray - Array containing ARGB values.
Returns:
Array holding red component of image.

getGreen

public static byte[] getGreen(int[] argbArray)
Extracts the green component from an ARGB image array. Note that since the results are stored in a signed byte array, treating values as integers will result in -ve numbers if value >128. Convert value by adding 256 to -ve numbers.

Parameters:
argbArray - Array containing ARGB values.
Returns:
Array holding green component of image.

getBlue

public static byte[] getBlue(int[] argbArray)
Extracts the blue component from an ARGB image array. Note that since the results are stored in a signed byte array, treating values as integers will result in -ve numbers if value >128. Convert value by adding 256 to -ve numbers.

Parameters:
argbArray - Array containing ARGB values.
Returns:
Array holding blue component of image.


Copyright Jo Wood, 1996-2004, last modified, 3rd September, 2004