TMI-76: Support 34/32 bit in PCXImageReader

This commit is contained in:
Harald Kuhr 2014-11-03 21:03:26 +01:00
parent ecc896f80d
commit 6df540808b

View File

@ -129,8 +129,11 @@ public final class PCXImageReader extends ImageReaderBase {
// PCX has 1 or 3 channels for 8 bit gray or 24 bit RGB, will be validated by ImageTypeSpecifier // PCX has 1 or 3 channels for 8 bit gray or 24 bit RGB, will be validated by ImageTypeSpecifier
return ImageTypeSpecifier.createBanded(cs, createIndices(channels, 1), createIndices(channels, 0), DataBuffer.TYPE_BYTE, false, false); return ImageTypeSpecifier.createBanded(cs, createIndices(channels, 1), createIndices(channels, 0), DataBuffer.TYPE_BYTE, false, false);
case 24: case 24:
// Some sources says this is possible... Untested. // Some sources says this is possible...
return ImageTypeSpecifier.createInterleaved(cs, createIndices(channels, 0), DataBuffer.TYPE_BYTE, false, false); return ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_3BYTE_BGR);
case 32:
// Some sources says this is possible...
return ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_4BYTE_ABGR);
default: default:
throw new IIOException("Unknown number of bytes per pixel: " + header.getBitsPerPixel()); throw new IIOException("Unknown number of bytes per pixel: " + header.getBitsPerPixel());
} }
@ -221,6 +224,32 @@ public final class PCXImageReader extends ImageReaderBase {
} }
} }
} }
else if (header.getBitsPerPixel() == 24 || header.getBitsPerPixel() == 32) {
// Can't use width here, as we need to take bytesPerLine into account, and re-create a width based on this
int rowWidth = (header.getBytesPerLine() * 8) / header.getBitsPerPixel();
WritableRaster rowRaster = rawType.createBufferedImage(rowWidth, 1).getRaster();
// Clip to source region
Raster clippedRow = clipRowToRect(rowRaster, srcRegion,
param != null ? param.getSourceBands() : null,
param != null ? param.getSourceXSubsampling() : 1);
for (int y = 0; y < height; y++) {
byte[] rowDataByte = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
readRowByte(input, srcRegion, xSub, ySub, rowDataByte, 0, rowDataByte.length, destRaster, clippedRow, y);
processImageProgress(100f * y / height);
if (y < srcRegion.y) {
break;
}
if (abortRequested()) {
processReadAborted();
break;
}
}
}
else { else {
// Can't use width here, as we need to take bytesPerLine into account, and re-create a width based on this // Can't use width here, as we need to take bytesPerLine into account, and re-create a width based on this
int rowWidth = (header.getBytesPerLine() * 8) / header.getBitsPerPixel(); int rowWidth = (header.getBytesPerLine() * 8) / header.getBitsPerPixel();