Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.awt.image.Raster

java.lang.Object
    |
    +----java.awt.image.Raster
Subclasses:
WritableRaster

public class Raster
extends Object
This class represents a rectanglular array of pixels and provides methods for retrieving image data. It contains a DataBuffer object that holds a buffer of image data in some format, a SampleModel which describes the format is capable of storing and retrieving Samples from the DataBuffer, and a Rect that defines the coordinate space of the raster (upper left corner, width and height). The Raster's coordinate space is determined by a point and a rectangle. The Point is the origin of the base Raster (this raster's ancestor that has no parent.) The rectangle called the bounds determines the span over which this Raster can process pixel and sample requests. A point and a rectangle are needed so that sub rasters can use the same DataBuffer and SampleModel as their parent rasters. The point marks the origin of the SampleModel in the sub raster's coordinate space (possibly translated from the parent's coordinate space.) The rectangle defines the span of the sub raster. For base Rasters, the upper left corner of the bounds rectangle is equal to the origin. All constructors are protected. The correct way to create a Raster is to use one of the static create methods defined in this class.


Field Summary
int  baseRasterOriginX
The X offset of the base Raster from the global origin.
int  baseRasterOriginY
The Y offset of the base Raster from the global origin.
DataBuffer  dataBuffer
DataBuffer that stores image data.
int  height
The height of the Raster.
int  minX
The X offset from the global origin.
int  minY
The Y offset from the global origin.
int  numBands
The number of bands in the raster.
int  numDataElements
The number of data elements per pixel.
Raster  parent
If non-null, the parent of this Raster.
SampleModel  sampleModel
SampleModel that describes how pixels are stored in the DataBuffer.
int  width
The width of the Raster.
 

Constructor Summary
 Raster(SampleModel sampleModel, Point origin)
Constructs a Raster with the given SampleModel.
 Raster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin)
Constructs a Raster with the given SampleModel and DataBuffer.
 Raster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point baseOrigin, Raster parent)
Constructs a Raster with the given SampleModel, DataBuffer, and parent.
 

Method Summary
WritableRaster  createCompatibleWritableRaster()
Create a compatible WritableRaster the same size as this Raster with the same SampleModel and a new initialized DataBuffer.
WritableRaster  createCompatibleWritableRaster(int w, int h)
Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer.
WritableRaster  createCompatibleWritableRaster(Rectangle rect)
Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer.
WritableRaster  createCompatibleWritableRaster(int x, int y, int w, int h)
Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer.
static WritableRaster  createComponentRaster(int dataType, int w, int h, int n, Point location)
Creates a Raster based on a ComponentSampleModel with the specified data type, width, height, and number of bands.
static WritableRaster  createComponentRaster(int dataType, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
Creates a Raster based on a ComponentSampleModel with the specified data type, width, height, scanline stride, pixel stride, and band offsets.
static WritableRaster  createComponentRaster(int dataType, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, DataBuffer dataBuffer, Point location)
Creates a Raster based on a ComponentSampleModel with the specified data type, width, height, scanline stride, pixel stride, band offsets, and data buffer.
static WritableRaster  createPackedRaster(int dataType, int w, int h, int[] bandMasks, Point location)
Creates a Raster based on a SinglePixelPackedSampleModel with the specified data type, width, height, and band masks.
static WritableRaster  createPackedRaster(int dataType, int w, int h, int n, int bitsPerBand, Point location)
Creates a Raster based on a packed SampleModel with the specified data type, width, height, number of bands, and bits per band.
static WritableRaster  createPackedRaster(int dataType, int w, int h, int scanlineStride, int[] bandMasks, DataBuffer dataBuffer, Point location)
Creates a Raster based on a SinglePixelPackedSampleModel with the specified data type, width, height, scanline stride, band masks, and data buffer.
static WritableRaster  createPackedRaster(int dataType, int w, int h, int bitsPerPixel, DataBuffer dataBuffer, Point location)
Creates a Raster based on a MultiPixelPackedSampleModel with the specified data type, width, height, bits per pixel, and data buffer.
static Raster  createRaster(SampleModel sm, DataBuffer db, Point location)
Creates a Raster with the specified SampleModel
Raster  createSubRaster(Rectangle rect)
Returns a Raster which references this Raster's DataBuffer
Raster  createSubRaster(int x, int y, int width, int height)
Returns a Raster which references this Raster's DataBuffer.
Raster  createSubRaster(int x, int y, int width, int height, int x0, int y0, int[] bandList)
Returns a translated SubRaster which references this Raster's DataBuffer.
Raster  createTranslatedRaster(Point location)
Create a Raster with the same size, SampleModel and DataBuffer as this one, but with a different location.
static WritableRaster  createWritableRaster(SampleModel sm, Point location)
Creates a WritableRaster with the specified SampleModel
static WritableRaster  createWritableRaster(SampleModel sm, DataBuffer db, Point location)
Creates a WritableRaster with the specified SampleModel and DataBuffer
int  getBaseRasterOriginX()
Returns the X coord of the origin of the base Raster in this Raster's coordinate system.
int  getBaseRasterOriginY()
Returns the Y coord of the origin of the base Raster in this Raster's coordinate system.
int  getBaseSubRasterOffsetX()
 
int  getBaseSubRasterOffsetY()
 
Rectangle  getBounds()
Returns the bounds Rectangle of this Raster.
DataBuffer  getDataBuffer()
Returns the DataBuffer associated with this Raster.
int  getHeight()
Returns the height in pixels of the Raster.
int  getMinX()
Returns the minimum X coordinate (in the Raster's coordinate system).
int  getMinY()
Returns the minimum Y coordinate (in the Raster's coordinate system).
int  getNumBands()
Returns the number of bands in this raster.
int  getNumDataElements()
Returns the number of data elements needed to store one pixel.
Raster  getParent()
Returns the parent Raster (if any) of this Raster
int[]  getPixel(int x, int y, int[] iarray)
Returns the samples in an array of int for the specified pixel.
float[]  getPixel(int x, int y, float[] farray)
Returns the samples in an array of Float for the specified pixel.
double[]  getPixel(int x, int y, double[] darray)
Returns the samples in an array of double for the specified pixel
int[]  getPixel(int x, int y, int w, int h, int[] iarray)
Returns a integer array of pixels representing a region of pixels
float[]  getPixel(int x, int y, int w, int h, float[] farray)
Return a float array of pixels representing a region of pixels
double[]  getPixel(int x, int y, int w, int h, double[] darray)
Return a double array of pixels representing a region of pixels
Object  getPixelData(int x, int y, Object obj)
Returns the data elements containing the pixel at x,y in packed format.
Object  getPixelData(int x, int y, int w, int h, Object obj)
Returns the data elements containing the pixel data for the pixels in the specified region.
int  getSample(int x, int y, int b)
Returns the requested sample in a specified band for a pixel.
int[]  getSample(int x, int y, int w, int h, int b, int[] iarray)
Returns an array of ints representing a region of samples.
float[]  getSample(int x, int y, int w, int h, int b, float[] farray)
Returns an array of floats representing a region of samples.
double[]  getSample(int x, int y, int w, int h, int b, double[] darray)
Return an array of ints representing a region of samples
double  getSampleDouble(int x, int y, int b)
Returns the requested sample in a specified band for a pixel.
float  getSampleFloat(int x, int y, int b)
Returns the requested sample in a specified band for a pixel.
SampleModel  getSampleModel()
Returns the SampleModel that describes that layout of the image data.
int  getTransferType()
 
int  getWidth()
Returns the width in pixels of the Raster.
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sampleModel

protected SampleModel sampleModel
SampleModel that describes how pixels are stored in the DataBuffer.

dataBuffer

protected DataBuffer dataBuffer
DataBuffer that stores image data.

width

protected int width
The width of the Raster.

height

protected int height
The height of the Raster.

minX

protected int minX
The X offset from the global origin.

minY

protected int minY
The Y offset from the global origin.

baseRasterOriginX

protected int baseRasterOriginX
The X offset of the base Raster from the global origin.

baseRasterOriginY

protected int baseRasterOriginY
The Y offset of the base Raster from the global origin.

numBands

protected int numBands
The number of bands in the raster.

numDataElements

protected int numDataElements
The number of data elements per pixel.

parent

protected Raster parent
If non-null, the parent of this Raster.
Constructor Detail

Raster

protected Raster(SampleModel sampleModel,
                 Point origin)
Constructs a Raster with the given SampleModel. The Raster's upper left corner is origin and it is the same size as the SampleModel. A DataBuffer large enough to describe the Raster is automatically created.
Parameters:
sampleModel - The SampleModel that specifies the layout.
origin - The Point that specified the origin.

Raster

protected Raster(SampleModel sampleModel,
                 DataBuffer dataBuffer,
                 Point origin)
Constructs a Raster with the given SampleModel and DataBuffer. The Raster's upper left corner is origin and it is the same size as the SampleModel. The DataBuffer is not initialized and must be compatible with SampleModel.
Parameters:
sampleModel - The SampleModel that specifies the layout.
dataBuffer - The DataBufferShort that contains the image data.
origin - The Point that specifies the origin.

Raster

protected Raster(SampleModel sampleModel,
                 DataBuffer dataBuffer,
                 Rectangle aRegion,
                 Point baseOrigin,
                 Raster parent)
Constructs a Raster with the given SampleModel, DataBuffer, and parent. When translated into the base Raster's coordinate system, aRegion must be contained by the base Raster. Origin is the coodinate in the new Raster's coordinate system of the origin of the base Raster. (The base Raster is the Raster's ancestor which has no parent.) Note that this constructor should generally be called by other constructors or create methods, it should not be used directly.
Parameters:
sampleModel - The SampleModel that specifies the layout.
dataBuffer - The DataBufferShort that contains the image data.
aRegion - The Rectangle that specifies the image area.
origin - The Point that specifies the origin.
parent - The parent (if any) of this raster.
Method Detail

createComponentRaster

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

createComponentRaster

public static WritableRaster createComponentRaster(int dataType,
                                                   int w,
                                                   int h,
                                                   int scanlineStride,
                                                   int pixelStride,
                                                   int[] bandOffsets,
                                                   Point location)
Creates a Raster based on a ComponentSampleModel with the specified data type, width, height, scanline stride, pixel stride, and band offsets.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType,
                                                int w,
                                                int h,
                                                int[] bandMasks,
                                                Point location)
Creates a Raster based on a SinglePixelPackedSampleModel with the specified data type, width, height, and band masks.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType,
                                                int w,
                                                int h,
                                                int n,
                                                int bitsPerBand,
                                                Point location)
Creates a Raster 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.

createComponentRaster

public static WritableRaster createComponentRaster(int dataType,
                                                   int w,
                                                   int h,
                                                   int scanlineStride,
                                                   int pixelStride,
                                                   int[] bandOffsets,
                                                   DataBuffer dataBuffer,
                                                   Point location)
Creates a Raster based on a ComponentSampleModel with the specified data type, width, height, scanline stride, pixel stride, band offsets, and data buffer.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType,
                                                int w,
                                                int h,
                                                int scanlineStride,
                                                int[] bandMasks,
                                                DataBuffer dataBuffer,
                                                Point location)
Creates a Raster based on a SinglePixelPackedSampleModel with the specified data type, width, height, scanline stride, band masks, and data buffer.

createPackedRaster

public static WritableRaster createPackedRaster(int dataType,
                                                int w,
                                                int h,
                                                int bitsPerPixel,
                                                DataBuffer dataBuffer,
                                                Point location)
Creates a Raster based on a MultiPixelPackedSampleModel with the specified data type, width, height, bits per pixel, and data buffer.

createRaster

public static Raster createRaster(SampleModel sm,
                                  DataBuffer db,
                                  Point location)
Creates a Raster with the specified SampleModel

createWritableRaster

public static WritableRaster createWritableRaster(SampleModel sm,
                                                  Point location)
Creates a WritableRaster with the specified SampleModel

createWritableRaster

public static WritableRaster createWritableRaster(SampleModel sm,
                                                  DataBuffer db,
                                                  Point location)
Creates a WritableRaster with the specified SampleModel and DataBuffer

getParent

public Raster getParent()
Returns the parent Raster (if any) of this Raster

getBaseRasterOriginX

public final int getBaseRasterOriginX()
Returns the X coord of the origin of the base Raster in this Raster's coordinate system.

getBaseRasterOriginY

public final int getBaseRasterOriginY()
Returns the Y coord of the origin of the base Raster in this Raster's coordinate system.

getBaseSubRasterOffsetX

public final int getBaseSubRasterOffsetX()

getBaseSubRasterOffsetY

public final int getBaseSubRasterOffsetY()

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster()
Create a compatible WritableRaster the same size as this Raster with the same SampleModel and a new initialized DataBuffer.

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(int w,
                                                     int h)
Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer.

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(Rectangle rect)
Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer. At the specified location.

createCompatibleWritableRaster

public WritableRaster createCompatibleWritableRaster(int x,
                                                     int y,
                                                     int w,
                                                     int h)
Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer. At the specified location.

createTranslatedRaster

public Raster createTranslatedRaster(Point location)
Create a Raster with the same size, SampleModel and DataBuffer as this one, but with a different location.
Parameters:
location - The upper left corner of the new returned Raster.

createSubRaster

public Raster createSubRaster(Rectangle rect)
Returns a Raster which references this Raster's DataBuffer
Parameters:
rect - is a rectangle in this Raster's coordinate space. An error is thrown if rect is not fully contained by this Raster.

createSubRaster

public Raster createSubRaster(int x,
                              int y,
                              int width,
                              int height)
Returns a Raster which references this Raster's DataBuffer. x,y, width and height form a Rectangle in this Raster's coordinate space. An error is thrown if this rectangle is not fully contained by this Raster.
Parameters:
x - The X coordinate of the upper left hand corner.
y - The Y coordinate of the upper left hand corner.
width - Width of the region starting at (x,y).
height - Height of the region starting at (x,y).

createSubRaster

public Raster createSubRaster(int x,
                              int y,
                              int width,
                              int height,
                              int x0,
                              int y0,
                              int[] bandList)
Returns a translated SubRaster which references this Raster's DataBuffer. x,y, width and height form a Rectangle in this Raster's coordinate space. The new Raster's coordinate system has an upper left corner of x0, y0. An error is thrown if rectangle is not fully contained by this Raster.
Parameters:
x - X of the upper left corner in this Raster's coordinates.
y - Y of the upper left corner in this Raster's coordinates.
width - Width of the region starting at (x,y).
height - Height of the region starting at (x,y).
x0 - X of the upper left corner of returned Raster.
y0 - Y of the upper left corner of returned Raster.
bandList - Array of band indices.

getBounds

public Rectangle getBounds()
Returns the bounds Rectangle of this Raster. This function returns the same information as getMinX/MinY/Width/Height.

getWidth

public final int getWidth()
Returns the width in pixels of the Raster.

getHeight

public final int getHeight()
Returns the height in pixels of the Raster.

getMinX

public final int getMinX()
Returns the minimum X coordinate (in the Raster's coordinate system).

getMinY

public final int getMinY()
Returns the minimum Y coordinate (in the Raster's coordinate system).

getNumBands

public final int getNumBands()
Returns the number of bands in this raster.

getNumDataElements

public final int getNumDataElements()
Returns the number of data elements needed to store one pixel.

getTransferType

public final int getTransferType()

getPixelData

public Object getPixelData(int x,
                           int y,
                           Object obj)
Returns the data elements containing the pixel at x,y in packed format. There will be no explicit bounds checking on the parameters. An ArrayOutOfBounds exception will be thrown at runtime if data outside of the array is accessed. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
outData - An object reference to an array of type defined by getTransferType() and length getNumDataElements(). If null an array of appropriate type and size will be allocated.
Returns:
An object reference to an array of type defined by getTransferType() with the request pixel data.

getPixelData

public Object getPixelData(int x,
                           int y,
                           int w,
                           int h,
                           Object obj)
Returns the data elements containing the pixel data for the pixels in the specified region. There will be no explicit bounds checking on the parameters. An ArrayOutOfBounds exception will be thrown at runtime if data outside of the array is accessed. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
width - Width of the pixel rectangle.
height - Height of the pixel rectangle.
outData - An object reference to an array of type defined by getTransferType() and length w*h*getNumDataElements(). If null an array of appropriate type and size will be allocated.
Returns:
An object reference to an array of type defined by getTransferType() with the request pixel data.

getPixel

public int[] getPixel(int x,
                      int y,
                      int[] iarray)
Returns the samples in an array of int for the specified pixel.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
iarray - An optionally preallocated int array.

getPixel

public float[] getPixel(int x,
                        int y,
                        float[] farray)
Returns the samples in an array of Float for the specified pixel.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
farray - An optionally preallocated float array.

getPixel

public double[] getPixel(int x,
                         int y,
                         double[] darray)
Returns the samples in an array of double for the specified pixel
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
darray - An optionally preallocated double array.

getPixel

public int[] getPixel(int x,
                      int y,
                      int w,
                      int h,
                      int[] iarray)
Returns a integer array of pixels representing a region of pixels
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - Width of the pixel rectangle.
h - Height of the pixel rectangle.
iarray - An optionally pre-allocated int array.

getPixel

public float[] getPixel(int x,
                        int y,
                        int w,
                        int h,
                        float[] farray)
Return a float array of pixels representing a region of pixels
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - Width of the pixel rectangle.
h - Height of the pixel rectangle.
farray - An optionally pre-allocated float array.

getPixel

public double[] getPixel(int x,
                         int y,
                         int w,
                         int h,
                         double[] darray)
Return a double array of pixels representing a region of pixels
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - Width of the pixel rectangle.
h - Height of the pixel rectangle.
darray - An optionally pre-allocated double array.

getSample

public int getSample(int x,
                     int y,
                     int b)
Returns the requested sample in a specified band for a pixel.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to return.

getSampleFloat

public float getSampleFloat(int x,
                            int y,
                            int b)
Returns the requested sample in a specified band for a pixel.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to return.

getSampleDouble

public double getSampleDouble(int x,
                              int y,
                              int b)
Returns the requested sample in a specified band for a pixel.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to return.

getSample

public int[] getSample(int x,
                       int y,
                       int w,
                       int h,
                       int b,
                       int[] iarray)
Returns an array of ints representing a region of samples.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - Width of the pixel rectangle.
h - Height of the pixel rectangle.
b - The band to return.
iarray - An optionally pre-allocated int array.

getSample

public float[] getSample(int x,
                         int y,
                         int w,
                         int h,
                         int b,
                         float[] farray)
Returns an array of floats representing a region of samples.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - Width of the pixel rectangle.
h - Height of the pixel rectangle.
b - The band to return.
farray - An optionally pre-allocated float array.

getSample

public double[] getSample(int x,
                          int y,
                          int w,
                          int h,
                          int b,
                          double[] darray)
Return an array of ints representing a region of samples
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - Width of the pixel rectangle.
h - Height of the pixel rectangle.
b - The band to return.
darray - An optionally pre-allocated double array.

getDataBuffer

public DataBuffer getDataBuffer()
Returns the DataBuffer associated with this Raster.

getSampleModel

public SampleModel getSampleModel()
Returns the SampleModel that describes that layout of the image data.

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.