mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 12:35:29 -04:00
Added workaround for 32 bit RAW format in Java < 6
This commit is contained in:
parent
96b65bc902
commit
608df15066
53
twelvemonkeys-imageio/pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/QTRAWDecompressor.java
Executable file → Normal file
53
twelvemonkeys-imageio/pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/QTRAWDecompressor.java
Executable file → Normal file
@ -56,32 +56,69 @@ final class QTRAWDecompressor extends QTDecompressor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage decompress(final QuickTime.ImageDesc pDescription, final InputStream pStream) throws IOException {
|
public BufferedImage decompress(final QuickTime.ImageDesc pDescription, final InputStream pStream) throws IOException {
|
||||||
DataInputStream stream = new DataInputStream(pStream);
|
|
||||||
|
|
||||||
byte[] data = new byte[pDescription.dataSize];
|
byte[] data = new byte[pDescription.dataSize];
|
||||||
|
|
||||||
|
DataInputStream stream = new DataInputStream(pStream);
|
||||||
|
try {
|
||||||
stream.readFully(data, 0, pDescription.dataSize);
|
stream.readFully(data, 0, pDescription.dataSize);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
stream.close();
|
stream.close();
|
||||||
|
}
|
||||||
|
|
||||||
DataBuffer buffer = new DataBufferByte(data, data.length);
|
DataBuffer buffer = new DataBufferByte(data, data.length);
|
||||||
|
|
||||||
WritableRaster raster;
|
WritableRaster raster;
|
||||||
|
|
||||||
// TODO: Depth parameter can be 1-32 (color) or 33-40 (gray scale)
|
// TODO: Depth parameter can be 1-32 (color) or 33-40 (gray scale)
|
||||||
switch (pDescription.depth) {
|
switch (pDescription.depth) {
|
||||||
case 24:
|
case 40: // 8 bit gray (untested)
|
||||||
raster = Raster.createInterleavedRaster(buffer, pDescription.width, pDescription.height, pDescription.width * 3, 3, new int[] {0, 1, 2}, null);
|
raster = Raster.createInterleavedRaster(
|
||||||
|
buffer,
|
||||||
|
pDescription.width, pDescription.height,
|
||||||
|
pDescription.width, 1,
|
||||||
|
new int[] {0},
|
||||||
|
null
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 24: // 24 bit RGB
|
||||||
raster = Raster.createInterleavedRaster(buffer, pDescription.width, pDescription.height, pDescription.width * 4, 4, new int[] {1, 2, 3, 0}, null);
|
raster = Raster.createInterleavedRaster(
|
||||||
|
buffer,
|
||||||
|
pDescription.width, pDescription.height,
|
||||||
|
pDescription.width * 3, 3,
|
||||||
|
new int[] {0, 1, 2},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 32: // 32 bit RGBA
|
||||||
|
// WORKAROUND: There is a bug in the way Java 2D interprets the band offsets before Java 6.
|
||||||
|
// So, instead of passing a correct offset array below, we swap channel 1 & 3...
|
||||||
|
for (int y = 0; y < pDescription.height; y++) {
|
||||||
|
for (int x = 0; x < pDescription.width; x++) {
|
||||||
|
int offset = 4 * y * pDescription.width + x * 4;
|
||||||
|
byte temp = data[offset + 1];
|
||||||
|
data[offset + 1] = data[offset + 3];
|
||||||
|
data[offset + 3] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
raster = Raster.createInterleavedRaster(
|
||||||
|
buffer,
|
||||||
|
pDescription.width, pDescription.height,
|
||||||
|
pDescription.width * 4, 4,
|
||||||
|
new int[] {3, 2, 1, 0}, // B & R mixed up. {1, 2, 3, 0} is correct
|
||||||
|
null
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IIOException("Unsupported RAW depth: " + pDescription.depth);
|
throw new IIOException("Unsupported RAW depth: " + pDescription.depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorModel cm = new ComponentColorModel(
|
ColorModel cm = new ComponentColorModel(
|
||||||
ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
pDescription.depth <= 32 ? ColorSpace.getInstance(ColorSpace.CS_sRGB) : ColorSpace.getInstance(ColorSpace.CS_GRAY),
|
||||||
pDescription.depth == 32,
|
pDescription.depth == 32,
|
||||||
false,
|
false,
|
||||||
Transparency.TRANSLUCENT,
|
pDescription.depth == 32 ? Transparency.TRANSLUCENT : Transparency.OPAQUE,
|
||||||
DataBuffer.TYPE_BYTE
|
DataBuffer.TYPE_BYTE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user