public class

ByteInterleavedRaster

extends ByteComponentRaster
java.lang.Object
   ↳ java.awt.image.Raster
     ↳ java.awt.image.WritableRaster
       ↳ sun.awt.image.SunWritableRaster
         ↳ sun.awt.image.ByteComponentRaster
           ↳ sun.awt.image.ByteInterleavedRaster

Class Overview

This class defines a Raster with pixels consisting of one or more 8-bit data elements stored in close proximity to each other in a single byte array.

The bit precision per data element is that of the data type (that is, the bit precision for this Raster is 8). There is only one pixel stride and one scanline stride for all bands. This type of Raster can be used with a ComponentColorModel if there are multiple bands, or an IndexColorModel if there is only one band.

Summary

[Expand]
Inherited Fields
From class sun.awt.image.ByteComponentRaster
From class java.awt.image.Raster
Public Constructors
ByteInterleavedRaster(SampleModel sampleModel, Point origin)
Constructs a ByteInterleavedRaster with the given SampleModel.
ByteInterleavedRaster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin)
Constructs a ByteInterleavedRaster with the given SampleModel and DataBuffer.
ByteInterleavedRaster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point origin, ByteInterleavedRaster parent)
Constructs a ByteInterleavedRaster with the given SampleModel, DataBuffer, and parent.
Public Methods
Raster createChild(int x, int y, int width, int height, int x0, int y0, int[] bandList)
Creates a subraster given a region of the raster.
WritableRaster createCompatibleWritableRaster(int w, int h)
Creates a Raster with the same layout but using a different width and height, and with new zeroed data arrays.
WritableRaster createCompatibleWritableRaster()
Creates a Raster with the same layout and the same width and height, and with new zeroed data arrays.
WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList)
Creates a Writable subRaster given a region of the Raster.
byte[] getByteData(int x, int y, int w, int h, int band, byte[] outData)
Returns a byte array of data elements from the specified rectangular region for the specified band.
byte[] getByteData(int x, int y, int w, int h, byte[] outData)
Returns a byte array of data elements from the specified rectangular region.
Object getDataElements(int x, int y, int w, int h, Object obj)
Returns an array of data elements from the specified rectangular region.
Object getDataElements(int x, int y, Object obj)
Returns the data elements for all bands at the specified location.
int getDataOffset(int band)
Returns the data offset for the specified band.
int[] getDataOffsets()
Returns a copy of the data offsets array.
byte[] getDataStorage()
Returns a reference to the data array.
int getPixelStride()
Returns pixel stride -- the number of data array elements between two samples for the same band on the same scanline.
int[] getPixels(int x, int y, int w, int h, int[] iArray)
Returns an int array containing all samples for a rectangle of pixels, one sample per array element.
int getSample(int x, int y, int b)
Returns the sample in a specified band for the pixel located at (x,y) as an int.
int[] getSamples(int x, int y, int w, int h, int b, int[] iArray)
Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element.
int getScanlineStride()
Returns the scanline stride -- the number of data array elements between a given sample and the sample in the same column of the next row in the same band.
void putByteData(int x, int y, int w, int h, byte[] inData)
Stores a byte array of data elements into the specified rectangular region.
void putByteData(int x, int y, int w, int h, int band, byte[] inData)
Stores a byte array of data elements into the specified rectangular region for the specified band.
void setDataElements(int x, int y, int w, int h, Object obj)
Stores an array of data elements into the specified rectangular region.
void setDataElements(int x, int y, Raster inRaster)
Stores the Raster data at the specified location.
void setDataElements(int x, int y, Object obj)
Stores the data elements for all bands at the specified location.
void setPixels(int x, int y, int w, int h, int[] iArray)
Sets all samples for a rectangle of pixels from an int array containing one sample per array element.
void setRect(int dx, int dy, Raster srcRaster)
Copies pixels from Raster srcRaster to this WritableRaster.
void setSample(int x, int y, int b, int s)
Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using an int for input.
void setSamples(int x, int y, int w, int h, int b, int[] iArray)
Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element.
String toString()
Returns a string representation of the object.
[Expand]
Inherited Methods
From class sun.awt.image.ByteComponentRaster
From class sun.awt.image.SunWritableRaster
From class java.awt.image.WritableRaster
From class java.awt.image.Raster
From class java.lang.Object

Public Constructors

public ByteInterleavedRaster (SampleModel sampleModel, Point origin)

Constructs a ByteInterleavedRaster 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. SampleModel must be of type SinglePixelPackedSampleModel or InterleavedSampleModel.

Parameters
sampleModel The SampleModel that specifies the layout.
origin The Point that specified the origin.

public ByteInterleavedRaster (SampleModel sampleModel, DataBuffer dataBuffer, Point origin)

Constructs a ByteInterleavedRaster 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 a DataBufferByte compatible with SampleModel. SampleModel must be of type SinglePixelPackedSampleModel or InterleavedSampleModel.

Parameters
sampleModel The SampleModel that specifies the layout.
dataBuffer The DataBufferShort that contains the image data.
origin The Point that specifies the origin.

public ByteInterleavedRaster (SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point origin, ByteInterleavedRaster parent)

Constructs a ByteInterleavedRaster with the given SampleModel, DataBuffer, and parent. DataBuffer must be a DataBufferByte and SampleModel must be of type SinglePixelPackedSampleModel or InterleavedSampleModel. When translated into the base Raster's coordinate system, aRegion must be contained by the base Raster. Origin is the coordinate 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.

Public Methods

public Raster createChild (int x, int y, int width, int height, int x0, int y0, int[] bandList)

Creates a subraster given a region of the raster. The x and y coordinates specify the horizontal and vertical offsets from the upper-left corner of this raster to the upper-left corner of the subraster. A subset of the bands of the parent Raster may be specified. If this is null, then all the bands are present in the subRaster. A translation to the subRaster may also be specified. Note that the subraster will reference the same DataBuffer as the parent raster, but using different offsets.

Parameters
x X offset.
y Y offset.
width Width (in pixels) of the subraster.
height Height (in pixels) of the subraster.
x0 Translated X origin of the subraster.
y0 Translated Y origin of the subraster.
bandList Array of band indices.
Returns
  • a new Raster.
Throws
RasterFormatException if the specified bounding box is outside of the parent raster.

public WritableRaster createCompatibleWritableRaster (int w, int h)

Creates a Raster with the same layout but using a different width and height, and with new zeroed data arrays.

Parameters
w the specified width of the new WritableRaster
h the specified height of the new WritableRaster
Returns
  • a compatible WritableRaster with the specified size and a new sample model and data buffer.

public WritableRaster createCompatibleWritableRaster ()

Creates a Raster with the same layout and the same width and height, and with new zeroed data arrays. If the Raster is a subRaster, this will call createCompatibleRaster(width, height).

Returns
  • a compatible WritableRaster with the same sample model and a new data buffer.

public WritableRaster createWritableChild (int x, int y, int width, int height, int x0, int y0, int[] bandList)

Creates a Writable subRaster given a region of the Raster. The x and y coordinates specify the horizontal and vertical offsets from the upper-left corner of this Raster to the upper-left corner of the subRaster. A subset of the bands of the parent Raster may be specified. If this is null, then all the bands are present in the subRaster. A translation to the subRaster may also be specified. Note that the subRaster will reference the same DataBuffer as the parent Raster, but using different offsets.

Parameters
x X offset.
y Y offset.
width Width (in pixels) of the subraster.
height Height (in pixels) of the subraster.
x0 Translated X origin of the subraster.
y0 Translated Y origin of the subraster.
bandList Array of band indices.
Returns
  • a WritableRaster sharing all or part of the DataBuffer of this WritableRaster.
Throws
RasterFormatException if the specified bounding box is outside of the parent Raster.

public byte[] getByteData (int x, int y, int w, int h, int band, byte[] outData)

Returns a byte array of data elements from the specified rectangular region for the specified band. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds.

       byte[] bandData = raster.getByteData(x, y, w, h, null);
       // To find the data element at location (x2, y2)
       byte bandElement = bandData[((y2-y)*w + (x2-x))];
 

Parameters
x The X coordinate of the upper left pixel location.
y The Y coordinate of the upper left pixel location.
band The band to return.
outData If non-null, data elements for all bands at the specified location are returned in this array.
Returns
  • Data array with data elements for all bands.

public byte[] getByteData (int x, int y, int w, int h, byte[] outData)

Returns a byte array of data elements from the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds.

       byte[] bandData = raster.getByteData(x, y, w, h, null);
       int numDataElements = raster.getnumDataElements();
       byte[] pixel = new byte[numDataElements];
       // To find a data element at location (x2, y2)
       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
                        pixel, 0, numDataElements);
 

Parameters
x The X coordinate of the upper left pixel location.
y The Y coordinate of the upper left pixel location.
outData If non-null, data elements for all bands at the specified location are returned in this array.
Returns
  • Data array with data elements for all bands.

public Object getDataElements (int x, int y, int w, int h, Object obj)

Returns an array of data elements from the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType.

       byte[] bandData = (byte[])raster.getDataElements(x, y, w, h, null);
       int numDataElements = raster.getNumDataElements();
       byte[] pixel = new byte[numDataElements];
       // To find a data element at location (x2, y2)
       System.arraycopy(bandData, ((y2-y)*w + (x2-x))*numDataElements,
                        pixel, 0, numDataElements);
 

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
obj 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.

public Object getDataElements (int x, int y, Object obj)

Returns the data elements for all bands at the specified location. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinate is out of bounds. 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.
obj 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.

public int getDataOffset (int band)

Returns the data offset for the specified band. The data offset is the index into the data array in which the first sample of the first scanline is stored.

Parameters
band The band whose offset is returned.

public int[] getDataOffsets ()

Returns a copy of the data offsets array. For each band the data offset is the index into the band's data array, of the first sample of the band.

public byte[] getDataStorage ()

Returns a reference to the data array.

public int getPixelStride ()

Returns pixel stride -- the number of data array elements between two samples for the same band on the same scanline.

public int[] getPixels (int x, int y, int w, int h, int[] iArray)

Returns an int array containing all samples for a rectangle of pixels, one sample per array element. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.

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
Returns
  • the samples for the specified rectangle of pixels.

public int getSample (int x, int y, int b)

Returns the sample in a specified band for the pixel located at (x,y) as an int. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.

Parameters
x The X coordinate of the pixel location
y The Y coordinate of the pixel location
b The band to return
Returns
  • the sample in the specified band for the pixel at the specified coordinate.

public int[] getSamples (int x, int y, int w, int h, int b, int[] iArray)

Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.

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
Returns
  • the samples for the specified band for the specified rectangle of pixels.

public int getScanlineStride ()

Returns the scanline stride -- the number of data array elements between a given sample and the sample in the same column of the next row in the same band.

public void putByteData (int x, int y, int w, int h, byte[] inData)

Stores a byte array of data elements into the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. The data elements in the data array are assumed to be packed. That is, a data element for the nth band at location (x2, y2) would be found at:

      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 

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.
inData The data elements to be stored.

public void putByteData (int x, int y, int w, int h, int band, byte[] inData)

Stores a byte array of data elements into the specified rectangular region for the specified band. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. The data elements in the data array are assumed to be packed. That is, a data element at location (x2, y2) would be found at:

      inData[((y2-y)*w + (x2-x)) + n]
 

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.
band The band to set.
inData The data elements to be stored.

public void setDataElements (int x, int y, int w, int h, Object obj)

Stores an array of data elements into the specified rectangular region. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds. A ClassCastException will be thrown if the input object is non null and references anything other than an array of transferType. The data elements in the data array are assumed to be packed. That is, a data element for the nth band at location (x2, y2) would be found at:

      inData[((y2-y)*w + (x2-x))*numDataElements + n]
 

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.
obj An object reference to an array of type defined by getTransferType() and length w*h*getNumDataElements() containing the pixel data to place between x,y and x+w-1, y+h-1.

public void setDataElements (int x, int y, Raster inRaster)

Stores the Raster data at the specified location. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinates are out of bounds.

Parameters
x The X coordinate of the pixel location.
y The Y coordinate of the pixel location.
inRaster Raster of data to place at x,y location.

public void setDataElements (int x, int y, Object obj)

Stores the data elements for all bands at the specified location. An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel coordinate is out of bounds. 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.
obj An object reference to an array of type defined by getTransferType() and length getNumDataElements() containing the pixel data to place at x,y.

public void setPixels (int x, int y, int w, int h, int[] iArray)

Sets all samples for a rectangle of pixels from an int array containing one sample per array element. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.

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 The input int pixel array.

public void setRect (int dx, int dy, Raster srcRaster)

Copies pixels from Raster srcRaster to this WritableRaster. For each (x, y) address in srcRaster, the corresponding pixel is copied to address (x+dx, y+dy) in this WritableRaster, unless (x+dx, y+dy) falls outside the bounds of this raster. srcRaster must have the same number of bands as this WritableRaster. The copy is a simple copy of source samples to the corresponding destination samples. For details, see setRect(Raster).

Parameters
dx The X translation factor from src space to dst space of the copy.
dy The Y translation factor from src space to dst space of the copy.
srcRaster The Raster from which to copy pixels.

public void setSample (int x, int y, int b, int s)

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using an int for input. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.

Parameters
x The X coordinate of the pixel location.
y The Y coordinate of the pixel location.
b The band to set.
s The input sample.

public void setSamples (int x, int y, int w, int h, int b, int[] iArray)

Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.

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 set.
iArray The input int sample array.

public String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a string representation of the object.