APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.image

public final Class BandedSampleModel

extends ComponentSampleModel
Class Inheritance

This class represents image data which is stored in a band interleaved fashion and for which each sample of a pixel occupies one data element of the DataBuffer. It subclasses ComponentSampleModel but provides a more efficient implementation for accessing band interleaved image data than is provided by ComponentSampleModel. This class should typically be used when working with images which store sample data for each band in a different bank of the DataBuffer. Accessor methods are provided so that image data can be manipulated directly. Pixel stride is the number of data array elements between two samples for the same band on the same scanline. The pixel stride for a BandedSampleModel is one. Scanline stride is the number of data array elements between a given sample and the corresponding sample in the same column of the next scanline. Band offsets denote the number of data array elements from the first data array element of the bank of the DataBuffer holding each band to the first sample of the band. The bands are numbered from 0 to N-1. Bank indices denote the correspondence between a bank of the data buffer and a band of image data. This class supports TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, and TYPE_DOUBLE datatypes

Field Summary

Inherited from java.awt.image.ComponentSampleModel:
bandOffsetsbankIndicesnumBandsnumBankspixelStridescanlineStride

Constructor Summary

AccessConstructor and Description
public
BandedSampleModel(int
The data type for storing samples.
dataType
,
int
The width (in pixels) of the region of image data described.
w
,
int
The height (in pixels) of the region of image data described.
h
,
int
The number of bands for the image data.
numBands
)

Constructs a BandedSampleModel with the specified parameters.

public
BandedSampleModel(int
The data type for storing samples.
dataType
,
int
The width (in pixels) of the region of image data described.
w
,
int
The height (in pixels) of the region of image data described.
h
,
int
The line stride of the of the image data.
scanlineStride
,
int[]
The bank index for each band.
bankIndices
,
int[]
The band offset for each band.
bandOffsets
)

Constructs a BandedSampleModel with the specified parameters.

Method Summary

Modifier and TypeMethod and Description
public SampleModel

Returns:

a new BandedSampleModel with the specified width and height.
createCompatibleSampleModel
(int
the width of the resulting BandedSampleModel
w
,
int
the height of the resulting BandedSampleModel
h
)

Overrides java.awt.image.ComponentSampleModel.createCompatibleSampleModel.

Creates a new BandedSampleModel with the specified width and height.

public DataBuffer
createDataBuffer()

Overrides java.awt.image.ComponentSampleModel.createDataBuffer.

Creates a DataBuffer that corresponds to this BandedSampleModel, The DataBuffer's data type, number of banks, and size will be consistent with this BandedSampleModel.

private static int[]
createIndicesArray(int numBands)

private static int[]
createOffsetArray(int numBands)

public SampleModel
createSubsetSampleModel(int[] bands)

Overrides java.awt.image.ComponentSampleModel.createSubsetSampleModel.

Creates a new BandedSampleModel with a subset of the bands of this BandedSampleModel.

public Object

Returns:

the data for the specified pixel.
getDataElements
(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
Object
If non-null, a primitive array in which to return the pixel data.
obj
,
DataBuffer
The DataBuffer containing the image data.
data
)

Overrides java.awt.image.ComponentSampleModel.getDataElements.

Returns data for a single pixel in a primitive array of type TransferType.

public int[]
getPixel(int x, int y, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getPixel.

Returns the samples for a specified pixel in an int array, one sample per array element.

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

Overrides java.awt.image.ComponentSampleModel.getPixels.

Returns all samples for a rectangle of pixels in an int array, one sample per array element.

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

Overrides java.awt.image.ComponentSampleModel.getSample.

Returns the sample in a specified band for the pixel located at (x,y) as an int.

public double
getSampleDouble(int x, int y, int b, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getSampleDouble.

Returns the sample in a specified band for a pixel located at (x,y) as a double.

public float
getSampleFloat(int x, int y, int b, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getSampleFloat.

Returns the sample in a specified band for the pixel located at (x,y) as a float.

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

Overrides java.awt.image.ComponentSampleModel.getSamples.

Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element.

public int
hashCode()

Overrides java.awt.image.ComponentSampleModel.hashCode.

Returns a hash code value for this object.

public void
setDataElements(int
The X coordinate of the pixel location
x
,
int
The Y coordinate of the pixel location
y
,
Object
If non-null, returns the primitive array in this object
obj
,
DataBuffer
The DataBuffer containing the image data
data
)

Overrides java.awt.image.ComponentSampleModel.setDataElements.

Sets the data for a single pixel in the specified DataBuffer from a primitive array of type TransferType.

public void
setPixel(int x, int y, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setPixel.

Sets a pixel in the DataBuffer using an int array of samples for input.

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

Overrides java.awt.image.ComponentSampleModel.setPixels.

Sets all samples for a rectangle of pixels from an int array containing one sample per array element.

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

Overrides java.awt.image.ComponentSampleModel.setSample.

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using an int for input.

public void
setSample(int x, int y, int b, float s, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setSample.

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a float for input.

public void
setSample(int x, int y, int b, double s, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setSample.

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a double for input.

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

Overrides java.awt.image.ComponentSampleModel.setSamples.

Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element.

Inherited from java.awt.image.ComponentSampleModel:
equalsgetBandOffsetsgetBankIndicesgetNumDataElementsgetOffsetgetOffsetgetPixelStridegetSampleSizegetSampleSizegetScanlineStrideorderBands

Constructor Detail

BandedSampleModelback to summary
public BandedSampleModel(int dataType, int w, int h, int numBands)

Constructs a BandedSampleModel with the specified parameters. The pixel stride will be one data element. The scanline stride will be the same as the width. Each band will be stored in a separate bank and all band offsets will be zero.

Parameters
dataType:int

The data type for storing samples.

w:int

The width (in pixels) of the region of image data described.

h:int

The height (in pixels) of the region of image data described.

numBands:int

The number of bands for the image data.

Exceptions
IllegalArgumentException:
  • if w and h are not both greater than 0
  • if the product of w and h is greater than Integer.MAX_VALUE
  • if numBands is not > 0
  • if dataType is not one of the supported data types for this sample model.
BandedSampleModelback to summary
public BandedSampleModel(int dataType, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets)

Constructs a BandedSampleModel with the specified parameters. The number of bands will be inferred from the lengths of the bandOffsets bankIndices arrays, which must be equal. The pixel stride will be one data element.

Parameters
dataType:int

The data type for storing samples.

w:int

The width (in pixels) of the region of image data described.

h:int

The height (in pixels) of the region of image data described.

scanlineStride:int

The line stride of the of the image data.

bankIndices:int[]

The bank index for each band.

bandOffsets:int[]

The band offset for each band.

Exceptions
IllegalArgumentException:
  • if w and h are not both greater than 0
  • if the product of w and h is greater than Integer.MAX_VALUE
  • if scanlineStride is less than 0
  • if bandOffsets.length is 0
  • if the length of bankIndices does not equal the length of bandOffsets
  • if any of the bank indices of bandIndices is less than 0
  • if dataType is not one of the supported data types for this sample model
NullPointerException:
  • if bankIndices is null
  • if bandOffsets is null

Method Detail

createCompatibleSampleModelback to summary
public SampleModel createCompatibleSampleModel(int w, int h)

Overrides java.awt.image.ComponentSampleModel.createCompatibleSampleModel.

Creates a new BandedSampleModel with the specified width and height. The new BandedSampleModel will have the same number of bands, storage data type, and bank indices as this BandedSampleModel. The band offsets will be compressed such that the offset between bands will be w*pixelStride and the minimum of all of the band offsets is zero.

Parameters
w:int

the width of the resulting BandedSampleModel

h:int

the height of the resulting BandedSampleModel

Returns:SampleModel

a new BandedSampleModel with the specified width and height.

Exceptions
IllegalArgumentException:
if the product of w and h is greater than Integer.MAX_VALUE or w or h is not greater than 0.
createDataBufferback to summary
public DataBuffer createDataBuffer()

Overrides java.awt.image.ComponentSampleModel.createDataBuffer.

Creates a DataBuffer that corresponds to this BandedSampleModel, The DataBuffer's data type, number of banks, and size will be consistent with this BandedSampleModel.

Exceptions
IllegalArgumentException:
if dataType is not one of the supported types.
createIndicesArrayback to summary
private static int[] createIndicesArray(int numBands)
createOffsetArrayback to summary
private static int[] createOffsetArray(int numBands)
createSubsetSampleModelback to summary
public SampleModel createSubsetSampleModel(int[] bands)

Overrides java.awt.image.ComponentSampleModel.createSubsetSampleModel.

Creates a new BandedSampleModel with a subset of the bands of this BandedSampleModel. The new BandedSampleModel can be used with any DataBuffer that the existing BandedSampleModel can be used with. The new BandedSampleModel/DataBuffer combination will represent an image with a subset of the bands of the original BandedSampleModel/DataBuffer combination.

Exceptions
NullPointerException:
if bands is null
IllegalArgumentException:
if the number of bands is not greater than 0
RasterFormatException:
if the number of bands is greater than the number of banks in this sample model.
ArrayIndexOutOfBoundsException:
if any of the bank indices is out of bounds
getDataElementsback to summary
public Object getDataElements(int x, int y, Object obj, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getDataElements.

Returns data for a single pixel in a primitive array of type TransferType. For a BandedSampleModel, this will be the same as the data type, and samples will be returned one per array element. Generally, obj should be passed in as null, so that the Object will be created automatically and will be of the right primitive data type.

The following code illustrates transferring data for one pixel from DataBuffer db1, whose storage layout is described by BandedSampleModel bsm1, to DataBuffer db2, whose storage layout is described by BandedSampleModel bsm2. The transfer will generally be more efficient than using getPixel/setPixel.

      BandedSampleModel bsm1, bsm2;
      DataBufferInt db1, db2;
      bsm2.setDataElements(x, y, bsm1.getDataElements(x, y, null, db1),
                           db2);
Using getDataElements/setDataElements to transfer between two DataBuffer/SampleModel pairs is legitimate if the SampleModels have the same number of bands, corresponding bands have the same number of bits per sample, and the TransferTypes are the same.

If obj is non-null, it should be a primitive array of type TransferType. Otherwise, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds, or if obj is non-null and is not large enough to hold the pixel data.

Parameters
x:int

The X coordinate of the pixel location

y:int

The Y coordinate of the pixel location

obj:Object

If non-null, a primitive array in which to return the pixel data.

data:DataBuffer

The DataBuffer containing the image data.

Returns:Object

the data for the specified pixel.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if obj is too small to hold the output.
See Also
setDataElements(int, int, Object, DataBuffer)
getPixelback to summary
public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getPixel.

Doc from java.awt.image.ComponentSampleModel.getPixel.

Returns the samples for a specified pixel in an int array, one sample per array element. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if iArray is too small to hold the output.
getPixelsback to summary
public int[] getPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getPixels.

Doc from java.awt.image.ComponentSampleModel.getPixels.

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

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or w or h is negative. or if iArray is too small to hold the output.
getSampleback to summary
public int getSample(int x, int y, int b, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getSample.

Doc from java.awt.image.ComponentSampleModel.getSample.

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

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or the band index are not in bounds.
getSampleDoubleback to summary
public double getSampleDouble(int x, int y, int b, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getSampleDouble.

Doc from java.awt.image.ComponentSampleModel.getSampleDouble.

Returns the sample in a specified band for a pixel located at (x,y) as a double. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or the band index are not in bounds.
getSampleFloatback to summary
public float getSampleFloat(int x, int y, int b, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getSampleFloat.

Doc from java.awt.image.ComponentSampleModel.getSampleFloat.

Returns the sample in a specified band for the pixel located at (x,y) as a float. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or the band index are not in bounds.
getSamplesback to summary
public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.getSamples.

Doc from java.awt.image.ComponentSampleModel.getSamples.

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

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or band index are not in bounds, or w or h is negative, or if iArray is too small to hold the output.
hashCodeback to summary
public int hashCode()

Overrides java.awt.image.ComponentSampleModel.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
setDataElementsback to summary
public void setDataElements(int x, int y, Object obj, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setDataElements.

Sets the data for a single pixel in the specified DataBuffer from a primitive array of type TransferType. For a BandedSampleModel, this will be the same as the data type, and samples are transferred one per array element.

The following code illustrates transferring data for one pixel from DataBuffer db1, whose storage layout is described by BandedSampleModel bsm1, to DataBuffer db2, whose storage layout is described by BandedSampleModel bsm2. The transfer will generally be more efficient than using getPixel/setPixel.

      BandedSampleModel bsm1, bsm2;
      DataBufferInt db1, db2;
      bsm2.setDataElements(x, y, bsm1.getDataElements(x, y, null, db1),
                           db2);
Using getDataElements/setDataElements to transfer between two DataBuffer/SampleModel pairs is legitimate if the SampleModels have the same number of bands, corresponding bands have the same number of bits per sample, and the TransferTypes are the same.

obj must be a primitive array of type TransferType. Otherwise, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds, or if obj is not large enough to hold the pixel data.

Parameters
x:int

The X coordinate of the pixel location

y:int

The Y coordinate of the pixel location

obj:Object

If non-null, returns the primitive array in this object

data:DataBuffer

The DataBuffer containing the image data

Exceptions
NullPointerException:
if obj or data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if obj is too small to hold the input.
See Also
getDataElements(int, int, Object, DataBuffer)
setPixelback to summary
public void setPixel(int x, int y, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setPixel.

Doc from java.awt.image.ComponentSampleModel.setPixel.

Sets a pixel in the DataBuffer using an int array of samples for input. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if iArray or {code data} is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if iArray is too small to hold the input.
setPixelsback to summary
public void setPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setPixels.

Doc from java.awt.image.ComponentSampleModel.setPixels.

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

Exceptions
NullPointerException:
if iArray or data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or w or h is negative. or if iArray is too small to hold the input.
setSampleback to summary
public void setSample(int x, int y, int b, int s, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setSample.

Doc from java.awt.image.ComponentSampleModel.setSample.

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

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or the band index are not in bounds.
setSampleback to summary
public void setSample(int x, int y, int b, float s, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setSample.

Doc from java.awt.image.ComponentSampleModel.setSample.

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a float for input. The default implementation of this method casts the input float sample to an int and then calls the setSample(int, int, int, DataBuffer) method using that int value. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or the band index are not in bounds.
setSampleback to summary
public void setSample(int x, int y, int b, double s, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setSample.

Doc from java.awt.image.ComponentSampleModel.setSample.

Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a double for input. The default implementation of this method casts the input double sample to an int and then calls the setSample(int, int, int, DataBuffer) method using that int value. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or the band index are not in bounds.
setSamplesback to summary
public void setSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)

Overrides java.awt.image.ComponentSampleModel.setSamples.

Doc from java.awt.image.ComponentSampleModel.setSamples.

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

Exceptions
NullPointerException:
if iArray or data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or band index are not in bounds, or w or h is negative, or if iArray is too small to hold the input.