javax.media.jai
Class RasterFactory

java.lang.Object
  extended byjavax.media.jai.RasterFactory

public class RasterFactory
extends Object

A convenience class for the construction of various types of WritableRaster and SampleModel objects.

This class provides the capability of creating Rasters with the enumerated data types in the java.awt.image.DataBuffer.

In some cases, instances of ComponentSampleModelJAI, a subclass of java.awt.image.ComponentSampleModel are instantiated instead of java.awt.image.BandedSampleModel in order to work around bugs in the current release of the Java 2 SDK.


Constructor Summary
RasterFactory()
           
 
Method Summary
static WritableRaster createBandedRaster(DataBuffer dataBuffer, int width, int height, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
          Creates a WritableRaster based on a ComponentSampleModel with the specified DataBuffer, width, height, scanline stride, bank indices, and band offsets.
static WritableRaster createBandedRaster(int dataType, int width, int height, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
          Creates a WritableRaster based on a ComponentSampleModel with the specified data type, width, height, scanline stride, bank indices and band offsets.
static WritableRaster createBandedRaster(int dataType, int width, int height, int bands, Point location)
          Creates a WritableRaster based on a ComponentSampleModel with the specified data type, width, height, and number of bands.
static SampleModel createBandedSampleModel(int dataType, int width, int height, int numBands)
          Creates a banded SampleModel with a given data type, width, height, and number of bands.
static SampleModel createBandedSampleModel(int dataType, int width, int height, int numBands, int[] bankIndices, int[] bandOffsets)
          Creates a banded SampleModel with a given data type, width, height, number of bands, bank indices, and band offsets.
static ComponentColorModel createComponentColorModel(int dataType, ColorSpace colorSpace, boolean useAlpha, boolean premultiplied, int transparency)
          Creates a component-based ColorModel with a given data type, color space, and transparency type.
static SampleModel createComponentSampleModel(SampleModel sm, int dataType, int width, int height, int numBands)
          Creates a component SampleModel with a given data type, width, height, and number of bands that is "compatible" with a given SampleModel.
static WritableRaster createInterleavedRaster(DataBuffer dataBuffer, int width, int height, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
          Creates a WritableRaster based on a PixelInterleavedSampleModel with the specified DataBuffer, width, height, scanline stride, pixel stride, and band offsets.
static WritableRaster createInterleavedRaster(int dataType, int width, int height, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
          Creates a WritableRaster based on a PixelInterleavedSampleModel with the specified data type, width, height, scanline stride, pixel stride, and band offsets.
static WritableRaster createInterleavedRaster(int dataType, int width, int height, int numBands, Point location)
          Creates a WritableRaster based on a PixelInterleavedSampleModel with the specified data type, width, height, and number of bands.
static WritableRaster createPackedRaster(DataBuffer dataBuffer, int width, int height, int scanlineStride, int[] bandMasks, Point location)
          Creates a WritableRaster based on a SinglePixelPackedSampleModel with the specified DataBuffer, width, height, scanline stride, and band masks.
static WritableRaster createPackedRaster(DataBuffer dataBuffer, int width, int height, int bitsPerPixel, Point location)
          Creates a WritableRaster based on a MultiPixelPackedSampleModel with the specified DataBuffer, width, height, and bits per pixel.
static WritableRaster createPackedRaster(int dataType, int width, int height, int[] bandMasks, Point location)
          Creates a WritableRaster based on a SinglePixelPackedSampleModel with the specified data type, width, height, and band masks.
static WritableRaster createPackedRaster(int dataType, int width, int height, int numBands, int bitsPerBand, Point location)
          Creates a WritableRaster based on a packed SampleModel with the specified data type, width, height, number of bands, and bits per band.
static SampleModel createPixelInterleavedSampleModel(int dataType, int width, int height, int numBands)
          Creates a pixel interleaved SampleModel with a given data type, width, height, and number of bands.
static SampleModel createPixelInterleavedSampleModel(int dataType, int width, int height, int pixelStride, int scanlineStride, int[] bandOffsets)
          Creates a pixel interleaved SampleModel with a given data type, width, height, pixel and scanline strides, and band offsets.
static Raster createRaster(SampleModel sampleModel, DataBuffer dataBuffer, Point location)
          Creates a WritableRaster with the specified SampleModel and DataBuffer.
static WritableRaster createWritableChild(WritableRaster raster, int parentX, int parentY, int width, int height, int childMinX, int childMinY, int[] bandList)
          Returns a new WritableRaster which shares all or part of the supplied WritableRaster's DataBuffer.
static WritableRaster createWritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Point location)
          Creates a WritableRaster with the specified SampleModel and DataBuffer.
static WritableRaster createWritableRaster(SampleModel sampleModel, Point location)
          Creates a WritableRaster with the specified SampleModel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RasterFactory

public RasterFactory()
Method Detail

createInterleavedRaster

public static WritableRaster createInterleavedRaster(int dataType,
                                                     int width,
                                                     int height,
                                                     int numBands,
                                                     Point location)
Creates a WritableRaster based on a PixelInterleavedSampleModel with the specified data type, width, height, and number of bands.

The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used. The dataType parameter should be one of the enumerated values defined in the DataBuffer class.

Parameters:
dataType - The data type of the SampleModel, one of DataBuffer.TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
numBands - The desired number of bands.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - if numbands is <1.

createInterleavedRaster

public static WritableRaster createInterleavedRaster(int dataType,
                                                     int width,
                                                     int height,
                                                     int scanlineStride,
                                                     int pixelStride,
                                                     int[] bandOffsets,
                                                     Point location)
Creates a WritableRaster based on a PixelInterleavedSampleModel with the specified data type, width, height, scanline stride, pixel stride, and band offsets. The number of bands is inferred from bandOffsets.length.

The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used. The dataType parameter should be one of the enumerated values defined in the DataBuffer class.

Parameters:
dataType - The data type of the WritableRaster, one of the enumerated dataType values in java.awt.image.DataBuffer.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
scanlineStride - The desired scanline stride.
pixelStride - The desired pixel stride.
bandOffsets - An array of ints indicating the relative offsets of the bands within a pixel.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - if bandOffsets is null, dataType is not one of the enumerated dataType value of java.awt.image.DataBuffer.
IllegalArgumentException - if the number of array elements required by the returned WritableRaster would exceed Integer.MAX_VALUE.

createBandedRaster

public static WritableRaster createBandedRaster(int dataType,
                                                int width,
                                                int height,
                                                int bands,
                                                Point location)
Creates a WritableRaster based on a ComponentSampleModel with the specified data type, width, height, and number of bands.

Note that the Raster's SampleModel will be of type ComponentSampleModel, not BandedSampleModel as might be expected.

The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used. The dataType parameter should be one of the enumerated values defined in the DataBuffer class.

Parameters:
dataType - The data type of the WritableRaster, one of the enumerated dataType values in java.awt.image.DataBuffer.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
bands - The desired number of bands.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - if bands is <1.

createBandedRaster

public static WritableRaster createBandedRaster(int dataType,
                                                int width,
                                                int height,
                                                int scanlineStride,
                                                int[] bankIndices,
                                                int[] bandOffsets,
                                                Point location)
Creates a WritableRaster based on a ComponentSampleModel with the specified data type, width, height, scanline stride, bank indices and band offsets. The number of bands is inferred from bankIndices.length and bandOffsets.length, which must be the same.

Note that the Raster's SampleModel will be of type ComponentSampleModel, not BandedSampleModel as might be expected.

The upper left corner of the WritableRaster is given by the location argument. The dataType parameter should be one of the enumerated values defined in the DataBuffer class.

Parameters:
dataType - The data type of the WritableRaster, one of the enumerated dataType values in java.awt.image.DataBuffer.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
scanlineStride - The desired scanline stride.
bankIndices - An array of ints indicating the bank index for each band.
bandOffsets - An array of ints indicating the relative offsets of the bands within a pixel.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - if bankIndices is null, bandOffsets is null, if bandOffsets.length is != bankIndices.length, if dataType is not one of the enumerated datatypes of java.awt.image.DataBuffer.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType,
                                                int width,
                                                int height,
                                                int[] bandMasks,
                                                Point location)
Creates a WritableRaster based on a SinglePixelPackedSampleModel with the specified data type, width, height, and band masks. The number of bands is inferred from bandMasks.length.

The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used. The dataType parameter should be one of the enumerated values defined in the DataBuffer class.

Parameters:
dataType - The data type of the WritableRaster, one of DataBuffer.TYPE_BYTE, TYPE_USHORT or TYPE_INT.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - is thrown if the dataType is not of either TYPE_BYTE or TYPE_USHORT or TYPE_INT.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType,
                                                int width,
                                                int height,
                                                int numBands,
                                                int bitsPerBand,
                                                Point location)
Creates a WritableRaster based on a packed SampleModel with the specified data type, width, height, number of bands, and bits per band. If the number of bands is one, the SampleModel will be a MultiPixelPackedSampleModel.

If the number of bands is more than one, the SampleModel will be a SinglePixelPackedSampleModel, with each band having bitsPerBand bits. In either case, the requirements on dataType and bitsPerBand imposed by the corresponding SampleModel must be met.

The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used. The dataType parameter should be one of the enumerated values defined in the DataBuffer class.

Parameters:
dataType - The data type of the WritableRaster, one of DataBuffer.TYPE_BYTE, TYPE_USHORT or TYPE_INT.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
numBands - The desired number of bands.
bitsPerBand - The number of bits per band.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - is thrown if the dataType is not of either TYPE_BYTE or TYPE_USHORT or TYPE_INT.
IllegalArgumentException - is thrown if bitsPerBand is negative or zero.

createInterleavedRaster

public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer,
                                                     int width,
                                                     int height,
                                                     int scanlineStride,
                                                     int pixelStride,
                                                     int[] bandOffsets,
                                                     Point location)
Creates a WritableRaster based on a PixelInterleavedSampleModel with the specified DataBuffer, width, height, scanline stride, pixel stride, and band offsets. The number of bands is inferred from bandOffsets.length. The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used.

Parameters:
dataBuffer - The DataBuffer to be used.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
scanlineStride - The desired scanline stride.
pixelStride - The desired pixel stride.
bandOffsets - An array of ints indicating the relative offsets of the bands within a pixel.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - if bandOffsets is null, if pixelStride*width is > scanlineStride, if dataTypeof the DataBuffer is not one the enumerated dataType value of java.awt.image.DataBuffer.

createBandedRaster

public static WritableRaster createBandedRaster(DataBuffer dataBuffer,
                                                int width,
                                                int height,
                                                int scanlineStride,
                                                int[] bankIndices,
                                                int[] bandOffsets,
                                                Point location)
Creates a WritableRaster based on a ComponentSampleModel with the specified DataBuffer, width, height, scanline stride, bank indices, and band offsets. The number of bands is inferred from bankIndices.length and bandOffsets.length, which must be the same. The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used.

Note that the Raster's SampleModel will be of type ComponentSampleModel, not BandedSampleModel as might be expected.

Parameters:
dataBuffer - The DataBuffer to be used.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
scanlineStride - The desired scanline stride.
bankIndices - An array of ints indicating the bank index for each band.
bandOffsets - An array of ints indicating the relative offsets of the bands within a pixel.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - if bankIndices is null, if bandOffsets is null, if bandOffsets.length is != bankIndices.length, if dataType is not one of the enumerated datatypes of java.awt.image.DataBuffer.

createPackedRaster

public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
                                                int width,
                                                int height,
                                                int scanlineStride,
                                                int[] bandMasks,
                                                Point location)
Creates a WritableRaster based on a SinglePixelPackedSampleModel with the specified DataBuffer, width, height, scanline stride, and band masks. The number of bands is inferred from bandMasks.length. The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used.

Parameters:
dataBuffer - The DataBuffer to be used.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
scanlineStride - The desired scanline stride.
bandMasks - An array of ints indicating the bitmasks for each band within a pixel.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - is thrown if the dataType is not of either TYPE_BYTE or TYPE_USHORT or TYPE_INT.

createPackedRaster

public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
                                                int width,
                                                int height,
                                                int bitsPerPixel,
                                                Point location)
Creates a WritableRaster based on a MultiPixelPackedSampleModel with the specified DataBuffer, width, height, and bits per pixel. The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used.

Parameters:
dataBuffer - The DataBuffer to be used.
width - The desired width of the WritableRaster.
height - The desired height of the WritableRaster.
bitsPerPixel - The desired pixel depth.
location - A Point indicating the starting coordinates of the WritableRaster.
Throws:
IllegalArgumentException - is thrown if the dataType of the dataBuffer is not of either TYPE_BYTE or TYPE_USHORT or TYPE_INT.

createRaster

public static Raster createRaster(SampleModel sampleModel,
                                  DataBuffer dataBuffer,
                                  Point location)
Creates a WritableRaster with the specified SampleModel and DataBuffer. The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used.

Parameters:
sampleModel - The SampleModel to be used.
dataBuffer - The DataBuffer to be used.
location - A Point indicating the starting coordinates of the WritableRaster.

createWritableRaster

public static WritableRaster createWritableRaster(SampleModel sampleModel,
                                                  Point location)
Creates a WritableRaster with the specified SampleModel. The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used.

Parameters:
sampleModel - The SampleModel to use.
location - A Point indicating the starting coordinates of the WritableRaster.

createWritableRaster

public static WritableRaster createWritableRaster(SampleModel sampleModel,
                                                  DataBuffer dataBuffer,
                                                  Point location)
Creates a WritableRaster with the specified SampleModel and DataBuffer. The upper left corner of the WritableRaster is given by the location argument. If location is null, (0, 0) will be used.

Parameters:
sampleModel - The SampleModel to be used.
dataBuffer - The DataBuffer to be used.
location - A Point indicating the starting coordinates of the WritableRaster.

createWritableChild

public static WritableRaster createWritableChild(WritableRaster raster,
                                                 int parentX,
                                                 int parentY,
                                                 int width,
                                                 int height,
                                                 int childMinX,
                                                 int childMinY,
                                                 int[] bandList)
Returns a new WritableRaster which shares all or part of the supplied WritableRaster's DataBuffer. The new WritableRaster will possess a reference to the supplied WritableRaster, accessible through its getParent() and getWritableParent() methods.

This method provides a workaround for a bug in the implementation of WritableRaster.createWritableChild in the initial relase of the Java2 platform.

The parentX, parentY, width and height parameters form a Rectangle in this WritableRaster's coordinate space, indicating the area of pixels to be shared. An error will be thrown if this Rectangle is not contained with the bounds of the supplied WritableRaster.

The new WritableRaster may additionally be translated to a different coordinate system for the plane than that used by the supplied WritableRaster. The childMinX and childMinY parameters give the new (x, y) coordinate of the upper-left pixel of the returned WritableRaster; the coordinate (childMinX, childMinY) in the new WritableRaster will map to the same pixel as the coordinate (parentX, parentY) in the supplied WritableRaster.

The new WritableRaster may be defined to contain only a subset of the bands of the supplied WritableRaster, possibly reordered, by means of the bandList parameter. If bandList is null, it is taken to include all of the bands of the supplied WritableRaster in their current order.

To create a new WritableRaster that contains a subregion of the supplied WritableRaster, but shares its coordinate system and bands, this method should be called with childMinX equal to parentX, childMinY equal to parentY, and bandList equal to null.

Parameters:
raster - The parent WritableRaster.
parentX - X coordinate of the upper left corner of the shared rectangle in this WritableRaster's coordinates.
parentY - Y coordinate of the upper left corner of the shared rectangle in this WritableRaster's coordinates.
width - Width of the shared rectangle starting at (parentX, parentY).
height - Height of the shared rectangle starting at (parentX, parentY).
childMinX - X coordinate of the upper left corner of the returned WritableRaster.
childMinY - Y coordinate of the upper left corner of the returned WritableRaster.
bandList - Array of band indices, or null to use all bands.
Throws:
RasterFormatException - if the subregion is outside of the raster bounds.

createBandedSampleModel

public static SampleModel createBandedSampleModel(int dataType,
                                                  int width,
                                                  int height,
                                                  int numBands,
                                                  int[] bankIndices,
                                                  int[] bandOffsets)
Creates a banded SampleModel with a given data type, width, height, number of bands, bank indices, and band offsets.

Note that the returned SampleModel will be of type ComponentSampleModel, not BandedSampleModel as might be expected. Its behavior will be equivalent to that of a BandedSampleModel, and in particular its pixel stride will always be 1.

Parameters:
dataType - The data type of the SampleModel, one of DataBuffer.TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
width - The desired width of the SampleModel.
height - The desired height of the SampleModel.
numBands - The desired number of bands.
bankIndices - An array of ints indicating the bank index for each band.
bandOffsets - An array of ints indicating the relative offsets of the bands within a pixel.
Throws:
IllegalArgumentException - if numBands is <1, if bandOffsets.length is != bankIndices.length.

createBandedSampleModel

public static SampleModel createBandedSampleModel(int dataType,
                                                  int width,
                                                  int height,
                                                  int numBands)
Creates a banded SampleModel with a given data type, width, height, and number of bands. The bank indices and band offsets are set to default values.

Note that the returned SampleModel will be of type ComponentSampleModel, not BandedSampleModel as might be expected. Its behavior will be equivalent to that of a BandedSampleModel, and in particular its pixel stride will always be 1.

Parameters:
dataType - The data type of the SampleModel, one of DataBuffer.TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
width - The desired width of the SampleModel.
height - The desired height of the SampleModel.
numBands - The desired number of bands.

createPixelInterleavedSampleModel

public static SampleModel createPixelInterleavedSampleModel(int dataType,
                                                            int width,
                                                            int height,
                                                            int pixelStride,
                                                            int scanlineStride,
                                                            int[] bandOffsets)
Creates a pixel interleaved SampleModel with a given data type, width, height, pixel and scanline strides, and band offsets.

Parameters:
dataType - The data type of the SampleModel, one of DataBuffer.TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
width - The desired width of the SampleModel.
height - The desired height of the SampleModel.
pixelStride - The desired pixel stride.
scanlineStride - The desired scanline stride.
bandOffsets - An array of ints indicating the relative offsets of the bands within a pixel.
Throws:
IllegalArgumentException - if bandOffsets is null, if the pixelStride*width is > than scanlineStride, if the dataType is not one of the above mentioned datatypes.

createPixelInterleavedSampleModel

public static SampleModel createPixelInterleavedSampleModel(int dataType,
                                                            int width,
                                                            int height,
                                                            int numBands)
Creates a pixel interleaved SampleModel with a given data type, width, height, and number of bands. The pixel stride, scanline stride, and band offsets are set to default values.

Parameters:
dataType - The data type of the SampleModel, one of DataBuffer.TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
width - The desired width of the SampleModel.
height - The desired height of the SampleModel.
numBands - The desired number of bands.
Throws:
IllegalArgumentException - if numBands is <1.

createComponentSampleModel

public static SampleModel createComponentSampleModel(SampleModel sm,
                                                     int dataType,
                                                     int width,
                                                     int height,
                                                     int numBands)
Creates a component SampleModel with a given data type, width, height, and number of bands that is "compatible" with a given SampleModel.

Parameters:
sm - The SampleModel to be compatible with.
dataType - The data type of the SampleModel, one of DataBuffer.TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
width - The desired width of the SampleModel.
height - The desired height of the SampleModel.
numBands - The desired number of bands.

createComponentColorModel

public static ComponentColorModel createComponentColorModel(int dataType,
                                                            ColorSpace colorSpace,
                                                            boolean useAlpha,
                                                            boolean premultiplied,
                                                            int transparency)
Creates a component-based ColorModel with a given data type, color space, and transparency type. Currently this method does not support data type DataBuffer.TYPE_SHORT. If useAlpha is false, both premultiplied and transparency input are ignored and they are set to be false and Transparency.OPQAUE , respectively.

Parameters:
dataType - The data type of the ColorModel, one of DataBuffer.TYPE_BYTE, TYPE_USHORT, TYPE_INT, TYPE_FLOAT, or TYPE_DOUBLE.
colorSpace - An instance of ColorSpace.
useAlpha - true if alpha is to be used.
premultiplied - true if alpha values are premultiplied. If useAlpha is false, the value of premultiplied is ignored.
transparency - One of Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT. If useAlpha is false, the value of transparency is ignored. If useAlpha is true, transparency must not equal Transparency.OPQAUE.
Throws:
IllegalArgumentExceptionException - if colorSpace is null.
IllegalArgumentException - if transparency has an unknown value, if useAlpha == true but transparency == Transparency.OPAQUE, or if dataType is not one of the standard types listed above.