BandedSampleModelpublic final class BandedSampleModel extends ComponentSampleModel The BandedSampleModel class provides samples of pixels in an image which is
stored in a band interleaved method. Each pixel's sample takes one data
element of the DataBuffer. The pixel stride for a BandedSampleModel is one. |
Constructors Summary |
---|
public BandedSampleModel(int dataType, int w, int h, int numBands)Instantiates a new BandedSampleModel object with the specified data type
of samples, the width, height and bands number of image data.
this(dataType, w, h, w, BandedSampleModel.createIndices(numBands), BandedSampleModel
.createOffsets(numBands));
| public BandedSampleModel(int dataType, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets)Instantiates a new BandedSampleModel object with the specified data type
of samples, the width, height and bands number of image data.
super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets);
|
Methods Summary |
---|
public java.awt.image.SampleModel | createCompatibleSampleModel(int w, int h)
return new BandedSampleModel(dataType, w, h, w, bankIndices, bandOffsets);
| public java.awt.image.DataBuffer | createDataBuffer()
DataBuffer data = null;
int size = scanlineStride * height;
switch (dataType) {
case DataBuffer.TYPE_BYTE:
data = new DataBufferByte(size, numBanks);
break;
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT:
data = new DataBufferShort(size, numBanks);
break;
case DataBuffer.TYPE_INT:
data = new DataBufferInt(size, numBanks);
break;
case DataBuffer.TYPE_FLOAT:
data = new DataBufferFloat(size, numBanks);
break;
case DataBuffer.TYPE_DOUBLE:
data = new DataBufferDouble(size, numBanks);
break;
}
return data;
| private static int[] | createIndices(int numBands)Creates the indices.
int indices[] = new int[numBands];
for (int i = 0; i < numBands; i++) {
indices[i] = i;
}
return indices;
| private static int[] | createOffsets(int numBands)Creates the offsets.
int offsets[] = new int[numBands];
for (int i = 0; i < numBands; i++) {
offsets[i] = 0;
}
return offsets;
| public java.awt.image.SampleModel | createSubsetSampleModel(int[] bands)
if (bands.length > numBands) {
// awt.64=The number of the bands in the subset is greater than the
// number of bands in the sample model
throw new RasterFormatException(Messages.getString("awt.64")); //$NON-NLS-1$
}
int indices[] = new int[bands.length];
int offsets[] = new int[bands.length];
for (int i = 0; i < bands.length; i++) {
indices[i] = bankIndices[bands[i]];
offsets[i] = bandOffsets[bands[i]];
}
return new BandedSampleModel(dataType, width, height, scanlineStride, indices, offsets);
| public java.lang.Object | getDataElements(int x, int y, java.lang.Object obj, java.awt.image.DataBuffer data)
switch (dataType) {
case DataBuffer.TYPE_BYTE: {
byte bdata[];
if (obj == null) {
bdata = new byte[numBands];
} else {
bdata = (byte[])obj;
}
for (int i = 0; i < numBands; i++) {
bdata[i] = (byte)getSample(x, y, i, data);
}
obj = bdata;
break;
}
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT: {
short sdata[];
if (obj == null) {
sdata = new short[numBands];
} else {
sdata = (short[])obj;
}
for (int i = 0; i < numBands; i++) {
sdata[i] = (short)getSample(x, y, i, data);
}
obj = sdata;
break;
}
case DataBuffer.TYPE_INT: {
int idata[];
if (obj == null) {
idata = new int[numBands];
} else {
idata = (int[])obj;
}
for (int i = 0; i < numBands; i++) {
idata[i] = getSample(x, y, i, data);
}
obj = idata;
break;
}
case DataBuffer.TYPE_FLOAT: {
float fdata[];
if (obj == null) {
fdata = new float[numBands];
} else {
fdata = (float[])obj;
}
for (int i = 0; i < numBands; i++) {
fdata[i] = getSampleFloat(x, y, i, data);
}
obj = fdata;
break;
}
case DataBuffer.TYPE_DOUBLE: {
double ddata[];
if (obj == null) {
ddata = new double[numBands];
} else {
ddata = (double[])obj;
}
for (int i = 0; i < numBands; i++) {
ddata[i] = getSampleDouble(x, y, i, data);
}
obj = ddata;
break;
}
}
return obj;
| public int[] | getPixel(int x, int y, int[] iArray, java.awt.image.DataBuffer data)
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 | getSample(int x, int y, int b, java.awt.image.DataBuffer data)
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$
}
return data.getElem(bankIndices[b], y * scanlineStride + x + bandOffsets[b]);
| public double | getSampleDouble(int x, int y, int b, java.awt.image.DataBuffer data)
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$
}
return data.getElemDouble(bankIndices[b], y * scanlineStride + x + bandOffsets[b]);
| public float | getSampleFloat(int x, int y, int b, java.awt.image.DataBuffer data)
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$
}
return data.getElemFloat(bankIndices[b], y * scanlineStride + x + bandOffsets[b]);
| public int[] | getSamples(int x, int y, int w, int h, int b, int[] iArray, java.awt.image.DataBuffer data)
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 int | hashCode()
int hash = super.hashCode();
int tmp = hash >>> 8;
hash <<= 8;
hash |= tmp;
return hash ^ 0x55;
| public void | setDataElements(int x, int y, java.lang.Object obj, java.awt.image.DataBuffer data)
switch (dataType) {
case DataBuffer.TYPE_BYTE:
byte bdata[] = (byte[])obj;
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, bdata[i] & 0xff, data);
}
break;
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT:
short sdata[] = (short[])obj;
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, sdata[i] & 0xffff, data);
}
break;
case DataBuffer.TYPE_INT:
int idata[] = (int[])obj;
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, idata[i], data);
}
break;
case DataBuffer.TYPE_FLOAT:
float fdata[] = (float[])obj;
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, fdata[i], data);
}
break;
case DataBuffer.TYPE_DOUBLE:
double ddata[] = (double[])obj;
for (int i = 0; i < numBands; i++) {
setSample(x, y, i, ddata[i], data);
}
break;
}
| public void | setPixel(int x, int y, int[] iArray, java.awt.image.DataBuffer data)
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)
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 | setSample(int x, int y, int b, double s, java.awt.image.DataBuffer data)
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$
}
data.setElemDouble(bankIndices[b], y * scanlineStride + x + bandOffsets[b], s);
| public void | setSample(int x, int y, int b, float s, java.awt.image.DataBuffer data)
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$
}
data.setElemFloat(bankIndices[b], y * scanlineStride + x + bandOffsets[b], s);
| public void | setSample(int x, int y, int b, int s, java.awt.image.DataBuffer data)
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$
}
data.setElem(bankIndices[b], y * scanlineStride + x + bandOffsets[b], s);
| public void | setSamples(int x, int y, int w, int h, int b, int[] iArray, java.awt.image.DataBuffer data)
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);
}
}
|
|