SampleModelpublic abstract class SampleModel extends Object The SampleModel class is abstract class for retrieving pixel's samples in the
data of an image. Each pixel contains several samples. A sample is the set of
values of the bands for single pixel. For example, each pixel in the RGB
model contains three samples and there are three corresponding bands in the
image data of such pixels representing red, green and blue components.
The image data is represented as a Raster with a DataBuffer and a
SampleModel. The SampleModel allows access to the samples in the DataBuffer. |
Fields Summary |
---|
protected int | widthThe width of the image data which this SampleModel describes. | protected int | heightThe height of the image data which this SampleModel describes. | protected int | numBandsThe number of bands of image data which this SampleModel describes. | protected int | dataTypeThe data type of the image data which this SampleModel describes. |
Constructors Summary |
---|
public SampleModel(int dataType, int w, int h, int numBands)Instantiates a new SampleModel with the specified data type, width,
height and number of bands.
if (w <= 0 || h <= 0) {
// awt.22E=w or h is less than or equal to zero
throw new IllegalArgumentException(Messages.getString("awt.22E")); //$NON-NLS-1$
}
double squre = ((double)w) * ((double)h);
if (squre >= Integer.MAX_VALUE) {
// awt.22F=The product of w and h is greater than Integer.MAX_VALUE
throw new IllegalArgumentException(Messages.getString("awt.22F")); //$NON-NLS-1$
}
if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_DOUBLE
&& dataType != DataBuffer.TYPE_UNDEFINED) {
// awt.230=dataType is not one of the supported data types
throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
}
if (numBands < 1) {
// awt.231=Number of bands must be more then 0
throw new IllegalArgumentException(Messages.getString("awt.231")); //$NON-NLS-1$
}
this.dataType = dataType;
this.width = w;
this.height = h;
this.numBands = numBands;
|
Methods Summary |
---|
public abstract java.awt.image.SampleModel | createCompatibleSampleModel(int a0, int a1)Creates the SampleModel which has the same data as in this SampleModel
with a different width and height.
| public abstract java.awt.image.DataBuffer | createDataBuffer()Creates a DataBuffer object which corresponds to the SampleModel.
| public abstract java.awt.image.SampleModel | createSubsetSampleModel(int[] bands)Creates a new SampleModel with the specified bands of this SampleModel.
| public abstract java.lang.Object | getDataElements(int x, int y, java.lang.Object obj, java.awt.image.DataBuffer data)Gets the data array for the specified pixel of the specified DataBuffer
with one of the following types: DataBuffer.TYPE_BYTE,
DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.
| public java.lang.Object | getDataElements(int x, int y, int w, int h, java.lang.Object obj, java.awt.image.DataBuffer data)Gets the array of pixel data for the specified rectangular area of pixels
of the specified DataBuffer with one of the following types:
DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT,
DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.
int numDataElements = getNumDataElements();
int idx = 0;
switch (getTransferType()) {
case DataBuffer.TYPE_BYTE:
byte bdata[];
byte bbuf[] = null;
if (obj == null) {
bdata = new byte[numDataElements * w * h];
} else {
bdata = (byte[])obj;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
bbuf = (byte[])getDataElements(j, i, bbuf, data);
for (int n = 0; n < numDataElements; n++) {
bdata[idx++] = bbuf[n];
}
}
}
obj = bdata;
break;
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT:
short sdata[];
short sbuf[] = null;
if (obj == null) {
sdata = new short[numDataElements * w * h];
} else {
sdata = (short[])obj;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
sbuf = (short[])getDataElements(j, i, sbuf, data);
for (int n = 0; n < numDataElements; n++) {
sdata[idx++] = sbuf[n];
}
}
}
obj = sdata;
break;
case DataBuffer.TYPE_INT:
int idata[];
int ibuf[] = null;
if (obj == null) {
idata = new int[numDataElements * w * h];
} else {
idata = (int[])obj;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
ibuf = (int[])getDataElements(j, i, ibuf, data);
for (int n = 0; n < numDataElements; n++) {
idata[idx++] = ibuf[n];
}
}
}
obj = idata;
break;
case DataBuffer.TYPE_FLOAT:
float fdata[];
float fbuf[] = null;
if (obj == null) {
fdata = new float[numDataElements * w * h];
} else {
fdata = (float[])obj;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
fbuf = (float[])getDataElements(j, i, fbuf, data);
for (int n = 0; n < numDataElements; n++) {
fdata[idx++] = fbuf[n];
}
}
}
obj = fdata;
break;
case DataBuffer.TYPE_DOUBLE:
double ddata[];
double dbuf[] = null;
if (obj == null) {
ddata = new double[numDataElements * w * h];
} else {
ddata = (double[])obj;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
dbuf = (double[])getDataElements(j, i, dbuf, data);
for (int n = 0; n < numDataElements; n++) {
ddata[idx++] = dbuf[n];
}
}
}
obj = ddata;
break;
}
return obj;
| public final int | getDataType()Gets the data type of image data of this SampleModel object.
return dataType;
| public final int | getHeight()Gets the height of the image data of this SampleModel object.
return height;
| public final int | getNumBands()Gets the number of bands in the image data of this SampleModel object.
return numBands;
| public abstract int | getNumDataElements()Returns the number of data elements for pixel transferring via the
getDataElements and setDataElements methods.
| public float[] | getPixel(int x, int y, float[] fArray, java.awt.image.DataBuffer data)Gets the samples of the specified pixel as a float array.
if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
float pixel[];
if (fArray == null) {
pixel = new float[numBands];
} else {
pixel = fArray;
}
for (int i = 0; i < numBands; i++) {
pixel[i] = getSampleFloat(x, y, i, data);
}
return pixel;
| public double[] | getPixel(int x, int y, double[] dArray, java.awt.image.DataBuffer data)Gets the samples of the specified pixel as a double array.
if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
double pixel[];
if (dArray == null) {
pixel = new double[numBands];
} else {
pixel = dArray;
}
for (int i = 0; i < numBands; i++) {
pixel[i] = getSampleDouble(x, y, i, data);
}
return pixel;
| public int[] | getPixel(int x, int y, int[] iArray, java.awt.image.DataBuffer data)Gets the samples of the specified pixel as an integer array.
if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
int pixel[];
if (iArray == null) {
pixel = new int[numBands];
} else {
pixel = iArray;
}
for (int i = 0; i < numBands; i++) {
pixel[i] = getSample(x, y, i, data);
}
return pixel;
| public int[] | getPixels(int x, int y, int w, int h, int[] iArray, java.awt.image.DataBuffer data)Gets the samples of the specified rectangular area of pixels as an
integer array.
if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
int pixels[];
int idx = 0;
if (iArray == null) {
pixels = new int[w * h * numBands];
} else {
pixels = iArray;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numBands; n++) {
pixels[idx++] = getSample(j, i, n, data);
}
}
}
return pixels;
| public float[] | getPixels(int x, int y, int w, int h, float[] fArray, java.awt.image.DataBuffer data)Gets the samples of the specified rectangular area of pixels as a float
array.
if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
float pixels[];
int idx = 0;
if (fArray == null) {
pixels = new float[w * h * numBands];
} else {
pixels = fArray;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numBands; n++) {
pixels[idx++] = getSampleFloat(j, i, n, data);
}
}
}
return pixels;
| public double[] | getPixels(int x, int y, int w, int h, double[] dArray, java.awt.image.DataBuffer data)Gets the samples of the specified rectangular area of pixels as a double
array.
if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
double pixels[];
int idx = 0;
if (dArray == null) {
pixels = new double[w * h * numBands];
} else {
pixels = dArray;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numBands; n++) {
pixels[idx++] = getSampleDouble(j, i, n, data);
}
}
}
return pixels;
| public abstract int | getSample(int x, int y, int b, java.awt.image.DataBuffer data)Gets the sample of a specified band for the specified pixel as an
integer.
| public double | getSampleDouble(int x, int y, int b, java.awt.image.DataBuffer data)Gets the sample of a specified band for the specified pixel as a double.
return getSample(x, y, b, data);
| public float | getSampleFloat(int x, int y, int b, java.awt.image.DataBuffer data)Gets the sample of a specified band for the specified pixel as a float.
return getSample(x, y, b, data);
| public abstract int | getSampleSize(int band)Gets the sample size in bits for the specified band.
| public abstract int[] | getSampleSize()Gets an array of the sample size in bits for all bands.
| public int[] | getSamples(int x, int y, int w, int h, int b, int[] iArray, java.awt.image.DataBuffer data)Gets the samples of a specified band for a specified rectangular area of
pixels as a integer array.
int samples[];
int idx = 0;
if (iArray == null) {
samples = new int[w * h];
} else {
samples = iArray;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
samples[idx++] = getSample(j, i, b, data);
}
}
return samples;
| public float[] | getSamples(int x, int y, int w, int h, int b, float[] fArray, java.awt.image.DataBuffer data)Gets the samples of a specified band for a specified rectangular area of
pixels as a float array.
float samples[];
int idx = 0;
if (fArray == null) {
samples = new float[w * h];
} else {
samples = fArray;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
samples[idx++] = getSampleFloat(j, i, b, data);
}
}
return samples;
| public double[] | getSamples(int x, int y, int w, int h, int b, double[] dArray, java.awt.image.DataBuffer data)Gets the samples of a specified band for a specified rectangular area of
pixels as a double array.
double samples[];
int idx = 0;
if (dArray == null) {
samples = new double[w * h];
} else {
samples = dArray;
}
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
samples[idx++] = getSampleDouble(j, i, b, data);
}
}
return samples;
| public int | getTransferType()Gets the transfer type used to transfer pixels via the getDataElements
and setDataElements methods. Transfer type value can be one of the
predefined type from DataBuffer class or not.
return dataType;
| public final int | getWidth()Gets the width of the image data of this SampleModel object.
return width;
| public abstract void | setDataElements(int x, int y, java.lang.Object obj, java.awt.image.DataBuffer data)Sets the data for a single pixel in the specified DataBuffer from a
primitive array with one of the following types: DataBuffer.TYPE_BYTE,
DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.
| public void | setDataElements(int x, int y, int w, int h, java.lang.Object obj, java.awt.image.DataBuffer data)Sets the data elements for a rectangular area of pixels in the specified
DataBuffer from a primitive array with one of the following types:
DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT,
DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.
int numDataElements = getNumDataElements();
int idx = 0;
switch (getTransferType()) {
case DataBuffer.TYPE_BYTE:
byte bbuf[] = new byte[numDataElements];
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numDataElements; n++) {
bbuf[n] = ((byte[])obj)[idx++];
}
setDataElements(j, i, bbuf, data);
}
}
break;
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT:
short sbuf[] = new short[numDataElements];
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numDataElements; n++) {
sbuf[n] = ((short[])obj)[idx++];
}
setDataElements(j, i, sbuf, data);
}
}
break;
case DataBuffer.TYPE_INT:
int ibuf[] = new int[numDataElements];
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numDataElements; n++) {
ibuf[n] = ((int[])obj)[idx++];
}
setDataElements(j, i, ibuf, data);
}
}
break;
case DataBuffer.TYPE_FLOAT:
float fbuf[] = new float[numDataElements];
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numDataElements; n++) {
fbuf[n] = ((float[])obj)[idx++];
}
setDataElements(j, i, fbuf, data);
}
}
break;
case DataBuffer.TYPE_DOUBLE:
double dbuf[] = new double[numDataElements];
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numDataElements; n++) {
dbuf[n] = ((double[])obj)[idx++];
}
setDataElements(j, i, dbuf, data);
}
}
break;
}
| public void | setPixel(int x, int y, float[] fArray, java.awt.image.DataBuffer data)Sets a pixel of the DataBuffer from a float array of samples.
if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, fArray[i], data);
}
| public void | setPixel(int x, int y, double[] dArray, java.awt.image.DataBuffer data)Sets a pixel of the DataBuffer from a double array of samples.
if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, dArray[i], data);
}
| public void | setPixel(int x, int y, int[] iArray, java.awt.image.DataBuffer data)Sets a pixel of the DataBuffer from a integer array of samples.
if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, iArray[i], data);
}
| public void | setPixels(int x, int y, int w, int h, int[] iArray, java.awt.image.DataBuffer data)Sets all of the samples for a rectangular area of pixels of the
DataBuffer from an integer array.
if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
int idx = 0;
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numBands; n++) {
setSample(j, i, n, iArray[idx++], data);
}
}
}
| public void | setPixels(int x, int y, int w, int h, float[] fArray, java.awt.image.DataBuffer data)Sets all of the samples for a rectangular area of pixels of the
DataBuffer from a float array.
if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
int idx = 0;
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numBands; n++) {
setSample(j, i, n, fArray[idx++], data);
}
}
}
| public void | setPixels(int x, int y, int w, int h, double[] dArray, java.awt.image.DataBuffer data)Sets all of the samples for a rectangular area of pixels of the
DataBuffer from a double array.
if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
int idx = 0;
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
for (int n = 0; n < numBands; n++) {
setSample(j, i, n, dArray[idx++], data);
}
}
}
| public abstract void | setSample(int x, int y, int b, int s, java.awt.image.DataBuffer data)Sets a sample of the specified band for the specified pixel in the
DataBuffer as integer value.
| public void | setSample(int x, int y, int b, float s, java.awt.image.DataBuffer data)Sets a sample of the specified band for the specified pixel in the
DataBuffer as float value.
setSample(x, y, b, (int)s, data);
| public void | setSample(int x, int y, int b, double s, java.awt.image.DataBuffer data)Sets a sample of the specified band for the specified pixel in the
DataBuffer as double value.
setSample(x, y, b, (int)s, data);
| public void | setSamples(int x, int y, int w, int h, int b, int[] iArray, java.awt.image.DataBuffer data)Sets the samples from an integer array in the specified band for the
specified rectangle of pixels.
int idx = 0;
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
setSample(j, i, b, iArray[idx++], data);
}
}
| public void | setSamples(int x, int y, int w, int h, int b, float[] fArray, java.awt.image.DataBuffer data)Sets the samples from an float array in the specified band for the
specified rectangle of pixels.
int idx = 0;
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
setSample(j, i, b, fArray[idx++], data);
}
}
| public void | setSamples(int x, int y, int w, int h, int b, double[] dArray, java.awt.image.DataBuffer data)Sets the samples from an double array in the specified band for the
specified rectangle of pixels.
int idx = 0;
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
setSample(j, i, b, dArray[idx++], data);
}
}
|
|