New code style. No functional changes.

This commit is contained in:
Harald Kuhr
2011-02-17 17:54:50 +01:00
parent 5bd896f80f
commit 770f948e1a
78 changed files with 1401 additions and 1412 deletions

View File

@@ -81,100 +81,98 @@ class BMHDChunk extends IFFChunk {
// words. The number of words per row is words=((w+15)/16)
// Dimensions of raster
int mWidth;
int mHeight;
int width;
int height;
// Source offsets
// Hmm.. Consider making these Image.properties?
int mXPos;
int mYPos;
int xPos;
int yPos;
// The number of source bitplanes in the BODY chunk (see below) is stored in
// nPlanes. An ILBM with a CMAP but no BODY and nPlanes = 0 is the
// recommended way to store a color map.
int mBitplanes;
int bitplanes;
int mMaskType;
int mCompressionType;
int maskType;
int compressionType;
int mTransparentIndex;
int transparentIndex;
// NOTE: Typical values are 10:11 (320 x 200)
int mXAspect;
int mYAspect;
int xAspect;
int yAspect;
// Source page dimension
// NOTE: The image may be larger than the page, probably ignore these
int mPageWidth;
int mPageHeight;
int pageWidth;
int pageHeight;
protected BMHDChunk(int pChunkLength) {
super(IFF.CHUNK_BMHD, pChunkLength);
}
protected BMHDChunk(int pWidth, int pHeight, int pBitplanes,
int pMaskType, int pCompressionType,
int pTransparentIndex) {
protected BMHDChunk(int pWidth, int pHeight, int pBitplanes, int pMaskType, int pCompressionType, int pTransparentIndex) {
super(IFF.CHUNK_BMHD, 20);
mWidth = pWidth;
mHeight = pHeight;
mXPos = 0;
mYPos = 0;
mBitplanes = pBitplanes;
mMaskType = pMaskType;
mCompressionType = pCompressionType;
mTransparentIndex = pTransparentIndex;
mXAspect = 1;
mYAspect = 1;
mPageWidth = Math.min(pWidth, Short.MAX_VALUE); // For some reason, these are signed?
mPageHeight = Math.min(pHeight, Short.MAX_VALUE);
width = pWidth;
height = pHeight;
xPos = 0;
yPos = 0;
bitplanes = pBitplanes;
maskType = pMaskType;
compressionType = pCompressionType;
transparentIndex = pTransparentIndex;
xAspect = 1;
yAspect = 1;
pageWidth = Math.min(pWidth, Short.MAX_VALUE); // For some reason, these are signed?
pageHeight = Math.min(pHeight, Short.MAX_VALUE);
}
void readChunk(DataInput pInput) throws IOException {
if (mChunkLength != 20) {
throw new IIOException("Unknown BMHD chunk length: " + mChunkLength);
if (chunkLength != 20) {
throw new IIOException("Unknown BMHD chunk length: " + chunkLength);
}
mWidth = pInput.readUnsignedShort();
mHeight = pInput.readUnsignedShort();
mXPos = pInput.readShort();
mYPos = pInput.readShort();
mBitplanes = pInput.readUnsignedByte();
mMaskType = pInput.readUnsignedByte();
mCompressionType = pInput.readUnsignedByte();
width = pInput.readUnsignedShort();
height = pInput.readUnsignedShort();
xPos = pInput.readShort();
yPos = pInput.readShort();
bitplanes = pInput.readUnsignedByte();
maskType = pInput.readUnsignedByte();
compressionType = pInput.readUnsignedByte();
pInput.readByte(); // PAD
mTransparentIndex = pInput.readUnsignedShort();
mXAspect = pInput.readUnsignedByte();
mYAspect = pInput.readUnsignedByte();
mPageWidth = pInput.readShort();
mPageHeight = pInput.readShort();
transparentIndex = pInput.readUnsignedShort();
xAspect = pInput.readUnsignedByte();
yAspect = pInput.readUnsignedByte();
pageWidth = pInput.readShort();
pageHeight = pInput.readShort();
}
void writeChunk(DataOutput pOutput) throws IOException {
pOutput.writeInt(mChunkId);
pOutput.writeInt(mChunkLength);
pOutput.writeInt(chunkId);
pOutput.writeInt(chunkLength);
pOutput.writeShort(mWidth);
pOutput.writeShort(mHeight);
pOutput.writeShort(mXPos);
pOutput.writeShort(mYPos);
pOutput.writeByte(mBitplanes);
pOutput.writeByte(mMaskType);
pOutput.writeByte(mCompressionType);
pOutput.writeShort(width);
pOutput.writeShort(height);
pOutput.writeShort(xPos);
pOutput.writeShort(yPos);
pOutput.writeByte(bitplanes);
pOutput.writeByte(maskType);
pOutput.writeByte(compressionType);
pOutput.writeByte(0); // PAD
pOutput.writeShort(mTransparentIndex);
pOutput.writeByte(mXAspect);
pOutput.writeByte(mYAspect);
pOutput.writeShort(mPageWidth);
pOutput.writeShort(mPageHeight);
pOutput.writeShort(transparentIndex);
pOutput.writeByte(xAspect);
pOutput.writeByte(yAspect);
pOutput.writeShort(pageWidth);
pOutput.writeShort(pageHeight);
}
public String toString() {
return super.toString()
+ " {w=" + mWidth + ", h=" + mHeight
+ ", x=" + mXPos + ", y=" + mYPos
+ ", planes=" + mBitplanes + ", mask=" + mMaskType
+ ", compression=" + mCompressionType + ", trans=" + mTransparentIndex
+ ", xAspect=" + mXAspect + ", yAspect=" + mYAspect
+ ", pageWidth=" + mPageWidth + ", pageHeight=" + mPageHeight + "}";
+ " {w=" + width + ", h=" + height
+ ", x=" + xPos + ", y=" + yPos
+ ", planes=" + bitplanes + ", mask=" + maskType
+ ", compression=" + compressionType + ", trans=" + transparentIndex
+ ", xAspect=" + xAspect + ", yAspect=" + yAspect
+ ", pageWidth=" + pageWidth + ", pageHeight=" + pageHeight + "}";
}
}

View File

@@ -40,7 +40,6 @@ import java.io.DataOutput;
* @version $Id: BODYChunk.java,v 1.0 28.feb.2006 01:25:49 haku Exp$
*/
class BODYChunk extends IFFChunk {
protected BODYChunk(int pChunkLength) {
super(IFF.CHUNK_BODY, pChunkLength);
}

View File

@@ -41,22 +41,21 @@ import java.io.IOException;
* @version $Id: CAMGChunk.java,v 1.0 28.feb.2006 02:10:07 haku Exp$
*/
class CAMGChunk extends IFFChunk {
// HIRES=0x8000, LACE=0x4
// #define CAMG_HAM 0x800 /* hold and modify */
// #define CAMG_EHB 0x80 /* extra halfbrite */
private int mCAMG;
private int camg;
public CAMGChunk(int pLength) {
super(IFF.CHUNK_CAMG, pLength);
}
void readChunk(DataInput pInput) throws IOException {
if (mChunkLength != 4) {
throw new IIOException("Unknown CAMG chunk length: " + mChunkLength);
if (chunkLength != 4) {
throw new IIOException("Unknown CAMG chunk length: " + chunkLength);
}
mCAMG = pInput.readInt();
camg = pInput.readInt();
}
void writeChunk(DataOutput pOutput) throws IOException {
@@ -64,11 +63,11 @@ class CAMGChunk extends IFFChunk {
}
boolean isHAM() {
return (mCAMG & 0x800) != 0;
return (camg & 0x800) != 0;
}
boolean isEHB() {
return (mCAMG & 0x80) != 0;
return (camg & 0x80) != 0;
}
public String toString() {

View File

@@ -54,34 +54,34 @@ class CMAPChunk extends IFFChunk {
// typedef ColorRegister ColorMap[n]; /* size = 3n bytes */
byte[] mReds;
byte[] mGreens;
byte[] mBlues;
byte[] reds;
byte[] greens;
byte[] blues;
boolean mEHB;
boolean ehb;
final private BMHDChunk mHeader;
final private CAMGChunk mCamg;
private IndexColorModel mModel;
final private BMHDChunk header;
final private CAMGChunk camg;
private IndexColorModel model;
protected CMAPChunk(int pChunkLength, BMHDChunk pHeader, CAMGChunk pCamg) {
super(IFF.CHUNK_CMAP, pChunkLength);
mHeader = pHeader;
mCamg = pCamg;
header = pHeader;
camg = pCamg;
}
public CMAPChunk(IndexColorModel pModel) {
super(IFF.CHUNK_CMAP, pModel.getMapSize() * 3);
mModel = pModel;
mHeader = null;
mCamg = null;
model = pModel;
header = null;
camg = null;
}
void readChunk(DataInput pInput) throws IOException {
int numColors = mChunkLength / 3;
int numColors = chunkLength / 3;
int paletteSize = numColors;
boolean isEHB = mCamg != null && mCamg.isEHB();
boolean isEHB = camg != null && camg.isEHB();
if (isEHB) {
if (numColors == 32) {
paletteSize = 64;
@@ -91,22 +91,22 @@ class CMAPChunk extends IFFChunk {
}
}
mReds = new byte[paletteSize];
mGreens = mReds.clone();
mBlues = mReds.clone();
reds = new byte[paletteSize];
greens = reds.clone();
blues = reds.clone();
for (int i = 0; i < numColors; i++) {
mReds[i] = pInput.readByte();
mGreens[i] = pInput.readByte();
mBlues[i] = pInput.readByte();
reds[i] = pInput.readByte();
greens[i] = pInput.readByte();
blues[i] = pInput.readByte();
}
if (isEHB && numColors == 32) {
// Create the half-brite colors
for (int i = 0; i < numColors; i++) {
mReds[i + numColors] = (byte) ((mReds[i] & 0xff) / 2);
mGreens[i + numColors] = (byte) ((mGreens[i] & 0xff) / 2);
mBlues[i + numColors] = (byte) ((mBlues[i] & 0xff) / 2);
reds[i + numColors] = (byte) ((reds[i] & 0xff) / 2);
greens[i + numColors] = (byte) ((greens[i] & 0xff) / 2);
blues[i + numColors] = (byte) ((blues[i] & 0xff) / 2);
}
}
@@ -120,7 +120,7 @@ class CMAPChunk extends IFFChunk {
// R8 := (Rn x 255 ) / maxColor
// All chunks are WORD aligned (even sized), may need to read pad...
if (mChunkLength % 2 != 0) {
if (chunkLength % 2 != 0) {
pInput.readByte();
}
@@ -128,33 +128,33 @@ class CMAPChunk extends IFFChunk {
// Would it work to double to numbers of colors, and create an indexcolormodel,
// with alpha, where all colors above the original color is all transparent?
// This is a waste of time and space, of course...
int trans = mHeader.mMaskType == BMHDChunk.MASK_TRANSPARENT_COLOR ? mHeader.mTransparentIndex : -1;
mModel = new InverseColorMapIndexColorModel(mHeader.mBitplanes, mReds.length, mReds, mGreens, mBlues, trans);
int trans = header.maskType == BMHDChunk.MASK_TRANSPARENT_COLOR ? header.transparentIndex : -1;
model = new InverseColorMapIndexColorModel(header.bitplanes, reds.length, reds, greens, blues, trans);
}
void writeChunk(DataOutput pOutput) throws IOException {
pOutput.writeInt(mChunkId);
pOutput.writeInt(mChunkLength);
pOutput.writeInt(chunkId);
pOutput.writeInt(chunkLength);
final int length = mModel.getMapSize();
final int length = model.getMapSize();
for (int i = 0; i < length; i++) {
pOutput.writeByte(mModel.getRed(i));
pOutput.writeByte(mModel.getGreen(i));
pOutput.writeByte(mModel.getBlue(i));
pOutput.writeByte(model.getRed(i));
pOutput.writeByte(model.getGreen(i));
pOutput.writeByte(model.getBlue(i));
}
if (mChunkLength % 2 != 0) {
if (chunkLength % 2 != 0) {
pOutput.writeByte(0); // PAD
}
}
public String toString() {
return super.toString() + " {colorMap=" + mModel + "}";
return super.toString() + " {colorMap=" + model + "}";
}
IndexColorModel getIndexColorModel() {
return mModel;
return model;
}
public BufferedImage createPaletteImage() {

View File

@@ -47,7 +47,7 @@ class GRABChunk extends IFFChunk {
// WORD x, y; /* relative coordinates (pixels) */
// } Point2D;
Point2D mPoint;
Point2D point;
protected GRABChunk(int pChunkLength) {
super(IFF.CHUNK_GRAB, pChunkLength);
@@ -55,22 +55,22 @@ class GRABChunk extends IFFChunk {
protected GRABChunk(Point2D pPoint) {
super(IFF.CHUNK_GRAB, 4);
mPoint = pPoint;
point = pPoint;
}
void readChunk(DataInput pInput) throws IOException {
if (mChunkLength != 4) {
throw new IIOException("Unknown GRAB chunk size: " + mChunkLength);
if (chunkLength != 4) {
throw new IIOException("Unknown GRAB chunk size: " + chunkLength);
}
mPoint = new Point(pInput.readShort(), pInput.readShort());
point = new Point(pInput.readShort(), pInput.readShort());
}
void writeChunk(DataOutput pOutput) throws IOException {
pOutput.writeShort((int) mPoint.getX());
pOutput.writeShort((int) mPoint.getY());
pOutput.writeShort((int) point.getX());
pOutput.writeShort((int) point.getY());
}
public String toString() {
return super.toString() + " {point=" + mPoint + "}";
return super.toString() + " {point=" + point + "}";
}
}

View File

@@ -41,45 +41,45 @@ import java.io.DataOutput;
*/
class GenericChunk extends IFFChunk {
byte[] mData;
byte[] data;
protected GenericChunk(int pChunkId, int pChunkLength) {
super(pChunkId, pChunkLength);
mData = new byte[pChunkLength <= 50 ? pChunkLength : 47];
data = new byte[pChunkLength <= 50 ? pChunkLength : 47];
}
protected GenericChunk(int pChunkId, byte[] pChunkData) {
super(pChunkId, pChunkData.length);
mData = pChunkData;
data = pChunkData;
}
void readChunk(DataInput pInput) throws IOException {
pInput.readFully(mData, 0, mData.length);
pInput.readFully(data, 0, data.length);
int toSkip = mChunkLength - mData.length;
int toSkip = chunkLength - data.length;
while (toSkip > 0) {
toSkip -= pInput.skipBytes(toSkip);
}
// Read pad
if (mChunkLength % 2 != 0) {
if (chunkLength % 2 != 0) {
pInput.readByte();
}
}
void writeChunk(DataOutput pOutput) throws IOException {
pOutput.writeInt(mChunkId);
pOutput.writeInt(mChunkLength);
pOutput.write(mData, 0, mData.length);
pOutput.writeInt(chunkId);
pOutput.writeInt(chunkLength);
pOutput.write(data, 0, data.length);
if (mData.length % 2 != 0) {
if (data.length % 2 != 0) {
pOutput.writeByte(0); // PAD
}
}
public String toString() {
return super.toString() + " {value=\""
+ new String(mData, 0, mData.length <= 50 ? mData.length : 47)
+ (mChunkLength <= 50 ? "" : "...") + "\"}";
+ new String(data, 0, data.length <= 50 ? data.length : 47)
+ (chunkLength <= 50 ? "" : "...") + "\"}";
}
}

View File

@@ -40,12 +40,12 @@ import java.io.DataOutput;
* @version $Id: IFFChunk.java,v 1.0 28.feb.2006 00:00:45 haku Exp$
*/
abstract class IFFChunk {
int mChunkId;
int mChunkLength;
int chunkId;
int chunkLength;
protected IFFChunk(int pChunkId, int pChunkLength) {
mChunkId = pChunkId;
mChunkLength = pChunkLength;
chunkId = pChunkId;
chunkLength = pChunkLength;
}
abstract void readChunk(DataInput pInput) throws IOException;
@@ -53,6 +53,6 @@ abstract class IFFChunk {
abstract void writeChunk(DataOutput pOutput) throws IOException;
public String toString() {
return IFFUtil.toChunkStr(mChunkId) + " chunk (" + mChunkLength + " bytes)";
return IFFUtil.toChunkStr(chunkId) + " chunk (" + chunkLength + " bytes)";
}
}

View File

@@ -96,16 +96,17 @@ public class IFFImageReader extends ImageReaderBase {
// - Contains definitions of some "new" chunks, as well as alternative FORM types
// http://amigan.1emu.net/reg/iff.html
private BMHDChunk mHeader;
private CMAPChunk mColorMap;
private BODYChunk mBody;
private GRABChunk mGrab;
private CAMGChunk mViewPort;
private int mFormType;
private long mBodyStart;
private BMHDChunk header;
private CMAPChunk colorMap;
private BODYChunk body;
@SuppressWarnings({"FieldCanBeLocal"})
private GRABChunk grab;
private CAMGChunk viewPort;
private int formType;
private long bodyStart;
private BufferedImage mImage;
private DataInputStream mByteRunStream;
private BufferedImage image;
private DataInputStream byteRunStream;
public IFFImageReader() {
super(IFFImageReaderSpi.sharedProvider());
@@ -118,20 +119,20 @@ public class IFFImageReader extends ImageReaderBase {
private void init(int pIndex) throws IOException {
checkBounds(pIndex);
if (mHeader == null) {
if (header == null) {
readMeta();
}
}
protected void resetMembers() {
mHeader = null;
mColorMap = null;
mBody = null;
mViewPort = null;
mFormType = 0;
header = null;
colorMap = null;
body = null;
viewPort = null;
formType = 0;
mImage = null;
mByteRunStream = null;
image = null;
byteRunStream = null;
}
private void readMeta() throws IOException {
@@ -141,15 +142,15 @@ public class IFFImageReader extends ImageReaderBase {
int remaining = imageInput.readInt() - 4; // We'll read 4 more in a sec
mFormType = imageInput.readInt();
if (mFormType != IFF.TYPE_ILBM && mFormType != IFF.TYPE_PBM) {
throw new IIOException("Only IFF (FORM) type ILBM and PBM supported: " + IFFUtil.toChunkStr(mFormType));
formType = imageInput.readInt();
if (formType != IFF.TYPE_ILBM && formType != IFF.TYPE_PBM) {
throw new IIOException("Only IFF (FORM) type ILBM and PBM supported: " + IFFUtil.toChunkStr(formType));
}
//System.out.println("IFF type FORM " + toChunkStr(type));
mGrab = null;
mViewPort = null;
grab = null;
viewPort = null;
while (remaining > 0) {
int chunkId = imageInput.readInt();
@@ -163,49 +164,49 @@ public class IFFImageReader extends ImageReaderBase {
switch (chunkId) {
case IFF.CHUNK_BMHD:
if (mHeader != null) {
if (header != null) {
throw new IIOException("Multiple BMHD chunks not allowed");
}
mHeader = new BMHDChunk(length);
mHeader.readChunk(imageInput);
header = new BMHDChunk(length);
header.readChunk(imageInput);
//System.out.println(mHeader);
//System.out.println(header);
break;
case IFF.CHUNK_CMAP:
if (mColorMap != null) {
if (colorMap != null) {
throw new IIOException("Multiple CMAP chunks not allowed");
}
mColorMap = new CMAPChunk(length, mHeader, mViewPort);
mColorMap.readChunk(imageInput);
colorMap = new CMAPChunk(length, header, viewPort);
colorMap.readChunk(imageInput);
//System.out.println(mColorMap);
//System.out.println(colorMap);
break;
case IFF.CHUNK_GRAB:
if (mGrab != null) {
if (grab != null) {
throw new IIOException("Multiple GRAB chunks not allowed");
}
mGrab = new GRABChunk(length);
mGrab.readChunk(imageInput);
grab = new GRABChunk(length);
grab.readChunk(imageInput);
//System.out.println(mGrab);
//System.out.println(grab);
break;
case IFF.CHUNK_CAMG:
if (mViewPort != null) {
if (viewPort != null) {
throw new IIOException("Multiple CAMG chunks not allowed");
}
mViewPort = new CAMGChunk(length);
mViewPort.readChunk(imageInput);
viewPort = new CAMGChunk(length);
viewPort.readChunk(imageInput);
//System.out.println(mViewPort);
//System.out.println(viewPort);
break;
case IFF.CHUNK_BODY:
if (mBody != null) {
if (body != null) {
throw new IIOException("Multiple BODY chunks not allowed");
}
mBody = new BODYChunk(length);
mBodyStart = imageInput.getStreamPosition();
body = new BODYChunk(length);
bodyStart = imageInput.getStreamPosition();
// NOTE: We don't read the body here, it's done later in the read(int, ImageReadParam) method
@@ -228,23 +229,23 @@ public class IFFImageReader extends ImageReaderBase {
processImageStarted(pIndex);
mImage = getDestination(pParam, getImageTypes(pIndex), mHeader.mWidth, mHeader.mHeight);
//System.out.println(mBody);
if (mBody != null) {
image = getDestination(pParam, getImageTypes(pIndex), header.width, header.height);
//System.out.println(body);
if (body != null) {
//System.out.println("Read body");
readBody(pParam);
}
else {
// TODO: Remove this hack when we have metadata
// In the rare case of an ILBM containing nothing but a CMAP
//System.out.println(mColorMap);
if (mColorMap != null) {
//System.out.println(colorMap);
if (colorMap != null) {
//System.out.println("Creating palette!");
mImage = mColorMap.createPaletteImage();
image = colorMap.createPaletteImage();
}
}
BufferedImage result = mImage;
BufferedImage result = image;
processImageComplete();
@@ -253,12 +254,12 @@ public class IFFImageReader extends ImageReaderBase {
public int getWidth(int pIndex) throws IOException {
init(pIndex);
return mHeader.mWidth;
return header.width;
}
public int getHeight(int pIndex) throws IOException {
init(pIndex);
return mHeader.mHeight;
return header.height;
}
public Iterator<ImageTypeSpecifier> getImageTypes(int pIndex) throws IOException {
@@ -266,8 +267,8 @@ public class IFFImageReader extends ImageReaderBase {
List<ImageTypeSpecifier> types = Arrays.asList(
getRawImageType(pIndex),
ImageTypeSpecifier.createFromBufferedImageType(mHeader.mBitplanes == 32 ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR)
// TODO: ImageTypeSpecifier.createFromBufferedImageType(mHeader.mBitplanes == 32 ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB),
ImageTypeSpecifier.createFromBufferedImageType(header.bitplanes == 32 ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR)
// TODO: ImageTypeSpecifier.createFromBufferedImageType(header.bitplanes == 32 ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB),
// TODO: Allow 32 bit always. Allow RGB and discard alpha, if present?
);
return types.iterator();
@@ -278,9 +279,9 @@ public class IFFImageReader extends ImageReaderBase {
init(pIndex);
// TODO: Stay DRY...
// TODO: Use this for creating the Image/Buffer in the read code below...
// NOTE: mColorMap may be null for 8 bit (gray), 24 bit or 32 bit only
// NOTE: colorMap may be null for 8 bit (gray), 24 bit or 32 bit only
ImageTypeSpecifier specifier;
switch (mHeader.mBitplanes) {
switch (header.bitplanes) {
case 1:
// 1 bit
case 2:
@@ -297,8 +298,8 @@ public class IFFImageReader extends ImageReaderBase {
// 8 bit
// May be HAM8
if (!isHAM()) {
if (mColorMap != null) {
IndexColorModel cm = mColorMap.getIndexColorModel();
if (colorMap != null) {
IndexColorModel cm = colorMap.getIndexColorModel();
specifier = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
break;
}
@@ -317,18 +318,18 @@ public class IFFImageReader extends ImageReaderBase {
specifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_4BYTE_ABGR);
break;
default:
throw new IIOException(String.format("Bit depth not implemented: %d", mHeader.mBitplanes));
throw new IIOException(String.format("Bit depth not implemented: %d", header.bitplanes));
}
return specifier;
}
private void readBody(final ImageReadParam pParam) throws IOException {
imageInput.seek(mBodyStart);
mByteRunStream = null;
imageInput.seek(bodyStart);
byteRunStream = null;
// NOTE: mColorMap may be null for 8 bit (gray), 24 bit or 32 bit only
if (mColorMap != null) {
IndexColorModel cm = mColorMap.getIndexColorModel();
// NOTE: colorMap may be null for 8 bit (gray), 24 bit or 32 bit only
if (colorMap != null) {
IndexColorModel cm = colorMap.getIndexColorModel();
readIndexed(pParam, imageInput, cm);
}
else {
@@ -338,8 +339,8 @@ public class IFFImageReader extends ImageReaderBase {
}
private void readIndexed(final ImageReadParam pParam, final ImageInputStream pInput, final IndexColorModel pModel) throws IOException {
final int width = mHeader.mWidth;
final int height = mHeader.mHeight;
final int width = header.width;
final int height = header.height;
final Rectangle aoi = getSourceRegion(pParam, width, height);
final Point offset = pParam == null ? new Point(0, 0) : pParam.getDestinationOffset();
@@ -360,9 +361,9 @@ public class IFFImageReader extends ImageReaderBase {
}
// Ensure band settings from param are compatible with images
checkReadParamBandSettings(pParam, isHAM() ? 3 : 1, mImage.getSampleModel().getNumBands());
checkReadParamBandSettings(pParam, isHAM() ? 3 : 1, image.getSampleModel().getNumBands());
WritableRaster destination = mImage.getRaster();
WritableRaster destination = image.getRaster();
if (destinationBands != null || offset.x != 0 || offset.y != 0) {
destination = destination.createWritableChild(0, 0, destination.getWidth(), destination.getHeight(), offset.x, offset.y, destinationBands);
}
@@ -403,7 +404,7 @@ public class IFFImageReader extends ImageReaderBase {
final byte[] data = ((DataBufferByte) raster.getDataBuffer()).getData();
final int planes = mHeader.mBitplanes;
final int planes = header.bitplanes;
Object dataElements = null;
Object outDataElements = null;
@@ -422,7 +423,7 @@ public class IFFImageReader extends ImageReaderBase {
return;
}
if (mFormType == IFF.TYPE_ILBM) {
if (formType == IFF.TYPE_ILBM) {
int pixelPos = 0;
for (int planePos = 0; planePos < planeWidth; planePos++) {
IFFUtil.bitRotateCW(planeData, planePos, planeWidth, row, pixelPos, 1);
@@ -436,13 +437,13 @@ public class IFFImageReader extends ImageReaderBase {
raster.setDataElements(0, 0, width, 1, row);
}
}
else if (mFormType == IFF.TYPE_PBM) {
else if (formType == IFF.TYPE_PBM) {
// TODO: Arraycopy might not be necessary, if it's okay with row larger than width
System.arraycopy(planeData, 0, row, 0, mHeader.mBitplanes * planeWidth);
System.arraycopy(planeData, 0, row, 0, header.bitplanes * planeWidth);
raster.setDataElements(0, 0, width, 1, row);
}
else {
throw new AssertionError(String.format("Unsupported FORM type: %s", mFormType));
throw new AssertionError(String.format("Unsupported FORM type: %s", formType));
}
int dstY = (srcY - aoi.y) / sourceYSubsampling;
@@ -470,7 +471,7 @@ public class IFFImageReader extends ImageReaderBase {
for (int srcX = 0; srcX < sourceRow.getWidth(); srcX += sourceXSubsampling) {
dataElements = sourceRow.getDataElements(srcX, 0, dataElements);
int rgb = icm.getRGB(dataElements);
outDataElements = mImage.getColorModel().getDataElements(rgb, outDataElements);
outDataElements = image.getColorModel().getDataElements(rgb, outDataElements);
int dstX = srcX / sourceXSubsampling;
destination.setDataElements(dstX, dstY, outDataElements);
}
@@ -479,7 +480,7 @@ public class IFFImageReader extends ImageReaderBase {
// TODO: This branch is never tested, and is probably "dead"
// ColorConvertOp
if (converter == null) {
converter = new ColorConvertOp(cm.getColorSpace(), mImage.getColorModel().getColorSpace(), null);
converter = new ColorConvertOp(cm.getColorSpace(), image.getColorModel().getColorSpace(), null);
}
converter.filter(
raster.createChild(aoi.x, 0, aoi.width, 1, 0, 0, null),
@@ -488,7 +489,7 @@ public class IFFImageReader extends ImageReaderBase {
}
}
processImageProgress(srcY * 100f / mHeader.mWidth);
processImageProgress(srcY * 100f / header.width);
if (abortRequested()) {
processReadAborted();
break;
@@ -502,8 +503,8 @@ public class IFFImageReader extends ImageReaderBase {
// bit of the red value for each pixel, and the last holds the most
// significant bit of the blue value.
private void readTrueColor(ImageReadParam pParam, final ImageInputStream pInput) throws IOException {
final int width = mHeader.mWidth;
final int height = mHeader.mHeight;
final int width = header.width;
final int height = header.height;
final Rectangle aoi = getSourceRegion(pParam, width, height);
final Point offset = pParam == null ? new Point(0, 0) : pParam.getDestinationOffset();
@@ -524,23 +525,23 @@ public class IFFImageReader extends ImageReaderBase {
}
// Ensure band settings from param are compatible with images
checkReadParamBandSettings(pParam, mHeader.mBitplanes / 8, mImage.getSampleModel().getNumBands());
checkReadParamBandSettings(pParam, header.bitplanes / 8, image.getSampleModel().getNumBands());
// NOTE: Each row of the image is stored in an integral number of 16 bit words.
// The number of words per row is words=((w+15)/16)
int planeWidth = 2 * ((width + 15) / 16);
final byte[] planeData = new byte[8 * planeWidth];
WritableRaster destination = mImage.getRaster();
WritableRaster destination = image.getRaster();
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(8 * planeWidth, 1);
// WritableRaster raster = image.getRaster().createCompatibleWritableRaster(width, 1);
WritableRaster raster = image.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();
final int channels = (mHeader.mBitplanes + 7) / 8;
final int channels = (header.bitplanes + 7) / 8;
final int planesPerChannel = 8;
Object dataElements = null;
@@ -559,7 +560,7 @@ public class IFFImageReader extends ImageReaderBase {
return;
}
if (mFormType == IFF.TYPE_ILBM) {
if (formType == IFF.TYPE_ILBM) {
// NOTE: Using (channels - c - 1) instead of just c,
// effectively reverses the channel order from RGBA to ABGR
int off = (channels - c - 1);
@@ -570,11 +571,11 @@ public class IFFImageReader extends ImageReaderBase {
pixelPos += 8;
}
}
else if (mFormType == IFF.TYPE_PBM) {
else if (formType == IFF.TYPE_PBM) {
System.arraycopy(planeData, 0, data, srcY * 8 * planeWidth, planeWidth);
}
else {
throw new AssertionError(String.format("Unsupported FORM type: %s", mFormType));
throw new AssertionError(String.format("Unsupported FORM type: %s", formType));
}
}
@@ -594,7 +595,7 @@ public class IFFImageReader extends ImageReaderBase {
}
}
processImageProgress(srcY * 100f / mHeader.mWidth);
processImageProgress(srcY * 100f / header.width);
if (abortRequested()) {
processReadAborted();
break;
@@ -605,11 +606,11 @@ public class IFFImageReader extends ImageReaderBase {
private void readPlaneData(final ImageInputStream pInput, final byte[] pData, final int pOffset, final int pPlaneWidth)
throws IOException {
switch (mHeader.mCompressionType) {
switch (header.compressionType) {
case BMHDChunk.COMPRESSION_NONE:
pInput.readFully(pData, pOffset, pPlaneWidth);
// Uncompressed rows must have even number of bytes
if ((mHeader.mBitplanes * pPlaneWidth) % 2 != 0) {
if ((header.bitplanes * pPlaneWidth) % 2 != 0) {
pInput.readByte();
}
break;
@@ -620,27 +621,27 @@ public class IFFImageReader extends ImageReaderBase {
// However, we don't know how long each compressed row is, without decoding it...
// The workaround below, is to use a decode buffer size of pPlaneWidth,
// to make sure we don't decode anything we don't have to (shouldn't).
if (mByteRunStream == null) {
mByteRunStream = new DataInputStream(
if (byteRunStream == null) {
byteRunStream = new DataInputStream(
new DecoderStream(
IIOUtil.createStreamAdapter(pInput, mBody.mChunkLength),
IIOUtil.createStreamAdapter(pInput, body.chunkLength),
new PackBitsDecoder(true),
pPlaneWidth * mHeader.mBitplanes
pPlaneWidth * header.bitplanes
)
);
}
mByteRunStream.readFully(pData, pOffset, pPlaneWidth);
byteRunStream.readFully(pData, pOffset, pPlaneWidth);
break;
default:
throw new IIOException(String.format("Unknown compression type: %d", mHeader.mCompressionType));
throw new IIOException(String.format("Unknown compression type: %d", header.compressionType));
}
}
private void hamToRGB(final byte[] pIndexed, final IndexColorModel pModel,
final byte[] pDest, final int pDestOffset) {
final int bits = mHeader.mBitplanes;
final int width = mHeader.mWidth;
final int bits = header.bitplanes;
final int width = header.width;
int lastRed = 0;
int lastGreen = 0;
int lastBlue = 0;
@@ -679,7 +680,7 @@ public class IFFImageReader extends ImageReaderBase {
}
private boolean isHAM() {
return mViewPort != null && mViewPort.isHAM();
return viewPort != null && viewPort.isHAM();
}
public static void main(String[] pArgs) throws IOException {

View File

@@ -208,9 +208,9 @@ public class IFFImageWriter extends ImageWriterBase {
}
// ILBM(4) + anno(8+len) + header(8+20) + cmap(8+len)? + body(8+len);
int size = 4 + 8 + anno.mChunkLength + 28 + 8 + pBodyLength;
int size = 4 + 8 + anno.chunkLength + 28 + 8 + pBodyLength;
if (cmap != null) {
size += 8 + cmap.mChunkLength;
size += 8 + cmap.chunkLength;
}
imageOutput.writeInt(IFF.CHUNK_FORM);

View File

@@ -51,7 +51,6 @@ public class IFFImageWriterSpi extends ImageWriterSpi {
*/
public IFFImageWriterSpi() {
this(IIOUtil.getProviderInfo(IFFImageWriterSpi.class));
}
private IFFImageWriterSpi(final ProviderInfo pProviderInfo) {