Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.awt.image.SampleModel

java.lang.Object
    |
    +----java.awt.image.SampleModel
Subclasses:
BandedSampleModel, ComponentSampleModel, MultiPixelPackedSampleModel, SinglePixelPackedSampleModel

public abstract class SampleModel
extends Object
This abstract class defines an interface for extracting samples of an image without knowing how the underlying data is stored in a DataBuffer. All image data is expressed as a collection of pixels. Each pixel consists of a number of samples. A sample is a collection of data for one band of an image. 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, ComponentSampleModel, BandedSampleModel, MultiPixelPackedSampleModel, SinglePixelPackedSampleModel

Field Summary
int  dataType
Data type of the underlying pixel data.
int  height
Height of the region of image data that this SampleModel describes.
int  numBands
number of bands of the inage data that this SampleModel describes.
int  width
Width 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
DataBuffer  createCompatibleDataBuffer()
Creates a DataBuffer that corresponds to this SampleModel.
DataBuffer  createCompatibleDataBuffer(int width, int height)
Creates a DataBuffer that corresponds to this SampleModel, with a different width and height.
SampleModel  createCompatibleSampleModel(int w, int h)
Creates a SampleModel which describes data in this SampleModel's format, but with a different width and height.
SampleModel  createSubsetSampleModel(int w, int h, int[] bands)
This creates a new SampleModel with the requested width and height and with a subset of the bands of this SampleModel.
int  getDataType()
Returns the data type.
int  getHeight()
Returns the height in pixels.
float  getMaxSampleValue()
Returns the maximum sample value for all bands.
float  getMaxSampleValue(int band)
Returns the maximum sample value for the specified band.
float  getMinSampleValue()
Returns the minimum sample value for all bands.
float  getMinSampleValue(int band)
Returns the minimum sample value for the specified band.
int  getNumBands()
Returns the total number of bands of image data.
int  getNumDataElements()
Returns the number of data elements needed to store a pixel.
int[]  getPixel(int x, int y, int[] iArray, DataBuffer data)
Returns the samples for a specified pixel in an array of int.
float[]  getPixel(int x, int y, float[] fArray, DataBuffer data)
Returns the samples for the specified pixel in an array of float.
double[]  getPixel(int x, int y, double[] dArray, DataBuffer data)
Returns the samples for the specified pixle in an array of double.
int[]  getPixel(int x, int y, int w, int h, int[] iArray, DataBuffer data)
Returns all samples for a rectangle of pixels in an int array, one sample per array element.
float[]  getPixel(int x, int y, int w, int h, float[] fArray, DataBuffer data)
Returns all samples for a rectangle of pixels in a float array, one sample per array element.
double[]  getPixel(int x, int y, int w, int h, double[] dArray, DataBuffer data)
Returns all samples for a rectangle of pixels in a double array, one sample per array element.
Object  getPixelData(int x, int y, Object obj, DataBuffer data)
Returns the pixel data in an array of primitives that can be byte, short or int.
Object  getPixelData(int x, int y, int w, int h, Object obj, DataBuffer data)
Returns the pixel data for the specified rectangle in an array of primitives that can be byte, short or int.
int  getSample(int x, int y, int b, DataBuffer data)
Returns the sample in a specified band for the pixel located at (x,y) as an int.
int[]  getSample(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)
Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element.
float[]  getSample(int x, int y, int w, int h, int b, float[] fArray, DataBuffer data)
Returns the samples for a specified band for the specified rectangle of pixels in a float array, one sample per array element.
double[]  getSample(int x, int y, int w, int h, int b, double[] dArray, DataBuffer data)
Returns the samples for a specified band for a specified rectangle of pixels in a double array, one sample per array element.
double  getSampleDouble(int x, int y, int b, DataBuffer data)
Returns the sample in a specified band for a pixel located at (x,y) as a double.
float  getSampleFloat(int x, int y, int b, DataBuffer data)
Returns the sample in a specified band for the pixel located at (x,y) as a float.
int[]  getSampleSize()
Returns the size in bits of samples for all bands.
int  getSampleSize(int band)
Returns the size in bits of samples for the specified band.
int  getTransferType()
Returns the transfer type of the data.
int  getWidth()
Returns the width in pixels.
void  setPixel(int x, int y, int[] iArray, DataBuffer data)
Sets a pixel in the DataBuffer using an int array of samples for input.
void  setPixel(int x, int y, float[] fArray, DataBuffer data)
Sets a pixel in the DataBuffer using a float array of samples for input.
void  setPixel(int x, int y, double[] dArray, DataBuffer data)
Sets a pixel in the DataBuffer using a double array of samples for input.
void  setPixel(int x, int y, int w, int h, int[] iArray, DataBuffer data)
Sets all samples for a rectangle of pixels from an int array containing one sample per array element.
void  setPixel(int x, int y, int w, int h, float[] fArray, DataBuffer data)
Sets all samples for a rectangle of pixels from a float array containing one sample per array element.
void  setPixel(int x, int y, int w, int h, double[] dArray, DataBuffer data)
Sets all samples for a rectangle of pixels from a double array containing one sample per array element.
void  setPixelData(int x, int y, Object obj, DataBuffer data)
Puts the pixel data from an Object that contains an array of primitives that can be byte, short or int.
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.
void  setSample(int x, int y, int b, float s, DataBuffer data)
Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a float for input.
void  setSample(int x, int y, int b, double s, DataBuffer data)
Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a double for input.
void  setSample(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)
Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element.
void  setSample(int x, int y, int w, int h, int b, float[] fArray, DataBuffer data)
Sets the samples in the specified band for the specified rectangle of pixels from a float array containing one sample per array element.
void  setSample(int x, int y, int w, int h, int b, double[] dArray, DataBuffer data)
Sets the samples in the specified band for the specified rectangle of pixels from a double array containing one sample per array element.
 
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 of the region of image data that this SampleModel describes.

height

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

numBands

protected int numBands
number of bands of the inage data that this SampleModel describes.

dataType

protected int dataType
Data type of the underlying pixel data.
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 underlying 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.
Method Detail

getWidth

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

getHeight

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

getNumBands

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

getNumDataElements

public abstract int getNumDataElements()
Returns the number of data elements needed to store a pixel.

getDataType

public final int getDataType()
Returns the data type.

getTransferType

public abstract int getTransferType()
Returns the transfer type of the data.

getPixel

public int[] getPixel(int x,
                      int y,
                      int[] iArray,
                      DataBuffer data)
Returns the samples for a specified pixel in an array of int.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
iArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getPixelData

public abstract Object getPixelData(int x,
                                    int y,
                                    Object obj,
                                    DataBuffer data)
Returns the pixel data in an array of primitives that can be byte, short or int. Which primitive type is returned depends on the transfer type. Data is returned in the packed format, thus increasing efficiency for data transfers. 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.
 	     SampleModel sm1, sm2;
	     DataBuffer db1, db2;
 	     sm2.setPixelData(x, y, sm1.getPixelData(x, y, null, db1), db2);
 
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
obj - If non-null, returns the primitive array in this object.
data - The DataBuffer containing the image data.

getPixelData

public Object getPixelData(int x,
                           int y,
                           int w,
                           int h,
                           Object obj,
                           DataBuffer data)
Returns the pixel data for the specified rectangle in an array of primitives that can be byte, short or int. Which primitive type is returned depends on the transfer type. Data is returned in the packed format, thus increasing efficiency for data transfers. 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.
 	     SampleModel sm1, sm2;
	     DataBuffer db1, db2;
 	     sm2.setPixelData(x, y, w, h, sm1.getPixelData(x, y, w,
 h, null, db1), db2);
 
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
obj - If non-null, returns the primitive array in this object.
data - The DataBuffer containing the image data.

setPixelData

public abstract void setPixelData(int x,
                                  int y,
                                  Object obj,
                                  DataBuffer data)
Puts the pixel data from an Object that contains an array of primitives that can be byte, short or int. Which primitive type it contains depends on the transfer type. Data in the Object is in the packed format, thus increasing efficiency for data transfers.
 	     SampleModel sm1, sm2;
	     DataBuffer db1, db2;
 	     sm2.setPixelData(x, y, sm1.getPixelData(x, y, null, db1), db2);
 
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
obj - If non-null, returns the primitive array in this object.
data - The DataBuffer containing the image data.

getPixel

public float[] getPixel(int x,
                        int y,
                        float[] fArray,
                        DataBuffer data)
Returns the samples for the specified pixel in an array of float.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
fArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getPixel

public double[] getPixel(int x,
                         int y,
                         double[] dArray,
                         DataBuffer data)
Returns the samples for the specified pixle in an array of double.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
dArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getPixel

public int[] getPixel(int x,
                      int y,
                      int w,
                      int h,
                      int[] iArray,
                      DataBuffer data)
Returns all samples for a rectangle of pixels in an int array, one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
iArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getPixel

public float[] getPixel(int x,
                        int y,
                        int w,
                        int h,
                        float[] fArray,
                        DataBuffer data)
Returns all samples for a rectangle of pixels in a float array, one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
fArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getPixel

public double[] getPixel(int x,
                         int y,
                         int w,
                         int h,
                         double[] dArray,
                         DataBuffer data)
Returns all samples for a rectangle of pixels in a double array, one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
dArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getSample

public abstract int getSample(int x,
                              int y,
                              int b,
                              DataBuffer data)
Returns the sample in a specified band for the pixel located at (x,y) as an int.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to return.
data - The DataBuffer containing the image data.

getSampleFloat

public float getSampleFloat(int x,
                            int y,
                            int b,
                            DataBuffer data)
Returns the sample in a specified band for the pixel located at (x,y) as a float.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to return.
data - The DataBuffer containing the image data.

getSampleDouble

public double getSampleDouble(int x,
                              int y,
                              int b,
                              DataBuffer data)
Returns the sample in a specified band for a pixel located at (x,y) as a double.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to return.
data - The DataBuffer containing the image data.

getSample

public int[] getSample(int x,
                       int y,
                       int w,
                       int h,
                       int b,
                       int[] iArray,
                       DataBuffer data)
Returns the samples for a specified band for the specified rectangle of pixels in an int array, one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
b - The band to return.
iArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getSample

public float[] getSample(int x,
                         int y,
                         int w,
                         int h,
                         int b,
                         float[] fArray,
                         DataBuffer data)
Returns the samples for a specified band for the specified rectangle of pixels in a float array, one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
b - The band to return.
fArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

getSample

public double[] getSample(int x,
                          int y,
                          int w,
                          int h,
                          int b,
                          double[] dArray,
                          DataBuffer data)
Returns the samples for a specified band for a specified rectangle of pixels in a double array, one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
b - The band to return.
dArray - If non-null, returns the samples in this array.
data - The DataBuffer containing the image data.

setPixel

public void setPixel(int x,
                     int y,
                     int[] iArray,
                     DataBuffer data)
Sets a pixel in the DataBuffer using an int array of samples for input.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
iArray - The input samples in an int array.
data - The DataBuffer containing the image data.

setPixel

public void setPixel(int x,
                     int y,
                     float[] fArray,
                     DataBuffer data)
Sets a pixel in the DataBuffer using a float array of samples for input.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
fArray - The input samples in a float array.
data - The DataBuffer containing the image data.

setPixel

public void setPixel(int x,
                     int y,
                     double[] dArray,
                     DataBuffer data)
Sets a pixel in the DataBuffer using a double array of samples for input.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
dArray - The input samples in a double array.
data - The DataBuffer containing the image data.

setPixel

public void setPixel(int x,
                     int y,
                     int w,
                     int h,
                     int[] iArray,
                     DataBuffer data)
Sets all samples for a rectangle of pixels from an int array containing one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
iArray - The input samples in an int array.
data - The DataBuffer containing the image data.

setPixel

public void setPixel(int x,
                     int y,
                     int w,
                     int h,
                     float[] fArray,
                     DataBuffer data)
Sets all samples for a rectangle of pixels from a float array containing one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
fArray - The input samples in a float array.
data - The DataBuffer containing the image data.

setPixel

public void setPixel(int x,
                     int y,
                     int w,
                     int h,
                     double[] dArray,
                     DataBuffer data)
Sets all samples for a rectangle of pixels from a double array containing one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
dArray - The input samples in a double array.
data - The DataBuffer containing the image data.

setSample

public abstract 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.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to set.
s - The input sample as an int.
data - The DataBuffer containing the image data.

setSample

public void setSample(int x,
                      int y,
                      int b,
                      float s,
                      DataBuffer data)
Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a float for input.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to set.
s - The input sample as a float.
data - The DataBuffer containing the image data.

setSample

public void setSample(int x,
                      int y,
                      int b,
                      double s,
                      DataBuffer data)
Sets a sample in the specified band for the pixel located at (x,y) in the DataBuffer using a double for input.
Parameters:
x - The X coordinate of the pixel location.
y - The Y coordinate of the pixel location.
b - The band to set.
s - The input sample as a double.
data - The DataBuffer containing the image data.

setSample

public void setSample(int x,
                      int y,
                      int w,
                      int h,
                      int b,
                      int[] iArray,
                      DataBuffer data)
Sets the samples in the specified band for the specified rectangle of pixels from an int array containing one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
b - The band to set.
iArray - The input samples in an int array.
data - The DataBuffer containing the image data.

setSample

public void setSample(int x,
                      int y,
                      int w,
                      int h,
                      int b,
                      float[] fArray,
                      DataBuffer data)
Sets the samples in the specified band for the specified rectangle of pixels from a float array containing one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
b - The band to set.
fArray - The input samples in a float array.
data - The DataBuffer containing the image data.

setSample

public void setSample(int x,
                      int y,
                      int w,
                      int h,
                      int b,
                      double[] dArray,
                      DataBuffer data)
Sets the samples in the specified band for the specified rectangle of pixels from a double array containing one sample per array element.
Parameters:
x - The X coordinate of the upper left pixel location.
y - The Y coordinate of the upper left pixel location.
w - The width of the pixel rectangle.
h - The height of the pixel rectangle.
b - The band to set.
dArray - The input samples in a double array.
data - The DataBuffer containing the image data.

createCompatibleSampleModel

public abstract SampleModel createCompatibleSampleModel(int w,
                                                        int h)
Creates a SampleModel which describes data in this SampleModel's format, but with a different width and height.

createSubsetSampleModel

public abstract SampleModel createSubsetSampleModel(int w,
                                                    int h,
                                                    int[] bands)
This creates a new SampleModel with the requested width and height and with a subset of the bands of this SampleModel.

createCompatibleDataBuffer

public abstract DataBuffer createCompatibleDataBuffer()
Creates a DataBuffer that corresponds to this SampleModel. The DataBuffer's width and height will match this SampleModel's.

createCompatibleDataBuffer

public abstract DataBuffer createCompatibleDataBuffer(int width,
                                                      int height)
Creates a DataBuffer that corresponds to this SampleModel, with a different width and height.

getMinSampleValue

public float getMinSampleValue()
Returns the minimum sample value for all bands.

getMinSampleValue

public float getMinSampleValue(int band)
Returns the minimum sample value for the specified band.

getMaxSampleValue

public float getMaxSampleValue()
Returns the maximum sample value for all bands.

getMaxSampleValue

public float getMaxSampleValue(int band)
Returns the maximum sample value for the specified band.

getSampleSize

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

getSampleSize

public abstract int getSampleSize(int band)
Returns the size in bits of samples for the specified band.

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

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.