Home » openjdk-7 » java » awt » image » [javadoc | source]
java.awt.image
public class: MultiPixelPackedSampleModel [javadoc | source]
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);
Field Summary
 int pixelBitStride    The number of bits from one pixel to the next. 
 int bitMask    Bitmask that extracts the rightmost pixel of a data element. 
 int pixelsPerDataElement    The number of pixels that fit in a data element. Also used as the number of bits per pixel. 
 int dataElementSize    The size of a data element in bits. 
 int dataBitOffset    The bit offset into the data array where the first pixel begins. 
 int scanlineStride    ScanlineStride of the data buffer described in data array elements. 
Fields inherited from java.awt.image.SampleModel:
width,  height,  numBands,  dataType
Constructor:
 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 from java.awt.image.MultiPixelPackedSampleModel Summary:
createCompatibleSampleModel,   createDataBuffer,   createSubsetSampleModel,   equals,   getBitOffset,   getDataBitOffset,   getDataElements,   getNumDataElements,   getOffset,   getPixel,   getPixelBitStride,   getSample,   getSampleSize,   getSampleSize,   getScanlineStride,   getTransferType,   hashCode,   setDataElements,   setPixel,   setSample
Methods from java.awt.image.SampleModel:
createCompatibleSampleModel,   createDataBuffer,   createSubsetSampleModel,   getDataElements,   getDataElements,   getDataType,   getHeight,   getNumBands,   getNumDataElements,   getPixel,   getPixel,   getPixel,   getPixels,   getPixels,   getPixels,   getSample,   getSampleDouble,   getSampleFloat,   getSampleSize,   getSampleSize,   getSamples,   getSamples,   getSamples,   getTransferType,   getWidth,   setDataElements,   setDataElements,   setPixel,   setPixel,   setPixel,   setPixels,   setPixels,   setPixels,   setSample,   setSample,   setSample,   setSamples,   setSamples,   setSamples
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.image.MultiPixelPackedSampleModel Detail:
 public SampleModel createCompatibleSampleModel(int w,
    int h) 
    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.
 public DataBuffer 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.
 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.
 public boolean equals(Object o) 
 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.
 public int getDataBitOffset() 
    Returns the data bit offset in bits.
 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 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.

 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.
 public int getOffset(int x,
    int y) 
    Returns the offset of pixel (x, y) in data array elements.
 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 is thrown if the coordinates are not in bounds.
 public int getPixelBitStride() 
    Returns the pixel bit stride in bits. This value is the same as the number of bits per pixel.
 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). An ArrayIndexOutOfBoundsException is thrown if the coordinates are not in bounds.
 public int[] getSampleSize() 
    Returns the number of bits per sample for all bands.
 public int getSampleSize(int band) 
    Returns the number of bits per sample for the specified band.
 public int getScanlineStride() 
    Returns the scanline stride.
 public int 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.
 public int hashCode() 
 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 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.

 public  void setPixel(int x,
    int y,
    int[] iArray,
    DataBuffer data) 
    Sets a pixel in the DataBuffer using an int array for input. ArrayIndexOutOfBoundsException is thrown if the coordinates are not in bounds.
 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. An ArrayIndexOutOfBoundsException is thrown if the coordinates are not in bounds.