*/
private ImageData readPlanarImage( PlanarImage image ) {
ColorModel cm = image.getColorModel();
int width = image.getWidth();
int height = image.getHeight();
PaletteData palette = null;
ImageData imageData = null;
// Image is indexed and has a palette.
if ( cm instanceof IndexColorModel) {
// Create SWT flavour palette from the colour model
IndexColorModel icm = (IndexColorModel)cm;
int colourCount = icm.getMapSize();
byte[][] data = new byte[3][colourCount];
icm.getReds(data[0]);
icm.getGreens(data[1]);
icm.getBlues(data[2]);
RGB[] colours = new RGB[ colourCount ];
for( int i = 0; i < colourCount; i++ ) {
int red = data[0][i] & 0xFF;
int green = data[1][i] & 0xFF;
int blue = data[2][i] & 0xFF;
colours[i] = new RGB( red, green, blue );
}
palette = new PaletteData( colours );
// Create indexed image
imageData = new ImageData( width, height,
icm.getPixelSize(),
palette );
// Copy the pixel data
copyIndexed( imageData, image.getData() );
// Greyscale if 8 bits per pixel but not indexed
} else if( cm.getPixelSize() == 8 ) {
// Create greyscale palette
RGB[] colours = new RGB[ 256 ];
for( int i = 0; i < 256; i++ ) {
colours[i] = new RGB( i, i, i );
}
palette = new PaletteData( colours );
// Create greyscale image
imageData = new ImageData( width, height, 8, palette );
// Copy pixel data
copyIndexed( imageData, image.getData() );
// Monochrome if 1 bit per pixel
} else if( cm.getPixelSize() == 1 ) {
// Create monochrome palette
RGB[] colours = new RGB[ 2 ];
colours[0] = new RGB( 255, 255, 255);
colours[1] = new RGB( 0, 0, 0 );
palette = new PaletteData( colours );
// Create monochrome image
imageData = new ImageData( width, height, 1, palette );
// Copy pixel data
copyIndexed( imageData, image.getData() );
// True colour if 24 bits per pixel
} else if( cm.getPixelSize() == 24 ) {
palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
imageData = new ImageData( width,height,24,palette );
copyTrueColour( imageData, image.getData() );
}
// this will be null if we could not determine the type of