Java Platform 1.2
Beta 4

Class java.awt.image.MultiPixelPackedSampleModel

java.lang.Object
  |
  +--java.awt.image.SampleModel
        |
        +--java.awt.image.MultiPixelPackedSampleModel

public class MultiPixelPackedSampleModel
extends SampleModel
This 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 may 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 may 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 storing pixel data in data elements of type dataType:

> 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, int scanlineStride, int dataBitOffset)
          Constructs a MultiPixelPackedSampleModel with given data type, width, height, number of bits per pixel, scanline stride and data bit offset.
MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits)
          Constructs a MultiPixelPackedSampleModel with the given data type, width, height and number of bits per pixel.
 
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 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 and setDataElements methods.
 int getOffset(int x, int y)
          Returns the offset (in data array elements) of pixel (x,y).
 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 via 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

MultiPixelPackedSampleModel

public MultiPixelPackedSampleModel(int dataType,
                                   int w,
                                   int h,
                                   int numberOfBits)
Constructs a MultiPixelPackedSampleModel with the given data type, width, height and number of bits per pixel.
Parameters:
dataType - The data type for storing samples.
w - The width (in pixels) of the region of image data described.
h - The height (in pixels) of the region of image data described.
numberOfBits - The number of bits per pixel.

MultiPixelPackedSampleModel

public MultiPixelPackedSampleModel(int dataType,
                                   int w,
                                   int h,
                                   int numberOfBits,
                                   int scanlineStride,
                                   int dataBitOffset)
Constructs a MultiPixelPackedSampleModel with given data type, width, height, number of bits per pixel, scanline stride and data bit offset.
Parameters:
dataType - The data type for storing samples.
w - The width (in pixels) of the region of image data described.
h - The height (in pixels) of the region of image data described.
numberOfBits - The number of bits per pixel.
scanlineStride - The line stride of the image data.
dataBitOffset - The data bit offset for the region of image data described.
Method Detail

createCompatibleSampleModel

public SampleModel createCompatibleSampleModel(int w,
                                               int h)
Creates a new MultiPixelPackedSampleModel with the specified width and height. The new MultiPixelPackedSampleModel will have the same storage data type and number of bits per pixel as this MultiPixelPackedSampleModel.
Overrides:
createCompatibleSampleModel in class SampleModel

createDataBuffer

public DataBuffer createDataBuffer()
Creates a DataBuffer that corresponds to this MultiPixelPackedSampleModel. The DataBuffer's data type and size will be consistent with this MultiPixelPackedSampleModel. The DataBuffer will have a single bank.
Overrides:
createDataBuffer in class SampleModel

getNumDataElements

public int getNumDataElements()
Returns the number of data elements needed to transfer one pixel via the getDataElements and setDataElements methods. For a MultiPixelPackedSampleModel, this is one.
Overrides:
getNumDataElements in class SampleModel

getSampleSize

public int[] getSampleSize()
Returns the number of bits per sample for all bands.
Overrides:
getSampleSize in class SampleModel

getSampleSize

public int getSampleSize(int band)
Returns the number of bits per sample for the specified band.
Overrides:
getSampleSize in class SampleModel

getOffset

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

getBitOffset

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 will be the same for all scanlines.)

getScanlineStride

public int getScanlineStride()
Returns the scanline stride.

getPixelBitStride

public int getPixelBitStride()
Returns the pixel bit stride in bits. This is the same as the number of bits per pixel.

getDataBitOffset

public int getDataBitOffset()
Returns the data bit offset in bits.

getTransferType

public int getTransferType()
Returns the TransferType used to transfer pixels via the getDataElements and setDataElements methods. The TransferType may or may not be the same as the storage DataType. The TransferType will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT.
Overrides:
getTransferType in class SampleModel

createSubsetSampleModel

public SampleModel createSubsetSampleModel(int[] bands)
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.
Overrides:
createSubsetSampleModel in class SampleModel

getSample

public 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). ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to return (assumed to be 0).
data - The DataBuffer containing the image data.
Overrides:
getSample in class SampleModel

setSample

public 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. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.
Parameters:
x - The X coordinate of the pixel location
y - The Y coordinate of the pixel location
b - The band to return (assumed to be 0)
s - The input sample as an int
data - The DataBuffer where image data is stored
Overrides:
setSample in class SampleModel

getDataElements

public Object getDataElements(int x,
                              int y,
                              Object obj,
                              DataBuffer data)
Returns data for a single pixel in a primitive array of type TransferType. For a MultiPixelPackedSampleModel, the array will have one element, and the type will be the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT that can hold a a single pixel. 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 MultiPixelPackedSampleModel mppsm1, to DataBuffer db2, whose storage layout is described by MultiPixelPackedSampleModel mppsm2. The transfer will generally be more efficient than using getPixel/setPixel.

 	     MultiPixelPackedSampleModel mppsm1, mppsm2;
	     DataBufferInt db1, db2;
 	     mppsm2.setDataElements(x, y, mppsm1.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 - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
obj - If non-null, a primitive array in which to return the pixel data.
data - The DataBuffer containing the image data.
Overrides:
getDataElements in class SampleModel

getPixel

public int[] getPixel(int x,
                      int y,
                      int[] iArray,
                      DataBuffer data)
Returns the specified (single band) pixel in the first element of an int array. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
iArray - If non-null, returns the pixel in this array.
data - The DataBuffer where image data is stored.
Overrides:
getPixel in class SampleModel

setDataElements

public 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. For a MultiPixelPackedSampleModel, only the first element of the array will hold valid data, and the type must be the smallest of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT that can hold a 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 will generally be more efficient than using getPixel/setPixel.

 	     MultiPixelPackedSampleModel mppsm1, mppsm2;
	     DataBufferInt db1, db2;
 	     mppsm2.setDataElements(x, y, mppsm1.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 - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
obj - A primitive array containing pixel data.
data - The DataBuffer containing the image data.
Overrides:
setDataElements in class SampleModel

setPixel

public void setPixel(int x,
                     int y,
                     int[] iArray,
                     DataBuffer data)
Sets a pixel in the DataBuffer using an int array for input. ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.
Parameters:
x - The X coordinate of the pixel location
y - The Y coordinate of the pixel location
iArray - The input pixel in an int array.
data - The DataBuffer containing the image data.
Overrides:
setPixel in class SampleModel

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.