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

@@ -39,34 +39,34 @@ import java.awt.image.BufferedImage;
* @version $Id: Bitmap.java,v 1.0 25.feb.2006 00:29:44 haku Exp$
*/
abstract class BitmapDescriptor {
protected final DirectoryEntry mEntry;
protected final DIBHeader mHeader;
protected final DirectoryEntry entry;
protected final DIBHeader header;
protected BufferedImage mImage;
protected BufferedImage image;
public BitmapDescriptor(final DirectoryEntry pEntry, final DIBHeader pHeader) {
Validate.notNull(pEntry, "entry");
Validate.notNull(pHeader, "header");
mEntry = pEntry;
mHeader = pHeader;
entry = pEntry;
header = pHeader;
}
abstract public BufferedImage getImage();
public final int getWidth() {
return mEntry.getWidth();
return entry.getWidth();
}
public final int getHeight() {
return mEntry.getHeight();
return entry.getHeight();
}
protected final int getColorCount() {
return mEntry.getColorCount() != 0 ? mEntry.getColorCount() : 1 << getBitCount();
return entry.getColorCount() != 0 ? entry.getColorCount() : 1 << getBitCount();
}
protected final int getBitCount() {
return mEntry.getBitCount() != 0 ? mEntry.getBitCount() : mHeader.getBitCount();
return entry.getBitCount() != 0 ? entry.getBitCount() : header.getBitCount();
}
}

View File

@@ -43,17 +43,17 @@ import java.util.Hashtable;
* @version $Id: BitmapIndexed.java,v 1.0 25.feb.2006 00:29:44 haku Exp$
*/
class BitmapIndexed extends BitmapDescriptor {
protected final int[] mBits;
protected final int[] mColors;
protected final int[] bits;
protected final int[] colors;
private BitmapMask mMask;
private BitmapMask mask;
public BitmapIndexed(final DirectoryEntry pEntry, final DIBHeader pHeader) {
super(pEntry, pHeader);
mBits = new int[getWidth() * getHeight()];
bits = new int[getWidth() * getHeight()];
// NOTE: We're adding space for one extra color, for transparency
mColors = new int[getColorCount() + 1];
colors = new int[getColorCount() + 1];
}
public BufferedImage createImageIndexed() {
@@ -64,10 +64,9 @@ class BitmapIndexed extends BitmapDescriptor {
// This is slightly obscure, and should probably be moved..
Hashtable<String, Object> properties = null;
if (mEntry instanceof DirectoryEntry.CUREntry) {
DirectoryEntry.CUREntry entry = (DirectoryEntry.CUREntry) mEntry;
if (entry instanceof DirectoryEntry.CUREntry) {
properties = new Hashtable<String, Object>(1);
properties.put("cursor_hotspot", entry.getHotspot());
properties.put("cursor_hotspot", ((DirectoryEntry.CUREntry) this.entry).getHotspot());
}
BufferedImage image = new BufferedImage(
@@ -82,13 +81,13 @@ class BitmapIndexed extends BitmapDescriptor {
final int trans = icm.getTransparentPixel();
for (int y = 0; y < getHeight(); y++) {
for (int x = 0; x < getWidth(); x++) {
if (mMask.isTransparent(x, y)) {
mBits[x + getWidth() * y] = trans;
if (mask.isTransparent(x, y)) {
bits[x + getWidth() * y] = trans;
}
}
}
raster.setSamples(0, 0, getWidth(), getHeight(), 0, mBits);
raster.setSamples(0, 0, getWidth(), getHeight(), 0, bits);
//System.out.println("Image: " + image);
@@ -102,18 +101,18 @@ class BitmapIndexed extends BitmapDescriptor {
// NOTE: This is a hack to make room for transparent pixel for mask
int bits = getBitCount();
int colors = mColors.length;
int colors = this.colors.length;
int trans = -1;
// Try to avoid USHORT transfertype, as it results in BufferedImage TYPE_CUSTOM
// NOTE: This code assumes icons are small, and is NOT optimized for performance...
if (colors > (1 << getBitCount())) {
int index = BitmapIndexed.findTransIndexMaybeRemap(mColors, mBits);
int index = BitmapIndexed.findTransIndexMaybeRemap(this.colors, this.bits);
if (index == -1) {
// No duplicate found, increase bitcount
bits++;
trans = mColors.length - 1;
trans = this.colors.length - 1;
}
else {
// Found a duplicate, use it as trans
@@ -124,7 +123,7 @@ class BitmapIndexed extends BitmapDescriptor {
// NOTE: Setting hasAlpha to true, makes things work on 1.2
return new InverseColorMapIndexColorModel(
bits, colors, mColors, 0, true, trans,
bits, colors, this.colors, 0, true, trans,
bits <= 8 ? DataBuffer.TYPE_BYTE : DataBuffer.TYPE_USHORT
);
}
@@ -170,13 +169,13 @@ class BitmapIndexed extends BitmapDescriptor {
}
public BufferedImage getImage() {
if (mImage == null) {
mImage = createImageIndexed();
if (image == null) {
image = createImageIndexed();
}
return mImage;
return image;
}
public void setMask(final BitmapMask pMask) {
mMask = pMask;
mask = pMask;
}
}

View File

@@ -38,19 +38,19 @@ import java.awt.image.BufferedImage;
* @version $Id: BitmapMask.java,v 1.0 25.feb.2006 00:29:44 haku Exp$
*/
class BitmapMask extends BitmapDescriptor {
protected final BitmapIndexed mMask;
protected final BitmapIndexed mask;
public BitmapMask(final DirectoryEntry pParent, final DIBHeader pHeader) {
super(pParent, pHeader);
mMask = new BitmapIndexed(pParent, pHeader);
mask = new BitmapIndexed(pParent, pHeader);
}
boolean isTransparent(final int pX, final int pY) {
// NOTE: 1: Fully transparent, 0: Opaque...
return mMask.mBits[pX + pY * getWidth()] != 0;
return mask.bits[pX + pY * getWidth()] != 0;
}
public BufferedImage getImage() {
return mMask.getImage();
return mask.getImage();
}
}

View File

@@ -43,6 +43,6 @@ class BitmapRGB extends BitmapDescriptor {
}
public BufferedImage getImage() {
return mImage;
return image;
}
}

View File

@@ -38,15 +38,15 @@ import java.awt.image.BufferedImage;
* @version $Id: BitmapUnsupported.java,v 1.0 25.feb.2006 00:29:44 haku Exp$
*/
class BitmapUnsupported extends BitmapDescriptor {
private String mMessage;
private String message;
public BitmapUnsupported(final DirectoryEntry pEntry, final String pMessage) {
super(pEntry, null);
mMessage = pMessage;
message = pMessage;
}
public BufferedImage getImage() {
throw new IllegalStateException(mMessage);
throw new IllegalStateException(message);
}
}

View File

@@ -41,16 +41,16 @@ import java.io.IOException;
* @see <a href="http://en.wikipedia.org/wiki/BMP_file_format">BMP file format (Wikipedia)</a>
*/
abstract class DIBHeader {
protected int mSize;
protected int size;
protected int mWidth;
protected int width;
// NOTE: If a bitmask is present, this value includes the height of the mask
// (so often header.height = entry.height * 2)
protected int mHeight;
protected int height;
protected int mPlanes;
protected int mBitCount;
protected int planes;
protected int bitCount;
/**
* 0 = BI_RGB: No compression
@@ -58,18 +58,18 @@ abstract class DIBHeader {
* 2 = BI_RLE4: 4 bit RLE Compression (4 bit only)
* 3 = BI_BITFIELDS: No compression (16 & 32 bit only)
*/
protected int mCompression;
protected int compression;
// May be 0 if not known
protected int mImageSize;
protected int imageSize;
protected int mXPixelsPerMeter;
protected int mYPixelsPerMeter;
protected int xPixelsPerMeter;
protected int yPixelsPerMeter;
protected int mColorsUsed;
protected int colorsUsed;
// 0 means all colors are important
protected int mColorsImportant;
protected int colorsImportant;
protected DIBHeader() {
}
@@ -102,47 +102,47 @@ abstract class DIBHeader {
protected abstract void read(int pSize, DataInput pStream) throws IOException;
public final int getSize() {
return mSize;
return size;
}
public final int getWidth() {
return mWidth;
return width;
}
public final int getHeight() {
return mHeight;
return height;
}
public final int getPlanes() {
return mPlanes;
return planes;
}
public final int getBitCount() {
return mBitCount;
return bitCount;
}
public int getCompression() {
return mCompression;
return compression;
}
public int getImageSize() {
return mImageSize;
return imageSize;
}
public int getXPixelsPerMeter() {
return mXPixelsPerMeter;
return xPixelsPerMeter;
}
public int getYPixelsPerMeter() {
return mYPixelsPerMeter;
return yPixelsPerMeter;
}
public int getColorsUsed() {
return mColorsUsed;
return colorsUsed;
}
public int getColorsImportant() {
return mColorsImportant;
return colorsImportant;
}
public String toString() {
@@ -176,22 +176,22 @@ abstract class DIBHeader {
throw new IIOException(String.format("Size: %s !=: %s", pSize, DIB.WINDOWS_V3_HEADER_SIZE));
}
mSize = pSize;
size = pSize;
mWidth = pStream.readInt();
mHeight = pStream.readInt();
width = pStream.readInt();
height = pStream.readInt();
mPlanes = pStream.readUnsignedShort();
mBitCount = pStream.readUnsignedShort();
mCompression = pStream.readInt();
planes = pStream.readUnsignedShort();
bitCount = pStream.readUnsignedShort();
compression = pStream.readInt();
mImageSize = pStream.readInt();
imageSize = pStream.readInt();
mXPixelsPerMeter = pStream.readInt();
mYPixelsPerMeter = pStream.readInt();
xPixelsPerMeter = pStream.readInt();
yPixelsPerMeter = pStream.readInt();
mColorsUsed = pStream.readInt();
mColorsImportant = pStream.readInt();
colorsUsed = pStream.readInt();
colorsImportant = pStream.readInt();
}
}
}

View File

@@ -41,10 +41,10 @@ import java.util.List;
* @version $Id: Directory.java,v 1.0 25.feb.2006 00:29:44 haku Exp$
*/
class Directory {
private final List<DirectoryEntry> mEntries;
private final List<DirectoryEntry> entries;
private Directory(int pImageCount) {
mEntries = Arrays.asList(new DirectoryEntry[pImageCount]);
entries = Arrays.asList(new DirectoryEntry[pImageCount]);
}
public static Directory read(final int pType, final int pImageCount, final DataInput pStream) throws IOException {
@@ -54,21 +54,21 @@ class Directory {
}
private void readEntries(final int pType, final DataInput pStream) throws IOException {
for (int i = 0; i < mEntries.size(); i++) {
mEntries.set(i, DirectoryEntry.read(pType, pStream));
for (int i = 0; i < entries.size(); i++) {
entries.set(i, DirectoryEntry.read(pType, pStream));
}
}
public DirectoryEntry getEntry(final int pEntryIndex) {
return mEntries.get(pEntryIndex);
return entries.get(pEntryIndex);
}
public int count() {
return mEntries.size();
return entries.size();
}
@Override
public String toString() {
return String.format("%s%s", getClass().getSimpleName(), mEntries);
return String.format("%s%s", getClass().getSimpleName(), entries);
}
}

View File

@@ -31,7 +31,6 @@ package com.twelvemonkeys.imageio.plugins.ico;
import javax.imageio.IIOException;
import java.io.DataInput;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.*;
/**
@@ -43,13 +42,13 @@ import java.awt.*;
* @see <a href="http://en.wikipedia.org/wiki/ICO_(icon_image_file_format)#Directory">Wikipedia</a>
*/
abstract class DirectoryEntry {
private int mWidth;
private int mHeight;
private int mColorCount;
int mPlanes;
int mBitCount;
private int mSize;
private int mOffset;
private int width;
private int height;
private int colorCount;
int planes;
int bitCount;
private int size;
private int offset;
private DirectoryEntry() {
}
@@ -79,58 +78,58 @@ abstract class DirectoryEntry {
protected void read(final DataInput pStream) throws IOException {
// Width/height = 0, means 256
int w = pStream.readUnsignedByte();
mWidth = w == 0 ? 256 : w;
width = w == 0 ? 256 : w;
int h = pStream.readUnsignedByte();
mHeight = h == 0 ? 256 : h;
height = h == 0 ? 256 : h;
// Color count = 0, means 256 or more colors
mColorCount = pStream.readUnsignedByte();
colorCount = pStream.readUnsignedByte();
// Ignore. Should be 0, but .NET (System.Drawing.Icon.Save) sets this value to 255, according to Wikipedia
pStream.readUnsignedByte();
mPlanes = pStream.readUnsignedShort(); // Should be 0 or 1 for ICO, x hotspot for CUR
mBitCount = pStream.readUnsignedShort(); // bit count for ICO, y hotspot for CUR
planes = pStream.readUnsignedShort(); // Should be 0 or 1 for ICO, x hotspot for CUR
bitCount = pStream.readUnsignedShort(); // bit count for ICO, y hotspot for CUR
// Size of bitmap in bytes
mSize = pStream.readInt();
mOffset = pStream.readInt();
size = pStream.readInt();
offset = pStream.readInt();
}
public String toString() {
return String.format(
"%s: width: %d, height: %d, colors: %d, planes: %d, bit count: %d, size: %d, offset: %d",
getClass().getSimpleName(),
mWidth, mHeight, mColorCount, mPlanes, mBitCount, mSize, mOffset
width, height, colorCount, planes, bitCount, size, offset
);
}
public int getBitCount() {
return mBitCount;
return bitCount;
}
public int getColorCount() {
return mColorCount;
return colorCount;
}
public int getHeight() {
return mHeight;
return height;
}
public int getOffset() {
return mOffset;
return offset;
}
public int getPlanes() {
return mPlanes;
return planes;
}
public int getSize() {
return mSize;
return size;
}
public int getWidth() {
return mWidth;
return width;
}
/**
@@ -145,11 +144,11 @@ abstract class DirectoryEntry {
super.read(pStream);
// NOTE: This is a hack...
mXHotspot = mPlanes;
mYHotspot = mBitCount;
mXHotspot = planes;
mYHotspot = bitCount;
mPlanes = 1; // Always 1 for all BMP types
mBitCount = 0;
planes = 1; // Always 1 for all BMP types
bitCount = 0;
}
public Point getHotspot() {

View File

@@ -69,13 +69,13 @@ import java.util.List;
// Known issue: 256x256 PNG encoded icons does not have IndexColorModel even if stated in DirectoryEntry (seem impossible as the PNGs are all true color)
public class ICOImageReader extends ImageReaderBase {
// TODO: Consider moving the reading to inner classes (subclasses of BitmapDescriptor)
private Directory mDirectory;
private Directory directory;
// TODO: Review these, make sure we don't have a memory leak
private Map<DirectoryEntry, DIBHeader> mHeaders = new WeakHashMap<DirectoryEntry, DIBHeader>();
private Map<DirectoryEntry, BitmapDescriptor> mDescriptors = new WeakWeakMap<DirectoryEntry, BitmapDescriptor>();
private Map<DirectoryEntry, DIBHeader> headers = new WeakHashMap<DirectoryEntry, DIBHeader>();
private Map<DirectoryEntry, BitmapDescriptor> descriptors = new WeakWeakMap<DirectoryEntry, BitmapDescriptor>();
private ImageReader mPNGImageReader;
private ImageReader pngImageReader;
public ICOImageReader() {
this(DIB.TYPE_ICO);
@@ -101,14 +101,14 @@ public class ICOImageReader extends ImageReaderBase {
}
protected void resetMembers() {
mDirectory = null;
directory = null;
mHeaders.clear();
mDescriptors.clear();
headers.clear();
descriptors.clear();
if (mPNGImageReader != null) {
mPNGImageReader.dispose();
mPNGImageReader = null;
if (pngImageReader != null) {
pngImageReader.dispose();
pngImageReader = null;
}
}
@@ -158,7 +158,7 @@ public class ICOImageReader extends ImageReaderBase {
}
@Override
public int getNumImages(final boolean pAllowSearch) throws IOException {
public int getNumImages(final boolean allowSearch) throws IOException {
return getDirectory().count();
}
@@ -260,38 +260,38 @@ public class ICOImageReader extends ImageReaderBase {
private ImageReader getPNGReader() throws IIOException {
// TODO: Prefer Sun's std JDK PNGImagerReader, because it has known behaviour?
if (mPNGImageReader == null) {
if (pngImageReader == null) {
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("PNG");
if (readers.hasNext()) {
mPNGImageReader = readers.next();
pngImageReader = readers.next();
}
else {
throw new IIOException("No PNGImageReader found using ImageIO, can't read PNG encoded ICO format.");
}
}
else {
mPNGImageReader.reset();
pngImageReader.reset();
}
return mPNGImageReader;
return pngImageReader;
}
private DIBHeader getHeader(final DirectoryEntry pEntry) throws IOException {
if (!mHeaders.containsKey(pEntry)) {
if (!headers.containsKey(pEntry)) {
imageInput.seek(pEntry.getOffset());
DIBHeader header = DIBHeader.read(imageInput);
mHeaders.put(pEntry, header);
headers.put(pEntry, header);
}
return mHeaders.get(pEntry);
return headers.get(pEntry);
}
private BufferedImage readBitmap(final DirectoryEntry pEntry) throws IOException {
// TODO: Get rid of the caching, as the images are mutable
BitmapDescriptor descriptor = mDescriptors.get(pEntry);
BitmapDescriptor descriptor = descriptors.get(pEntry);
if (descriptor == null || !mDescriptors.containsKey(pEntry)) {
if (descriptor == null || !descriptors.containsKey(pEntry)) {
DIBHeader header = getHeader(pEntry);
int offset = pEntry.getOffset() + header.getSize();
@@ -333,7 +333,7 @@ public class ICOImageReader extends ImageReaderBase {
}
}
mDescriptors.put(pEntry, descriptor);
descriptors.put(pEntry, descriptor);
}
return descriptor.getImage();
@@ -354,8 +354,8 @@ public class ICOImageReader extends ImageReaderBase {
break;
}
BitmapMask mask = new BitmapMask(pBitmap.mEntry, pBitmap.mHeader);
readBitmapIndexed1(mask.mMask, true);
BitmapMask mask = new BitmapMask(pBitmap.entry, pBitmap.header);
readBitmapIndexed1(mask.mask, true);
pBitmap.setMask(mask);
}
@@ -364,7 +364,7 @@ public class ICOImageReader extends ImageReaderBase {
for (int i = 0; i < colorCount; i++) {
// aRGB (a is "Reserved")
pBitmap.mColors[i] = (imageInput.readInt() & 0xffffff) | 0xff000000;
pBitmap.colors[i] = (imageInput.readInt() & 0xffffff) | 0xff000000;
}
}
@@ -379,7 +379,7 @@ public class ICOImageReader extends ImageReaderBase {
int pos = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth();
for (int x = 0; x < pBitmap.getWidth(); x++) {
pBitmap.mBits[pos++] = ((row[rowPos] & xOrVal) / xOrVal) & 0xFF;
pBitmap.bits[pos++] = ((row[rowPos] & xOrVal) / xOrVal) & 0xFF;
if (xOrVal == 1) {
xOrVal = 0x80;
@@ -423,7 +423,7 @@ public class ICOImageReader extends ImageReaderBase {
rowPos++;
}
pBitmap.mBits[pos++] = value & 0xFF;
pBitmap.bits[pos++] = value & 0xFF;
high4 = !high4;
}
@@ -447,7 +447,7 @@ public class ICOImageReader extends ImageReaderBase {
int pos = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth();
for (int x = 0; x < pBitmap.getWidth(); x++) {
pBitmap.mBits[pos++] = row[rowPos++] & 0xFF;
pBitmap.bits[pos++] = row[rowPos++] & 0xFF;
}
if (abortRequested()) {
@@ -480,7 +480,7 @@ public class ICOImageReader extends ImageReaderBase {
WritableRaster raster = Raster.createPackedRaster(
buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null
);
pBitmap.mImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
for (int y = 0; y < pBitmap.getHeight(); y++) {
int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth();
@@ -516,7 +516,7 @@ public class ICOImageReader extends ImageReaderBase {
WritableRaster raster = Raster.createInterleavedRaster(
buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), 3, bOffs, null
);
pBitmap.mImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
for (int y = 0; y < pBitmap.getHeight(); y++) {
int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth();
@@ -542,7 +542,7 @@ public class ICOImageReader extends ImageReaderBase {
WritableRaster raster = Raster.createPackedRaster(
buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null
);
pBitmap.mImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
for (int y = 0; y < pBitmap.getHeight(); y++) {
int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth();
@@ -559,11 +559,11 @@ public class ICOImageReader extends ImageReaderBase {
private Directory getDirectory() throws IOException {
assertInput();
if (mDirectory == null) {
if (directory == null) {
readFileHeader();
}
return mDirectory;
return directory;
}
private void readFileHeader() throws IOException {
@@ -577,7 +577,7 @@ public class ICOImageReader extends ImageReaderBase {
int imageCount = imageInput.readUnsignedShort();
// Read directory
mDirectory = Directory.read(type, imageCount, imageInput);
directory = Directory.read(type, imageCount, imageInput);
}
final DirectoryEntry getEntry(final int pImageIndex) throws IOException {