Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsType.java Sat May 26 21:19:03 2012 @@ -18,88 +18,83 @@ package org.apache.commons.imaging.forma import java.io.UnsupportedEncodingException; - -public class IcnsType -{ +public class IcnsType { private final int type; private final int width; private final int height; private final int bitsPerPixel; private final boolean hasMask; - public static final IcnsType ICNS_16x12_1BIT_IMAGE_AND_MASK = - new IcnsType("icm#", 16, 12, 1, true); - public static final IcnsType ICNS_16x12_4BIT_IMAGE = - new IcnsType("icm4", 16, 12, 4, false); - public static final IcnsType ICNS_16x12_8BIT_IMAGE = - new IcnsType("icm8", 16, 12, 8, false); - - public static final IcnsType ICNS_16x16_8BIT_MASK = - new IcnsType("s8mk", 16, 16, 8, true); - public static final IcnsType ICNS_16x16_1BIT_IMAGE_AND_MASK = - new IcnsType("ics#", 16, 16, 1, true); - public static final IcnsType ICNS_16x16_4BIT_IMAGE = - new IcnsType("ics4", 16, 16, 4, false); - public static final IcnsType ICNS_16x16_8BIT_IMAGE = - new IcnsType("ics8", 16, 16, 8, false); - public static final IcnsType ICNS_16x16_32BIT_IMAGE = - new IcnsType("is32", 16, 16, 32, false); - - public static final IcnsType ICNS_32x32_8BIT_MASK = - new IcnsType("l8mk", 32, 32, 8, true); - public static final IcnsType ICNS_32x32_1BIT_IMAGE_AND_MASK = - new IcnsType("ICN#", 32, 32, 1, true); - public static final IcnsType ICNS_32x32_4BIT_IMAGE = - new IcnsType("icl4", 32, 32, 4, false); - public static final IcnsType ICNS_32x32_8BIT_IMAGE = - new IcnsType("icl8", 32, 32, 8, false); - public static final IcnsType ICNS_32x32_32BIT_IMAGE = - new IcnsType("il32", 32, 32, 32, false); - - public static final IcnsType ICNS_48x48_8BIT_MASK = - new IcnsType("h8mk", 48, 48, 8, true); - public static final IcnsType ICNS_48x48_1BIT_IMAGE_AND_MASK = - new IcnsType("ich#", 48, 48, 1, true); - public static final IcnsType ICNS_48x48_4BIT_IMAGE = - new IcnsType("ich4", 48, 48, 4, false); - public static final IcnsType ICNS_48x48_8BIT_IMAGE = - new IcnsType("ich8", 48, 48, 8, false); - public static final IcnsType ICNS_48x48_32BIT_IMAGE = - new IcnsType("ih32", 48, 48, 32, false); - - public static final IcnsType ICNS_128x128_8BIT_MASK = - new IcnsType("t8mk", 128, 128, 8, true); - public static final IcnsType ICNS_128x128_32BIT_IMAGE = - new IcnsType("it32", 128, 128, 32, false); - - public static final IcnsType ICNS_256x256_32BIT_ARGB_IMAGE = - new IcnsType("ic08", 256, 256, 32, false); - - public static final IcnsType ICNS_512x512_32BIT_ARGB_IMAGE = - new IcnsType("ic09", 512, 512, 32, false); - - private static final IcnsType[] allImageTypes = - { - ICNS_16x12_1BIT_IMAGE_AND_MASK, ICNS_16x12_4BIT_IMAGE, ICNS_16x12_8BIT_IMAGE, - ICNS_16x16_1BIT_IMAGE_AND_MASK, ICNS_16x16_4BIT_IMAGE, ICNS_16x16_8BIT_IMAGE, ICNS_16x16_32BIT_IMAGE, - ICNS_32x32_1BIT_IMAGE_AND_MASK, ICNS_32x32_4BIT_IMAGE, ICNS_32x32_8BIT_IMAGE, ICNS_32x32_32BIT_IMAGE, - ICNS_48x48_1BIT_IMAGE_AND_MASK, ICNS_48x48_4BIT_IMAGE, ICNS_48x48_8BIT_IMAGE, ICNS_48x48_32BIT_IMAGE, - ICNS_128x128_32BIT_IMAGE, - ICNS_256x256_32BIT_ARGB_IMAGE, - ICNS_512x512_32BIT_ARGB_IMAGE - }; - - private static final IcnsType[] allMaskTypes = - { - ICNS_16x12_1BIT_IMAGE_AND_MASK, - ICNS_16x16_1BIT_IMAGE_AND_MASK, ICNS_16x16_8BIT_MASK, - ICNS_32x32_1BIT_IMAGE_AND_MASK, ICNS_32x32_8BIT_MASK, - ICNS_48x48_1BIT_IMAGE_AND_MASK, ICNS_48x48_8BIT_MASK, - ICNS_128x128_8BIT_MASK - }; + public static final IcnsType ICNS_16x12_1BIT_IMAGE_AND_MASK = new IcnsType( + "icm#", 16, 12, 1, true); + public static final IcnsType ICNS_16x12_4BIT_IMAGE = new IcnsType("icm4", + 16, 12, 4, false); + public static final IcnsType ICNS_16x12_8BIT_IMAGE = new IcnsType("icm8", + 16, 12, 8, false); + + public static final IcnsType ICNS_16x16_8BIT_MASK = new IcnsType("s8mk", + 16, 16, 8, true); + public static final IcnsType ICNS_16x16_1BIT_IMAGE_AND_MASK = new IcnsType( + "ics#", 16, 16, 1, true); + public static final IcnsType ICNS_16x16_4BIT_IMAGE = new IcnsType("ics4", + 16, 16, 4, false); + public static final IcnsType ICNS_16x16_8BIT_IMAGE = new IcnsType("ics8", + 16, 16, 8, false); + public static final IcnsType ICNS_16x16_32BIT_IMAGE = new IcnsType("is32", + 16, 16, 32, false); + + public static final IcnsType ICNS_32x32_8BIT_MASK = new IcnsType("l8mk", + 32, 32, 8, true); + public static final IcnsType ICNS_32x32_1BIT_IMAGE_AND_MASK = new IcnsType( + "ICN#", 32, 32, 1, true); + public static final IcnsType ICNS_32x32_4BIT_IMAGE = new IcnsType("icl4", + 32, 32, 4, false); + public static final IcnsType ICNS_32x32_8BIT_IMAGE = new IcnsType("icl8", + 32, 32, 8, false); + public static final IcnsType ICNS_32x32_32BIT_IMAGE = new IcnsType("il32", + 32, 32, 32, false); + + public static final IcnsType ICNS_48x48_8BIT_MASK = new IcnsType("h8mk", + 48, 48, 8, true); + public static final IcnsType ICNS_48x48_1BIT_IMAGE_AND_MASK = new IcnsType( + "ich#", 48, 48, 1, true); + public static final IcnsType ICNS_48x48_4BIT_IMAGE = new IcnsType("ich4", + 48, 48, 4, false); + public static final IcnsType ICNS_48x48_8BIT_IMAGE = new IcnsType("ich8", + 48, 48, 8, false); + public static final IcnsType ICNS_48x48_32BIT_IMAGE = new IcnsType("ih32", + 48, 48, 32, false); + + public static final IcnsType ICNS_128x128_8BIT_MASK = new IcnsType("t8mk", + 128, 128, 8, true); + public static final IcnsType ICNS_128x128_32BIT_IMAGE = new IcnsType( + "it32", 128, 128, 32, false); + + public static final IcnsType ICNS_256x256_32BIT_ARGB_IMAGE = new IcnsType( + "ic08", 256, 256, 32, false); + + public static final IcnsType ICNS_512x512_32BIT_ARGB_IMAGE = new IcnsType( + "ic09", 512, 512, 32, false); + + private static final IcnsType[] allImageTypes = { + ICNS_16x12_1BIT_IMAGE_AND_MASK, ICNS_16x12_4BIT_IMAGE, + ICNS_16x12_8BIT_IMAGE, ICNS_16x16_1BIT_IMAGE_AND_MASK, + ICNS_16x16_4BIT_IMAGE, ICNS_16x16_8BIT_IMAGE, + ICNS_16x16_32BIT_IMAGE, ICNS_32x32_1BIT_IMAGE_AND_MASK, + ICNS_32x32_4BIT_IMAGE, ICNS_32x32_8BIT_IMAGE, + ICNS_32x32_32BIT_IMAGE, ICNS_48x48_1BIT_IMAGE_AND_MASK, + ICNS_48x48_4BIT_IMAGE, ICNS_48x48_8BIT_IMAGE, + ICNS_48x48_32BIT_IMAGE, ICNS_128x128_32BIT_IMAGE, + ICNS_256x256_32BIT_ARGB_IMAGE, ICNS_512x512_32BIT_ARGB_IMAGE }; + + private static final IcnsType[] allMaskTypes = { + ICNS_16x12_1BIT_IMAGE_AND_MASK, ICNS_16x16_1BIT_IMAGE_AND_MASK, + ICNS_16x16_8BIT_MASK, ICNS_32x32_1BIT_IMAGE_AND_MASK, + ICNS_32x32_8BIT_MASK, ICNS_48x48_1BIT_IMAGE_AND_MASK, + ICNS_48x48_8BIT_MASK, ICNS_128x128_8BIT_MASK }; - private IcnsType(String type, int width, int height, int bitsPerPixel, boolean hasMask) - { + private IcnsType(String type, int width, int height, int bitsPerPixel, + boolean hasMask) { this.type = typeAsInt(type); this.width = width; this.height = height; @@ -107,125 +102,96 @@ public class IcnsType this.hasMask = hasMask; } - public int getType() - { + public int getType() { return type; } - public int getWidth() - { + public int getWidth() { return width; } - public int getHeight() - { + public int getHeight() { return height; } - public int getBitsPerPixel() - { + public int getBitsPerPixel() { return bitsPerPixel; } - public boolean hasMask() - { + public boolean hasMask() { return hasMask; } @Override - public String toString() - { - return getClass().getName() + "[" + - "width=" + width + "," + - "height=" + height + "," + - "bpp=" + bitsPerPixel + "," + - "hasMask=" + hasMask + "]"; + public String toString() { + return getClass().getName() + "[" + "width=" + width + "," + "height=" + + height + "," + "bpp=" + bitsPerPixel + "," + "hasMask=" + + hasMask + "]"; } - public static IcnsType findAnyType(int type) - { - for (int i = 0; i < allImageTypes.length; i++) - { + public static IcnsType findAnyType(int type) { + for (int i = 0; i < allImageTypes.length; i++) { if (allImageTypes[i].getType() == type) return allImageTypes[i]; } - for (int i = 0; i < allMaskTypes.length; i++) - { + for (int i = 0; i < allMaskTypes.length; i++) { if (allMaskTypes[i].getType() == type) return allMaskTypes[i]; } return null; } - public static IcnsType findImageType(int type) - { - for (int i = 0; i < allImageTypes.length; i++) - { + public static IcnsType findImageType(int type) { + for (int i = 0; i < allImageTypes.length; i++) { if (allImageTypes[i].getType() == type) return allImageTypes[i]; } return null; } - public static IcnsType find8BPPMaskType(IcnsType imageType) - { - for (int i = 0; i < allMaskTypes.length; i++) - { - if (allMaskTypes[i].getBitsPerPixel() == 8 && - allMaskTypes[i].getWidth() == imageType.getWidth() && - allMaskTypes[i].getHeight() == imageType.getHeight()) - { + public static IcnsType find8BPPMaskType(IcnsType imageType) { + for (int i = 0; i < allMaskTypes.length; i++) { + if (allMaskTypes[i].getBitsPerPixel() == 8 + && allMaskTypes[i].getWidth() == imageType.getWidth() + && allMaskTypes[i].getHeight() == imageType.getHeight()) { return allMaskTypes[i]; } } return null; } - public static IcnsType find1BPPMaskType(IcnsType imageType) - { - for (int i = 0; i < allMaskTypes.length; i++) - { - if (allMaskTypes[i].getBitsPerPixel() == 1 && - allMaskTypes[i].getWidth() == imageType.getWidth() && - allMaskTypes[i].getHeight() == imageType.getHeight()) - { + public static IcnsType find1BPPMaskType(IcnsType imageType) { + for (int i = 0; i < allMaskTypes.length; i++) { + if (allMaskTypes[i].getBitsPerPixel() == 1 + && allMaskTypes[i].getWidth() == imageType.getWidth() + && allMaskTypes[i].getHeight() == imageType.getHeight()) { return allMaskTypes[i]; } } return null; } - public static int typeAsInt(String type) - { + public static int typeAsInt(String type) { byte[] bytes = null; - try - { + try { bytes = type.getBytes("US-ASCII"); - } - catch (UnsupportedEncodingException cannotHappen) - { + } catch (UnsupportedEncodingException cannotHappen) { } if (bytes.length != 4) throw new IllegalArgumentException("Invalid ICNS type"); - return ((0xff & bytes[0]) << 24) | - ((0xff & bytes[1]) << 16) | - ((0xff & bytes[2]) << 8) | - (0xff & bytes[3]); + return ((0xff & bytes[0]) << 24) | ((0xff & bytes[1]) << 16) + | ((0xff & bytes[2]) << 8) | (0xff & bytes[3]); } - public static String describeType(int type) - { + public static String describeType(int type) { byte[] bytes = new byte[4]; - bytes[0] = (byte)(0xff & (type >> 24)); - bytes[1] = (byte)(0xff & (type >> 16)); - bytes[2] = (byte)(0xff & (type >> 8)); - bytes[3] = (byte)(0xff & type); - try - { + bytes[0] = (byte) (0xff & (type >> 24)); + bytes[1] = (byte) (0xff & (type >> 16)); + bytes[2] = (byte) (0xff & (type >> 8)); + bytes[3] = (byte) (0xff & type); + try { return new String(bytes, "US-ASCII"); - } - catch (UnsupportedEncodingException cannotHappen) - { + } catch (UnsupportedEncodingException cannotHappen) { } return null; } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/Rle24Compression.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/Rle24Compression.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/Rle24Compression.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/Rle24Compression.java Sat May 26 21:19:03 2012 @@ -16,10 +16,8 @@ */ package org.apache.commons.imaging.formats.icns; -class Rle24Compression -{ - public static byte[] decompress(int width, int height, byte[] data) - { +class Rle24Compression { + public static byte[] decompress(int width, int height, byte[] data) { final int pixelCount = width * height; final byte[] result = new byte[4 * pixelCount]; @@ -39,26 +37,21 @@ class Rle24Compression dataPos = 4; // argb, band by band in 3 passes, with no alpha - for (int band = 1; band <= 3; band++) - { + for (int band = 1; band <= 3; band++) { int remaining = pixelCount; int resultPos = 0; - while (remaining > 0) - { - if ((data[dataPos] & 0x80) != 0) - { + while (remaining > 0) { + if ((data[dataPos] & 0x80) != 0) { int count = (0xff & data[dataPos]) - 125; for (int i = 0; i < count; i++) - result[band + 4*(resultPos++)] = data[dataPos + 1]; + result[band + 4 * (resultPos++)] = data[dataPos + 1]; dataPos += 2; remaining -= count; - } - else - { + } else { int count = (0xff & data[dataPos]) + 1; dataPos++; for (int i = 0; i < count; i++) - result[band + 4*(resultPos++)] = data[dataPos++]; + result[band + 4 * (resultPos++)] = data[dataPos++]; remaining -= count; } } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/ico/IcoImageParser.java Sat May 26 21:19:03 2012 @@ -44,98 +44,81 @@ import org.apache.commons.imaging.palett import org.apache.commons.imaging.palette.SimplePalette; import org.apache.commons.imaging.util.Debug; -public class IcoImageParser extends ImageParser -{ +public class IcoImageParser extends ImageParser { - public IcoImageParser() - { + public IcoImageParser() { super.setByteOrder(BYTE_ORDER_LSB); } @Override - public String getName() - { + public String getName() { return "ico-Custom"; } @Override - public String getDefaultExtension() - { + public String getDefaultExtension() { return DEFAULT_EXTENSION; } private static final String DEFAULT_EXTENSION = ".ico"; - private static final String ACCEPTED_EXTENSIONS[] = { - ".ico", ".cur", - }; + private static final String ACCEPTED_EXTENSIONS[] = { ".ico", ".cur", }; @Override - protected String[] getAcceptedExtensions() - { + protected String[] getAcceptedExtensions() { return ACCEPTED_EXTENSIONS; } @Override - protected ImageFormat[] getAcceptedTypes() - { - return new ImageFormat[]{ - ImageFormat.IMAGE_FORMAT_ICO, // + protected ImageFormat[] getAcceptedTypes() { + return new ImageFormat[] { ImageFormat.IMAGE_FORMAT_ICO, // }; } @Override - public boolean embedICCProfile(File src, File dst, byte profile[]) - { + public boolean embedICCProfile(File src, File dst, byte profile[]) { return false; } @Override public IImageMetadata getMetadata(ByteSource byteSource, Map params) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { return null; } @Override public ImageInfo getImageInfo(ByteSource byteSource, Map params) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { return null; } @Override - public Dimension getImageSize(ByteSource byteSource, - Map params) - throws ImageReadException, IOException - { + public Dimension getImageSize(ByteSource byteSource, Map params) + throws ImageReadException, IOException { return null; } @Override - public byte[] getICCProfileBytes(ByteSource byteSource, - Map params) - throws ImageReadException, IOException - { + public byte[] getICCProfileBytes(ByteSource byteSource, Map params) + throws ImageReadException, IOException { return null; } - private static class FileHeader - { + private static class FileHeader { public final int reserved; // Reserved (2 bytes), always 0 - public final int iconType; // IconType (2 bytes), if the image is an icon it?s 1, for cursors the value is 2. - public final int iconCount; //IconCount (2 bytes), number of icons in this file. + public final int iconType; // IconType (2 bytes), if the image is an + // icon it?s 1, for cursors the value is 2. + public final int iconCount; // IconCount (2 bytes), number of icons in + // this file. public FileHeader(final int reserved, final int iconType, - final int iconCount) - { + final int iconCount) { this.reserved = reserved; this.iconType = iconType; this.iconCount = iconCount; } - public void dump(PrintWriter pw) - { + public void dump(PrintWriter pw) { pw.println("FileHeader"); pw.println("Reserved: " + reserved); pw.println("IconType: " + iconType); @@ -145,23 +128,23 @@ public class IcoImageParser extends Imag } private FileHeader readFileHeader(InputStream is) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { int Reserved = read2Bytes("Reserved", is, "Not a Valid ICO File"); int IconType = read2Bytes("IconType", is, "Not a Valid ICO File"); int IconCount = read2Bytes("IconCount", is, "Not a Valid ICO File"); if (Reserved != 0) - throw new ImageReadException("Not a Valid ICO File: reserved is " + Reserved); + throw new ImageReadException("Not a Valid ICO File: reserved is " + + Reserved); if (IconType != 1 && IconType != 2) - throw new ImageReadException("Not a Valid ICO File: icon type is " + IconType); + throw new ImageReadException("Not a Valid ICO File: icon type is " + + IconType); return new FileHeader(Reserved, IconType, IconCount); } - private static class IconInfo - { + private static class IconInfo { public final byte Width; public final byte Height; public final byte ColorCount; @@ -173,8 +156,7 @@ public class IcoImageParser extends Imag public IconInfo(final byte width, final byte height, final byte colorCount, final byte reserved, final int planes, - final int bitCount, final int imageSize, final int imageOffset) - { + final int bitCount, final int imageSize, final int imageOffset) { Width = width; Height = height; ColorCount = colorCount; @@ -185,8 +167,7 @@ public class IcoImageParser extends Imag ImageOffset = imageOffset; } - public void dump(PrintWriter pw) - { + public void dump(PrintWriter pw) { pw.println("IconInfo"); pw.println("Width: " + Width); pw.println("Height: " + Height); @@ -200,23 +181,107 @@ public class IcoImageParser extends Imag } private IconInfo readIconInfo(InputStream is) throws ImageReadException, - IOException - { - byte Width = readByte("Width", is, "Not a Valid ICO File"); // Width (1 byte), Width of Icon (1 to 255) - byte Height = readByte("Height", is, "Not a Valid ICO File"); // Height (1 byte), Height of Icon (1 to 255) - byte ColorCount = readByte("ColorCount", is, "Not a Valid ICO File"); // ColorCount (1 byte), Number of colors, either 0 for 24 bit or higher, 2 for monochrome or 16 for 16 color images. - byte Reserved = readByte("Reserved", is, "Not a Valid ICO File"); // Reserved (1 byte), Not used (always 0) - int Planes = read2Bytes("Planes", is, "Not a Valid ICO File"); // Planes (2 bytes), always 1 - int BitCount = read2Bytes("BitCount", is, "Not a Valid ICO File"); // BitCount (2 bytes), number of bits per pixel (1 for monochrome, 4 for 16 colors, 8 for 256 colors, 24 for true colors, 32 for true colors + alpha channel) - int ImageSize = read4Bytes("ImageSize", is, "Not a Valid ICO File"); // ImageSize (4 bytes), Length of resource in bytes - int ImageOffset = read4Bytes("ImageOffset", is, "Not a Valid ICO File"); // ImageOffset (4 bytes), start of the image in the file. + IOException { + byte Width = readByte("Width", is, "Not a Valid ICO File"); // Width (1 + // byte), + // Width of + // Icon (1 + // to 255) + byte Height = readByte("Height", is, "Not a Valid ICO File"); // Height + // (1 + // byte), + // Height + // of Icon + // (1 to + // 255) + byte ColorCount = readByte("ColorCount", is, "Not a Valid ICO File"); // ColorCount + // (1 + // byte), + // Number + // of + // colors, + // either + // 0 + // for + // 24 + // bit + // or + // higher, + // 2 + // for + // monochrome + // or + // 16 + // for + // 16 + // color + // images. + byte Reserved = readByte("Reserved", is, "Not a Valid ICO File"); // Reserved + // (1 + // byte), + // Not + // used + // (always + // 0) + int Planes = read2Bytes("Planes", is, "Not a Valid ICO File"); // Planes + // (2 + // bytes), + // always + // 1 + int BitCount = read2Bytes("BitCount", is, "Not a Valid ICO File"); // BitCount + // (2 + // bytes), + // number + // of + // bits + // per + // pixel + // (1 + // for + // monochrome, + // 4 + // for + // 16 + // colors, + // 8 + // for + // 256 + // colors, + // 24 + // for + // true + // colors, + // 32 + // for + // true + // colors + // + + // alpha + // channel) + int ImageSize = read4Bytes("ImageSize", is, "Not a Valid ICO File"); // ImageSize + // (4 + // bytes), + // Length + // of + // resource + // in + // bytes + int ImageOffset = read4Bytes("ImageOffset", is, "Not a Valid ICO File"); // ImageOffset + // (4 + // bytes), + // start + // of + // the + // image + // in + // the + // file. return new IconInfo(Width, Height, ColorCount, Reserved, Planes, BitCount, ImageSize, ImageOffset); } - private static class BitmapHeader - { + private static class BitmapHeader { public final int Size; public final int Width; public final int Height; @@ -233,8 +298,7 @@ public class IcoImageParser extends Imag final int planes, final int bitCount, final int compression, final int sizeImage, final int pelsPerMeter, final int pelsPerMeter2, final int colorsUsed, - final int colorsImportant) - { + final int colorsImportant) { Size = size; Width = width; Height = height; @@ -248,8 +312,7 @@ public class IcoImageParser extends Imag ColorsImportant = colorsImportant; } - public void dump(PrintWriter pw) - { + public void dump(PrintWriter pw) { pw.println("BitmapHeader"); pw.println("Size: " + Size); @@ -266,101 +329,149 @@ public class IcoImageParser extends Imag } } - private static abstract class IconData - { + private static abstract class IconData { public final IconInfo iconInfo; - public IconData(final IconInfo iconInfo) - { + public IconData(final IconInfo iconInfo) { this.iconInfo = iconInfo; } - public void dump(PrintWriter pw) - { + public void dump(PrintWriter pw) { iconInfo.dump(pw); pw.println(); dumpSubclass(pw); } protected abstract void dumpSubclass(PrintWriter pw); - public abstract BufferedImage readBufferedImage() throws ImageReadException; + + public abstract BufferedImage readBufferedImage() + throws ImageReadException; } - private static class BitmapIconData extends IconData - { + private static class BitmapIconData extends IconData { public final BitmapHeader header; public final BufferedImage bufferedImage; - public BitmapIconData(final IconInfo iconInfo, final BitmapHeader header, - final BufferedImage bufferedImage) - { + public BitmapIconData(final IconInfo iconInfo, + final BitmapHeader header, final BufferedImage bufferedImage) { super(iconInfo); this.header = header; this.bufferedImage = bufferedImage; } @Override - public BufferedImage readBufferedImage() throws ImageReadException - { + public BufferedImage readBufferedImage() throws ImageReadException { return bufferedImage; } @Override - protected void dumpSubclass(PrintWriter pw) - { + protected void dumpSubclass(PrintWriter pw) { pw.println("BitmapIconData"); header.dump(pw); pw.println(); } } - private static class PNGIconData extends IconData - { + private static class PNGIconData extends IconData { public final BufferedImage bufferedImage; - public PNGIconData(final IconInfo iconInfo, final BufferedImage bufferedImage) - { + public PNGIconData(final IconInfo iconInfo, + final BufferedImage bufferedImage) { super(iconInfo); this.bufferedImage = bufferedImage; } @Override - public BufferedImage readBufferedImage() - { + public BufferedImage readBufferedImage() { return bufferedImage; } @Override - protected void dumpSubclass(PrintWriter pw) - { + protected void dumpSubclass(PrintWriter pw) { pw.println("PNGIconData"); pw.println(); } } - private IconData readBitmapIconData(byte[] iconData, IconInfo fIconInfo) throws ImageReadException, IOException - { + private IconData readBitmapIconData(byte[] iconData, IconInfo fIconInfo) + throws ImageReadException, IOException { ByteArrayInputStream is = new ByteArrayInputStream(iconData); - int Size = read4Bytes("Size", is, "Not a Valid ICO File"); // Size (4 bytes), size of this structure (always 40) - int Width = read4Bytes("Width", is, "Not a Valid ICO File"); // Width (4 bytes), width of the image (same as iconinfo.width) - int Height = read4Bytes("Height", is, "Not a Valid ICO File"); // Height (4 bytes), scanlines in the color map + transparent map (iconinfo.height * 2) - int Planes = read2Bytes("Planes", is, "Not a Valid ICO File"); // Planes (2 bytes), always 1 - int BitCount = read2Bytes("BitCount", is, "Not a Valid ICO File"); // BitCount (2 bytes), 1,4,8,16,24,32 (see iconinfo for details) - int Compression = read4Bytes("Compression", is, "Not a Valid ICO File"); // Compression (4 bytes), we don?t use this (0) - int SizeImage = read4Bytes("SizeImage", is, "Not a Valid ICO File"); // SizeImage (4 bytes), we don?t use this (0) + int Size = read4Bytes("Size", is, "Not a Valid ICO File"); // Size (4 + // bytes), + // size of + // this + // structure + // (always + // 40) + int Width = read4Bytes("Width", is, "Not a Valid ICO File"); // Width (4 + // bytes), + // width of + // the + // image + // (same as + // iconinfo.width) + int Height = read4Bytes("Height", is, "Not a Valid ICO File"); // Height + // (4 + // bytes), + // scanlines + // in the + // color + // map + + // transparent + // map + // (iconinfo.height + // * 2) + int Planes = read2Bytes("Planes", is, "Not a Valid ICO File"); // Planes + // (2 + // bytes), + // always + // 1 + int BitCount = read2Bytes("BitCount", is, "Not a Valid ICO File"); // BitCount + // (2 + // bytes), + // 1,4,8,16,24,32 + // (see + // iconinfo + // for + // details) + int Compression = read4Bytes("Compression", is, "Not a Valid ICO File"); // Compression + // (4 + // bytes), + // we + // don?t + // use + // this + // (0) + int SizeImage = read4Bytes("SizeImage", is, "Not a Valid ICO File"); // SizeImage + // (4 + // bytes), + // we + // don?t + // use + // this + // (0) int XPelsPerMeter = read4Bytes("XPelsPerMeter", is, - "Not a Valid ICO File"); // XPelsPerMeter (4 bytes), we don?t use this (0) + "Not a Valid ICO File"); // XPelsPerMeter (4 bytes), we don?t + // use this (0) int YPelsPerMeter = read4Bytes("YPelsPerMeter", is, - "Not a Valid ICO File"); // YPelsPerMeter (4 bytes), we don?t use this (0) - int ColorsUsed = read4Bytes("ColorsUsed", is, "Not a Valid ICO File"); // ColorsUsed (4 bytes), we don?t use this (0) + "Not a Valid ICO File"); // YPelsPerMeter (4 bytes), we don?t + // use this (0) + int ColorsUsed = read4Bytes("ColorsUsed", is, "Not a Valid ICO File"); // ColorsUsed + // (4 + // bytes), + // we + // don?t + // use + // this + // (0) int ColorsImportant = read4Bytes("ColorsImportant", is, - "Not a Valid ICO File"); // ColorsImportant (4 bytes), we don?t use this (0) + "Not a Valid ICO File"); // ColorsImportant (4 bytes), we don?t + // use this (0) int RedMask = 0; int GreenMask = 0; int BlueMask = 0; int AlphaMask = 0; - if (Compression == 3) - { + if (Compression == 3) { RedMask = read4Bytes("RedMask", is, "Not a Valid ICO File"); GreenMask = read4Bytes("GreenMask", is, "Not a Valid ICO File"); BlueMask = read4Bytes("BlueMask", is, "Not a Valid ICO File"); @@ -368,12 +479,13 @@ public class IcoImageParser extends Imag byte[] RestOfFile = readByteArray("RestOfFile", is.available(), is); if (Size != 40) - throw new ImageReadException("Not a Valid ICO File: Wrong bitmap header size " + Size); + throw new ImageReadException( + "Not a Valid ICO File: Wrong bitmap header size " + Size); if (Planes != 1) - throw new ImageReadException("Not a Valid ICO File: Planes can't be " + Planes); + throw new ImageReadException( + "Not a Valid ICO File: Planes can't be " + Planes); - if (Compression == 0 && BitCount == 32) - { + if (Compression == 0 && BitCount == 32) { // 32 BPP RGB icons need an alpha channel, but BMP files don't have // one unless BI_BITFIELDS is used... Compression = 3; @@ -387,8 +499,8 @@ public class IcoImageParser extends Imag BitCount, Compression, SizeImage, XPelsPerMeter, YPelsPerMeter, ColorsUsed, ColorsImportant); - int bitmapPixelsOffset = 14 + 56 + - 4 * ((ColorsUsed == 0 && BitCount <= 8) ? (1 << BitCount) : ColorsUsed); + int bitmapPixelsOffset = 14 + 56 + 4 * ((ColorsUsed == 0 && BitCount <= 8) ? (1 << BitCount) + : ColorsUsed); int bitmapSize = 14 + 56 + RestOfFile.length; ByteArrayOutputStream baos = new ByteArrayOutputStream(bitmapSize); @@ -419,38 +531,38 @@ public class IcoImageParser extends Imag bos.write(RestOfFile); bos.flush(); - ByteArrayInputStream bmpInputStream = new ByteArrayInputStream(baos.toByteArray()); - BufferedImage bmpImage = new BmpImageParser().getBufferedImage(bmpInputStream, null); - - // Transparency map is optional with 32 BPP icons, because they already have - // an alpha channel, and Windows only uses the transparency map when it has to - // display the icon on a < 32 BPP screen. But it's still used instead of alpha + ByteArrayInputStream bmpInputStream = new ByteArrayInputStream( + baos.toByteArray()); + BufferedImage bmpImage = new BmpImageParser().getBufferedImage( + bmpInputStream, null); + + // Transparency map is optional with 32 BPP icons, because they already + // have + // an alpha channel, and Windows only uses the transparency map when it + // has to + // display the icon on a < 32 BPP screen. But it's still used instead of + // alpha // if the image would be completely transparent with alpha... int t_scanline_size = (Width + 7) / 8; if ((t_scanline_size % 4) != 0) - t_scanline_size += 4 - (t_scanline_size % 4); // pad scanline to 4 byte size. - int tcolor_map_size_bytes = t_scanline_size * (Height/2); + t_scanline_size += 4 - (t_scanline_size % 4); // pad scanline to 4 + // byte size. + int tcolor_map_size_bytes = t_scanline_size * (Height / 2); byte[] transparency_map = null; - try - { + try { transparency_map = this.readByteArray("transparency_map", - tcolor_map_size_bytes, bmpInputStream, "Not a Valid ICO File"); - } - catch (IOException ioEx) - { + tcolor_map_size_bytes, bmpInputStream, + "Not a Valid ICO File"); + } catch (IOException ioEx) { if (BitCount != 32) - throw ioEx; + throw ioEx; } boolean allAlphasZero = true; - if (BitCount == 32) - { - for (int y = 0; allAlphasZero && y < bmpImage.getHeight(); y++) - { - for (int x = 0; x < bmpImage.getWidth(); x++) - { - if ((bmpImage.getRGB(x, y) & 0xff000000) != 0) - { + if (BitCount == 32) { + for (int y = 0; allAlphasZero && y < bmpImage.getHeight(); y++) { + for (int x = 0; x < bmpImage.getWidth(); x++) { + if ((bmpImage.getRGB(x, y) & 0xff000000) != 0) { allAlphasZero = false; break; } @@ -458,55 +570,45 @@ public class IcoImageParser extends Imag } } BufferedImage resultImage; - if (allAlphasZero) - { - resultImage = new BufferedImage(bmpImage.getWidth(), bmpImage.getHeight(), - BufferedImage.TYPE_INT_ARGB); - for (int y = 0; y < resultImage.getHeight(); y++) - { - for (int x = 0; x < resultImage.getWidth(); x++) - { + if (allAlphasZero) { + resultImage = new BufferedImage(bmpImage.getWidth(), + bmpImage.getHeight(), BufferedImage.TYPE_INT_ARGB); + for (int y = 0; y < resultImage.getHeight(); y++) { + for (int x = 0; x < resultImage.getWidth(); x++) { int alpha = 0xff; - if (transparency_map != null) - { + if (transparency_map != null) { int alpha_byte = 0xff & transparency_map[t_scanline_size * (bmpImage.getHeight() - y - 1) + (x / 8)]; alpha = 0x01 & (alpha_byte >> (7 - (x % 8))); alpha = (alpha == 0) ? 0xff : 0x00; } - resultImage.setRGB(x, y, (alpha << 24) | (0xffffff & bmpImage.getRGB(x, y))); + resultImage.setRGB(x, y, (alpha << 24) + | (0xffffff & bmpImage.getRGB(x, y))); } } - } - else + } else resultImage = bmpImage; return new BitmapIconData(fIconInfo, header, resultImage); } private IconData readIconData(byte[] iconData, IconInfo fIconInfo) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { ImageFormat imageFormat = Imaging.guessFormat(iconData); - if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_PNG)) - { + if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_PNG)) { BufferedImage bufferedImage = Imaging.getBufferedImage(iconData); PNGIconData pngIconData = new PNGIconData(fIconInfo, bufferedImage); return pngIconData; - } - else - { + } else { return readBitmapIconData(iconData, fIconInfo); } } - private static class ImageContents - { + private static class ImageContents { public final FileHeader fileHeader; public final IconData iconDatas[]; public ImageContents(final FileHeader fileHeader, - final IconData[] iconDatas) - { + final IconData[] iconDatas) { super(); this.fileHeader = fileHeader; this.iconDatas = iconDatas; @@ -514,40 +616,31 @@ public class IcoImageParser extends Imag } private ImageContents readImage(ByteSource byteSource) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { InputStream is = null; - try - { + try { is = byteSource.getInputStream(); FileHeader fileHeader = readFileHeader(is); IconInfo fIconInfos[] = new IconInfo[fileHeader.iconCount]; - for (int i = 0; i < fileHeader.iconCount; i++) - { + for (int i = 0; i < fileHeader.iconCount; i++) { fIconInfos[i] = readIconInfo(is); } IconData fIconDatas[] = new IconData[fileHeader.iconCount]; - for (int i = 0; i < fileHeader.iconCount; i++) - { - byte[] iconData = byteSource.getBlock(fIconInfos[i].ImageOffset, - fIconInfos[i].ImageSize); + for (int i = 0; i < fileHeader.iconCount; i++) { + byte[] iconData = byteSource.getBlock( + fIconInfos[i].ImageOffset, fIconInfos[i].ImageSize); fIconDatas[i] = readIconData(iconData, fIconInfos[i]); } return new ImageContents(fileHeader, fIconDatas); - } - finally - { - try - { + } finally { + try { if (is != null) { is.close(); } - } - catch (Exception e) - { + } catch (Exception e) { Debug.debug(e); } @@ -556,8 +649,7 @@ public class IcoImageParser extends Imag @Override public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { ImageContents contents = readImage(byteSource); contents.fileHeader.dump(pw); for (int i = 0; i < contents.iconDatas.length; i++) @@ -567,8 +659,7 @@ public class IcoImageParser extends Imag @Override public final BufferedImage getBufferedImage(ByteSource byteSource, - Map params) throws ImageReadException, IOException - { + Map params) throws ImageReadException, IOException { ImageContents contents = readImage(byteSource); FileHeader fileHeader = contents.fileHeader; if (fileHeader.iconCount > 0) @@ -579,14 +670,12 @@ public class IcoImageParser extends Imag @Override public List getAllBufferedImages(ByteSource byteSource) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { List result = new ArrayList(); ImageContents contents = readImage(byteSource); FileHeader fileHeader = contents.fileHeader; - for (int i = 0; i < fileHeader.iconCount; i++) - { + for (int i = 0; i < fileHeader.iconCount; i++) { IconData iconData = contents.iconDatas[i]; BufferedImage image = iconData.readBufferedImage(); @@ -597,34 +686,33 @@ public class IcoImageParser extends Imag return result; } - // public boolean extractImages(ByteSource byteSource, File dst_dir, - // String dst_root, ImageParser encoder) throws ImageReadException, - // IOException, ImageWriteException - // { - // ImageContents contents = readImage(byteSource); + // public boolean extractImages(ByteSource byteSource, File dst_dir, + // String dst_root, ImageParser encoder) throws ImageReadException, + // IOException, ImageWriteException + // { + // ImageContents contents = readImage(byteSource); // - // FileHeader fileHeader = contents.fileHeader; - // for (int i = 0; i < fileHeader.iconCount; i++) - // { - // IconData iconData = contents.iconDatas[i]; + // FileHeader fileHeader = contents.fileHeader; + // for (int i = 0; i < fileHeader.iconCount; i++) + // { + // IconData iconData = contents.iconDatas[i]; // - // BufferedImage image = readBufferedImage(iconData); + // BufferedImage image = readBufferedImage(iconData); // - // int size = Math.max(iconData.iconInfo.Width, - // iconData.iconInfo.Height); - // File file = new File(dst_dir, dst_root + "_" + size + "_" - // + iconData.iconInfo.BitCount - // + encoder.getDefaultExtension()); - // encoder.writeImage(image, new FileOutputStream(file), null); - // } + // int size = Math.max(iconData.iconInfo.Width, + // iconData.iconInfo.Height); + // File file = new File(dst_dir, dst_root + "_" + size + "_" + // + iconData.iconInfo.BitCount + // + encoder.getDefaultExtension()); + // encoder.writeImage(image, new FileOutputStream(file), null); + // } // - // return true; - // } + // return true; + // } @Override public void writeImage(BufferedImage src, OutputStream os, Map params) - throws ImageWriteException, IOException - { + throws ImageWriteException, IOException { // make copy of params; we'll clear keys as we consume them. params = (params == null) ? new HashMap() : new HashMap(params); @@ -632,24 +720,22 @@ public class IcoImageParser extends Imag if (params.containsKey(PARAM_KEY_FORMAT)) params.remove(PARAM_KEY_FORMAT); - if (params.size() > 0) - { + if (params.size() > 0) { Object firstKey = params.keySet().iterator().next(); throw new ImageWriteException("Unknown parameter: " + firstKey); } final PaletteFactory paletteFactory = new PaletteFactory(); - final SimplePalette palette = paletteFactory.makePaletteSimple(src, 256); + final SimplePalette palette = paletteFactory + .makePaletteSimple(src, 256); final int bitCount; final boolean hasTransparency = paletteFactory.hasTransparency(src); - if (palette == null) - { + if (palette == null) { if (hasTransparency) bitCount = 32; else bitCount = 24; - } - else if (palette.length() <= 2) + } else if (palette.length() <= 2) bitCount = 1; else if (palette.length() <= 16) bitCount = 4; @@ -660,13 +746,15 @@ public class IcoImageParser extends Imag int scanline_size = (bitCount * src.getWidth() + 7) / 8; if ((scanline_size % 4) != 0) - scanline_size += 4 - (scanline_size % 4); // pad scanline to 4 byte size. + scanline_size += 4 - (scanline_size % 4); // pad scanline to 4 byte + // size. int t_scanline_size = (src.getWidth() + 7) / 8; if ((t_scanline_size % 4) != 0) - t_scanline_size += 4 - (t_scanline_size % 4); // pad scanline to 4 byte size. - int imageSize = 40 + 4 * (bitCount <= 8 ? (1 << bitCount) : 0) + - src.getHeight() * scanline_size + - src.getHeight() * t_scanline_size; + t_scanline_size += 4 - (t_scanline_size % 4); // pad scanline to 4 + // byte size. + int imageSize = 40 + 4 * (bitCount <= 8 ? (1 << bitCount) : 0) + + src.getHeight() * scanline_size + src.getHeight() + * t_scanline_size; // ICONDIR bos.write2Bytes(0); // reserved @@ -676,8 +764,7 @@ public class IcoImageParser extends Imag // ICONDIRENTRY int iconDirEntryWidth = src.getWidth(); int iconDirEntryHeight = src.getHeight(); - if (iconDirEntryWidth > 255 || iconDirEntryHeight > 255) - { + if (iconDirEntryWidth > 255 || iconDirEntryHeight > 255) { iconDirEntryWidth = 0; iconDirEntryHeight = 0; } @@ -703,20 +790,15 @@ public class IcoImageParser extends Imag bos.write4Bytes(0); // colors used, 0 = (1 << bitCount) (ignored) bos.write4Bytes(0); // colors important - if (palette != null) - { - for (int i = 0; i < (1 << bitCount); i++) - { - if (i < palette.length()) - { + if (palette != null) { + for (int i = 0; i < (1 << bitCount); i++) { + if (i < palette.length()) { int argb = palette.getEntry(i); bos.write(0xff & argb); bos.write(0xff & (argb >> 8)); bos.write(0xff & (argb >> 16)); bos.write(0); - } - else - { + } else { bos.write(0); bos.write(0); bos.write(0); @@ -728,39 +810,29 @@ public class IcoImageParser extends Imag int bit_cache = 0; int bits_in_cache = 0; int row_padding = scanline_size - (bitCount * src.getWidth() + 7) / 8; - for (int y = src.getHeight() - 1; y >= 0; y--) - { - for (int x = 0; x < src.getWidth(); x++) - { + for (int y = src.getHeight() - 1; y >= 0; y--) { + for (int x = 0; x < src.getWidth(); x++) { int argb = src.getRGB(x, y); - if (bitCount < 8) - { + if (bitCount < 8) { int rgb = 0xffffff & argb; int index = palette.getPaletteIndex(rgb); bit_cache <<= bitCount; bit_cache |= index; bits_in_cache += bitCount; - if (bits_in_cache >= 8) - { + if (bits_in_cache >= 8) { bos.write(0xff & bit_cache); bit_cache = 0; bits_in_cache = 0; } - } - else if (bitCount == 8) - { + } else if (bitCount == 8) { int rgb = 0xffffff & argb; int index = palette.getPaletteIndex(rgb); bos.write(0xff & index); - } - else if (bitCount == 24) - { + } else if (bitCount == 24) { bos.write(0xff & argb); bos.write(0xff & (argb >> 8)); bos.write(0xff & (argb >> 16)); - } - else if (bitCount == 32) - { + } else if (bitCount == 32) { bos.write(0xff & argb); bos.write(0xff & (argb >> 8)); bos.write(0xff & (argb >> 16)); @@ -768,8 +840,7 @@ public class IcoImageParser extends Imag } } - if (bits_in_cache > 0) - { + if (bits_in_cache > 0) { bit_cache <<= (8 - bits_in_cache); bos.write(0xff & bit_cache); bit_cache = 0; @@ -781,26 +852,22 @@ public class IcoImageParser extends Imag } int t_row_padding = t_scanline_size - (src.getWidth() + 7) / 8; - for (int y = src.getHeight() - 1; y >= 0; y--) - { - for (int x = 0; x < src.getWidth(); x++) - { + for (int y = src.getHeight() - 1; y >= 0; y--) { + for (int x = 0; x < src.getWidth(); x++) { int argb = src.getRGB(x, y); int alpha = 0xff & (argb >> 24); bit_cache <<= 1; if (alpha == 0) bit_cache |= 1; bits_in_cache++; - if (bits_in_cache >= 8) - { + if (bits_in_cache >= 8) { bos.write(0xff & bit_cache); bit_cache = 0; bits_in_cache = 0; } } - if (bits_in_cache > 0) - { + if (bits_in_cache > 0) { bit_cache <<= (8 - bits_in_cache); bos.write(0xff & bit_cache); bit_cache = 0; @@ -815,12 +882,12 @@ public class IcoImageParser extends Imag /** * Extracts embedded XML metadata as XML string. *

- * + * * @param byteSource * File containing image data. * @param params * Map of optional parameters, defined in SanselanConstants. - * @return Xmp Xml as String, if present. Otherwise, returns null. + * @return Xmp Xml as String, if present. Otherwise, returns null. */ @Override public String getXmpXml(ByteSource byteSource, Map params) Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/Block.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/Block.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/Block.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/Block.java Sat May 26 21:19:03 2012 @@ -15,15 +15,13 @@ package org.apache.commons.imaging.formats.jpeg; -public final class Block -{ +public final class Block { public final int[] samples; public final int width; public final int height; - public Block(int width, int height) - { - samples = new int[width*height]; + public Block(int width, int height) { + samples = new int[width * height]; this.width = width; this.height = height; } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegConstants.java Sat May 26 21:19:03 2012 @@ -22,66 +22,67 @@ import java.util.List; import org.apache.commons.imaging.common.BinaryConstant; -public interface JpegConstants -{ +public interface JpegConstants { public static final int MAX_SEGMENT_SIZE = 0xffff; - public static final BinaryConstant JFIF0_SIGNATURE = new BinaryConstant(new byte[] { - 0x4a, // J - 0x46, // F - 0x49, // I - 0x46, // F - 0x0, // - }); - public static final BinaryConstant JFIF0_SIGNATURE_ALTERNATIVE = new BinaryConstant(new byte[] { - 0x4a, // J - 0x46, // F - 0x49, // I - 0x46, // F - 0x20, // - }); - - public static final BinaryConstant EXIF_IDENTIFIER_CODE = new BinaryConstant(new byte[] { - 0x45, // E - 0x78, // x - 0x69, // i - 0x66, // f - }); - - public static final BinaryConstant XMP_IDENTIFIER = new BinaryConstant(new byte[] { - 0x68, // h - 0x74, // t - 0x74, // t - 0x70, // p - 0x3A, // : - 0x2F, // / - 0x2F, // / - 0x6E, // n - 0x73, // s - 0x2E, // . - 0x61, // a - 0x64, // d - 0x6F, // o - 0x62, // b - 0x65, // e - 0x2E, // . - 0x63, // c - 0x6F, // o - 0x6D, // m - 0x2F, // / - 0x78, // x - 0x61, // a - 0x70, // p - 0x2F, // / - 0x31, // 1 - 0x2E, // . - 0x30, // 0 - 0x2F, // / - 0, // 0-terminated us-ascii string. - }); - - public static final BinaryConstant SOI = new BinaryConstant(new byte[] { (byte) 0xff, (byte) 0xd8 }); - public static final BinaryConstant EOI = new BinaryConstant(new byte[] { (byte) 0xff, (byte) 0xd9 }); + public static final BinaryConstant JFIF0_SIGNATURE = new BinaryConstant( + new byte[] { 0x4a, // J + 0x46, // F + 0x49, // I + 0x46, // F + 0x0, // + }); + public static final BinaryConstant JFIF0_SIGNATURE_ALTERNATIVE = new BinaryConstant( + new byte[] { 0x4a, // J + 0x46, // F + 0x49, // I + 0x46, // F + 0x20, // + }); + + public static final BinaryConstant EXIF_IDENTIFIER_CODE = new BinaryConstant( + new byte[] { 0x45, // E + 0x78, // x + 0x69, // i + 0x66, // f + }); + + public static final BinaryConstant XMP_IDENTIFIER = new BinaryConstant( + new byte[] { 0x68, // h + 0x74, // t + 0x74, // t + 0x70, // p + 0x3A, // : + 0x2F, // / + 0x2F, // / + 0x6E, // n + 0x73, // s + 0x2E, // . + 0x61, // a + 0x64, // d + 0x6F, // o + 0x62, // b + 0x65, // e + 0x2E, // . + 0x63, // c + 0x6F, // o + 0x6D, // m + 0x2F, // / + 0x78, // x + 0x61, // a + 0x70, // p + 0x2F, // / + 0x31, // 1 + 0x2E, // . + 0x30, // 0 + 0x2F, // / + 0, // 0-terminated us-ascii string. + }); + + public static final BinaryConstant SOI = new BinaryConstant(new byte[] { + (byte) 0xff, (byte) 0xd8 }); + public static final BinaryConstant EOI = new BinaryConstant(new byte[] { + (byte) 0xff, (byte) 0xd9 }); public static final int JPEG_APP0 = 0xE0; public static final int JPEG_APP0_Marker = (0xff00) | (JPEG_APP0); @@ -115,41 +116,39 @@ public interface JpegConstants public static final int DNLMarker = 0xFFdc; public static final int COMMarker = 0xFFfe; - public static final List MARKERS = Collections.unmodifiableList(Arrays.asList( - JPEG_APP0, JPEG_APP0_Marker, JPEG_APP1_Marker, JPEG_APP2_Marker, - JPEG_APP13_Marker, JPEG_APP14_Marker, JPEG_APP15_Marker, - JFIFMarker, SOF0Marker, SOF1Marker, SOF2Marker, SOF3Marker, - DHTMarker, SOF5Marker, SOF6Marker, SOF7Marker, SOF8Marker, - SOF9Marker, SOF10Marker, SOF11Marker, DACMarker, SOF13Marker, - SOF14Marker, SOF15Marker, EOIMarker, SOS_Marker, - DQTMarker, DNLMarker, COMMarker )); - - public static final BinaryConstant icc_profile_label = new BinaryConstant(new byte[] { - 0x49, 0x43, 0x43, 0x5F, - 0x50, 0x52, 0x4F, 0x46, - 0x49, 0x4C, 0x45, 0x0 - }); - - public static final BinaryConstant PHOTOSHOP_IDENTIFICATION_STRING = new BinaryConstant(new byte[] { - 0x50, // P - 0x68, // h - 0x6F, // o - 0x74, // t - 0x6F, // o - 0x73, // s - 0x68, // h - 0x6F, // o - 0x70, // p - 0x20, // - 0x33, // 3 - 0x2E, // . - 0x30, // 0 - 0, - }); - public static final BinaryConstant CONST_8BIM = new BinaryConstant(new byte[] { - 0x38, // 8 - 0x42, // B - 0x49, // I - 0x4D, // M - }); + public static final List MARKERS = Collections + .unmodifiableList(Arrays.asList(JPEG_APP0, JPEG_APP0_Marker, + JPEG_APP1_Marker, JPEG_APP2_Marker, JPEG_APP13_Marker, + JPEG_APP14_Marker, JPEG_APP15_Marker, JFIFMarker, + SOF0Marker, SOF1Marker, SOF2Marker, SOF3Marker, DHTMarker, + SOF5Marker, SOF6Marker, SOF7Marker, SOF8Marker, SOF9Marker, + SOF10Marker, SOF11Marker, DACMarker, SOF13Marker, + SOF14Marker, SOF15Marker, EOIMarker, SOS_Marker, DQTMarker, + DNLMarker, COMMarker)); + + public static final BinaryConstant icc_profile_label = new BinaryConstant( + new byte[] { 0x49, 0x43, 0x43, 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49, + 0x4C, 0x45, 0x0 }); + + public static final BinaryConstant PHOTOSHOP_IDENTIFICATION_STRING = new BinaryConstant( + new byte[] { 0x50, // P + 0x68, // h + 0x6F, // o + 0x74, // t + 0x6F, // o + 0x73, // s + 0x68, // h + 0x6F, // o + 0x70, // p + 0x20, // + 0x33, // 3 + 0x2E, // . + 0x30, // 0 + 0, }); + public static final BinaryConstant CONST_8BIM = new BinaryConstant( + new byte[] { 0x38, // 8 + 0x42, // B + 0x49, // I + 0x4D, // M + }); } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java Sat May 26 21:19:03 2012 @@ -56,9 +56,9 @@ public class JpegImageMetadata implement public TiffField findEXIFValue(TagInfo tagInfo) { try { if (exif != null) { - return exif.findField(tagInfo); + return exif.findField(tagInfo); } else { - return null; + return null; } } catch (ImageReadException cannotHappen) { return null; @@ -79,15 +79,16 @@ public class JpegImageMetadata implement /** * Returns the size of the first JPEG thumbnail found in the EXIF metadata. - * + * * @return Thumbnail width and height or null if no thumbnail. * @throws ImageReadException * @throws IOException */ - public Dimension getEXIFThumbnailSize() throws ImageReadException, IOException { + public Dimension getEXIFThumbnailSize() throws ImageReadException, + IOException { byte[] data = getEXIFThumbnailData(); - if( data != null ){ + if (data != null) { return Imaging.getImageSize(data); } return null; @@ -95,7 +96,7 @@ public class JpegImageMetadata implement /** * Returns the data of the first JPEG thumbnail found in the EXIF metadata. - * + * * @return JPEG data or null if no thumbnail. * @throws ImageReadException * @throws IOException @@ -110,12 +111,12 @@ public class JpegImageMetadata implement .get(i); byte[] data = null; - if( dir.getJpegImageData() != null ){ + if (dir.getJpegImageData() != null) { data = dir.getJpegImageData().data; } // Support other image formats here. - if( data != null ){ + if (data != null) { return data; } } @@ -125,8 +126,8 @@ public class JpegImageMetadata implement /** * Get the thumbnail image if available. * - * @return the thumbnail image. - * May be null if no image could be found. + * @return the thumbnail image. May be null if no image could + * be found. * @throws ImageReadException * @throws IOException */ @@ -149,9 +150,10 @@ public class JpegImageMetadata implement JpegImageData jpegImageData = dir.getJpegImageData(); if (jpegImageData != null) { - ByteArrayInputStream input = new ByteArrayInputStream(jpegImageData.data); + ByteArrayInputStream input = new ByteArrayInputStream( + jpegImageData.data); // JPEG thumbnail as JPEG or other format; try to parse. - image = ImageIO.read(input); + image = ImageIO.read(input); if (image != null) { return image; }