ewe.fx
Class ImageTool

java.lang.Object
  extended byewe.fx.ImageTool

public class ImageTool
extends Object

This class is used for two purposes. It can be used as an Image creator, creating images of a specific type. And it contains a set of useful static methods for manipulating images and image data.


Field Summary
 int[] createColorTable
          This is the optional color map that will be used for createImage().
 int createOptions
          These are the options that will be used for createImage().
static int SCALE_KEEP_ASPECT_RATIO
          An option for one of the scale() methods.
static int SCALE_ROUGH
          An option for the scale() methods.
static int SCALE_USE_EXACT_TYPE
          An option for one of the scale() methods.
 
Constructor Summary
ImageTool()
           
ImageTool(int createOptions)
           
ImageTool(int createOptions, int[] createColorTable)
           
 
Method Summary
static Image createCompatibleImage(ImageData source, int newWidth, int newHeight)
          Create a new Image that is compatible with the source ImageData.
static Image createCompatibleImage(ImageData source, int destinationImageDataType, int newWidth, int newHeight)
          Create a new Image that is compatible with the source ImageData, given a specific destination ImageData type.
 Image createImage(int width, int height)
          This creates an Image using the createOptions and createColorTable fields.
static Image createImageUsing(ImageTool it, int width, int height, int defaultOptions)
          If the specified ImageTool is null, then an image will be created using the default options, otherwise the specified ImageTool is used to create the image.
static void fromARGB(int[] argbData, int argbOffset, int argbScanLineLength, int destImageDataType, int destWidth, int[] destColorTable, Object destScanLines, int destOffset, int destScanLineLength, int numScanLines)
           
static int[] getGrayScaleColorTable(int imageDataType)
          Create and return a Gray scale color table.
static Object getScanLineBuffer(ImageData imageData, int numScanLines, Object oldBuffer)
          Create an int[] or byte[] buffer to read/write scan lines from the specified ImageData, re-using a previous buffer object if possible.
static int imageDataTypeToImageCreationOptions(int imageDataType)
          Convert an ImageData.TYPE_XXXX value to an Image.XXX_IMAGE option for creating an image.
static void imprint(ImageData big, ImageData small)
          This method "imprints" the data in the small ImageData into the big ImageData at the top left corner of the big ImageData.
static boolean isAGrayScaleImage(int imageDataType)
           
static boolean isAnIndexedImage(int imageDataType)
           
static int[] makeDefaultColorTable(int imageDataType)
          Create and return a Color Table for one of the TYPE_INDEXED_XXX types.
static void scale(ImageData source, ImageData destination)
          Scale a source Image so that it fits exactly into the destination Image using smooth scaling.
static void scale(ImageData source, ImageData destination, int options)
          Scale a source Image so that it fits exactly into the destination Image.
static Image scale(ImageData source, int newWidth, int newHeight, int scaleOptions)
          Scale an image and return a new image.
static void scaleSection(ImageData source, int newWidth, int newHeight, ImageData dest, int destX, int destY, int options)
          Scale an image and then place a section of the scaled image into an ImageData object.
static Image scaleSection(ImageData source, int newWidth, int newHeight, Rect destinationArea, int scaleOptions)
          Scale an image and return a section of the scaled image.
static Image scaleSourceSection(ImageData source, Rect sourceArea, int newWidth, int newHeight, int scaleOptions)
          Scale a section of an image and return a new image.
static void toARGB(int sourceImageDataType, int sourceWidth, int[] sourceColorTable, Object sourceScanLines, int sourceOffset, int sourceScanLineLength, int[] argbData, int argbOffset, int argbScanLineLength, int numScanLines)
           
static ImageData toImageData(IImage image)
          Return the best ImageData implementation for the specified IImage.
static int toImageDataType(int imageCreationOptionsOrImageDataType)
           
static boolean usesColorTable(int imageDataType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

createOptions

public int createOptions
These are the options that will be used for createImage(). By default it is zero.


createColorTable

public int[] createColorTable
This is the optional color map that will be used for createImage(). This is only necessary for the INDEX_xxx_IMAGE types.


SCALE_ROUGH

public static final int SCALE_ROUGH
An option for the scale() methods. It indicates that rough scaling should be done.

See Also:
Constant Field Values

SCALE_KEEP_ASPECT_RATIO

public static final int SCALE_KEEP_ASPECT_RATIO
An option for one of the scale() methods. It indicates that the aspect ration of the original image should be kept.

See Also:
Constant Field Values

SCALE_USE_EXACT_TYPE

public static final int SCALE_USE_EXACT_TYPE
An option for one of the scale() methods. It indicates that the created scaled image should be made to be of the same type as the source image.

See Also:
Constant Field Values
Constructor Detail

ImageTool

public ImageTool()

ImageTool

public ImageTool(int createOptions)

ImageTool

public ImageTool(int createOptions,
                 int[] createColorTable)
Method Detail

toImageDataType

public static int toImageDataType(int imageCreationOptionsOrImageDataType)

imageDataTypeToImageCreationOptions

public static int imageDataTypeToImageCreationOptions(int imageDataType)
                                               throws IllegalArgumentException
Convert an ImageData.TYPE_XXXX value to an Image.XXX_IMAGE option for creating an image.

Throws:
IllegalArgumentException

isAnIndexedImage

public static boolean isAnIndexedImage(int imageDataType)

isAGrayScaleImage

public static boolean isAGrayScaleImage(int imageDataType)

usesColorTable

public static boolean usesColorTable(int imageDataType)

createImage

public Image createImage(int width,
                         int height)
                  throws SystemResourceException,
                         ImageTypeNotSupportedException,
                         IllegalArgumentException
This creates an Image using the createOptions and createColorTable fields.

Throws:
SystemResourceException
ImageTypeNotSupportedException
IllegalArgumentException

createImageUsing

public static Image createImageUsing(ImageTool it,
                                     int width,
                                     int height,
                                     int defaultOptions)
                              throws SystemResourceException,
                                     ImageTypeNotSupportedException,
                                     IllegalArgumentException
If the specified ImageTool is null, then an image will be created using the default options, otherwise the specified ImageTool is used to create the image.

Throws:
SystemResourceException
ImageTypeNotSupportedException
IllegalArgumentException

createCompatibleImage

public static Image createCompatibleImage(ImageData source,
                                          int destinationImageDataType,
                                          int newWidth,
                                          int newHeight)
                                   throws IllegalArgumentException,
                                          SystemResourceException,
                                          ImageTypeNotSupportedException
Create a new Image that is compatible with the source ImageData, given a specific destination ImageData type.

Parameters:
source - The source ImageData.
destinationImageDataType - The desired new ImageData type. If this is one of the TYPE_INDEXED_XXX values, then the source ImageData must be of the exact same type so that the source color table can be transferred to the new image.
newWidth - The new width for the image.
newHeight - The new height for the image.
Returns:
The newly created image.
Throws:
IllegalArgumentException
SystemResourceException
ImageTypeNotSupportedException

createCompatibleImage

public static Image createCompatibleImage(ImageData source,
                                          int newWidth,
                                          int newHeight)
                                   throws IllegalArgumentException,
                                          SystemResourceException,
                                          ImageTypeNotSupportedException
Create a new Image that is compatible with the source ImageData.

Parameters:
source - The source ImageData.
newWidth - The new width for the image.
newHeight - The new height for the image.
Returns:
The newly created image.
Throws:
IllegalArgumentException
SystemResourceException
ImageTypeNotSupportedException

scale

public static Image scale(ImageData source,
                          int newWidth,
                          int newHeight,
                          int scaleOptions)
                   throws IllegalArgumentException,
                          SystemResourceException,
                          ImageTypeNotSupportedException
Scale an image and return a new image.

Parameters:
source - the source ImageData
newWidth - the new width for the image.
newHeight - the new height for the image.
scaleOptions - any of the SCALE_XXX options.
Returns:
a scaled image. The type of the scaled image may not be the same as the source ImageData if the image was scaled down and smooth scaling was selected.
Throws:
IllegalArgumentException
SystemResourceException
ImageTypeNotSupportedException

scaleSourceSection

public static Image scaleSourceSection(ImageData source,
                                       Rect sourceArea,
                                       int newWidth,
                                       int newHeight,
                                       int scaleOptions)
                                throws IllegalArgumentException,
                                       SystemResourceException,
                                       ImageTypeNotSupportedException
Scale a section of an image and return a new image.

Parameters:
source - the source ImageData
sourceArea - the area within the source image to scale.
newWidth - the new width for the image.
newHeight - the new height for the image.
scaleOptions - any of the SCALE_XXX options.
Returns:
a scaled image. The type of the scaled image may not be the same as the source ImageData if the image was scaled down and smooth scaling was selected.
Throws:
IllegalArgumentException
SystemResourceException
ImageTypeNotSupportedException

scaleSection

public static Image scaleSection(ImageData source,
                                 int newWidth,
                                 int newHeight,
                                 Rect destinationArea,
                                 int scaleOptions)
                          throws IllegalArgumentException,
                                 SystemResourceException,
                                 ImageTypeNotSupportedException
Scale an image and return a section of the scaled image.

Parameters:
source - the source ImageData
newWidth - the new width for the image.
newHeight - the new height for the image.
destinationArea - the area in the scaled image to return.
scaleOptions - any of the SCALE_XXX options.
Returns:
a scaled image. The type of the scaled image may not be the same as the source ImageData if the image was scaled down and smooth scaling was selected.
Throws:
IllegalArgumentException
SystemResourceException
ImageTypeNotSupportedException

scale

public static void scale(ImageData source,
                         ImageData destination)
Scale a source Image so that it fits exactly into the destination Image using smooth scaling.

Parameters:
source - The source ImageData
destination - The destination Image.

scale

public static void scale(ImageData source,
                         ImageData destination,
                         int options)
Scale a source Image so that it fits exactly into the destination Image.

Parameters:
source - The source ImageData
destination - The destination Image.
options - only SCALE_ROUGH or 0.

toImageData

public static ImageData toImageData(IImage image)
Return the best ImageData implementation for the specified IImage. If the IImage implements ImageData, then the image will be returned, otherwise the IImage will be wrapped in an RGBImageData value and returned.


scaleSection

public static void scaleSection(ImageData source,
                                int newWidth,
                                int newHeight,
                                ImageData dest,
                                int destX,
                                int destY,
                                int options)
Scale an image and then place a section of the scaled image into an ImageData object. The section will be the same width and height as the destination.

Parameters:
source - The source image.
newWidth - The width of the complete image after scaling.
newHeight - The heigh to the complete image after scaling.
dest - The destination imageData.
destX - The x point within the scaled image that should go into the destination image.
destY - The y point within the scaled image that should go into the destination image.
options - Options for scaling - so far only the SCALE_ROUGH is supported.

imprint

public static void imprint(ImageData big,
                           ImageData small)
This method "imprints" the data in the small ImageData into the big ImageData at the top left corner of the big ImageData.


getGrayScaleColorTable

public static int[] getGrayScaleColorTable(int imageDataType)
Create and return a Gray scale color table. The returned table should not be altered.


makeDefaultColorTable

public static int[] makeDefaultColorTable(int imageDataType)
Create and return a Color Table for one of the TYPE_INDEXED_XXX types. The returned table may be modified if necessary.


getScanLineBuffer

public static Object getScanLineBuffer(ImageData imageData,
                                       int numScanLines,
                                       Object oldBuffer)
Create an int[] or byte[] buffer to read/write scan lines from the specified ImageData, re-using a previous buffer object if possible.

Parameters:
imageData - The imageData to read/write scan lines.
numScanLines - The number of scan lines to read/write.
oldBuffer - An object to be re-used if possible.
Returns:
An int[] or byte[] big enough to hold the scan line data.

toARGB

public static void toARGB(int sourceImageDataType,
                          int sourceWidth,
                          int[] sourceColorTable,
                          Object sourceScanLines,
                          int sourceOffset,
                          int sourceScanLineLength,
                          int[] argbData,
                          int argbOffset,
                          int argbScanLineLength,
                          int numScanLines)

fromARGB

public static void fromARGB(int[] argbData,
                            int argbOffset,
                            int argbScanLineLength,
                            int destImageDataType,
                            int destWidth,
                            int[] destColorTable,
                            Object destScanLines,
                            int destOffset,
                            int destScanLineLength,
                            int numScanLines)