is new.
java.lang.Objectjava.awt.image.SampleModel
java.awt.image.MultiPixelPackedSampleModel
public 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 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);
| Field Summary |
|---|
| 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. |
| 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
(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. |
| int |
hashCode
() Returns a hash code value for the object. |
| 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 , finalize , getClass , notify , notifyAll , toString , wait , wait , wait |
| Constructor Detail |
|---|
public MultiPixelPackedSampleModel(int dataType,
int w,
int h,
int numberOfBits)
public MultiPixelPackedSampleModel(int dataType,
int w,
int h,
int numberOfBits,
int scanlineStride,
int dataBitOffset)
| Method Detail |
|---|
public SampleModel createCompatibleSampleModel(int w,
int h)
public DataBuffer createDataBuffer()
public int getNumDataElements()
public int[] getSampleSize()
public int getSampleSize(int band)
public int getOffset(int x,
int y)
x - the X coordinate of the specified pixel
y - the Y coordinate of the specified pixel
public int getBitOffset(int x)
public int getScanlineStride()
public int getPixelBitStride()
public int getDataBitOffset()
public int getTransferType()
public SampleModel createSubsetSampleModel(int[] bands)
public int getSample(int x,
int y,
int b,
DataBuffer data)
x
X coordinate
y - the Y coordinate of the specified pixel
public void setSample(int x,
int y,
int b,
int s,
DataBuffer data)
x
X coordinate
y - the Y coordinate of the specified pixel
public Object getDataElements(int x,
int y,
Object obj,
DataBuffer data)
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.
x
the X coordinate
specified
pixel
y - the Y coordinate of the specified pixel
public int[] getPixel(int x,
int y,
int[] iArray,
DataBuffer data)
x
X coordinate
specified
pixel
y - the Y coordinate of the specified pixel
public void setDataElements(int x,
int y,
Object obj,
DataBuffer data)
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.
x
X coordinate
y - the Y coordinate of the pixel location
public void setPixel(int x,
int y,
int[] iArray,
DataBuffer data)
x
X coordinate
y - the Y coordinate of the pixel location
public boolean equals(Object o)
The equals method implements an equivalence relation on non-null object references:
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.
public int hashCode()
The general contract of hashCode is:
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 Java TM programming language.)