dataType
is not
* one of the supported data types
*/
public BandedSampleModel(int dataType, int w, int h, int numBands) {
super(dataType, w, h, 1, w,
BandedSampleModel.createIndicesArray(numBands),
BandedSampleModel.createOffsetArray(numBands));
}
/**
* Constructs a BandedSampleModel with the specified parameters.
* The number of bands will be inferred from the lengths of the
* bandOffsets bankIndices arrays, which must be equal. The pixel
* stride will be one data element.
* @param dataType The data type for storing samples.
* @param w The width (in pixels) of the region of
* image data described.
* @param h The height (in pixels) of the region of
* image data described.
* @param scanlineStride The line stride of the of the image data.
* @param bankIndices The bank index for each band.
* @param bandOffsets The band offset for each band.
* @throws IllegalArgumentException if dataType
is not
* one of the supported data types
*/
public BandedSampleModel(int dataType,
int w, int h,
int scanlineStride,
int bankIndices[],
int bandOffsets[]) {
super(dataType, w, h, 1,scanlineStride, bankIndices, bandOffsets);
}
/**
* Creates a new BandedSampleModel with the specified
* width and height. The new BandedSampleModel will have the same
* number of bands, storage data type, and bank indices
* as this BandedSampleModel. The band offsets will be compressed
* such that the offset between bands will be w*pixelStride and
* the minimum of all of the band offsets is zero.
* @param w the width of the resulting BandedSampleModel
* @param h the height of the resulting BandedSampleModel
* @return a new BandedSampleModel
with the specified
* width and height.
* @throws IllegalArgumentException if w
or
* h
equals either
* Integer.MAX_VALUE
or
* Integer.MIN_VALUE
* @throws IllegalArgumentException if dataType
is not
* one of the supported data types
*/
public SampleModel createCompatibleSampleModel(int w, int h) {
int[] bandOffs;
if (numBanks == 1) {
bandOffs = orderBands(bandOffsets, w*h);
}
else {
bandOffs = new int[bandOffsets.length];
}
SampleModel sampleModel =
new BandedSampleModel(dataType, w, h, w, bankIndices, bandOffs);
return sampleModel;
}
/**
* Creates a new BandedSampleModel with a subset of the bands of this
* BandedSampleModel. The new BandedSampleModel can be
* used with any DataBuffer that the existing BandedSampleModel
* can be used with. The new BandedSampleModel/DataBuffer
* combination will represent an image with a subset of the bands
* of the original BandedSampleModel/DataBuffer combination.
* @throws RasterFormatException if the number of bands is greater than
* the number of banks in this sample model.
* @throws IllegalArgumentException if dataType
is not
* one of the supported data types
*/
public SampleModel createSubsetSampleModel(int bands[]) {
if (bands.length > bankIndices.length)
throw new RasterFormatException("There are only " +
bankIndices.length +
" bands");
int newBankIndices[] = new int[bands.length];
int newBandOffsets[] = new int[bands.length];
for (int i=0; i
* The following code illustrates transferring data for one pixel from
* DataBuffer db1
, whose storage layout is described by
* BandedSampleModel bsm1
, to DataBuffer db2
,
* whose storage layout is described by
* BandedSampleModel bsm2
.
* The transfer will generally be more efficient than using
* getPixel/setPixel.
*
* BandedSampleModel bsm1, bsm2; * DataBufferInt db1, db2; * bsm2.setDataElements(x, y, bsm1.getDataElements(x, y, null, db1), * db2); ** Using getDataElements/setDataElements to transfer between two * DataBuffer/SampleModel pairs is legitimate if the SampleModels have * the same number of bands, corresponding bands have the same number of * bits per sample, and the TransferTypes are the same. *
* If obj is non-null, it should be a primitive array of type TransferType.
* Otherwise, a ClassCastException is thrown. An
* ArrayIndexOutOfBoundsException may be thrown if the coordinates are
* not in bounds, or if obj is non-null and is not large enough to hold
* the pixel data.
* @param x The X coordinate of the pixel location
* @param y The Y coordinate of the pixel location
* @param obj If non-null, a primitive array in which to return
* the pixel data.
* @param data The DataBuffer containing the image data.
* @return the data for the specified pixel.
* @see #setDataElements(int, int, Object, DataBuffer)
*/
public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!");
}
int type = getTransferType();
int numDataElems = getNumDataElements();
int pixelOffset = y*scanlineStride + x;
switch(type) {
case DataBuffer.TYPE_BYTE:
byte[] bdata;
if (obj == null) {
bdata = new byte[numDataElems];
} else {
bdata = (byte[])obj;
}
for (int i=0; i
* The following code illustrates transferring data for one pixel from
* DataBuffer
* obj must be a primitive array of type TransferType. Otherwise,
* a ClassCastException is thrown. An
* ArrayIndexOutOfBoundsException may be thrown if the coordinates are
* not in bounds, or if obj is not large enough to hold the pixel data.
* @param x The X coordinate of the pixel location
* @param y The Y coordinate of the pixel location
* @param obj If non-null, returns the primitive array in this
* object
* @param data The DataBuffer containing the image data
* @see #getDataElements(int, int, Object, DataBuffer)
*/
public void setDataElements(int x, int y, Object obj, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!");
}
int type = getTransferType();
int numDataElems = getNumDataElements();
int pixelOffset = y*scanlineStride + x;
switch(type) {
case DataBuffer.TYPE_BYTE:
byte[] barray = (byte[])obj;
for (int i=0; idb1
, whose storage layout is described by
* BandedSampleModel bsm1
, to DataBuffer db2
,
* whose storage layout is described by
* BandedSampleModel bsm2
.
* The transfer will generally be more efficient than using
* getPixel/setPixel.
*
* BandedSampleModel bsm1, bsm2;
* DataBufferInt db1, db2;
* bsm2.setDataElements(x, y, bsm1.getDataElements(x, y, null, db1),
* db2);
*
* Using getDataElements/setDataElements to transfer between two
* DataBuffer/SampleModel pairs is legitimate if the SampleModels have
* the same number of bands, corresponding bands have the same number of
* bits per sample, and the TransferTypes are the same.
*