package com.ctreber.aclib.image.ico;
import java.awt.Image;
import java.io.IOException;
import com.ctreber.aclib.image.FileDecoder;
/**
* <p>Icon entry in image file.</p>
*
* <p>© 2002 Christian Treber, [email]ct@ctreber.com[/email] (Mar 27, 2003)</p>
* @author Christian Treber, [email]ct@ctreber.com[/email]
*
*/
public class ICOEntry
{
private ICOHeader fHeader;
private int fWidth;
private int fHeight;
private int fColorCount;
private int fReserved;
private int fPlanes;
private int fBitCount;
private int fSize;
private int fOffset;
private ICOBitmap fBitmap;
// RGB images have no mask
private ICOBitmapMask fMask;
// 16 Bytes
public ICOEntry(FileDecoder pDec) throws IOException
{
ICOFile.log(2, "Reading entry at " + pDec.getPos());
fWidth = pDec.readUInt1();
fHeight = pDec.readUInt1();
fColorCount = pDec.readUInt1();
fReserved = pDec.readUInt1();
fPlanes = pDec.readUInt2();
fBitCount = pDec.readUInt2();
fSize = pDec.readUInt4();
fOffset = pDec.readUInt4();
ICOFile.log(2, this.toString());
}
public String toString()
{
return
"Entry: width: " + fWidth +
", height: " + fHeight +
", colorCount: " + fColorCount + " (" + getColorCount() + ")" +
", planes: " + fPlanes +
", bitCount: " + fBitCount +
", size: " + fSize +
", offset: " + fOffset;
}
/**
* @return Image with indexed colors. Returns null if an indexed image can't
* be created (from an RGB icon). Transparency information that might be
* present in the ICO file is lost. See {@link #getImageRGB}.
*/
public Image getImageIndexed()
{
if(!(fBitmap instanceof ICOBitmapIndexed))
{
// Can't create indexed image from RGB icon.
return null;
}
ICOBitmapIndexed lBitmap = (ICOBitmapIndexed)fBitmap;
return lBitmap.createImageIndexed();
}
/**
* @return Bits per pixel. If the bit count of the entry is 0, the bit count
* of the header is returned. See {@link #getBitCountRaw}.
*/
public int getBitCount()
{
return fBitCount != 0 ? fBitCount : fHeader.getBitCount();
}
/**
* @return The original bit count. See {@link #getBitCount}.
*/
public int getBitCountRaw()
{
return fBitCount;
}
/**
* @return Image with ARGB colors. This method works for indexed color and
* RGB ICO files. Transparency information that might be present in the ICO
* is used. See {@link #getImageIndexed}.
*/
public Image getImageRGB()
{
return fBitmap.createImageRGB();
}
/**
* @return The original color count (note "0" means "256").
* See {@link #getColorCount}
*/
public int getColorCountRaw()
{
return fColorCount;
}
/**
* @return The actual color count. See {@link #getColorCountRaw}
*/
public int getColorCount()
{
return fColorCount == 0 ? 256 : fColorCount;
}
public int getHeight()
{
return fHeight;
}
public int getOffset()
{
return fOffset;
}
public int getPlanes()
{
return fPlanes;
}
public int getReserved()
{
return fReserved;
}
public int getSize()
{
return fSize;
}
public int getWidth()
{
return fWidth;
}
public ICOHeader getHeader()
{
return fHeader;
}
public void setHeader(ICOHeader pHeader)
{
fHeader = pHeader;
}
public ICOBitmapMask getMask()
{
return fMask;
}
public void setMask(ICOBitmapMask pLBitmapAnd)
{
fMask = pLBitmapAnd;
}
public ICOBitmap getBitmap()
{
return fBitmap;
}
public void setBitmap(ICOBitmap pLBitmapXor)
{
fBitmap = pLBitmapXor;
}
}