java.awt.image
public class ComponentSampleModel extends SampleModel
Modifier and Type | Field and Description |
---|---|
protected int[] |
bandOffsets
The offsets to the first sample for each band.
|
protected int[] |
bankIndices
The indices of the bank used to store each band in a data buffer.
|
protected int |
numBands
The number of bands in the image.
|
protected int |
numBanks
Used when creating data buffers.
|
protected int |
pixelStride
The number of data elements between a sample for one pixel and the
corresponding sample for the next pixel in the same row.
|
protected int |
scanlineStride
The number of data elements between a sample in one row and the
corresponding sample in the next row.
|
dataType, height, width
Constructor and Description |
---|
ComponentSampleModel(int dataType,
int w,
int h,
int pixelStride,
int scanlineStride,
int[] bandOffsets)
Creates a new sample model that assumes that all bands are stored in a
single bank of the
DataBuffer . |
ComponentSampleModel(int dataType,
int w,
int h,
int pixelStride,
int scanlineStride,
int[] bankIndices,
int[] bandOffsets)
Creates a new sample model that assumes that all bands are stored in a
single bank of the
DataBuffer . |
Modifier and Type | Method and Description |
---|---|
SampleModel |
createCompatibleSampleModel(int w,
int h)
Creates a new sample model that is compatible with this one, but with the
specified dimensions.
|
DataBuffer |
createDataBuffer()
Creates a new data buffer that is compatible with this sample model.
|
SampleModel |
createSubsetSampleModel(int[] bands)
Creates a new sample model that provides access to a subset of the bands
that this sample model supports.
|
boolean |
equals(Object obj)
Tests this sample model for equality with an arbitrary object.
|
int[] |
getBandOffsets()
Returns the offsets to the first sample in each band.
|
int[] |
getBankIndices()
Returns the indices of the bank(s) in the
DataBuffer used to
store the samples for each band. |
Object |
getDataElements(int x,
int y,
Object obj,
DataBuffer data)
Returns the samples for the pixel at location
(x, y) in
a primitive array (the array type is determined by the data type for
this model). |
int |
getNumDataElements()
Returns the number of data elements used to store the samples for one
pixel.
|
int |
getOffset(int x,
int y)
Returns the offset of the sample in band 0 for the pixel at location
(x, y) . |
int |
getOffset(int x,
int y,
int b)
Returns the offset of the sample in band
b for the pixel at
location (x, y) . |
int[] |
getPixel(int x,
int y,
int[] iArray,
DataBuffer data)
Returns all the samples for the pixel at location
(x, y)
stored in the specified data buffer. |
int[] |
getPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
Returns the samples for all the pixels in a rectangular region.
|
int |
getPixelStride()
Returns the distance (in terms of element indices) between the sample for
one pixel and the corresponding sample for the next pixel in a row.
|
int |
getSample(int x,
int y,
int b,
DataBuffer data)
Returns the sample for band
b of the pixel at
(x, y) that is stored in the specified data buffer. |
int[] |
getSampleSize()
Returns the size in bits for each sample (one per band).
|
int |
getSampleSize(int band)
Returns the size in bits for the samples in the specified band.
|
int |
getScanlineStride()
Returns the distance (in terms of element indices) between the sample for
one pixel and the corresponding sample for the equivalent pixel in the
next row.
|
int |
hashCode()
Returns a hash code for this sample model.
|
void |
setDataElements(int x,
int y,
Object obj,
DataBuffer data)
Sets the samples for the pixel at location
(x, y) from the
supplied primitive array (the array type must be consistent with the data
type for this model). |
void |
setPixel(int x,
int y,
int[] iArray,
DataBuffer data)
Sets the sample values for the pixel at location
(x, y)
stored in the specified data buffer. |
void |
setSample(int x,
int y,
int b,
int s,
DataBuffer data)
Sets the sample value for band
b of the pixel at location
(x, y) in the specified data buffer. |
getDataElements, getDataType, getHeight, getNumBands, getPixel, getPixel, getPixels, getPixels, getSampleDouble, getSampleFloat, getSamples, getSamples, getSamples, getTransferType, getWidth, setDataElements, setPixel, setPixel, setPixels, setPixels, setPixels, setSample, setSample, setSamples, setSamples, setSamples
protected int[] bandOffsets
protected int[] bankIndices
protected int numBands
protected int numBanks
protected int scanlineStride
protected int pixelStride
public ComponentSampleModel(int dataType, int w, int h, int pixelStride, int scanlineStride, int[] bandOffsets)
DataBuffer
.
Note that the bandOffsets
array is copied to internal storage
to prevent subsequent changes to the array from affecting this object.
dataType
- the data type (one of DataBuffer.TYPE_BYTE
,
DataBuffer.TYPE_USHORT
, DataBuffer.TYPE_SHORT
,
DataBuffer.TYPE_INT
, DataBuffer.TYPE_FLOAT
or
DataBuffer.TYPE_DOUBLE
).w
- the width in pixels.h
- the height in pixels.pixelStride
- the number of data elements in the step from a sample
in one pixel to the corresponding sample in the next pixel.scanlineStride
- the number of data elements in the step from a
sample in a pixel to the corresponding sample in the pixel in the next
row.bandOffsets
- the offset to the first element for each band, with
the size of the array defining the number of bands (null
not permitted).IllegalArgumentException
- if dataType
is not one of
the specified values.IllegalArgumentException
- if w
is less than or equal
to zero.IllegalArgumentException
- if h
is less than or equal
to zero.IllegalArgumentException
- if w * h
exceeds
Integer.MAX_VALUE
.IllegalArgumentException
- if pixelStride
is negative.IllegalArgumentException
- if scanlineStride
is less
than or equal to zero.IllegalArgumentException
- if bandOffsets
has zero
length.public ComponentSampleModel(int dataType, int w, int h, int pixelStride, int scanlineStride, int[] bankIndices, int[] bandOffsets)
DataBuffer
.dataType
- the data type (one of DataBuffer.TYPE_BYTE
,
DataBuffer.TYPE_USHORT
, DataBuffer.TYPE_SHORT
,
DataBuffer.TYPE_INT
, DataBuffer.TYPE_FLOAT
or
DataBuffer.TYPE_DOUBLE
).w
- the width in pixels.h
- the height in pixels.pixelStride
- the number of data elements in the step from a sample
in one pixel to the corresponding sample in the next pixel.scanlineStride
- the number of data elements in the step from a
sample in a pixel to the corresponding sample in the pixel in the next
row.bankIndices
- the index of the bank in which each band is stored
(null
not permitted). This array is copied to internal
storage so that subsequent updates to the array do not affect the sample
model.bandOffsets
- the offset to the first element for each band, with
the size of the array defining the number of bands (null
not permitted). This array is copied to internal storage so that
subsequent updates to the array do not affect the sample model.IllegalArgumentException
- if dataType
is not one of
the specified values.IllegalArgumentException
- if w
is less than or equal
to zero.IllegalArgumentException
- if h
is less than or equal
to zero.IllegalArgumentException
- if w * h
exceeds
Integer.MAX_VALUE
.IllegalArgumentException
- if pixelStride
is negative.IllegalArgumentException
- if scanlineStride
is less
than or equal to zero.IllegalArgumentException
- if bandOffsets
has zero
length.public SampleModel createCompatibleSampleModel(int w, int h)
createCompatibleSampleModel
in class SampleModel
w
- the width (must be greater than zero).h
- the height (must be greater than zero).public SampleModel createSubsetSampleModel(int[] bands)
createSubsetSampleModel
in class SampleModel
bands
- the bands (null
not permitted).public DataBuffer createDataBuffer()
createDataBuffer
in class SampleModel
public int getOffset(int x, int y)
(x, y)
. This offset can be used to read a sample value from
a DataBuffer
.x
- the x-coordinate.y
- the y-coordinate.getOffset(int, int, int)
public int getOffset(int x, int y, int b)
b
for the pixel at
location (x, y)
. This offset can be used to read a sample
value from a DataBuffer
.x
- the x-coordinate.y
- the y-coordinate.b
- the band index.public final int[] getSampleSize()
getSampleSize
in class SampleModel
SampleModel.getDataType()
public final int getSampleSize(int band)
getSampleSize
in class SampleModel
band
- the band index (ignored here).SampleModel.getDataType()
public final int[] getBankIndices()
DataBuffer
used to
store the samples for each band. The returned array is a copy, so that
altering it will not impact the sample model.public final int[] getBandOffsets()
public final int getScanlineStride()
DataBuffer
.public final int getPixelStride()
DataBuffer
.public final int getNumDataElements()
getNumDataElements
in class SampleModel
public Object getDataElements(int x, int y, Object obj, DataBuffer data)
(x, y)
in
a primitive array (the array type is determined by the data type for
this model). The obj
argument provides an option to supply
an existing array to hold the result, if this is null
a new
array will be allocated.getDataElements
in class SampleModel
x
- the x-coordinate.y
- the y-coordinate.obj
- a primitive array that, if not null
, will be
used to store and return the sample values.data
- the data buffer (null
not permitted).public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
(x, y)
stored in the specified data buffer.getPixel
in class SampleModel
x
- the x-coordinate.y
- the y-coordinate.iArray
- an array that will be populated with the sample values and
returned as the result. The size of this array should be equal to the
number of bands in the model. If the array is null
, a new
array is created.data
- the data buffer (null
not permitted).setPixel(int, int, int[], DataBuffer)
public int[] getPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)
getPixels
in class SampleModel
x
- the x-coordinate.y
- the y-coordinate.w
- the width.h
- the height.iArray
- an array that if non-null
will be populated
with the sample values and returned as the result.data
- the data buffer (null
not permitted).public int getSample(int x, int y, int b, DataBuffer data)
b
of the pixel at
(x, y)
that is stored in the specified data buffer.getSample
in class SampleModel
x
- the x-coordinate.y
- the y-coordinate.b
- the band index.data
- the data buffer (null
not permitted).ArrayIndexOutOfBoundsException
- if (x, y)
is outside
the bounds [0, 0, width, height]
.setSample(int, int, int, int, DataBuffer)
public void setDataElements(int x, int y, Object obj, DataBuffer data)
(x, y)
from the
supplied primitive array (the array type must be consistent with the data
type for this model).setDataElements
in class SampleModel
x
- the x-coordinate.y
- the y-coordinate.obj
- a primitive array containing the pixel's sample values.data
- the data buffer (null
not permitted).setDataElements(int, int, Object, DataBuffer)
public void setPixel(int x, int y, int[] iArray, DataBuffer data)
(x, y)
stored in the specified data buffer.setPixel
in class SampleModel
x
- the x-coordinate.y
- the y-coordinate.iArray
- the pixel sample values (null
not permitted).data
- the data buffer (null
not permitted).getPixel(int, int, int[], DataBuffer)
public void setSample(int x, int y, int b, int s, DataBuffer data)
b
of the pixel at location
(x, y)
in the specified data buffer.setSample
in class SampleModel
x
- the x-coordinate.y
- the y-coordinate.b
- the band index.s
- the sample value.data
- the data buffer (null
not permitted).getSample(int, int, int, DataBuffer)
public boolean equals(Object obj)
true
if and only if:
obj
is not null
;obj
is an instance of ComponentSampleModel
;
dataType
,
width
, height
, pixelStride
,
scanlineStride
, bandOffsets
and
bankIndices
fields.equals
in class Object
obj
- the object to test (null
permitted).true
if this sample model is equal to
obj
, and false
otherwise.Object.hashCode()
public int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)