Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. All rights reserved.

JSR-209 (Final Approval Ballot)

java.awt.image
Class SinglePixelPackedSampleModel

java.lang.Object
  extended byjava.awt.image.SampleModel
      extended byjava.awt.image.SinglePixelPackedSampleModel

public class SinglePixelPackedSampleModel
extends SampleModel

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
 
Fields inherited from class java.awt.image.SampleModel
dataType, height, numBands, width
 
Constructor Summary
protected SinglePixelPackedSampleModel(int dataType, int w, int h, int[] bitMasks)
          Constructs a SinglePixelPackedSampleModel with bitMasks.length bands.
protected 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.
 
Method Summary
 boolean equals(java.lang.Object o)
          Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element.
 int[] getBitMasks()
          Returns the bit masks for all bands.
 int[] getBitOffsets()
          Returns the bit offsets into the data array element representing a pixel for all bands.
 int getOffset(int x, int y)
          Returns the offset (in data array elements) of pixel (x,y).
 int[] getSampleSize()
          Returns the number of bits per sample for all bands.
 int getScanlineStride()
          Returns the scanline stride of this SinglePixelPackedSampleModel.
 int hashCode()
           
 
Methods inherited from class java.awt.image.SampleModel
getDataType, getHeight, getNumBands, getWidth
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SinglePixelPackedSampleModel

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

Parameters:
dataType - The data type for storing samples.
w - The width (in pixels) of the region of the image data described.
h - The height (in pixels) of the region of the image data described.
bitMasks - The bit masks for all bands.
Throws:
java.lang.IllegalArgumentException - if dataType is not either DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT

SinglePixelPackedSampleModel

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

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.
scanlineStride - The line stride of the image data.
bitMasks - The bit masks for all bands.
Throws:
java.lang.IllegalArgumentException - if w or h is not greater than 0
java.lang.IllegalArgumentException - if any mask in bitMask is not contiguous
java.lang.IllegalArgumentException - if dataType is not either DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
Method Detail

getSampleSize

public int[] getSampleSize()
Returns the number of bits per sample for all bands.

Specified by:
getSampleSize in class SampleModel
Returns:
the size of samples for all bands.

getOffset

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));
 

Returns:
the offset of the specified pixel.

getBitOffsets

public int[] getBitOffsets()
Returns the bit offsets into the data array element representing a pixel for all bands.

Returns:
the bit offsets representing a pixel for all bands.

getBitMasks

public int[] getBitMasks()
Returns the bit masks for all bands.

Returns:
the bit masks for all bands.

getScanlineStride

public int getScanlineStride()
Returns the scanline stride of this SinglePixelPackedSampleModel.

Returns:
the scanline stride of this SinglePixelPackedSampleModel.

equals

public boolean equals(java.lang.Object o)
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.

See Also:
#getSamples(int, int, int, int, int, int[], DataBuffer)

hashCode

public int hashCode()

JSR-209 (Final Approval Ballot)

Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 209 specification.