private Image GetImage()
{
byte[] bdata = null; // buffer for byte data
//short[] sdata = null; // buffer for short data
//int[] idata = null; // buffer for int data
// if (sampleModel.GetDataType() == DataBuffer.TYPE_BYTE)
// bdata = (byte[])((DataBufferByte)tile.GetDataBuffer()).GetData();
// else if (sampleModel.GetDataType() == DataBuffer.TYPE_USHORT)
// sdata = (short[])((DataBufferUShort)tile.GetDataBuffer()).GetData();
// else if (sampleModel.GetDataType() == DataBuffer.TYPE_INT)
// idata = (int[])((DataBufferInt)tile.GetDataBuffer()).GetData();
// There should only be one tile.
switch (imageType) {
case VERSION_2_1_BIT:
// no compression
return Read1Bit(3);
case VERSION_2_4_BIT:
// no compression
return Read4Bit(3);
case VERSION_2_8_BIT:
// no compression
return Read8Bit(3);
case VERSION_2_24_BIT:
// no compression
bdata = new byte[width * height * 3];
Read24Bit(bdata);
return new ImgRaw(width, height, 3, 8, bdata);
case VERSION_3_1_BIT:
// 1-bit images cannot be compressed.
return Read1Bit(4);
case VERSION_3_4_BIT:
switch ((int)compression) {
case BI_RGB:
return Read4Bit(4);
case BI_RLE4:
return ReadRLE4();
default:
throw new
Exception("Invalid compression specified for BMP file.");
}
case VERSION_3_8_BIT:
switch ((int)compression) {
case BI_RGB:
return Read8Bit(4);
case BI_RLE8:
return ReadRLE8();
default:
throw new
Exception("Invalid compression specified for BMP file.");
}
case VERSION_3_24_BIT:
// 24-bit images are not compressed
bdata = new byte[width * height * 3];
Read24Bit(bdata);
return new ImgRaw(width, height, 3, 8, bdata);
case VERSION_3_NT_16_BIT:
return Read1632Bit(false);
case VERSION_3_NT_32_BIT:
return Read1632Bit(true);
case VERSION_4_1_BIT:
return Read1Bit(4);
case VERSION_4_4_BIT:
switch ((int)compression) {
case BI_RGB:
return Read4Bit(4);
case BI_RLE4:
return ReadRLE4();
default:
throw new
Exception("Invalid compression specified for BMP file.");
}
case VERSION_4_8_BIT:
switch ((int)compression) {
case BI_RGB:
return Read8Bit(4);
case BI_RLE8:
return ReadRLE8();
default:
throw new
Exception("Invalid compression specified for BMP file.");
}
case VERSION_4_16_BIT:
return Read1632Bit(false);
case VERSION_4_24_BIT:
bdata = new byte[width * height * 3];
Read24Bit(bdata);
return new ImgRaw(width, height, 3, 8, bdata);
case VERSION_4_32_BIT:
return Read1632Bit(true);
}
return null;
}