MultiPixelPackedSampleModel (Java 2 Platform SE 5.0) (original) (raw)
java.awt.image
Class MultiPixelPackedSampleModel
java.lang.Object
java.awt.image.SampleModel
java.awt.image.MultiPixelPackedSampleModel
public class MultiPixelPackedSampleModel
extends SampleModel
The MultiPixelPackedSampleModel
class represents one-banded images and can pack multiple one-sample pixels into one data element. Pixels are not allowed to span data elements. The data type can be DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT. Each pixel must be a power of 2 number of bits and a power of 2 number of pixels must fit exactly in one data element. Pixel bit stride is equal to the number of bits per pixel. Scanline stride is in data elements and the last several data elements might be padded with unused pixels. Data bit offset is the offset in bits from the beginning of the DataBuffer to the first pixel and must be a multiple of pixel bit stride.
The following code illustrates extracting the bits for pixelx, y
from DataBuffer
data
and storing the pixel data in data elements of typedataType
:
int dataElementSize = DataBuffer.getDataTypeSize(dataType);
int bitnum = dataBitOffset + x*pixelBitStride;
int element = data.getElem(y*scanlineStride + bitnum/dataElementSize);
int shift = dataElementSize - (bitnum & (dataElementSize-1))
- pixelBitStride;
int pixel = (element >> shift) & ((1 << pixelBitStride) - 1);
Field Summary |
---|
Fields inherited from class java.awt.image.SampleModel |
---|
dataType, height, numBands, width |
Constructor Summary |
---|
[MultiPixelPackedSampleModel](../../../java/awt/image/MultiPixelPackedSampleModel.html#MultiPixelPackedSampleModel%28int, int, int, int%29)(int dataType, int w, int h, int numberOfBits) Constructs a MultiPixelPackedSampleModel with the specified data type, width, height and number of bits per pixel. |
[MultiPixelPackedSampleModel](../../../java/awt/image/MultiPixelPackedSampleModel.html#MultiPixelPackedSampleModel%28int, int, int, int, int, int%29)(int dataType, int w, int h, int numberOfBits, int scanlineStride, int dataBitOffset) Constructs a MultiPixelPackedSampleModel with specified data type, width, height, number of bits per pixel, scanline stride and data bit offset. |
Method Summary | |
---|---|
SampleModel | [createCompatibleSampleModel](../../../java/awt/image/MultiPixelPackedSampleModel.html#createCompatibleSampleModel%28int, int%29)(int w, int h) Creates a new MultiPixelPackedSampleModel with the specified width and height. |
DataBuffer | createDataBuffer() Creates a DataBuffer that corresponds to thisMultiPixelPackedSampleModel. |
SampleModel | createSubsetSampleModel(int[] bands) Creates a new MultiPixelPackedSampleModel with a subset of the bands of this MultiPixelPackedSampleModel. |
boolean | equals(Object o) Indicates whether some other object is "equal to" this one. |
int | getBitOffset(int x) Returns the offset, in bits, into the data element in which it is stored for the xth pixel of a scanline. |
int | getDataBitOffset() Returns the data bit offset in bits. |
Object | [getDataElements](../../../java/awt/image/MultiPixelPackedSampleModel.html#getDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29)(int x, int y,Object obj,DataBuffer data) Returns data for a single pixel in a primitive array of type TransferType. |
int | getNumDataElements() Returns the number of data elements needed to transfer one pixel via the [getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#getDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29) and [setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#setDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29) methods. |
int | [getOffset](../../../java/awt/image/MultiPixelPackedSampleModel.html#getOffset%28int, int%29)(int x, int y) Returns the offset of pixel (x, y) in data array elements. |
int[] | [getPixel](../../../java/awt/image/MultiPixelPackedSampleModel.html#getPixel%28int, int, int[], java.awt.image.DataBuffer%29)(int x, int y, int[] iArray,DataBuffer data) Returns the specified single band pixel in the first element of an int array. |
int | getPixelBitStride() Returns the pixel bit stride in bits. |
int | [getSample](../../../java/awt/image/MultiPixelPackedSampleModel.html#getSample%28int, int, int, java.awt.image.DataBuffer%29)(int x, int y, int b,DataBuffer data) Returns as int the sample in a specified band for the pixel located at (x, y). |
int[] | getSampleSize() Returns the number of bits per sample for all bands. |
int | getSampleSize(int band) Returns the number of bits per sample for the specified band. |
int | getScanlineStride() Returns the scanline stride. |
int | getTransferType() Returns the TransferType used to transfer pixels by way of thegetDataElements and setDataElements methods. |
int | hashCode() Returns a hash code value for the object. |
void | [setDataElements](../../../java/awt/image/MultiPixelPackedSampleModel.html#setDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29)(int x, int y,Object obj,DataBuffer data) Sets the data for a single pixel in the specified DataBuffer from a primitive array of type TransferType. |
void | [setPixel](../../../java/awt/image/MultiPixelPackedSampleModel.html#setPixel%28int, int, int[], java.awt.image.DataBuffer%29)(int x, int y, int[] iArray,DataBuffer data) Sets a pixel in the DataBuffer using anint array for input. |
void | [setSample](../../../java/awt/image/MultiPixelPackedSampleModel.html#setSample%28int, int, int, int, java.awt.image.DataBuffer%29)(int x, int y, int b, int s,DataBuffer data) Sets a sample in the specified band for the pixel located at (x, y) in the DataBuffer using anint for input. |
Methods inherited from class java.awt.image.SampleModel |
---|
[getDataElements](../../../java/awt/image/SampleModel.html#getDataElements%28int, int, int, int, java.lang.Object, java.awt.image.DataBuffer%29), getDataType, getHeight, getNumBands, [getPixel](../../../java/awt/image/SampleModel.html#getPixel%28int, int, double[], java.awt.image.DataBuffer%29), [getPixel](../../../java/awt/image/SampleModel.html#getPixel%28int, int, float[], java.awt.image.DataBuffer%29), [getPixels](../../../java/awt/image/SampleModel.html#getPixels%28int, int, int, int, double[], java.awt.image.DataBuffer%29), [getPixels](../../../java/awt/image/SampleModel.html#getPixels%28int, int, int, int, float[], java.awt.image.DataBuffer%29), [getPixels](../../../java/awt/image/SampleModel.html#getPixels%28int, int, int, int, int[], java.awt.image.DataBuffer%29), [getSampleDouble](../../../java/awt/image/SampleModel.html#getSampleDouble%28int, int, int, java.awt.image.DataBuffer%29), [getSampleFloat](../../../java/awt/image/SampleModel.html#getSampleFloat%28int, int, int, java.awt.image.DataBuffer%29), [getSamples](../../../java/awt/image/SampleModel.html#getSamples%28int, int, int, int, int, double[], java.awt.image.DataBuffer%29), [getSamples](../../../java/awt/image/SampleModel.html#getSamples%28int, int, int, int, int, float[], java.awt.image.DataBuffer%29), [getSamples](../../../java/awt/image/SampleModel.html#getSamples%28int, int, int, int, int, int[], java.awt.image.DataBuffer%29), getWidth, [setDataElements](../../../java/awt/image/SampleModel.html#setDataElements%28int, int, int, int, java.lang.Object, java.awt.image.DataBuffer%29), [setPixel](../../../java/awt/image/SampleModel.html#setPixel%28int, int, double[], java.awt.image.DataBuffer%29), [setPixel](../../../java/awt/image/SampleModel.html#setPixel%28int, int, float[], java.awt.image.DataBuffer%29), [setPixels](../../../java/awt/image/SampleModel.html#setPixels%28int, int, int, int, double[], java.awt.image.DataBuffer%29), [setPixels](../../../java/awt/image/SampleModel.html#setPixels%28int, int, int, int, float[], java.awt.image.DataBuffer%29), [setPixels](../../../java/awt/image/SampleModel.html#setPixels%28int, int, int, int, int[], java.awt.image.DataBuffer%29), [setSample](../../../java/awt/image/SampleModel.html#setSample%28int, int, int, double, java.awt.image.DataBuffer%29), [setSample](../../../java/awt/image/SampleModel.html#setSample%28int, int, int, float, java.awt.image.DataBuffer%29), [setSamples](../../../java/awt/image/SampleModel.html#setSamples%28int, int, int, int, int, double[], java.awt.image.DataBuffer%29), [setSamples](../../../java/awt/image/SampleModel.html#setSamples%28int, int, int, int, int, float[], java.awt.image.DataBuffer%29), [setSamples](../../../java/awt/image/SampleModel.html#setSamples%28int, int, int, int, int, int[], java.awt.image.DataBuffer%29) |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, [wait](../../../java/lang/Object.html#wait%28long, int%29) |
Constructor Detail |
---|
MultiPixelPackedSampleModel
public MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits)
Constructs a MultiPixelPackedSampleModel
with the specified data type, width, height and number of bits per pixel.
Parameters:
dataType
- the data type for storing samples
w
- the width, in pixels, of the region of image data described
h
- the height, in pixels, of the region of image data described
numberOfBits
- the number of bits per pixel
Throws:
[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")
- if dataType
is not either DataBuffer.TYPE_BYTE
,DataBuffer.TYPE_USHORT
, orDataBuffer.TYPE_INT
MultiPixelPackedSampleModel
public MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits, int scanlineStride, int dataBitOffset)
Constructs a MultiPixelPackedSampleModel
with specified data type, width, height, number of bits per pixel, scanline stride and data bit offset.
Parameters:
dataType
- the data type for storing samples
w
- the width, in pixels, of the region of image data described
h
- the height, in pixels, of the region of image data described
numberOfBits
- the number of bits per pixel
scanlineStride
- the line stride of the image data
dataBitOffset
- the data bit offset for the region of image data described
Throws:
[RasterFormatException](../../../java/awt/image/RasterFormatException.html "class in java.awt.image")
- if the number of bits per pixel is not a power of 2 or if a power of 2 number of pixels do not fit in one data element.
[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")
- if w
orh
is not greater than 0
[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")
- if dataType
is not either DataBuffer.TYPE_BYTE
,DataBuffer.TYPE_USHORT
, orDataBuffer.TYPE_INT
Method Detail |
---|
createCompatibleSampleModel
public SampleModel createCompatibleSampleModel(int w, int h)
Creates a new MultiPixelPackedSampleModel
with the specified width and height. The new MultiPixelPackedSampleModel
has the same storage data type and number of bits per pixel as thisMultiPixelPackedSampleModel
.
Specified by:
[createCompatibleSampleModel](../../../java/awt/image/SampleModel.html#createCompatibleSampleModel%28int, int%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
w
- the specified width
h
- the specified height
Returns:
a SampleModel with the specified width and height and with the same storage data type and number of bits per pixel as this MultiPixelPackedSampleModel
.
Throws:
[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")
- if w
orh
is not greater than 0
createDataBuffer
public DataBuffer createDataBuffer()
Creates a DataBuffer
that corresponds to thisMultiPixelPackedSampleModel
. TheDataBuffer
object's data type and size is consistent with this MultiPixelPackedSampleModel
. The DataBuffer
has a single bank.
Specified by:
[createDataBuffer](../../../java/awt/image/SampleModel.html#createDataBuffer%28%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Returns:
a DataBuffer
with the same data type and size as this MultiPixelPackedSampleModel
.
getNumDataElements
public int getNumDataElements()
Returns the number of data elements needed to transfer one pixel via the [getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#getDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29) and [setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#setDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29) methods. For a MultiPixelPackedSampleModel
, this is one.
Specified by:
[getNumDataElements](../../../java/awt/image/SampleModel.html#getNumDataElements%28%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Returns:
the number of data elements.
See Also:
[SampleModel.getDataElements(int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#getDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29), [SampleModel.getDataElements(int, int, int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#getDataElements%28int, int, int, int, java.lang.Object, java.awt.image.DataBuffer%29), [SampleModel.setDataElements(int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#setDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29), [SampleModel.setDataElements(int, int, int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#setDataElements%28int, int, int, int, java.lang.Object, java.awt.image.DataBuffer%29), SampleModel.getTransferType()
getSampleSize
public int[] getSampleSize()
Returns the number of bits per sample for all bands.
Specified by:
[getSampleSize](../../../java/awt/image/SampleModel.html#getSampleSize%28%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Returns:
the number of bits per sample.
getSampleSize
public int getSampleSize(int band)
Returns the number of bits per sample for the specified band.
Specified by:
[getSampleSize](../../../java/awt/image/SampleModel.html#getSampleSize%28int%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
band
- the specified band
Returns:
the number of bits per sample for the specified band.
getOffset
public int getOffset(int x, int y)
Returns the offset of pixel (x, y) in data array elements.
Parameters:
x, y
- the specified pixel
Returns:
the offset of the specified pixel.
getBitOffset
public int getBitOffset(int x)
Returns the offset, in bits, into the data element in which it is stored for the x
th pixel of a scanline. This offset is the same for all scanlines.
Parameters:
x
- the specified pixel
Returns:
the bit offset of the specified pixel.
getScanlineStride
public int getScanlineStride()
Returns the scanline stride.
Returns:
the scanline stride of thisMultiPixelPackedSampleModel
.
getPixelBitStride
public int getPixelBitStride()
Returns the pixel bit stride in bits. This value is the same as the number of bits per pixel.
Returns:
the pixelBitStride
of this MultiPixelPackedSampleModel
.
getDataBitOffset
public int getDataBitOffset()
Returns the data bit offset in bits.
Returns:
the dataBitOffset
of thisMultiPixelPackedSampleModel
.
getTransferType
public int getTransferType()
Returns the TransferType used to transfer pixels by way of thegetDataElements
and setDataElements
methods. The TransferType might or might not be the same as the storage DataType. The TransferType is one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT.
Overrides:
[getTransferType](../../../java/awt/image/SampleModel.html#getTransferType%28%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Returns:
the transfertype.
See Also:
[SampleModel.getDataElements(int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#getDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29), [SampleModel.getDataElements(int, int, int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#getDataElements%28int, int, int, int, java.lang.Object, java.awt.image.DataBuffer%29), [SampleModel.setDataElements(int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#setDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29), [SampleModel.setDataElements(int, int, int, int, Object, DataBuffer)](../../../java/awt/image/SampleModel.html#setDataElements%28int, int, int, int, java.lang.Object, java.awt.image.DataBuffer%29), SampleModel.getNumDataElements(), DataBuffer
createSubsetSampleModel
public SampleModel createSubsetSampleModel(int[] bands)
Creates a new MultiPixelPackedSampleModel
with a subset of the bands of this MultiPixelPackedSampleModel
. Since aMultiPixelPackedSampleModel
only has one band, the bands argument must have a length of one and indicate the zeroth band.
Specified by:
[createSubsetSampleModel](../../../java/awt/image/SampleModel.html#createSubsetSampleModel%28int[]%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
bands
- the specified bands
Returns:
a new SampleModel
with a subset of bands of this MultiPixelPackedSampleModel
.
Throws:
[RasterFormatException](../../../java/awt/image/RasterFormatException.html "class in java.awt.image")
- if the number of bands requested is not one.
[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")
- if w
orh
is not greater than 0
getSample
public int getSample(int x, int y, int b, DataBuffer data)
Returns as int
the sample in a specified band for the pixel located at (x, y). An ArrayIndexOutOfBoundsException
is thrown if the coordinates are not in bounds.
Specified by:
[getSample](../../../java/awt/image/SampleModel.html#getSample%28int, int, int, java.awt.image.DataBuffer%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
x, y
- the coordinates of the specified pixel
b
- the band to return, which is assumed to be 0
data
- the DataBuffer
containing the image data
Returns:
the specified band containing the sample of the specified pixel.
Throws:
ArrayIndexOutOfBoundException
- if the specified coordinates are not in bounds.
See Also:
[setSample(int, int, int, int, DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#setSample%28int, int, int, int, java.awt.image.DataBuffer%29)
setSample
public void setSample(int x, int y, int b, int s, DataBuffer data)
Sets a sample in the specified band for the pixel located at (x, y) in the DataBuffer
using anint
for input. An ArrayIndexOutOfBoundsException
is thrown if the coordinates are not in bounds.
Specified by:
[setSample](../../../java/awt/image/SampleModel.html#setSample%28int, int, int, int, java.awt.image.DataBuffer%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
x, y
- the coordinates of the specified pixel
b
- the band to return, which is assumed to be 0
s
- the input sample as an int
data
- the DataBuffer
where image data is stored
Throws:
[ArrayIndexOutOfBoundsException](../../../java/lang/ArrayIndexOutOfBoundsException.html "class in java.lang")
- if the coordinates are not in bounds.
See Also:
[getSample(int, int, int, DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#getSample%28int, int, int, java.awt.image.DataBuffer%29)
getDataElements
public Object getDataElements(int x, int y, Object obj, DataBuffer data)
Returns data for a single pixel in a primitive array of type TransferType. For a MultiPixelPackedSampleModel
, the array has one element, and the type is the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT that can hold a single pixel. Generally, obj
should be passed in as null
, so that the Object
is created automatically and is the correct primitive data type.
The following code illustrates transferring data for one pixel fromDataBuffer
db1
, whose storage layout is described by MultiPixelPackedSampleModel
mppsm1
, to DataBuffer
db2
, whose storage layout is described byMultiPixelPackedSampleModel
mppsm2
. The transfer is generally more efficient than usinggetPixel
or setPixel
.
MultiPixelPackedSampleModel mppsm1, mppsm2;
DataBufferInt db1, db2;
mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null,
db1), db2);
Using getDataElements
or 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 not null
, it should be a primitive array of type TransferType. Otherwise, a ClassCastException
is thrown. AnArrayIndexOutOfBoundsException
is thrown if the coordinates are not in bounds, or if obj
is not null
and is not large enough to hold the pixel data.
Specified by:
[getDataElements](../../../java/awt/image/SampleModel.html#getDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
x, y
- coordinates of the pixel location.
obj
- a primitive array in which to return the pixel data ornull
.
data
- the DataBuffer
containing the image data.
Returns:
an Object
containing data for the specified pixel.
Throws:
[ClassCastException](../../../java/lang/ClassCastException.html "class in java.lang")
- if obj
is not a primitive array of type TransferType or is not null
[ArrayIndexOutOfBoundsException](../../../java/lang/ArrayIndexOutOfBoundsException.html "class in java.lang")
- if the coordinates are not in bounds, or if obj
is not null
or not large enough to hold the pixel data
See Also:
[setDataElements(int, int, Object, DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#setDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29)
getPixel
public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
Returns the specified single band pixel in the first element of an int
array.ArrayIndexOutOfBoundsException
is thrown if the coordinates are not in bounds.
Overrides:
[getPixel](../../../java/awt/image/SampleModel.html#getPixel%28int, int, int[], java.awt.image.DataBuffer%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
x, y
- the coordinates of the pixel location
iArray
- the array containing the pixel to be returned ornull
data
- the DataBuffer
where image data is stored
Returns:
an array containing the specified pixel.
Throws:
[ArrayIndexOutOfBoundsException](../../../java/lang/ArrayIndexOutOfBoundsException.html "class in java.lang")
- if the coordinates are not in bounds
See Also:
[setPixel(int, int, int[], DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#setPixel%28int, int, int[], java.awt.image.DataBuffer%29)
setDataElements
public void setDataElements(int x, int y, Object obj, DataBuffer data)
Sets the data for a single pixel in the specified DataBuffer
from a primitive array of type TransferType. For a MultiPixelPackedSampleModel
, only the first element of the array holds valid data, and the type must be the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT that can hold a single pixel.
The following code illustrates transferring data for one pixel fromDataBuffer
db1
, whose storage layout is described by MultiPixelPackedSampleModel
mppsm1
, to DataBuffer
db2
, whose storage layout is described byMultiPixelPackedSampleModel
mppsm2
. The transfer is generally more efficient than usinggetPixel
or setPixel
.
MultiPixelPackedSampleModel mppsm1, mppsm2;
DataBufferInt db1, db2;
mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null,
db1), db2);
Using getDataElements
or setDataElements
to transfer between two DataBuffer/SampleModel
pairs is legitimate if the SampleModel
objects 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. AnArrayIndexOutOfBoundsException
is thrown if the coordinates are not in bounds, or if obj
is not large enough to hold the pixel data.
Specified by:
[setDataElements](../../../java/awt/image/SampleModel.html#setDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
x, y
- the coordinates of the pixel location
obj
- a primitive array containing pixel data
data
- the DataBuffer
containing the image data
See Also:
[getDataElements(int, int, Object, DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#getDataElements%28int, int, java.lang.Object, java.awt.image.DataBuffer%29)
setPixel
public void setPixel(int x, int y, int[] iArray, DataBuffer data)
Sets a pixel in the DataBuffer
using anint
array for input.ArrayIndexOutOfBoundsException
is thrown if the coordinates are not in bounds.
Overrides:
[setPixel](../../../java/awt/image/SampleModel.html#setPixel%28int, int, int[], java.awt.image.DataBuffer%29)
in class [SampleModel](../../../java/awt/image/SampleModel.html "class in java.awt.image")
Parameters:
x, y
- the coordinates of the pixel location
iArray
- the input pixel in an int
array
data
- the DataBuffer
containing the image data
See Also:
[getPixel(int, int, int[], DataBuffer)](../../../java/awt/image/MultiPixelPackedSampleModel.html#getPixel%28int, int, int[], java.awt.image.DataBuffer%29)
equals
public boolean equals(Object o)
Description copied from class: [Object](../../../java/lang/Object.html#equals%28java.lang.Object%29)
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y) consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
The equals method for class Object
implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x
andy
, this method returns true
if and only if x
and y
refer to the same object (x == y
has the value true
).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
Overrides:
[equals](../../../java/lang/Object.html#equals%28java.lang.Object%29)
in class [Object](../../../java/lang/Object.html "class in java.lang")
Parameters:
o
- the reference object with which to compare.
Returns:
true
if this object is the same as the obj argument; false
otherwise.
See Also:
hashCode
public int hashCode()
Description copied from class: [Object](../../../java/lang/Object.html#hashCode%28%29)
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable
.
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(Object) 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 Object.equals(java.lang.Object) 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 hashtables.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
Overrides:
[hashCode](../../../java/lang/Object.html#hashCode%28%29)
in class [Object](../../../java/lang/Object.html "class in java.lang")
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.