A Raster defines values for pixels occupying a particular rectangular area of the plane, not necessarily including (0, 0). The rectangle, known as the Raster's bounding rectangle and available by means of the getBounds method, is defined by minX, minY, width, and height values. The minX and minY values define the coordinate of the upper left corner of the Raster. References to pixels outside of the bounding rectangle may result in an exception being thrown, or may result in references to unintended elements of the Raster's associated DataBuffer. It is the user's responsibility to avoid accessing such pixels.
A SampleModel describes how samples of a Raster are stored in the primitive array elements of a DataBuffer. Samples may be stored one per data element, as in a PixelInterleavedSampleModel or BandedSampleModel, or packed several to an element, as in a SinglePixelPackedSampleModel or MultiPixelPackedSampleModel. The SampleModel is also controls whether samples are sign extended, allowing unsigned data to be stored in signed Java data types such as byte, short, and int.
Although a Raster may live anywhere in the plane, a SampleModel makes use of a simple coordinate system that starts at (0, 0). A Raster therefore contains a translation factor that allows pixel locations to be mapped between the Raster's coordinate system and that of the SampleModel. The translation from the SampleModel coordinate system to that of the Raster may be obtained by the getSampleModelTranslateX and getSampleModelTranslateY methods.
A Raster may share a DataBuffer with another Raster either by explicit construction or by the use of the createChild and createTranslatedChild methods. Rasters created by these methods can return a reference to the Raster they were created from by means of the getParent method. For a Raster that was not constructed by means of a call to createTranslatedChild or createChild, getParent will return null.
The createTranslatedChild method returns a new Raster that shares all of the data of the current Raster, but occupies a bounding rectangle of the same width and height but with a different starting point. For example, if the parent Raster occupied the region (10, 10) to (100, 100), and the translated Raster was defined to start at (50, 50), then pixel (20, 20) of the parent and pixel (60, 60) of the child occupy the same location in the DataBuffer shared by the two Rasters. In the first case, (-10, -10) should be added to a pixel coordinate to obtain the corresponding SampleModel coordinate, and in the second case (-50, -50) should be added.
The translation between a parent and child Raster may be determined by subtracting the child's sampleModelTranslateX and sampleModelTranslateY values from those of the parent.
The createChild method may be used to create a new Raster occupying only a subset of its parent's bounding rectangle (with the same or a translated coordinate system) or with a subset of the bands of its parent.
All constructors are protected. The correct way to create a Raster is to use one of the static create methods defined in this class. These methods create instances of Raster that use the standard Interleaved, Banded, and Packed SampleModels and that may be processed more efficiently than a Raster created by combining an externally generated SampleModel and DataBuffer.
Field Detail |
protected SampleModel sampleModel
protected DataBuffer dataBuffer
protected int minX
protected int minY
protected int width
protected int height
protected int sampleModelTranslateX
protected int sampleModelTranslateY
protected int numBands
protected int numDataElements
protected Raster parent
Constructor Detail |
protected Raster(SampleModel sampleModel, Point origin)
sampleModel
- The SampleModel that specifies the layoutorigin
- The Point that specified the originRasterFormatException
- if computing either origin.x + sampleModel.getWidth()
or origin.y + sampleModel.getHeight()
results in integer overflowNullPointerException
- either sampleModel
or origin
is nullprotected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin)
sampleModel
- The SampleModel that specifies the layoutdataBuffer
- The DataBuffer that contains the image dataorigin
- The Point that specifies the originRasterFormatException
- if computing either origin.x + sampleModel.getWidth()
or origin.y + sampleModel.getHeight()
results in integer overflowNullPointerException
- either sampleModel
or origin
is nullprotected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point sampleModelTranslate, Raster parent)
sampleModel
- The SampleModel that specifies the layoutdataBuffer
- The DataBuffer that contains the image dataaRegion
- The Rectangle that specifies the image areasampleModelTranslate
- The Point that specifies the translation from SampleModel to Raster coordinatesparent
- The parent (if any) of this rasterNullPointerException
- if any of sampleModel
, dataBuffer
, aRegion
or sampleModelTranslate
is nullRasterFormatException
- if aRegion
has width or height less than or equal to zero, or computing either aRegion.x + aRegion.width
or aRegion.y + aRegion.height
results in integer overflowMethod Detail |
public static WritableRaster createInterleavedRaster(int dataType, int w, int h, int bands, Point location)
The upper left corner of the Raster 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.
Note that interleaved DataBuffer.TYPE_INT
Rasters are not supported. To create a 1-band Raster of type DataBuffer.TYPE_INT
, use Raster.createPackedRaster().
The only dataTypes supported currently are TYPE_BYTE and TYPE_USHORT.
dataType
- the data type for storing samplesw
- the width in pixels of the image datah
- the height in pixels of the image databands
- the number of bandslocation
- the upper-left corner of the Raster
RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowpublic static WritableRaster createInterleavedRaster(int dataType, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
The upper left corner of the Raster 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.
Note that interleaved DataBuffer.TYPE_INT
Rasters are not supported. To create a 1-band Raster of type DataBuffer.TYPE_INT
, use Raster.createPackedRaster().
The only dataTypes supported currently are TYPE_BYTE and TYPE_USHORT.
dataType
- the data type for storing samplesw
- the width in pixels of the image datah
- the height in pixels of the image datascanlineStride
- the line stride of the image datapixelStride
- the pixel stride of the image databandOffsets
- the offsets of all bandslocation
- the upper-left corner of the Raster
RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, or DataBuffer.TYPE_USHORT
.public static WritableRaster createBandedRaster(int dataType, int w, int h, int bands, Point location)
The upper left corner of the Raster 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.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT, and TYPE_INT.
dataType
- the data type for storing samplesw
- the width in pixels of the image datah
- the height in pixels of the image databands
- the number of bandslocation
- the upper-left corner of the Raster
RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowArrayIndexOutOfBoundsException
- if bands
is less than 1public static WritableRaster createBandedRaster(int dataType, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
The upper left corner of the Raster is given by the location argument. The dataType parameter should be one of the enumerated values defined in the DataBuffer class.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT, and TYPE_INT.
dataType
- the data type for storing samplesw
- the width in pixels of the image datah
- the height in pixels of the image datascanlineStride
- the line stride of the image databankIndices
- the bank indices for each bandbandOffsets
- the offsets of all bandslocation
- the upper-left corner of the Raster
RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, DataBuffer.TYPE_USHORT
or DataBuffer.TYPE_INT
ArrayIndexOutOfBoundsException
- if bankIndices
or bandOffsets
is null
public static WritableRaster createPackedRaster(int dataType, int w, int h, int[] bandMasks, Point location)
The upper left corner of the Raster 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.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT, and TYPE_INT.
dataType
- the data type for storing samplesw
- the width in pixels of the image datah
- the height in pixels of the image databandMasks
- an array containing an entry for each bandlocation
- the upper-left corner of the Raster
RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, DataBuffer.TYPE_USHORT
or DataBuffer.TYPE_INT
public static WritableRaster createPackedRaster(int dataType, int w, int h, int bands, int bitsPerBand, Point location)
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 Raster 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.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT, and TYPE_INT.
dataType
- the data type for storing samplesw
- the width in pixels of the image datah
- the height in pixels of the image databands
- the number of bandsbitsPerBand
- the number of bits per bandlocation
- the upper-left corner of the Raster
RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if the product of bitsPerBand
and bands
is greater than the number of bits held by dataType
IllegalArgumentException
- if bitsPerBand
or bands
is not greater than zeroIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, DataBuffer.TYPE_USHORT
or DataBuffer.TYPE_INT
public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int pixelStride, int[] bandOffsets, Point location)
Note that interleaved DataBuffer.TYPE_INT
Rasters are not supported. To create a 1-band Raster of type DataBuffer.TYPE_INT
, use Raster.createPackedRaster().
dataBuffer
- the DataBuffer
that contains the image dataw
- the width in pixels of the image datah
- the height in pixels of the image datascanlineStride
- the line stride of the image datapixelStride
- the pixel stride of the image databandOffsets
- the offsets of all bandslocation
- the upper-left corner of the Raster
DataBuffer
, width, height, scanline stride, pixel stride and band offsets.RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, DataBuffer.TYPE_USHORT
RasterFormatException
- if dataBuffer
has more than one bank.NullPointerException
- if dataBuffer
is nullpublic static WritableRaster createBandedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location)
dataBuffer
- the DataBuffer
that contains the image dataw
- the width in pixels of the image datah
- the height in pixels of the image datascanlineStride
- the line stride of the image databankIndices
- the bank indices for each bandbandOffsets
- the offsets of all bandslocation
- the upper-left corner of the Raster
DataBuffer
, width, height, scanline stride, bank indices and band offsets.RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, DataBuffer.TYPE_USHORT
or DataBuffer.TYPE_INT
NullPointerException
- if dataBuffer
is nullpublic static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride, int[] bandMasks, Point location)
dataBuffer
- the DataBuffer
that contains the image dataw
- the width in pixels of the image datah
- the height in pixels of the image datascanlineStride
- the line stride of the image databandMasks
- an array containing an entry for each bandlocation
- the upper-left corner of the Raster
DataBuffer
, width, height, scanline stride, and band masks.RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, DataBuffer.TYPE_USHORT
or DataBuffer.TYPE_INT
RasterFormatException
- if dataBuffer
has more than one bank.NullPointerException
- if dataBuffer
is nullpublic static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h, int bitsPerPixel, Point location)
dataBuffer
- the DataBuffer
that contains the image dataw
- the width in pixels of the image datah
- the height in pixels of the image databitsPerPixel
- the number of bits for each pixellocation
- the upper-left corner of the Raster
DataBuffer
, width, height, and bits per pixel.RasterFormatException
- if w
or h
is less than or equal to zero, or computing either location.x + w
or location.y + h
results in integer overflowIllegalArgumentException
- if dataType
is not one of the supported data types, which are DataBuffer.TYPE_BYTE
, DataBuffer.TYPE_USHORT
or DataBuffer.TYPE_INT
RasterFormatException
- if dataBuffer
has more than one bank.NullPointerException
- if dataBuffer
is nullpublic static Raster createRaster(SampleModel sm, DataBuffer db, Point location)
sm
- the specified SampleModel
db
- the specified DataBuffer
location
- the upper-left corner of the Raster
Raster
with the specified SampleModel
, DataBuffer
, and location.RasterFormatException
- if computing either location.x + sm.getWidth()
or location.y + sm.getHeight()
results in integer overflowRasterFormatException
- if dataBuffer
has more than one bank and the sampleModel
is PixelInterleavedSampleModel, SinglePixelPackedSampleModel, or MultiPixelPackedSampleModel.NullPointerException
- if either SampleModel or DataBuffer is nullpublic static WritableRaster createWritableRaster(SampleModel sm, Point location)
sm
- the specified SampleModel
location
- the upper-left corner of the WritableRaster
WritableRaster
with the specified SampleModel
and location.RasterFormatException
- if computing either location.x + sm.getWidth()
or location.y + sm.getHeight()
results in integer overflowpublic static WritableRaster createWritableRaster(SampleModel sm, DataBuffer db, Point location)
sm
- the specified SampleModel
db
- the specified DataBuffer
location
- the upper-left corner of the WritableRaster
WritableRaster
with the specified SampleModel
, DataBuffer
, and location.RasterFormatException
- if computing either location.x + sm.getWidth()
or location.y + sm.getHeight()
results in integer overflowRasterFormatException
- if dataBuffer
has more than one bank and the sampleModel
is PixelInterleavedSampleModel, SinglePixelPackedSampleModel, or MultiPixelPackedSampleModel.NullPointerException
- if either SampleModel or DataBuffer is nullpublic Raster getParent()
null
.public final int getSampleModelTranslateX()
public final int getSampleModelTranslateY()
public WritableRaster createCompatibleWritableRaster()
WritableRaster
with the same sample model and a new data buffer.public WritableRaster createCompatibleWritableRaster(int w, int h)
w
- the specified width of the new WritableRaster
h
- the specified height of the new WritableRaster
WritableRaster
with the specified size and a new sample model and data buffer.RasterFormatException
- if the width or height is less than or equal to zero.public WritableRaster createCompatibleWritableRaster(Rectangle rect)
rect
- a Rectangle
that specifies the size and location of the WritableRaster
WritableRaster
with the specified size and location and a new sample model and data buffer.RasterFormatException
- if rect
has width or height less than or equal to zero, or computing either rect.x + rect.width
or rect.y + rect.height
results in integer overflowNullPointerException
- if rect is null
public WritableRaster createCompatibleWritableRaster(int x, int y, int w, int h)
x, y
- the coordinates of the upper-left corner of the WritableRaster
w
- the specified width of the WritableRaster
h
- the specified height of the WritableRaster
WritableRaster
with the specified size and location and a new sample model and data buffer.RasterFormatException
- if w
or h
is less than or equal to zero, or computing either x + w
or y + h
results in integer overflowpublic Raster createTranslatedChild(int childMinX, int childMinY)
childMinX, childMinY
- coordinates of the upper-left corner of the new Raster
Raster
with the same size, SampleModel, and DataBuffer as this Raster
, but with the specified location.RasterFormatException
- if computing either childMinX + this.getWidth()
or childMinY + this.getHeight()
results in integer overflowpublic Raster createChild(int parentX, int parentY, int width, int height, int childMinX, int childMinY, int[] bandList)
The parentX, parentY, width and height parameters form a Rectangle in this Raster'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 current Raster.
The new Raster may additionally be translated to a different coordinate system for the plane than that used by the current Raster. The childMinX and childMinY parameters give the new (x, y) coordinate of the upper-left pixel of the returned Raster; the coordinate (childMinX, childMinY) in the new Raster will map to the same pixel as the coordinate (parentX, parentY) in the current Raster.
The new Raster may be defined to contain only a subset of the bands of the current Raster, possibly reordered, by means of the bandList parameter. If bandList is null, it is taken to include all of the bands of the current Raster in their current order.
To create a new Raster that contains a subregion of the current Raster, 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.
parentX, parentY
- coordinates of the upper-left corner in this Raster's coordinateswidth
- Width of the region starting at (parentX, parentY)height
- Height of the region starting at (parentX, parentY).childMinX, childMinY
- coordinates of the upper-left corner of the returned RasterbandList
- Array of band indices, or null to use all bandsRaster
.RasterFormatException
- if width
or height
is less than or equal to zero, or computing any of parentX + width
, parentY + height
, childMinX + width
, or childMinY + height
results in integer overflowRasterFormatException
- if the specified subregion is outside of the raster bounds.public Rectangle getBounds()
Raster
.public final int getMinX()
Raster
.public final int getMinY()
Raster
.public final int getWidth()
Raster
.public final int getHeight()
Raster
.public final int getNumBands()
Raster
.public final int getNumDataElements()
public final int getTransferType()
public DataBuffer getDataBuffer()
DataBuffer
of this Raster
.public SampleModel getSampleModel()
SampleModel
of this Raster
.public Object getDataElements(int x, int y, Object outData)
x, y
- the coordinates of the pixel locationoutData
- 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 allocatedArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if outData is too small to hold the output.public Object getDataElements(int x, int y, int w, int h, Object outData)
x, y
- the coordinates of the upper-left pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectangleoutData
- 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.ArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if outData is too small to hold the output.public int[] getPixel(int x, int y, int[] iArray)
x, y
- the coordinates of the pixel locationiArray
- An optionally preallocated int arrayArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if iArray is too small to hold the output.public float[] getPixel(int x, int y, float[] fArray)
x, y
- the coordinates of the pixel locationfArray
- An optionally preallocated float arrayArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if fArray is too small to hold the output.public double[] getPixel(int x, int y, double[] dArray)
x, y
- the coordinates of the pixel locationdArray
- An optionally preallocated double arrayArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if dArray is too small to hold the output.public int[] getPixels(int x, int y, int w, int h, int[] iArray)
x, y
- the coordinates of the upper-left pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectangleiArray
- An optionally pre-allocated int arrayArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if iArray is too small to hold the output.public float[] getPixels(int x, int y, int w, int h, float[] fArray)
x, y
- the coordinates of the pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectanglefArray
- An optionally pre-allocated float arrayArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if fArray is too small to hold the output.public double[] getPixels(int x, int y, int w, int h, double[] dArray)
x, y
- the coordinates of the upper-left pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectangledArray
- An optionally pre-allocated double arrayArrayIndexOutOfBoundsException
- if the coordinates are not in bounds, or if dArray is too small to hold the output.public int getSample(int x, int y, int b)
x, y
- the coordinates of the pixel locationb
- The band to returnArrayIndexOutOfBoundsException
- if the coordinates or the band index are not in bounds.public float getSampleFloat(int x, int y, int b)
x, y
- the coordinates of the pixel locationb
- The band to returnArrayIndexOutOfBoundsException
- if the coordinates or the band index are not in bounds.public double getSampleDouble(int x, int y, int b)
x, y
- the coordinates of the pixel locationb
- The band to returnArrayIndexOutOfBoundsException
- if the coordinates or the band index are not in bounds.public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray)
x, y
- the coordinates of the upper-left pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectangleb
- The band to returniArray
- An optionally pre-allocated int arrayArrayIndexOutOfBoundsException
- if the coordinates or the band index are not in bounds, or if iArray is too small to hold the output.public float[] getSamples(int x, int y, int w, int h, int b, float[] fArray)
x, y
- the coordinates of the upper-left pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectangleb
- The band to returnfArray
- An optionally pre-allocated float arrayArrayIndexOutOfBoundsException
- if the coordinates or the band index are not in bounds, or if fArray is too small to hold the output.public double[] getSamples(int x, int y, int w, int h, int b, double[] dArray)
x, y
- the coordinates of the upper-left pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectangleb
- The band to returndArray
- An optionally pre-allocated double arrayArrayIndexOutOfBoundsException
- if the coordinates or the band index are not in bounds, or if dArray is too small to hold the output.