private Image ReadRLE8()
{
// If imageSize field is not provided, calculate it.
int imSize = (int)imageSize;
if (imSize == 0) {
imSize = (int)(bitmapFileSize - bitmapOffset);
}
// Read till we have the whole image
byte[] values = new byte[imSize];
int bytesRead = 0;
while (bytesRead < imSize) {
bytesRead += inputStream.Read(values, bytesRead,
imSize - bytesRead);
}
// Since data is compressed, decompress it
byte[] val = DecodeRLE(true, values);
// Uncompressed data does not have any padding
imSize = width * height;
if (isBottomUp) {
// Convert the bottom up image to a top down format by copying
// one scanline from the bottom to the top at a time.
// int bytesPerScanline = (int)Math.Ceil((double)width/8.0);
byte[] temp = new byte[val.Length];
int bytesPerScanline = width;
for (int i=0; i<height; i++) {
Array.Copy(val,
imSize - (i+1)*(bytesPerScanline),
temp,
i*bytesPerScanline, bytesPerScanline);
}
val = temp;
}
return IndexedModel(val, 8, 4);
}