if (!(dataBuffer instanceof DataBufferByte)) {
throw new RasterFormatException("ByteInterleavedRasters must have " +
"byte DataBuffers");
}
DataBufferByte dbb = (DataBufferByte)dataBuffer;
this.data = stealData(dbb, 0);
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
if (sampleModel instanceof PixelInterleavedSampleModel ||
(sampleModel instanceof ComponentSampleModel &&
isInterleaved((ComponentSampleModel)sampleModel))) {
ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
this.scanlineStride = csm.getScanlineStride();
this.pixelStride = csm.getPixelStride();
this.dataOffsets = csm.getBandOffsets();
for (int i = 0; i < getNumDataElements(); i++) {
dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
}
} else if (sampleModel instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel sppsm =
(SinglePixelPackedSampleModel)sampleModel;
this.packed = true;
this.bitMasks = sppsm.getBitMasks();
this.bitOffsets = sppsm.getBitOffsets();
this.scanlineStride = sppsm.getScanlineStride();
this.pixelStride = 1;
this.dataOffsets = new int[1];
this.dataOffsets[0] = dbb.getOffset();
dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
} else {
throw new RasterFormatException("ByteInterleavedRasters must " +
"have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
" or interleaved ComponentSampleModel. Sample model is " +