java.awt.image
Class MultiPixelPackedSampleModel

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 pixel
x, y from DataBufferdata
and storing the pixel data in data elements of type
dataType:

createCompatibleSampleModel

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 this
MultiPixelPackedSampleModel.

createDataBuffer

Creates a DataBuffer that corresponds to this
MultiPixelPackedSampleModel. The
DataBuffer object's data type and size
is consistent with this MultiPixelPackedSampleModel.
The DataBuffer has a single bank.

getOffset

getBitOffset

Returns the offset, in bits, into the data element in which it is
stored for the xth 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 this
MultiPixelPackedSampleModel.

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 this
MultiPixelPackedSampleModel.

getTransferType

public int getTransferType()

Returns the TransferType used to transfer pixels by way of the
getDataElements 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.

createSubsetSampleModel

Creates a new MultiPixelPackedSampleModel with a
subset of the bands of this
MultiPixelPackedSampleModel. Since a
MultiPixelPackedSampleModel only has one band, the
bands argument must have a length of one and indicate the zeroth
band.

getDataElements

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 from
DataBufferdb1, whose storage layout is
described by MultiPixelPackedSampleModelmppsm1, to DataBufferdb2,
whose storage layout is described by
MultiPixelPackedSampleModelmppsm2.
The transfer is generally more efficient than using
getPixel or setPixel.

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. An
ArrayIndexOutOfBoundsException 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.

setDataElements

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 from
DataBufferdb1, whose storage layout is
described by MultiPixelPackedSampleModelmppsm1, to DataBufferdb2,
whose storage layout is described by
MultiPixelPackedSampleModelmppsm2.
The transfer is generally more efficient than using
getPixel or setPixel.

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. An
ArrayIndexOutOfBoundsException is thrown if the
coordinates are not in bounds, or if obj is not large
enough to hold the pixel data.

It is reflexive: for any non-null reference value
x, x.equals(x) should return
true.

It is symmetric: for any non-null reference values
x and y, x.equals(y)
should return true if and only if
y.equals(x) returns true.

It is transitive: for any non-null reference values
x, y, and z, if
x.equals(y) returns true and
y.equals(z) returns true, then
x.equals(z) should return true.

It is consistent: for any non-null reference values
x and y, multiple invocations of
x.equals(y) consistently return true
or consistently return false, provided no
information used in equals comparisons on the
objects is modified.

For any non-null reference value x,
x.equals(null) should return false.

The equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, 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.

hashCode

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