// Get the data array out of the DataBuffer
byte bdata[] = null;
short sdata[] = null;
int idata[] = null;
float fdata[] = null;
DataBuffer buffer = sampleModel.createDataBuffer();
int dataType = sampleModel.getDataType();
if (dataType == DataBuffer.TYPE_BYTE) {
bdata = ((DataBufferByte)buffer).getData();
} else if (dataType == DataBuffer.TYPE_USHORT) {
sdata = ((DataBufferUShort)buffer).getData();
} else if (dataType == DataBuffer.TYPE_SHORT) {
sdata = ((DataBufferShort)buffer).getData();
} else if (dataType == DataBuffer.TYPE_INT) {
idata = ((DataBufferInt)buffer).getData();
} else if (dataType == DataBuffer.TYPE_FLOAT) {
if(buffer instanceof DataBufferFloat) {
fdata = ((DataBufferFloat)buffer).getData();
} else {
// This is a hack to make this work with JAI which in some
// cases downcasts the DataBuffer to a type-specific class.
// In the case of float data this current means the JAI class
// com.lightcrafts.mediax.jai.DataBufferFloat.
try {
Method getDataMethod =
buffer.getClass().getMethod("getData", null);
fdata = (float[])getDataMethod.invoke(buffer, null);
} catch(Exception e) {
String message = JaiI18N.getString("TIFFImage18");
ImagingListenerProxy.errorOccurred(message,
new ImagingException(message, e),