From 0a71af54056355fbb8292778a6cbe5f07d9aaf27 Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Wed, 4 Nov 2009 16:08:20 +0100 Subject: [PATCH] Fixed reading of gray-scale IFFs. Added some comments & clean-up. --- .../imageio/plugins/iff/CAMGChunk.java | 1 + .../imageio/plugins/iff/IFFImageReader.java | 18 ++++++++++++++---- .../imageio/plugins/iff/IFFUtil.java | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/CAMGChunk.java b/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/CAMGChunk.java index 7b906951..98ecb5f8 100755 --- a/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/CAMGChunk.java +++ b/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/CAMGChunk.java @@ -42,6 +42,7 @@ import java.io.IOException; */ class CAMGChunk extends IFFChunk { + // HIRES=0x8000, LACE=0x4 // #define CAMG_HAM 0x800 /* hold and modify */ // #define CAMG_EHB 0x80 /* extra halfbrite */ diff --git a/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFImageReader.java b/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFImageReader.java index 99a3a004..44b20f88 100755 --- a/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFImageReader.java +++ b/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFImageReader.java @@ -91,6 +91,16 @@ import java.util.List; * @see Wikipedia: IFF ILBM */ public class IFFImageReader extends ImageReaderBase { + // http://home.comcast.net/~erniew/lwsdk/docs/filefmts/ilbm.html + // http://www.fileformat.info/format/iff/spec/7866a9f0e53c42309af667c5da3bd426/view.htm + // - Contains definitions of some "new" chunks, as well as alternative FORM types + + // TODO: One other existing deep bit ordering that you may encounter is the 21-bit + // NewTek format. + // + // NewTek deep ILBM bit ordering: + // saved first ------------------------------------------------------> saved last + // R7 G7 B7 R6 G6 B6 R5 G5 B5 R4 G4 B4 R3 G3 B3 R2 G2 B2 R1 G1 B1 R0 G0 B0 private BMHDChunk mHeader; private CMAPChunk mColorMap; @@ -294,9 +304,8 @@ public class IFFImageReader extends ImageReaderBase { // 8 bit // May be HAM8 if (!isHAM()) { - // TODO: This is probably a bug, as mColorMap is null in case of gray.. - IndexColorModel cm = mColorMap.getIndexColorModel(); - if (cm != null) { + if (mColorMap != null) { + IndexColorModel cm = mColorMap.getIndexColorModel(); specifier = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); break; } @@ -533,7 +542,8 @@ public class IFFImageReader extends ImageReaderBase { if (destinationBands != null || offset.x != 0 || offset.y != 0) { destination = destination.createWritableChild(0, 0, destination.getWidth(), destination.getHeight(), offset.x, offset.y, destinationBands); } - WritableRaster raster = mImage.getRaster().createCompatibleWritableRaster(width, 1); +// WritableRaster raster = mImage.getRaster().createCompatibleWritableRaster(width, 1); + WritableRaster raster = mImage.getRaster().createCompatibleWritableRaster(8 * planeWidth, 1); Raster sourceRow = raster.createChild(aoi.x, 0, aoi.width, 1, 0, 0, sourceBands); final byte[] data = ((DataBufferByte) raster.getDataBuffer()).getData(); diff --git a/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFUtil.java b/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFUtil.java index 4d58f616..843d2eb9 100755 --- a/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFUtil.java +++ b/twelvemonkeys-imageio/iff/src/main/java/com/twelvemonkeys/imageio/plugins/iff/IFFUtil.java @@ -57,7 +57,8 @@ class IFFUtil { 0x00000000l << n, 0x00000001l << n, 0x00000100l << n, 0x00000101l << n, 0x00010000l << n, 0x00010001l << n, 0x00010100l << n, 0x00010101l << n, 0x01000000l << n, 0x01000001l << n, 0x01000100l << n, 0x01000101l << n, - 0x01010000l << n, 0x01010001l << n, 0x01010100l << n, 0x01010101l << n}; + 0x01010000l << n, 0x01010001l << n, 0x01010100l << n, 0x01010101l << n + }; } static private final long[][] RTABLE = {