|
JavaTM 2 Platform Std. Ed. v1.3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.image.SampleModel | +--java.awt.image.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 DataBuffer
data
and storing the pixel data in data elements of type
dataType
:
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);
Fields inherited from class java.awt.image.SampleModel |
dataType, height, numBands, width |
Constructor Summary | |
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. |
|
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. |
Method Summary | |
SampleModel |
createCompatibleSampleModel(int w,
int h)
Creates a new MultiPixelPackedSampleModel with the
specified width and height. |
DataBuffer |
createDataBuffer()
Creates a DataBuffer that corresponds to this
MultiPixelPackedSampleModel . |
SampleModel |
createSubsetSampleModel(int[] bands)
Creates a new MultiPixelPackedSampleModel with a
subset of the bands of this
MultiPixelPackedSampleModel . |
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. |
int |
getDataBitOffset()
Returns the data bit offset in bits. |
Object |
getDataElements(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) and setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
methods. |
int |
getOffset(int x,
int y)
Returns the offset of pixel (x, y) in data array elements. |
int[] |
getPixel(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(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 the getDataElements and setDataElements
methods. |
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. |
void |
setPixel(int x,
int y,
int[] iArray,
DataBuffer data)
Sets a pixel in the DataBuffer using an
int array for input. |
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 an
int for input. |
Methods inherited from class java.awt.image.SampleModel |
getDataElements, getDataType, getHeight, getNumBands, getPixel, getPixel, getPixels, getPixels, getPixels, getSampleDouble, getSampleFloat, getSamples, getSamples, getSamples, getWidth, setDataElements, setPixel, setPixel, setPixels, setPixels, setPixels, setSample, setSample, setSamples, setSamples, setSamples |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits)
MultiPixelPackedSampleModel
with the
specified data type, width, height and number of bits per pixel.dataType
- the data type for storing samplesw
- the width, in pixels, of the region of
image data describedh
- the height, in pixels, of the region of
image data describednumberOfBits
- the number of bits per pixelIllegalArgumentException
- if dataType
is not
either DataBuffer.TYPE_BYTE
,
DataBuffer.TYPE_USHORT
, or
DataBuffer.TYPE_INT
public MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits, int scanlineStride, int dataBitOffset)
MultiPixelPackedSampleModel
with
specified data type, width, height, number of bits per pixel,
scanline stride and data bit offset.dataType
- the data type for storing samplesw
- the width, in pixels, of the region of
image data describedh
- the height, in pixels, of the region of
image data describednumberOfBits
- the number of bits per pixelscanlineStride
- the line stride of the image datadataBitOffset
- the data bit offset for the region of image
data describedRasterFormatException
- 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
- if w
or
h
is not greater than 0IllegalArgumentException
- if dataType
is not
either DataBuffer.TYPE_BYTE
,
DataBuffer.TYPE_USHORT
, or
DataBuffer.TYPE_INT
Method Detail |
public SampleModel createCompatibleSampleModel(int w, int h)
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
.createCompatibleSampleModel
in class SampleModel
w
- the specified widthh
- the specified heightSampleModel
with the specified width and height
and with the same storage data type and number of bits per pixel
as this MultiPixelPackedSampleModel
.IllegalArgumentException
- if w
or
h
is not greater than 0public DataBuffer createDataBuffer()
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.createDataBuffer
in class SampleModel
DataBuffer
with the same data type and
size as this MultiPixelPackedSampleModel
.public int getNumDataElements()
getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
and setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
methods. For a MultiPixelPackedSampleModel
, this is
one.getNumDataElements
in class SampleModel
public int[] getSampleSize()
getSampleSize
in class SampleModel
public int getSampleSize(int band)
getSampleSize
in class SampleModel
band
- the specified bandpublic int getOffset(int x, int y)
x, y
- the specified pixelpublic int getBitOffset(int x)
x
th pixel of a scanline.
This offset is the same for all scanlines.x
- the specified pixelpublic int getScanlineStride()
MultiPixelPackedSampleModel
.public int getPixelBitStride()
pixelBitStride
of this
MultiPixelPackedSampleModel
.public int getDataBitOffset()
dataBitOffset
of this
MultiPixelPackedSampleModel
.public int getTransferType()
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.getTransferType
in class SampleModel
public SampleModel createSubsetSampleModel(int[] bands)
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.createSubsetSampleModel
in class SampleModel
bands
- the specified bandsSampleModel
with a subset of bands of
this MultiPixelPackedSampleModel
.RasterFormatException
- if the number of bands requested
is not one.IllegalArgumentException
- if w
or
h
is not greater than 0public int getSample(int x, int y, int b, DataBuffer data)
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.getSample
in class SampleModel
x, y
- the coordinates of the specified pixelb
- the band to return, which is assumed to be 0data
- the DataBuffer
containing the image
dataArrayIndexOutOfBoundException
- if the specified
coordinates are not in bounds.public void setSample(int x, int y, int b, int s, DataBuffer data)
DataBuffer
using an
int
for input.
An ArrayIndexOutOfBoundsException
is thrown if the
coordinates are not in bounds.setSample
in class SampleModel
x, y
- the coordinates of the specified pixelb
- the band to return, which is assumed to be 0s
- the input sample as an int
data
- the DataBuffer
where image data is storedArrayIndexOutOfBoundsException
- if the coordinates are
not in bounds.public Object getDataElements(int x, int y, Object obj, DataBuffer data)
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
DataBuffer
db1
, whose storage layout is
described by MultiPixelPackedSampleModel
mppsm1
, to DataBuffer
db2
,
whose storage layout is described by
MultiPixelPackedSampleModel
mppsm2
.
The transfer is generally more efficient than using
getPixel
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. 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.
getDataElements
in class SampleModel
x, y
- coordinates of the pixel location.obj
- a primitive array in which to return the pixel data or
null
.data
- the DataBuffer
containing the image data.Object
containing data for the specified
pixel.ClassCastException
- if obj
is not a
primitive array of type TransferType or is not null
ArrayIndexOutOfBoundsException
- if the coordinates are
not in bounds, or if obj
is not null
or
not large enough to hold the pixel datapublic int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
int
array.
ArrayIndexOutOfBoundsException
is thrown if the
coordinates are not in bounds.getPixel
in class SampleModel
x, y
- the coordinates of the pixel locationiArray
- the array containing the pixel to be returned or
null
data
- the DataBuffer
where image data is storedArrayIndexOutOfBoundsException
- if the coordinates
are not in boundspublic void setDataElements(int x, int y, Object obj, DataBuffer data)
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
DataBuffer
db1
, whose storage layout is
described by MultiPixelPackedSampleModel
mppsm1
, to DataBuffer
db2
,
whose storage layout is described by
MultiPixelPackedSampleModel
mppsm2
.
The transfer is generally more efficient than using
getPixel
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. An
ArrayIndexOutOfBoundsException
is thrown if the
coordinates are not in bounds, or if obj
is not large
enough to hold the pixel data.
setDataElements
in class SampleModel
x, y
- the coordinates of the pixel locationobj
- a primitive array containing pixel datadata
- the DataBuffer
containing the image datapublic void setPixel(int x, int y, int[] iArray, DataBuffer data)
DataBuffer
using an
int
array for input.
ArrayIndexOutOfBoundsException
is thrown if
the coordinates are not in bounds.setPixel
in class SampleModel
x, y
- the coordinates of the pixel locationiArray
- the input pixel in an int
arraydata
- the DataBuffer
containing the image data
|
JavaTM 2 Platform Std. Ed. v1.3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.