}
}
} catch (IOException ioe) {
String message = JaiI18N.getString("BMPImageDecoder5");
ImagingListenerProxy.errorOccurred(message,
new ImagingException(message, ioe),
this, false);
// throw new RuntimeException(JaiI18N.getString("BMPImageDecoder5"));
}
if (height > 0) {
// bottom up image
isBottomUp = true;
} else {
// top down image
isBottomUp = false;
height = Math.abs(height);
}
// Reset Image Layout so there's only one tile.
tileWidth = width;
tileHeight = height;
// When number of bitsPerPixel is <= 8, we use IndexColorModel.
if (bitsPerPixel == 1 || bitsPerPixel == 4 || bitsPerPixel == 8) {
numBands = 1;
if (bitsPerPixel == 8) {
sampleModel =
RasterFactory.createPixelInterleavedSampleModel(
DataBuffer.TYPE_BYTE,
width, height,
numBands);
} else {
// 1 and 4 bit pixels can be stored in a packed format.
sampleModel =
new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
width, height,
bitsPerPixel);
}
// Create IndexColorModel from the palette.
byte r[], g[], b[];
int size;
if (imageType == VERSION_2_1_BIT ||
imageType == VERSION_2_4_BIT ||
imageType == VERSION_2_8_BIT) {
size = palette.length/3;
if (size > 256) {
size = 256;
}
int off;
r = new byte[size];
g = new byte[size];
b = new byte[size];
for (int i=0; i<size; i++) {
off = 3 * i;
b[i] = palette[off];
g[i] = palette[off+1];
r[i] = palette[off+2];
}
} else {
size = palette.length/4;
if (size > 256) {
size = 256;
}
int off;
r = new byte[size];
g = new byte[size];
b = new byte[size];
for (int i=0; i<size; i++) {
off = 4 * i;
b[i] = palette[off];
g[i] = palette[off+1];
r[i] = palette[off+2];
}
}
if (ImageCodec.isIndicesForGrayscale(r, g, b))
colorModel = ImageCodec.createComponentColorModel(sampleModel);
else
colorModel = new IndexColorModel(bitsPerPixel, size, r, g, b);
} else if (bitsPerPixel == 16) {
numBands = 3;
sampleModel =
new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
width, height,
new int[] {redMask, greenMask, blueMask});
colorModel =
new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
16, redMask, greenMask, blueMask, 0,
false, DataBuffer.TYPE_USHORT);
} else if (bitsPerPixel == 32) {
numBands = alphaMask == 0 ? 3 : 4;
// The number of bands in the SampleModel is determined by
// the length of the mask array passed in.
int[] bitMasks = numBands == 3 ?
new int[] {redMask, greenMask, blueMask} :
new int[] {redMask, greenMask, blueMask, alphaMask};
sampleModel =
new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
width, height,
bitMasks);
colorModel =
new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
32, redMask, greenMask, blueMask, alphaMask,
false, DataBuffer.TYPE_INT);
} else {
numBands = 3;
// Create SampleModel
sampleModel =
RasterFactory.createPixelInterleavedSampleModel(
DataBuffer.TYPE_BYTE, width, height, numBands);
colorModel =
ImageCodec.createComponentColorModel(sampleModel);
}
try {
inputStream.reset();
inputStream.skip(bitmapOffset);
} catch (IOException ioe) {
String message = JaiI18N.getString("BMPImageDecoder9");
ImagingListenerProxy.errorOccurred(message,
new ImagingException(message, ioe),
this, false);
}
}