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

public Class SinglePixelPackedSampleModel

extends SampleModel
Class Inheritance
Imports
java.util.Arrays

This class represents pixel data packed such that the N samples which make up a single pixel are stored in a single data array element, and each data data array element holds samples for only one pixel. This class supports TYPE_BYTE, TYPE_USHORT, TYPE_INT data types. All data array elements reside in the first bank of a DataBuffer. Accessor methods are provided so that the image data can be manipulated directly. Scanline stride is the number of data array elements between a given sample and the corresponding sample in the same column of the next scanline. Bit masks are the masks required to extract the samples representing the bands of the pixel. Bit offsets are the offsets in bits into the data array element of the samples representing the bands of the pixel.

The following code illustrates extracting the bits of the sample representing band b for pixel x,y from DataBuffer data:

int sample = data.getElem(y * scanlineStride + x);
     sample = (sample & bitMasks[b]) >>> bitOffsets[b];

Field Summary

Modifier and TypeField and Description
private int[]
bitMasks

Bit masks for all bands of the image data.

private int[]
bitOffsets

Bit Offsets for all bands of the image data.

private int[]
bitSizes

Bit sizes for all the bands of the image data.

private int
maxBitSize

Maximum bit size.

private int
scanlineStride

Line stride of the region of image data described by this SinglePixelPackedSampleModel.

Inherited from java.awt.image.SampleModel:
dataTypeheightnumBandswidth

Constructor Summary

AccessConstructor and Description
public
SinglePixelPackedSampleModel(int
The data type for storing samples.
dataType
,
int
The width (in pixels) of the region of the image data described.
w
,
int
The height (in pixels) of the region of the image data described.
h
,
int[]
The bit masks for all bands.
bitMasks
)

Constructs a SinglePixelPackedSampleModel with bitMasks.length bands.

public
SinglePixelPackedSampleModel(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 line stride of the image data.
scanlineStride
,
int[]
The bit masks for all bands.
bitMasks
)

Constructs a SinglePixelPackedSampleModel with bitMasks.length bands and a scanline stride equal to scanlineStride data array elements.

Method Summary

Modifier and TypeMethod and Description
public SampleModel

Returns:

a SinglePixelPackedSampleModel with the specified width and height.
createCompatibleSampleModel
(int
the width of the resulting SampleModel
w
,
int
the height of the resulting SampleModel
h
)

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

Creates a new SinglePixelPackedSampleModel with the specified width and height.

public DataBuffer
createDataBuffer()

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

Creates a DataBuffer that corresponds to this SinglePixelPackedSampleModel.

public SampleModel
createSubsetSampleModel(int[] bands)

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

This creates a new SinglePixelPackedSampleModel with a subset of the bands of this SinglePixelPackedSampleModel.

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 masks for all bands.
getBitMasks
()

Returns the bit masks for all bands.

public int[]

Returns:

the bit offsets representing a pixel for all bands.
getBitOffsets
()

Returns the bit offsets into the data array element representing a pixel for all bands.

private long
getBufferSize()

Returns the size of the buffer (in data array elements) needed for a data buffer that matches this SinglePixelPackedSampleModel.

public Object

Returns:

the data for the specified pixel.
getDataElements
(int
The X coordinate of the pixel location.
x
,
int
The Y coordinate of the pixel location.
y
,
Object
If non-null, a primitive array in which to return the pixel data.
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
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 (in data array elements) of pixel (x,y).

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

Overrides java.awt.image.SampleModel.getPixel.

Returns the samples for a specified pixel in an int array, one sample per array element.

public int[]
getPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.getPixels.

Returns all samples for a rectangle of pixels in an int array, one sample per array element.

public int
getSample(int x, int y, int b, DataBuffer data)

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

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

public int[]
getSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.getSamples.

Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element.

public int[]
getSampleSize()

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

Returns the number of bits per sample for all bands.

public int

Returns:

the size of the samples of the specified band.
getSampleSize
(int
the specified band
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 SinglePixelPackedSampleModel.
getScanlineStride
()

Returns the scanline stride of this SinglePixelPackedSampleModel.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private static native void
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 x, int y, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.setPixel.

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

public void
setPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.setPixels.

Sets all samples for a rectangle of pixels from an int array containing one sample per array element.

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.

public void
setSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.setSamples.

Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element.

Inherited from java.awt.image.SampleModel:
getDataElementsgetDataTypegetHeightgetNumBandsgetPixelgetPixelgetPixelsgetPixelsgetSampleDoublegetSampleFloatgetSamplesgetSamplesgetTransferTypegetWidthsetDataElementssetPixelsetPixelsetPixelssetPixelssetSamplesetSamplesetSamplessetSamples

Field Detail

bitMasksback to summary
private int[] bitMasks

Bit masks for all bands of the image data.

bitOffsetsback to summary
private int[] bitOffsets

Bit Offsets for all bands of the image data.

bitSizesback to summary
private int[] bitSizes

Bit sizes for all the bands of the image data.

maxBitSizeback to summary
private int maxBitSize

Maximum bit size.

scanlineStrideback to summary
private int scanlineStride

Line stride of the region of image data described by this SinglePixelPackedSampleModel.

Constructor Detail

SinglePixelPackedSampleModelback to summary
public SinglePixelPackedSampleModel(int dataType, int w, int h, int[] bitMasks)

Constructs a SinglePixelPackedSampleModel with bitMasks.length bands. Each sample is stored in a data array element in the position of its corresponding bit mask. Each bit mask must be contiguous and masks must not overlap. Bit masks exceeding data type capacity are truncated.

Parameters
dataType:int

The data type for storing samples.

w:int

The width (in pixels) of the region of the image data described.

h:int

The height (in pixels) of the region of the image data described.

bitMasks:int[]

The bit masks for all bands.

Exceptions
IllegalArgumentException:
if dataType is not either DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
SinglePixelPackedSampleModelback to summary
public SinglePixelPackedSampleModel(int dataType, int w, int h, int scanlineStride, int[] bitMasks)

Constructs a SinglePixelPackedSampleModel with bitMasks.length bands and a scanline stride equal to scanlineStride data array elements. Each sample is stored in a data array element in the position of its corresponding bit mask. Each bit mask must be contiguous and masks must not overlap. Bit masks exceeding data type capacity are truncated.

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.

scanlineStride:int

The line stride of the image data.

bitMasks:int[]

The bit masks for all bands.

Exceptions
IllegalArgumentException:
  • if w or h is not greater than 0
  • if any mask in bitMask is not contiguous
  • if dataType is not either DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT

Method Detail

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

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

Creates a new SinglePixelPackedSampleModel with the specified width and height. The new SinglePixelPackedSampleModel will have the same storage data type and bit masks as this SinglePixelPackedSampleModel.

Parameters
w:int

the width of the resulting SampleModel

h:int

the height of the resulting SampleModel

Returns:SampleModel

a SinglePixelPackedSampleModel with the specified width and height.

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 SinglePixelPackedSampleModel. The DataBuffer's data type and size will be consistent with this SinglePixelPackedSampleModel. The DataBuffer will have a single bank.

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

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

This creates a new SinglePixelPackedSampleModel with a subset of the bands of this SinglePixelPackedSampleModel. The new SinglePixelPackedSampleModel can be used with any DataBuffer that the existing SinglePixelPackedSampleModel can be used with. The new SinglePixelPackedSampleModel/DataBuffer combination will represent an image with a subset of the bands of the original SinglePixelPackedSampleModel/DataBuffer combination.

Exceptions
NullPointerException:
if bands is null
IllegalArgumentException:
if the number of bands is not greater than 0
RasterFormatException:
if the length of the bands argument is greater than the number of bands in the sample model.
ArrayIndexOutOfBoundsException:
if any of the bank indices is out of bounds
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.

getBitMasksback to summary
public int[] getBitMasks()

Returns the bit masks for all bands.

Returns:int[]

the bit masks for all bands.

getBitOffsetsback to summary
public int[] getBitOffsets()

Returns the bit offsets into the data array element representing a pixel for all bands.

Returns:int[]

the bit offsets representing a pixel for all bands.

getBufferSizeback to summary
private long getBufferSize()

Returns the size of the buffer (in data array elements) needed for a data buffer that matches this SinglePixelPackedSampleModel.

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 SinglePixelPackedSampleModel, the array will have one element, and the type will be the same as the storage data type. Generally, obj should be passed in as null, so that the Object will be created automatically and will be of the right primitive data type.

The following code illustrates transferring data for one pixel from DataBuffer db1, whose storage layout is described by SinglePixelPackedSampleModel sppsm1, to DataBuffer db2, whose storage layout is described by SinglePixelPackedSampleModel sppsm2. The transfer will generally be more efficient than using getPixel/setPixel.

      SinglePixelPackedSampleModel sppsm1, sppsm2;
      DataBufferInt db1, db2;
      sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null,
                             db1), db2);
Using getDataElements/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 non-null, it should be a primitive array of type TransferType. Otherwise, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds, or if obj is non-null and 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

If non-null, a primitive array in which to return the pixel data.

data:DataBuffer

The DataBuffer containing the image data.

Returns:Object

the data for the specified pixel.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if obj is too small to hold the output.
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 SinglePixelPackedSampleModel, this is one.

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

Returns the offset (in data array elements) of pixel (x,y). The data element containing pixel x,y can be retrieved from a DataBuffer data with a SinglePixelPackedSampleModel sppsm as:

       data.getElem(sppsm.getOffset(x, y));
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.

Doc from java.awt.image.SampleModel.getPixel.

Returns the samples for a specified pixel in an int array, one sample per array element. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if iArray is too small to hold the output.
getPixelsback to summary
public int[] getPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.getPixels.

Doc from java.awt.image.SampleModel.getPixels.

Returns all samples for a rectangle of pixels in an int array, one sample per array element. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Annotations
@Override
Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or w or h is negative or if iArray is too small to hold the output.
getSampleback to summary
public int getSample(int x, int y, int b, DataBuffer data)

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

Doc from java.awt.image.SampleModel.getSample.

Returns the sample in a specified band for the pixel located at (x,y) as an int. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or the band index are not in bounds.
getSamplesback to summary
public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.getSamples.

Doc from java.awt.image.SampleModel.getSamples.

Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or band index are not in bounds, or w or h is negative, or if iArray is too small to hold the output.
getSampleSizeback to summary
public int[] getSampleSize()

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

Returns the number of bits per sample for all bands.

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.

Parameters
band:int

the specified band

Returns:int

the size of the samples of the specified band.

Exceptions
ArrayIndexOutOfBoundsException:
if the band index is less than zero or greater than or equal to getNumBands()
getScanlineStrideback to summary
public int getScanlineStride()

Returns the scanline stride of this SinglePixelPackedSampleModel.

Returns:int

the scanline stride of this SinglePixelPackedSampleModel.

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.
initIDsback to summary
private static native void initIDs()

Hides java.awt.image.SampleModel.initIDs.

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 SinglePixelPackedSampleModel, only the first element of the array will hold valid data, and the type of the array must be the same as the storage data type of the SinglePixelPackedSampleModel.

The following code illustrates transferring data for one pixel from DataBuffer db1, whose storage layout is described by SinglePixelPackedSampleModel sppsm1, to DataBuffer db2, whose storage layout is described by SinglePixelPackedSampleModel sppsm2. The transfer will generally be more efficient than using getPixel/setPixel.

      SinglePixelPackedSampleModel sppsm1, sppsm2;
      DataBufferInt db1, db2;
      sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null,
                             db1), db2);
Using getDataElements/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.

obj must be a primitive array of type TransferType. Otherwise, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException may be 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.

Doc from java.awt.image.SampleModel.setPixel.

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

Exceptions
NullPointerException:
if iArray or {code data} is null.
ArrayIndexOutOfBoundsException:
if the coordinates are not in bounds, or if iArray is too small to hold the input.
setPixelsback to summary
public void setPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.setPixels.

Doc from java.awt.image.SampleModel.setPixels.

Sets all samples for a rectangle of pixels from an int array containing one sample per array element. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

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

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

Doc from 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. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

setSamplesback to summary
public void setSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)

Overrides java.awt.image.SampleModel.setSamples.

Doc from java.awt.image.SampleModel.setSamples.

Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Exceptions
NullPointerException:
if iArray or data is null.
ArrayIndexOutOfBoundsException:
if the coordinates or band index are not in bounds, or w or h is negative, or if iArray is too small to hold the input.