APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.image

public Class MultiPixelPackedSampleModel

extends SampleModel
Class Inheritance

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

Modifier and TypeField and Description
pack-priv int
bitMask

Bitmask that extracts the rightmost pixel of a data element.

pack-priv int
dataBitOffset

The bit offset into the data array where the first pixel begins.

pack-priv int
dataElementSize

The size of a data element in bits.

pack-priv int
pixelBitStride

The number of bits from one pixel to the next.

pack-priv int
pixelsPerDataElement

The number of pixels that fit in a data element.

pack-priv int
scanlineStride

ScanlineStride of the data buffer described in data array elements.

Inherited from java.awt.image.SampleModel:
dataTypeheightnumBandswidth

Constructor Summary

AccessConstructor and Description
public
MultiPixelPackedSampleModel(int
the data type for storing samples
dataType
,
int
the width, in pixels, of the region of image data described
w
,
int
the height, in pixels, of the region of image data described
h
,
int
the number of bits per pixel
numberOfBits
)

Constructs a MultiPixelPackedSampleModel with the specified data type, width, height and number of bits per pixel.

public
MultiPixelPackedSampleModel(int
the data type for storing samples
dataType
,
int
the width, in pixels, of the region of image data described
w
,
int
the height, in pixels, of the region of image data described
h
,
int
the number of bits per pixel
numberOfBits
,
int
the line stride of the image data
scanlineStride
,
int
the data bit offset for the region of image data described
dataBitOffset
)

Constructs a MultiPixelPackedSampleModel with specified data type, width, height, number of bits per pixel, scanline stride and data bit offset.

Method Summary

Modifier and TypeMethod and Description
public SampleModel

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.
createCompatibleSampleModel
(int
the specified width
w
,
int
the specified height
h
)

Implements abstract java.awt.image.SampleModel.createCompatibleSampleModel.

Creates a new MultiPixelPackedSampleModel with the specified width and height.

public DataBuffer

Returns:

a DataBuffer with the same data type and size as this MultiPixelPackedSampleModel.
createDataBuffer
()

Implements abstract java.awt.image.SampleModel.createDataBuffer.

Creates a DataBuffer that corresponds to this MultiPixelPackedSampleModel.

public SampleModel

Returns:

a new SampleModel with the same bands as this MultiPixelPackedSampleModel.
createSubsetSampleModel
(int[]
the specified bands (ignored)
bands
)

Implements abstract java.awt.image.SampleModel.createSubsetSampleModel.

Creates a new MultiPixelPackedSampleModel with a subset of the bands of this MultiPixelPackedSampleModel.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int

Returns:

the bit offset of the specified pixel.
getBitOffset
(int
the specified pixel
x
)

Returns the offset, in bits, into the data element in which it is stored for the xth pixel of a scanline.

public int

Returns:

the dataBitOffset of this MultiPixelPackedSampleModel.
getDataBitOffset
()

Returns the data bit offset in bits.

public Object

Returns:

an Object containing data for the specified pixel.
getDataElements
(int
the X coordinate of the specified pixel
x
,
int
the Y coordinate of the specified pixel
y
,
Object
a primitive array in which to return the pixel data or null.
obj
,
DataBuffer
the DataBuffer containing the image data.
data
)

Implements abstract java.awt.image.SampleModel.getDataElements.

Returns data for a single pixel in a primitive array of type TransferType.

public int

Returns:

the number of data elements.
getNumDataElements
()

Implements abstract java.awt.image.SampleModel.getNumDataElements.

Returns the number of data elements needed to transfer one pixel via the getDataElements and setDataElements methods.

public int

Returns:

the offset of the specified pixel.
getOffset
(int
the X coordinate of the specified pixel
x
,
int
the Y coordinate of the specified pixel
y
)

Returns the offset of pixel (x, y) in data array elements.

public int[]

Returns:

an array containing the specified pixel.
getPixel
(int
the X coordinate of the specified pixel
x
,
int
the Y coordinate of the specified pixel
y
,
int[]
the array containing the pixel to be returned or null
iArray
,
DataBuffer
the DataBuffer where image data is stored
data
)

Overrides java.awt.image.SampleModel.getPixel.

Returns the specified single band pixel in the first element of an int array.

public int

Returns:

the pixelBitStride of this MultiPixelPackedSampleModel.
getPixelBitStride
()

Returns the pixel bit stride in bits.

public int

Returns:

the specified band containing the sample of the specified pixel.
getSample
(int
the X coordinate of the specified pixel
x
,
int
the Y coordinate of the specified pixel
y
,
int
the band to return, which must be 0
b
,
DataBuffer
the DataBuffer containing the image data
data
)

Implements abstract java.awt.image.SampleModel.getSample.

Returns as int the sample in a specified band for the pixel located at (x, y).

public int[]

Returns:

the number of bits per sample.
getSampleSize
()

Implements abstract java.awt.image.SampleModel.getSampleSize.

Returns the number of bits per sample for all bands.

public int

Returns:

the number of bits per sample for the specified band.
getSampleSize
(int
the specified band (ignored)
band
)

Implements abstract java.awt.image.SampleModel.getSampleSize.

Returns the number of bits per sample for the specified band.

public int

Returns:

the scanline stride of this MultiPixelPackedSampleModel.
getScanlineStride
()

Returns the scanline stride.

public int

Returns:

the transfertype.
getTransferType
()

Overrides java.awt.image.SampleModel.getTransferType.

Returns the TransferType used to transfer pixels by way of the getDataElements and setDataElements methods.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
setDataElements(int
the X coordinate of the pixel location
x
,
int
the Y coordinate of the pixel location
y
,
Object
a primitive array containing pixel data
obj
,
DataBuffer
the DataBuffer containing the image data
data
)

Implements abstract java.awt.image.SampleModel.setDataElements.

Sets the data for a single pixel in the specified DataBuffer from a primitive array of type TransferType.

public void
setPixel(int
the X coordinate of the pixel location
x
,
int
the Y coordinate of the pixel location
y
,
int[]
the input pixel in an int array
iArray
,
DataBuffer
the DataBuffer containing the image data
data
)

Overrides java.awt.image.SampleModel.setPixel.

Sets a pixel in the DataBuffer using an int array for input.

public void
setSample(int
the X coordinate of the specified pixel
x
,
int
the Y coordinate of the specified pixel
y
,
int
the band to set, which must be 0
b
,
int
the input sample as an int
s
,
DataBuffer
the DataBuffer where image data is stored
data
)

Implements abstract java.awt.image.SampleModel.setSample.

Sets a sample in the specified band for the pixel located at (x, y) in the DataBuffer using an int for input.

Inherited from java.awt.image.SampleModel:
getDataElementsgetDataTypegetHeightgetNumBandsgetPixelgetPixelgetPixelsgetPixelsgetPixelsgetSampleDoublegetSampleFloatgetSamplesgetSamplesgetSamplesgetWidthsetDataElementssetPixelsetPixelsetPixelssetPixelssetPixelssetSamplesetSamplesetSamplessetSamplessetSamples

Field Detail

bitMaskback to summary
pack-priv int bitMask

Bitmask that extracts the rightmost pixel of a data element.

dataBitOffsetback to summary
pack-priv int dataBitOffset

The bit offset into the data array where the first pixel begins.

dataElementSizeback to summary
pack-priv int dataElementSize

The size of a data element in bits.

pixelBitStrideback to summary
pack-priv int pixelBitStride

The number of bits from one pixel to the next.

pixelsPerDataElementback to summary
pack-priv int pixelsPerDataElement

The number of pixels that fit in a data element. Also used as the number of bits per pixel.

scanlineStrideback to summary
pack-priv int scanlineStride

ScanlineStride of the data buffer described in data array elements.

Constructor Detail

MultiPixelPackedSampleModelback to summary
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:int

the data type for storing samples

w:int

the width, in pixels, of the region of image data described

h:int

the height, in pixels, of the region of image data described

numberOfBits:int

the number of bits per pixel

Exceptions
IllegalArgumentException:
  • if dataType is not either DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
  • if either w or h is less than or equal to 0
RasterFormatException:
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.
MultiPixelPackedSampleModelback to summary
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:int

the data type for storing samples

w:int

the width, in pixels, of the region of image data described

h:int

the height, in pixels, of the region of image data described

numberOfBits:int

the number of bits per pixel

scanlineStride:int

the line stride of the image data

dataBitOffset:int

the data bit offset for the region of image data described

Exceptions
IllegalArgumentException:
  • if dataType is not either DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
  • if either w or h is less than or equal to 0
  • if scanlineStride is less than or equal to 0
  • if dataBitOffset is less than zero, or not a multiple of numberOfBits.
RasterFormatException:
  • if ((numberOfBits * (long)w) + DataBuffer.getDataTypeSize(dataType) - 1) / DataBuffer.getDataTypeSize(dataType) is greater than scanlineStride
  • 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.

Method Detail

createCompatibleSampleModelback to summary
public SampleModel createCompatibleSampleModel(int w, int h)

Implements abstract java.awt.image.SampleModel.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.

Parameters
w:int

the specified width

h:int

the specified height

Returns:SampleModel

a SampleModel with the specified width and height and with the same storage data type and number of bits per pixel as this MultiPixelPackedSampleModel.

Exceptions
IllegalArgumentException:
if w or h is not greater than 0
createDataBufferback to summary
public DataBuffer createDataBuffer()

Implements abstract java.awt.image.SampleModel.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.

Returns:DataBuffer

a DataBuffer with the same data type and size as this MultiPixelPackedSampleModel.

createSubsetSampleModelback to summary
public SampleModel createSubsetSampleModel(int[] bands)

Implements abstract java.awt.image.SampleModel.createSubsetSampleModel.

Creates a new MultiPixelPackedSampleModel with a subset of the bands of this MultiPixelPackedSampleModel. Since a MultiPixelPackedSampleModel only has one band, the bands argument is ignored.

Parameters
bands:int[]

the specified bands (ignored)

Returns:SampleModel

a new SampleModel with the same bands as this MultiPixelPackedSampleModel.

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

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

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

getBitOffsetback to summary
public 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. This offset is the same for all scanlines.

Parameters
x:int

the specified pixel

Returns:int

the bit offset of the specified pixel.

getDataBitOffsetback to summary
public int getDataBitOffset()

Returns the data bit offset in bits.

Returns:int

the dataBitOffset of this MultiPixelPackedSampleModel.

getDataElementsback to summary
public Object getDataElements(int x, int y, Object obj, DataBuffer data)

Implements abstract java.awt.image.SampleModel.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 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.

Parameters
x:int

the X coordinate of the specified pixel

y:int

the Y coordinate of the specified pixel

obj:Object

a primitive array in which to return the pixel data or null.

data:DataBuffer

the DataBuffer containing the image data.

Returns:Object

an Object containing data for the specified pixel.

Exceptions
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 data
  • if the coordinates are not in bounds, or if {code obj} is too small to hold the output.
NullPointerException:
if data is null.
See Also
setDataElements(int, int, Object, DataBuffer)
getNumDataElementsback to summary
public int getNumDataElements()

Implements abstract java.awt.image.SampleModel.getNumDataElements.

Returns the number of data elements needed to transfer one pixel via the getDataElements and setDataElements methods. For a MultiPixelPackedSampleModel, this is one.

Returns:int

the number of data elements.

getOffsetback to summary
public int getOffset(int x, int y)

Returns the offset of pixel (x, y) in data array elements.

Parameters
x:int

the X coordinate of the specified pixel

y:int

the Y coordinate of the specified pixel

Returns:int

the offset of the specified pixel.

getPixelback to summary
public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.getPixel.

Returns the specified single band pixel in the first element of an int array. ArrayIndexOutOfBoundsException is thrown if the coordinates are not in bounds.

Parameters
x:int

the X coordinate of the specified pixel

y:int

the Y coordinate of the specified pixel

iArray:int[]

the array containing the pixel to be returned or null

data:DataBuffer

the DataBuffer where image data is stored

Returns:int[]

an array containing the specified pixel.

Exceptions
ArrayIndexOutOfBoundsException:
  • if the coordinates are not in bounds, or if iArray is too small to hold the output.
  • if the coordinates are not in bounds, or if iArray is too small to hold the output.
NullPointerException:
if data is null.
See Also
setPixel(int, int, int[], DataBuffer)
getPixelBitStrideback to summary
public int getPixelBitStride()

Returns the pixel bit stride in bits. This value is the same as the number of bits per pixel.

Returns:int

the pixelBitStride of this MultiPixelPackedSampleModel.

getSampleback to summary
public int getSample(int x, int y, int b, DataBuffer data)

Implements abstract java.awt.image.SampleModel.getSample.

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.

Parameters
x:int

the X coordinate of the specified pixel

y:int

the Y coordinate of the specified pixel

b:int

the band to return, which must be 0

data:DataBuffer

the DataBuffer containing the image data

Returns:int

the specified band containing the sample of the specified pixel.

Exceptions
ArrayIndexOutOfBoundsException:
if the specified coordinates are not in bounds.
See Also
setSample(int, int, int, int, DataBuffer)
getSampleSizeback to summary
public int[] getSampleSize()

Implements abstract java.awt.image.SampleModel.getSampleSize.

Returns the number of bits per sample for all bands.

Returns:int[]

the number of bits per sample.

getSampleSizeback to summary
public int getSampleSize(int band)

Implements abstract java.awt.image.SampleModel.getSampleSize.

Returns the number of bits per sample for the specified band.

Since MultiPixelPackedSampleModel has only one band, this method ignores the band parameter and returns the sample size of the single band.

Parameters
band:int

the specified band (ignored)

Returns:int

the number of bits per sample for the specified band.

getScanlineStrideback to summary
public int getScanlineStride()

Returns the scanline stride.

Returns:int

the scanline stride of this MultiPixelPackedSampleModel.

getTransferTypeback to summary
public int getTransferType()

Overrides java.awt.image.SampleModel.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.

Returns:int

the transfertype.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

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 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 equals 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 hash tables.
setDataElementsback to summary
public void setDataElements(int x, int y, Object obj, DataBuffer data)

Implements abstract java.awt.image.SampleModel.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 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.

Parameters
x:int

the X coordinate of the pixel location

y:int

the Y coordinate of the pixel location

obj:Object

a primitive array containing pixel data

data:DataBuffer

the DataBuffer containing the image data

Exceptions
NullPointerException:
if obj or data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if obj is too small to hold the input.
See Also
getDataElements(int, int, Object, DataBuffer)
setPixelback to summary
public void setPixel(int x, int y, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.setPixel.

Sets a pixel in the DataBuffer using an int array for input. ArrayIndexOutOfBoundsException is thrown if the coordinates are not in bounds.

Parameters
x:int

the X coordinate of the pixel location

y:int

the Y coordinate of the pixel location

iArray:int[]

the input pixel in an int array

data:DataBuffer

the DataBuffer containing the image data

Exceptions
NullPointerException:
if iArray or data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if iArray is too small to hold the input.
See Also
getPixel(int, int, int[], DataBuffer)
setSampleback to summary
public void setSample(int x, int y, int b, int s, DataBuffer data)

Implements abstract java.awt.image.SampleModel.setSample.

Sets a sample in the specified band for the pixel located at (x, y) in the DataBuffer using an int for input. An ArrayIndexOutOfBoundsException is thrown if the coordinates are not in bounds.

Parameters
x:int

the X coordinate of the specified pixel

y:int

the Y coordinate of the specified pixel

b:int

the band to set, which must be 0

s:int

the input sample as an int

data:DataBuffer

the DataBuffer where image data is stored

Exceptions
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds.
See Also
getSample(int, int, int, DataBuffer)