return;
}
// Writeback should only be necessary on destRasters which
// should be writable so this cast should succeed.
WritableRaster wr = (WritableRaster)raster;
if (wr.getSampleModel() instanceof ComponentSampleModel) {
ComponentSampleModel csm =
(ComponentSampleModel)wr.getSampleModel();
int rasScanlineStride = csm.getScanlineStride();
int rasPixelStride = csm.getPixelStride();
int subRasterOffset =
(rect.y-raster.getSampleModelTranslateY())*rasScanlineStride+
(rect.x-raster.getSampleModelTranslateX())*rasPixelStride;
int rasBankIndices[] = csm.getBankIndices();
int rasBandOffsets[] = csm.getBandOffsets();
int rasDataOffsets[] = raster.getDataBuffer().getOffsets();
if (rasDataOffsets.length == 1) {
for (int i = 0; i < numBands; i++) {
rasBandOffsets[i] += rasDataOffsets[0] +
subRasterOffset;
}
} else if (rasDataOffsets.length == rasBandOffsets.length) {
for (int i = 0; i < numBands; i++) {
rasBandOffsets[i] += rasDataOffsets[i] +
subRasterOffset;
}
}
Object mlibDataArray = null;
switch (getDataType()) {
case DataBuffer.TYPE_BYTE:
byte bArray[][] = new byte[numBands][];
for (int i = 0; i < numBands; i++) {
bArray[i] = mlimages[0].getByteData();
}
mlibDataArray = bArray;
break;
case DataBuffer.TYPE_USHORT:
short usArray[][] = new short[numBands][];
for (int i = 0; i < numBands; i++) {
usArray[i] = mlimages[0].getUShortData();
}
mlibDataArray = usArray;
break;
case DataBuffer.TYPE_SHORT:
short sArray[][] = new short[numBands][];
for (int i = 0; i < numBands; i++) {
sArray[i] = mlimages[0].getShortData();
}
mlibDataArray = sArray;
break;
case DataBuffer.TYPE_INT:
int iArray[][] = new int[numBands][];
for (int i = 0; i < numBands; i++) {
iArray[i] = mlimages[0].getIntData();
}
mlibDataArray = iArray;
break;
case DataBuffer.TYPE_FLOAT:
float fArray[][] = new float[numBands][];
for (int i = 0; i < numBands; i++) {
fArray[i] = mlimages[0].getFloatData();
}
mlibDataArray = fArray;
break;
case DataBuffer.TYPE_DOUBLE:
double dArray[][] = new double[numBands][];
for (int i = 0; i < numBands; i++) {
dArray[i] = mlimages[0].getDoubleData();
}
mlibDataArray = dArray;
break;
}
byte tmpDataArray[] = null;
Object rasDataArray = null;
switch (csm.getDataType()) {
case DataBuffer.TYPE_BYTE: {
DataBufferByte dbb =
(DataBufferByte)raster.getDataBuffer();
byte rasByteDataArray[][] = new byte[numBands][];
for (int i = 0; i < numBands; i++) {
rasByteDataArray[i] =
dbb.getData(rasBankIndices[i]);
}
tmpDataArray = rasByteDataArray[0];
rasDataArray = rasByteDataArray;
}
break;
case DataBuffer.TYPE_USHORT: {
DataBufferUShort dbus =
(DataBufferUShort)raster.getDataBuffer();
short rasUShortDataArray[][] = new short[numBands][];
for (int i = 0; i < numBands; i++) {
rasUShortDataArray[i] =
dbus.getData(rasBankIndices[i]);
}
rasDataArray = rasUShortDataArray;
}
break;
case DataBuffer.TYPE_SHORT: {
DataBufferShort dbs =
(DataBufferShort)raster.getDataBuffer();
short rasShortDataArray[][] = new short[numBands][];
for (int i = 0; i < numBands; i++) {
rasShortDataArray[i] =
dbs.getData(rasBankIndices[i]);
}
rasDataArray = rasShortDataArray;
}
break;
case DataBuffer.TYPE_INT: {
DataBufferInt dbi =
(DataBufferInt)raster.getDataBuffer();
int rasIntDataArray[][] = new int[numBands][];
for (int i = 0; i < numBands; i++) {
rasIntDataArray[i] =
dbi.getData(rasBankIndices[i]);
}
rasDataArray = rasIntDataArray;
}
break;
case DataBuffer.TYPE_FLOAT: {
DataBuffer dbf =
raster.getDataBuffer();
float rasFloatDataArray[][] = new float[numBands][];
for (int i = 0; i < numBands; i++) {
rasFloatDataArray[i] =
DataBufferUtils.getDataFloat(dbf, rasBankIndices[i]);
}
rasDataArray = rasFloatDataArray;
}
break;
case DataBuffer.TYPE_DOUBLE: {
DataBuffer dbd =
raster.getDataBuffer();
double rasDoubleDataArray[][] = new double[numBands][];
for (int i = 0; i < numBands; i++) {
rasDoubleDataArray[i] =
DataBufferUtils.getDataDouble(dbd, rasBankIndices[i]);
}
rasDataArray = rasDoubleDataArray;
}
break;
}
// src = mlib && dst = ras
Image.Reformat(
rasDataArray,
mlibDataArray,
numBands,
rect.width,rect.height,
getMediaLibDataType(csm.getDataType()),
rasBandOffsets,
rasScanlineStride,
rasPixelStride,
getMediaLibDataType(this.getDataType()),
bandOffsets,
rect.width*numBands,
numBands);
} else {
// If COPIED and the raster doesn't have ComponentSampleModel
// data is moved with getPixel/setPixel (even byte/short)
switch (getDataType()) {
case DataBuffer.TYPE_INT:
wr.setPixels(rect.x,rect.y,
rect.width,rect.height,
mlimages[0].getIntData());
break;
case DataBuffer.TYPE_FLOAT:
wr.setPixels(rect.x,rect.y,
rect.width,rect.height,
mlimages[0].getFloatData());
break;
case DataBuffer.TYPE_DOUBLE:
wr.setPixels(rect.x,rect.y,
rect.width,rect.height,
mlimages[0].getDoubleData());
break;
}
}