JSR-209 (Final Release)

java.awt.image
Class SampleModel

java.lang.Object
  extended byjava.awt.image.SampleModel
Direct Known Subclasses:
SinglePixelPackedSampleModel

public abstract class SampleModel
extends java.lang.Object

This abstract class defines an interface for extracting samples of pixels in an image. All image data is expressed as a collection of pixels. Each pixel consists of a number of samples. A sample is a datum for one band of an image and a band consists of all samples of a particular type in an image. For example, a pixel might contain three samples representing its red, green and blue components. There are three bands in the image containing this pixel. One band consists of all the red samples from all pixels in the image. The second band consists of all the green samples and the remaining band consists of all of the blue samples. The pixel can be stored in various formats. For example, all samples from a particular band can be stored contiguously or all samples from a single pixel can be stored contiguously.

Subclasses of SampleModel specify the types of samples they can represent (e.g. unsigned 8-bit byte, signed 16-bit short, etc.) and may specify how the samples are organized in memory. In the Java 2D(tm) API, built-in image processing operators may not operate on all possible sample types, but generally will work for unsigned integral samples of 16 bits or less. Some operators support a wider variety of sample types.

A collection of pixels is represented as a Raster, which consists of a DataBuffer and a SampleModel. The SampleModel allows access to samples in the DataBuffer and may provide low-level information that a programmer can use to directly manipulate samples and pixels in the DataBuffer.

This class is generally a fall back method for dealing with images. More efficient code will cast the SampleModel to the appropriate subclass and extract the information needed to directly manipulate pixels in the DataBuffer.

See Also:
DataBuffer, Raster, java.awt.image.ComponentSampleModel, java.awt.image.PixelInterleavedSampleModel, java.awt.image.BandedSampleModel, java.awt.image.MultiPixelPackedSampleModel, SinglePixelPackedSampleModel

Field Summary
protected  int dataType
          Data type of the DataBuffer storing the pixel data.
protected  int height
          Height in pixels of the region of image data that this SampleModel describes.
protected  int numBands
          Number of bands of the image data that this SampleModel describes.
protected  int width
          Width in pixels of the region of image data that this SampleModel describes.
 
Constructor Summary
SampleModel(int dataType, int w, int h, int numBands)
          Constructs a SampleModel with the specified parameters.
 
Method Summary
 int getDataType()
          Returns the data type of the DataBuffer storing the pixel data.
 int getHeight()
          Returns the height in pixels.
 int getNumBands()
          Returns the total number of bands of image data.
abstract  int[] getSampleSize()
          Returns the size in bits of samples for all bands.
 int getWidth()
          Returns the width in pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected int width
Width in pixels of the region of image data that this SampleModel describes.


height

protected int height
Height in pixels of the region of image data that this SampleModel describes.


numBands

protected int numBands
Number of bands of the image data that this SampleModel describes.


dataType

protected int dataType
Data type of the DataBuffer storing the pixel data.

See Also:
DataBuffer
Constructor Detail

SampleModel

public SampleModel(int dataType,
                   int w,
                   int h,
                   int numBands)
Constructs a SampleModel with the specified parameters.

Parameters:
dataType - The data type of the DataBuffer storing the pixel data.
w - The width (in pixels) of the region of image data.
h - The height (in pixels) of the region of image data.
numBands - The number of bands of the image data.
Throws:
java.lang.IllegalArgumentException - if w or h is not greater than 0
java.lang.IllegalArgumentException - if the product of w and h is greater than Integer.MAX_VALUE
java.lang.IllegalArgumentException - if dataType is not one of the supported data types
Method Detail

getWidth

public final int getWidth()
Returns the width in pixels.

Returns:
the width in pixels of the region of image data that this SampleModel describes.

getHeight

public final int getHeight()
Returns the height in pixels.

Returns:
the height in pixels of the region of image data that this SampleModel describes.

getNumBands

public final int getNumBands()
Returns the total number of bands of image data.

Returns:
the number of bands of image data that this SampleModel describes.

getDataType

public final int getDataType()
Returns the data type of the DataBuffer storing the pixel data.

Returns:
the data type.

getSampleSize

public abstract int[] getSampleSize()
Returns the size in bits of samples for all bands.

Returns:
the size of samples for all bands.

JSR-209 (Final Release)

Java and Java 2D are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Copyright 1993 - 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All Rights Reserved.
Use of this specification is subject to this license.