);
final WritableRaster outBuffer;
if (dataType == DataBuffer.TYPE_BYTE)
outBuffer = new ByteInterleavedRaster(sm, new Point(0, 0));
else
outBuffer = new ShortInterleavedRaster(sm, new Point(0, 0));
int stripIndex = 0;
for ( int y = 0; y < imageHeight; y += stripHeight ) {
if ( thread != null && thread.isCanceled() )
return;
final int currentStripHeight = Math.min( stripHeight, imageHeight - y );
// Create a child raster of the out buffer for the current strip
final WritableRaster raster = outBuffer.createWritableChild(0, 0, imageWidth, currentStripHeight, 0, y, null);
// Prefetch tiles, uses all CPUs
if (image instanceof PlanarImage)
((PlanarImage) image).getTiles(((PlanarImage) image).getTileIndices(raster.getBounds()));
image.copyData(raster);
int offset;
if (raster instanceof ByteInterleavedRaster) {
final ByteInterleavedRaster interleaved =
(ByteInterleavedRaster) raster;
final int[] offsets = interleaved.getDataOffsets();
offset = offsets[0];
for (int i = 1; i < offsets.length; i++)
offset = Math.min(offset, offsets[i]);
final DataBufferByte db = (DataBufferByte)raster.getDataBuffer();
final int written = writeStripByte( stripIndex, db.getData(), offset, bands * imageWidth * currentStripHeight );
if ( written != bands * imageWidth * currentStripHeight )
throw new LCImageLibException(
"something is wrong: " + written + " != " +
(bands * imageWidth * currentStripHeight)
);
} else {
final ShortInterleavedRaster interleaved =
(ShortInterleavedRaster) raster;
final int[] offsets = interleaved.getDataOffsets();
offset = offsets[0];
for (int i = 1; i < offsets.length; i++)
offset = Math.min(offset, offsets[i]);
final DataBufferUShort db = (DataBufferUShort) raster.getDataBuffer();