commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1342971 [7/20] - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/formats/bmp/ main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/ main/java/org/apache/commons/imaging/formats/bmp/writers/ main/java/org...
Date Sat, 26 May 2012 21:19:22 GMT
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java Sat May 26 21:19:03 2012
@@ -28,14 +28,12 @@ import org.apache.commons.imaging.common
 import org.apache.commons.imaging.palette.PaletteFactory;
 import org.apache.commons.imaging.palette.SimplePalette;
 
-public class PcxWriter implements PcxConstants
-{
+public class PcxWriter implements PcxConstants {
     private int encoding;
     private int bitDepth = -1;
     private PixelDensity pixelDensity = null;
 
-    public PcxWriter(Map params) throws ImageWriteException
-    {
+    public PcxWriter(Map params) throws ImageWriteException {
         // make copy of params; we'll clear keys as we consume them.
         params = (params == null) ? new HashMap() : new HashMap(params);
 
@@ -46,11 +44,9 @@ public class PcxWriter implements PcxCon
         // uncompressed PCX files are not even documented in ZSoft's spec,
         // let alone supported by most image viewers
         encoding = PcxImageParser.PcxHeader.ENCODING_RLE;
-        if (params.containsKey(PARAM_KEY_PCX_COMPRESSION))
-        {
+        if (params.containsKey(PARAM_KEY_PCX_COMPRESSION)) {
             Object value = params.remove(PARAM_KEY_PCX_COMPRESSION);
-            if (value != null)
-            {
+            if (value != null) {
                 if (!(value instanceof Number))
                     throw new ImageWriteException(
                             "Invalid compression parameter: " + value);
@@ -60,65 +56,55 @@ public class PcxWriter implements PcxCon
             }
         }
 
-        if (params.containsKey(PARAM_KEY_PCX_BIT_DEPTH))
-        {
+        if (params.containsKey(PARAM_KEY_PCX_BIT_DEPTH)) {
             Object value = params.remove(PARAM_KEY_PCX_BIT_DEPTH);
-            if (value != null)
-            {
+            if (value != null) {
                 if (!(value instanceof Number))
                     throw new ImageWriteException(
                             "Invalid bit depth parameter: " + value);
-                bitDepth = ((Number)value).intValue();
+                bitDepth = ((Number) value).intValue();
             }
         }
-        
-        if (params.containsKey(PARAM_KEY_PIXEL_DENSITY))
-        {
+
+        if (params.containsKey(PARAM_KEY_PIXEL_DENSITY)) {
             Object value = params.remove(PARAM_KEY_PIXEL_DENSITY);
-            if (value != null)
-            {
+            if (value != null) {
                 if (!(value instanceof PixelDensity))
                     throw new ImageWriteException(
                             "Invalid pixel density parameter");
-                pixelDensity = (PixelDensity) params.remove(PARAM_KEY_PIXEL_DENSITY);
+                pixelDensity = (PixelDensity) params
+                        .remove(PARAM_KEY_PIXEL_DENSITY);
             }
         }
-        if (pixelDensity == null)
-        {
+        if (pixelDensity == null) {
             // DPI is mandatory, so we have to invent something
             pixelDensity = PixelDensity.createFromPixelsPerInch(72, 72);
         }
 
-        if (params.size() > 0)
-        {
+        if (params.size() > 0) {
             Object firstKey = params.keySet().iterator().next();
             throw new ImageWriteException("Unknown parameter: " + firstKey);
         }
     }
 
     private void writeScanLine(BinaryOutputStream bos, byte[] scanline)
-            throws IOException, ImageWriteException
-    {
+            throws IOException, ImageWriteException {
         if (encoding == PcxImageParser.PcxHeader.ENCODING_UNCOMPRESSED)
             bos.writeByteArray(scanline);
-        else
-        {
-            if (encoding == PcxImageParser.PcxHeader.ENCODING_RLE)
-            {
+        else {
+            if (encoding == PcxImageParser.PcxHeader.ENCODING_RLE) {
                 int previousByte = -1;
                 int repeatCount = 0;
-                for (int i = 0; i < scanline.length; i++)
-                {
-                    if ((scanline[i] & 0xff) == previousByte && repeatCount < 63)
+                for (int i = 0; i < scanline.length; i++) {
+                    if ((scanline[i] & 0xff) == previousByte
+                            && repeatCount < 63)
                         ++repeatCount;
-                    else
-                    {
-                        if (repeatCount > 0)
-                        {
-                            if (repeatCount == 1 && (previousByte & 0xc0) != 0xc0)
+                    else {
+                        if (repeatCount > 0) {
+                            if (repeatCount == 1
+                                    && (previousByte & 0xc0) != 0xc0)
                                 bos.write(previousByte);
-                            else
-                            {
+                            else {
                                 bos.write(0xc0 | repeatCount);
                                 bos.write(previousByte);
                             }
@@ -127,50 +113,44 @@ public class PcxWriter implements PcxCon
                         repeatCount = 1;
                     }
                 }
-                if (repeatCount > 0)
-                {
+                if (repeatCount > 0) {
                     if (repeatCount == 1 && (previousByte & 0xc0) != 0xc0)
                         bos.write(previousByte);
-                    else
-                    {
+                    else {
                         bos.write(0xc0 | repeatCount);
                         bos.write(previousByte);
                     }
                 }
-            }
-            else
-                throw new ImageWriteException("Invalid PCX encoding " + encoding);
+            } else
+                throw new ImageWriteException("Invalid PCX encoding "
+                        + encoding);
         }
     }
 
     public void writeImage(BufferedImage src, OutputStream os)
-            throws ImageWriteException, IOException
-    {
+            throws ImageWriteException, IOException {
         final PaletteFactory paletteFactory = new PaletteFactory();
-        final SimplePalette palette = paletteFactory.makePaletteSimple(src, 256);
-        BinaryOutputStream bos = new BinaryOutputStream(os, BinaryOutputStream.BYTE_ORDER_INTEL);
-        if (palette == null || bitDepth == 24 || bitDepth == 32)
-        {
+        final SimplePalette palette = paletteFactory
+                .makePaletteSimple(src, 256);
+        BinaryOutputStream bos = new BinaryOutputStream(os,
+                BinaryOutputStream.BYTE_ORDER_INTEL);
+        if (palette == null || bitDepth == 24 || bitDepth == 32) {
             if (bitDepth == 32)
                 write32BppPCX(src, bos);
             else
                 write24BppPCX(src, bos);
-        }
-        else if (palette.length() > 16 || bitDepth == 8)
+        } else if (palette.length() > 16 || bitDepth == 8)
             write256ColorPCX(src, palette, bos);
         else if (palette.length() > 2 || bitDepth == 4)
             write16ColorPCX(src, palette, bos);
-        else
-        {
+        else {
             boolean onlyBlackAndWhite = true;
-            if (palette.length() >= 1)
-            {
+            if (palette.length() >= 1) {
                 int rgb = palette.getEntry(0);
                 if (rgb != 0 && rgb != 0xffffff)
                     onlyBlackAndWhite = false;
             }
-            if (palette.length() == 2)
-            {
+            if (palette.length() == 2) {
                 int rgb = palette.getEntry(1);
                 if (rgb != 0 && rgb != 0xffffff)
                     onlyBlackAndWhite = false;
@@ -183,10 +163,9 @@ public class PcxWriter implements PcxCon
     }
 
     private void write32BppPCX(BufferedImage src, BinaryOutputStream bos)
-            throws ImageWriteException, IOException
-    {
-        final int bytesPerLine = src.getWidth() % 2 == 0 ?
-            src.getWidth() : src.getWidth() + 1;
+            throws ImageWriteException, IOException {
+        final int bytesPerLine = src.getWidth() % 2 == 0 ? src.getWidth() : src
+                .getWidth() + 1;
 
         // PCX header
         bos.write(10); // manufacturer
@@ -197,8 +176,9 @@ public class PcxWriter implements PcxCon
         bos.write2Bytes(0); // yMin
         bos.write2Bytes(src.getWidth() - 1); // xMax
         bos.write2Bytes(src.getHeight() - 1); // yMax
-        bos.write2Bytes((short)Math.round(pixelDensity.horizontalDensityInches())); // hDpi
-        bos.write2Bytes((short)Math.round(pixelDensity.verticalDensityInches())); // vDpi
+        bos.write2Bytes((short) Math.round(pixelDensity
+                .horizontalDensityInches())); // hDpi
+        bos.write2Bytes((short) Math.round(pixelDensity.verticalDensityInches())); // vDpi
         bos.writeByteArray(new byte[48]); // 16 color palette
         bos.write(0); // reserved
         bos.write(1); // planes
@@ -210,26 +190,23 @@ public class PcxWriter implements PcxCon
 
         int rgbs[] = new int[src.getWidth()];
         byte rgbBytes[] = new byte[4 * bytesPerLine];
-        for (int y = 0; y < src.getHeight(); y++)
-        {
+        for (int y = 0; y < src.getHeight(); y++) {
             src.getRGB(0, y, src.getWidth(), 1, rgbs, 0, src.getWidth());
-            for (int x = 0; x < rgbs.length; x++)
-            {
-                rgbBytes[4*x + 0] = (byte) (rgbs[x] & 0xff);
-                rgbBytes[4*x + 1] = (byte) ((rgbs[x] >> 8) & 0xff);
-                rgbBytes[4*x + 2] = (byte) ((rgbs[x] >> 16) & 0xff);
-                rgbBytes[4*x + 3] = 0;
+            for (int x = 0; x < rgbs.length; x++) {
+                rgbBytes[4 * x + 0] = (byte) (rgbs[x] & 0xff);
+                rgbBytes[4 * x + 1] = (byte) ((rgbs[x] >> 8) & 0xff);
+                rgbBytes[4 * x + 2] = (byte) ((rgbs[x] >> 16) & 0xff);
+                rgbBytes[4 * x + 3] = 0;
             }
             writeScanLine(bos, rgbBytes);
         }
     }
 
     private void write24BppPCX(BufferedImage src, BinaryOutputStream bos)
-            throws ImageWriteException, IOException
-    {
-        final int bytesPerLine = src.getWidth() % 2 == 0 ?
-            src.getWidth() : src.getWidth() + 1;
-        
+            throws ImageWriteException, IOException {
+        final int bytesPerLine = src.getWidth() % 2 == 0 ? src.getWidth() : src
+                .getWidth() + 1;
+
         // PCX header
         bos.write(10); // manufacturer
         bos.write(5); // version
@@ -239,8 +216,9 @@ public class PcxWriter implements PcxCon
         bos.write2Bytes(0); // yMin
         bos.write2Bytes(src.getWidth() - 1); // xMax
         bos.write2Bytes(src.getHeight() - 1); // yMax
-        bos.write2Bytes((short)Math.round(pixelDensity.horizontalDensityInches())); // hDpi
-        bos.write2Bytes((short)Math.round(pixelDensity.verticalDensityInches())); // vDpi
+        bos.write2Bytes((short) Math.round(pixelDensity
+                .horizontalDensityInches())); // hDpi
+        bos.write2Bytes((short) Math.round(pixelDensity.verticalDensityInches())); // vDpi
         bos.writeByteArray(new byte[48]); // 16 color palette
         bos.write(0); // reserved
         bos.write(3); // planes
@@ -252,11 +230,9 @@ public class PcxWriter implements PcxCon
 
         int rgbs[] = new int[src.getWidth()];
         byte rgbBytes[] = new byte[3 * bytesPerLine];
-        for (int y = 0; y < src.getHeight(); y++)
-        {
+        for (int y = 0; y < src.getHeight(); y++) {
             src.getRGB(0, y, src.getWidth(), 1, rgbs, 0, src.getWidth());
-            for (int x = 0; x < rgbs.length; x++)
-            {
+            for (int x = 0; x < rgbs.length; x++) {
                 rgbBytes[x] = (byte) ((rgbs[x] >> 16) & 0xff);
                 rgbBytes[bytesPerLine + x] = (byte) ((rgbs[x] >> 8) & 0xff);
                 rgbBytes[2 * bytesPerLine + x] = (byte) (rgbs[x] & 0xff);
@@ -265,9 +241,9 @@ public class PcxWriter implements PcxCon
         }
     }
 
-    private void writeBlackAndWhitePCX(BufferedImage src, SimplePalette palette, BinaryOutputStream bos)
-            throws ImageWriteException, IOException
-    {
+    private void writeBlackAndWhitePCX(BufferedImage src,
+            SimplePalette palette, BinaryOutputStream bos)
+            throws ImageWriteException, IOException {
         int bytesPerLine = (src.getWidth() + 7) / 8;
         if (bytesPerLine % 2 != 0)
             ++bytesPerLine;
@@ -282,8 +258,9 @@ public class PcxWriter implements PcxCon
         bos.write2Bytes(0); // yMin
         bos.write2Bytes(src.getWidth() - 1); // xMax
         bos.write2Bytes(src.getHeight() - 1); // yMax
-        bos.write2Bytes((short)Math.round(pixelDensity.horizontalDensityInches())); // hDpi
-        bos.write2Bytes((short)Math.round(pixelDensity.verticalDensityInches())); // vDpi
+        bos.write2Bytes((short) Math.round(pixelDensity
+                .horizontalDensityInches())); // hDpi
+        bos.write2Bytes((short) Math.round(pixelDensity.verticalDensityInches())); // vDpi
         bos.writeByteArray(new byte[48]); // 16 color palette
         bos.write(0); // reserved
         bos.write(1); // planes
@@ -294,11 +271,9 @@ public class PcxWriter implements PcxCon
         bos.writeByteArray(new byte[54]);
 
         byte[] row = new byte[bytesPerLine];
-        for (int y = 0; y < src.getHeight(); y++)
-        {
-            Arrays.fill(row, (byte)0);
-            for (int x = 0; x < src.getWidth(); x++)
-            {
+        for (int y = 0; y < src.getHeight(); y++) {
+            Arrays.fill(row, (byte) 0);
+            for (int x = 0; x < src.getWidth(); x++) {
                 int rgb = 0xffffff & src.getRGB(x, y);
                 int bit;
                 if (rgb == 0x000000)
@@ -306,31 +281,30 @@ public class PcxWriter implements PcxCon
                 else if (rgb == 0xffffff)
                     bit = 1;
                 else
-                    throw new ImageWriteException("Pixel neither black nor white");
+                    throw new ImageWriteException(
+                            "Pixel neither black nor white");
                 row[x / 8] |= (bit << (7 - (x % 8)));
             }
             writeScanLine(bos, row);
         }
     }
 
-    private void write16ColorPCX(BufferedImage src, SimplePalette palette, BinaryOutputStream bos)
-            throws ImageWriteException, IOException
-    {
+    private void write16ColorPCX(BufferedImage src, SimplePalette palette,
+            BinaryOutputStream bos) throws ImageWriteException, IOException {
         int bytesPerLine = (src.getWidth() + 1) / 2;
         if (bytesPerLine % 2 != 0)
             ++bytesPerLine;
 
-        byte[] palette16 = new byte[16*3];
-        for (int i = 0; i < 16; i++)
-        {
+        byte[] palette16 = new byte[16 * 3];
+        for (int i = 0; i < 16; i++) {
             int rgb;
             if (i < palette.length())
                 rgb = palette.getEntry(i);
             else
                 rgb = 0;
-            palette16[3*i + 0] = (byte) (0xff & (rgb >> 16));
-            palette16[3*i + 1] = (byte) (0xff & (rgb >> 8));
-            palette16[3*i + 2] = (byte) (0xff & rgb);
+            palette16[3 * i + 0] = (byte) (0xff & (rgb >> 16));
+            palette16[3 * i + 1] = (byte) (0xff & (rgb >> 8));
+            palette16[3 * i + 2] = (byte) (0xff & rgb);
         }
 
         // PCX header
@@ -342,8 +316,9 @@ public class PcxWriter implements PcxCon
         bos.write2Bytes(0); // yMin
         bos.write2Bytes(src.getWidth() - 1); // xMax
         bos.write2Bytes(src.getHeight() - 1); // yMax
-        bos.write2Bytes((short)Math.round(pixelDensity.horizontalDensityInches())); // hDpi
-        bos.write2Bytes((short)Math.round(pixelDensity.verticalDensityInches())); // vDpi
+        bos.write2Bytes((short) Math.round(pixelDensity
+                .horizontalDensityInches())); // hDpi
+        bos.write2Bytes((short) Math.round(pixelDensity.verticalDensityInches())); // vDpi
         bos.writeByteArray(palette16); // 16 color palette
         bos.write(0); // reserved
         bos.write(1); // planes
@@ -354,24 +329,21 @@ public class PcxWriter implements PcxCon
         bos.writeByteArray(new byte[54]);
 
         byte[] indeces = new byte[bytesPerLine];
-        for (int y = 0; y < src.getHeight(); y++)
-        {
-            Arrays.fill(indeces, (byte)0);
-            for (int x = 0; x < src.getWidth(); x++)
-            {
+        for (int y = 0; y < src.getHeight(); y++) {
+            Arrays.fill(indeces, (byte) 0);
+            for (int x = 0; x < src.getWidth(); x++) {
                 int argb = src.getRGB(x, y);
                 int index = palette.getPaletteIndex(0xffffff & argb);
-                indeces[x / 2] |= (index << 4*(1 - (x % 2)));
+                indeces[x / 2] |= (index << 4 * (1 - (x % 2)));
             }
             writeScanLine(bos, indeces);
         }
     }
 
-    private void write256ColorPCX(BufferedImage src, SimplePalette palette, BinaryOutputStream bos)
-            throws ImageWriteException, IOException
-    {
-        final int bytesPerLine = src.getWidth() % 2 == 0 ?
-            src.getWidth() : src.getWidth() + 1;
+    private void write256ColorPCX(BufferedImage src, SimplePalette palette,
+            BinaryOutputStream bos) throws ImageWriteException, IOException {
+        final int bytesPerLine = src.getWidth() % 2 == 0 ? src.getWidth() : src
+                .getWidth() + 1;
 
         // PCX header
         bos.write(10); // manufacturer
@@ -382,8 +354,9 @@ public class PcxWriter implements PcxCon
         bos.write2Bytes(0); // yMin
         bos.write2Bytes(src.getWidth() - 1); // xMax
         bos.write2Bytes(src.getHeight() - 1); // yMax
-        bos.write2Bytes((short)Math.round(pixelDensity.horizontalDensityInches())); // hDpi
-        bos.write2Bytes((short)Math.round(pixelDensity.verticalDensityInches())); // vDpi
+        bos.write2Bytes((short) Math.round(pixelDensity
+                .horizontalDensityInches())); // hDpi
+        bos.write2Bytes((short) Math.round(pixelDensity.verticalDensityInches())); // vDpi
         bos.writeByteArray(new byte[48]); // 16 color palette
         bos.write(0); // reserved
         bos.write(1); // planes
@@ -394,10 +367,8 @@ public class PcxWriter implements PcxCon
         bos.writeByteArray(new byte[54]);
 
         byte[] indeces = new byte[bytesPerLine];
-        for (int y = 0; y < src.getHeight(); y++)
-        {
-            for (int x = 0; x < src.getWidth(); x++)
-            {
+        for (int y = 0; y < src.getHeight(); y++) {
+            for (int x = 0; x < src.getWidth(); x++) {
                 int argb = src.getRGB(x, y);
                 int index = palette.getPaletteIndex(0xffffff & argb);
                 indeces[x] = (byte) index;
@@ -406,8 +377,7 @@ public class PcxWriter implements PcxCon
         }
         // palette
         bos.write(12);
-        for (int i = 0; i < 256; i++)
-        {
+        for (int i = 0; i < 256; i++) {
             int rgb;
             if (i < palette.length())
                 rgb = palette.getEntry(i);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java Sat May 26 21:19:03 2012
@@ -18,38 +18,33 @@ package org.apache.commons.imaging.forma
 
 import org.apache.commons.imaging.ImageReadException;
 
-public class BitParser
-{
+public class BitParser {
     private final byte bytes[];
     private final int bitsPerPixel;
     private final int bitDepth;
 
-    public BitParser(byte bytes[], int bitsPerPixel, int bitDepth)
-    {
+    public BitParser(byte bytes[], int bitsPerPixel, int bitDepth) {
         this.bytes = bytes;
         this.bitsPerPixel = bitsPerPixel;
         this.bitDepth = bitDepth;
     }
 
     public int getSample(int pixelIndexInScanline, int sampleIndex)
-            throws ImageReadException
-    {
+            throws ImageReadException {
         int pixelIndexBits = bitsPerPixel * pixelIndexInScanline;
         int sampleIndexBits = pixelIndexBits + (sampleIndex * bitDepth);
         int sampleIndexBytes = sampleIndexBits >> 3;
 
         if (bitDepth == 8)
             return 0xff & bytes[sampleIndexBytes];
-        else if (bitDepth < 8)
-        {
+        else if (bitDepth < 8) {
             int b = 0xff & bytes[sampleIndexBytes];
             int bitsToShift = 8 - ((pixelIndexBits & 7) + bitDepth);
             b >>= bitsToShift;
 
             int bitmask = (1 << bitDepth) - 1;
             return b & bitmask;
-        } else if (bitDepth == 16)
-        {
+        } else if (bitDepth == 16) {
             return (((0xff & bytes[sampleIndexBytes]) << 8) | (0xff & bytes[sampleIndexBytes + 1]));
         }
 
@@ -57,8 +52,7 @@ public class BitParser
     }
 
     public int getSampleAsByte(int pixelIndexInScanline, int sampleIndex)
-            throws ImageReadException
-    {
+            throws ImageReadException {
         int sample = getSample(pixelIndexInScanline, sampleIndex);
 
         int rot = 8 - bitDepth;
@@ -69,4 +63,4 @@ public class BitParser
 
         return 0xff & sample;
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/GammaCorrection.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/GammaCorrection.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/GammaCorrection.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/GammaCorrection.java Sat May 26 21:19:03 2012
@@ -16,40 +16,33 @@
  */
 package org.apache.commons.imaging.formats.png;
 
-public class GammaCorrection
-{
+public class GammaCorrection {
     private static final boolean DEBUG = false;
 
     private final int lookupTable[];
 
-    public GammaCorrection(double src_gamma, double dst_gamma)
-    {
+    public GammaCorrection(double src_gamma, double dst_gamma) {
 
-        if (DEBUG)
-        {
+        if (DEBUG) {
             System.out.println("src_gamma: " + src_gamma);
             System.out.println("dst_gamma: " + dst_gamma);
         }
 
         lookupTable = new int[256];
-        for (int i = 0; i < 256; i++)
-        {
+        for (int i = 0; i < 256; i++) {
             lookupTable[i] = correctSample(i, src_gamma, dst_gamma);
-            if (DEBUG)
-            {
+            if (DEBUG) {
                 System.out
                         .println("lookup_table[" + i + "]: " + lookupTable[i]);
             }
         }
     }
 
-    public int correctSample(int sample)
-    {
+    public int correctSample(int sample) {
         return lookupTable[sample];
     }
 
-    public int correctARGB(int pixel)
-    {
+    public int correctARGB(int pixel) {
         int alpha = (0xff000000) & pixel;
         int red = (pixel >> 16) & 0xff;
         int green = (pixel >> 8) & 0xff;
@@ -65,8 +58,7 @@ public class GammaCorrection
         return rgb;
     }
 
-    private int correctSample(int sample, double src_gamma, double dst_gamma)
-    {
+    private int correctSample(int sample, double src_gamma, double dst_gamma) {
         // if (kUseAdobeGammaMethod && val <= 32)
         // {
         // double slope = Math.round(255.0d * Math.pow((32.0 / 255.0d),
@@ -78,4 +70,4 @@ public class GammaCorrection
                 / dst_gamma));
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngConstants.java Sat May 26 21:19:03 2012
@@ -20,69 +20,71 @@ import org.apache.commons.imaging.Imagin
 import org.apache.commons.imaging.common.BinaryConstant;
 import org.apache.commons.imaging.common.BinaryFileFunctions;
 
-public interface PngConstants extends ImagingConstants
-{
+public interface PngConstants extends ImagingConstants {
 
     public static final int COMPRESSION_DEFLATE_INFLATE = 0;
 
-    public final static BinaryConstant IHDR_CHUNK_TYPE = new BinaryConstant(new byte[] { 73, 72, 68, 82 });
-    public final static BinaryConstant PLTE_CHUNK_TYPE = new BinaryConstant(new byte[] { 80, 76, 84, 69 });
-    public final static BinaryConstant IEND_CHUNK_TYPE = new BinaryConstant(new byte[] { 73, 69, 78, 68 });
-    public final static BinaryConstant IDAT_CHUNK_TYPE = new BinaryConstant(new byte[] { 73, 68, 65, 84 });
-    public final static BinaryConstant iTXt_CHUNK_TYPE = new BinaryConstant(new byte[] { //
+    public final static BinaryConstant IHDR_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { 73, 72, 68, 82 });
+    public final static BinaryConstant PLTE_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { 80, 76, 84, 69 });
+    public final static BinaryConstant IEND_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { 73, 69, 78, 68 });
+    public final static BinaryConstant IDAT_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { 73, 68, 65, 84 });
+    public final static BinaryConstant iTXt_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { //
             105, //
-            84, //
-            88, //
-            116, //
-    });
-    public final static BinaryConstant tEXt_CHUNK_TYPE = new BinaryConstant(new byte[] { //
+                    84, //
+                    88, //
+                    116, //
+            });
+    public final static BinaryConstant tEXt_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { //
             0x74, //
-            0x45, //
-            0x58, //
-            0x74, //
-    });
-    public final static BinaryConstant zTXt_CHUNK_TYPE = new BinaryConstant(new byte[] { //
+                    0x45, //
+                    0x58, //
+                    0x74, //
+            });
+    public final static BinaryConstant zTXt_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { //
             0x7A, //
-            0x54, //
-            0x58, //
-            0x74, //
-    });
-    public final static BinaryConstant IPHYS_CHUNK_TYPE = new BinaryConstant(new byte[] {
-            'p',
-            'H',
-            'Y',
-            's'
-    });
-
-    public final static int IEND = BinaryFileFunctions.charsToQuad('I', 'E', 'N',
-            'D');
-    public final static int IHDR = BinaryFileFunctions.charsToQuad('I', 'H', 'D',
-            'R');
-    public final static int iCCP = BinaryFileFunctions.charsToQuad('i', 'C', 'C',
-            'P');
-    public final static int tEXt = BinaryFileFunctions.charsToQuad('t', 'E', 'X',
-            't');
-    public final static int zTXt = BinaryFileFunctions.charsToQuad('z', 'T', 'X',
-            't');
-    public final static int pHYs = BinaryFileFunctions.charsToQuad('p', 'H', 'Y',
-            's');
-    public final static int PLTE = BinaryFileFunctions.charsToQuad('P', 'L', 'T',
-            'E');
-    public final static int IDAT = BinaryFileFunctions.charsToQuad('I', 'D', 'A',
-            'T');
-    public final static int tRNS = BinaryFileFunctions.charsToQuad('t', 'R', 'N',
-            'S');
-    public final static int gAMA = BinaryFileFunctions.charsToQuad('g', 'A', 'M',
-            'A');
-    public final static int sRGB = BinaryFileFunctions.charsToQuad('s', 'R', 'G',
-            'B');
+                    0x54, //
+                    0x58, //
+                    0x74, //
+            });
+    public final static BinaryConstant IPHYS_CHUNK_TYPE = new BinaryConstant(
+            new byte[] { 'p', 'H', 'Y', 's' });
+
+    public final static int IEND = BinaryFileFunctions.charsToQuad('I', 'E',
+            'N', 'D');
+    public final static int IHDR = BinaryFileFunctions.charsToQuad('I', 'H',
+            'D', 'R');
+    public final static int iCCP = BinaryFileFunctions.charsToQuad('i', 'C',
+            'C', 'P');
+    public final static int tEXt = BinaryFileFunctions.charsToQuad('t', 'E',
+            'X', 't');
+    public final static int zTXt = BinaryFileFunctions.charsToQuad('z', 'T',
+            'X', 't');
+    public final static int pHYs = BinaryFileFunctions.charsToQuad('p', 'H',
+            'Y', 's');
+    public final static int PLTE = BinaryFileFunctions.charsToQuad('P', 'L',
+            'T', 'E');
+    public final static int IDAT = BinaryFileFunctions.charsToQuad('I', 'D',
+            'A', 'T');
+    public final static int tRNS = BinaryFileFunctions.charsToQuad('t', 'R',
+            'N', 'S');
+    public final static int gAMA = BinaryFileFunctions.charsToQuad('g', 'A',
+            'M', 'A');
+    public final static int sRGB = BinaryFileFunctions.charsToQuad('s', 'R',
+            'G', 'B');
 
     // XMP chunk type.
-    public final static int iTXt = BinaryFileFunctions.charsToQuad('i', 'T', 'X',
-            't');
+    public final static int iTXt = BinaryFileFunctions.charsToQuad('i', 'T',
+            'X', 't');
 
-    public static final BinaryConstant PNG_Signature = new BinaryConstant(new byte[]{
-        (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, });
+    public static final BinaryConstant PNG_Signature = new BinaryConstant(
+            new byte[] { (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, });
 
     public static final String PARAM_KEY_PNG_BIT_DEPTH = "PNG_BIT_DEPTH";
     public static final String PARAM_KEY_PNG_FORCE_INDEXED_COLOR = "PNG_FORCE_INDEXED_COLOR";
@@ -135,7 +137,7 @@ public interface PngConstants extends Im
 
     /**
      * Parameter key.
-     *
+     * 
      * Only used when writing Png images.
      * <p>
      * Valid values: a list of WriteTexts.
@@ -143,4 +145,4 @@ public interface PngConstants extends Im
      */
     public static final String PARAM_KEY_PNG_TEXT_CHUNKS = "PNG_TEXT_CHUNKS";
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngCrc.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngCrc.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngCrc.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngCrc.java Sat May 26 21:19:03 2012
@@ -17,8 +17,7 @@
 package org.apache.commons.imaging.formats.png;
 
 // should just use ints, not longs
-public class PngCrc
-{
+public class PngCrc {
     /* Table of CRCs of all 8-bit messages. */
     private final long crc_table[] = new long[256];
 
@@ -26,16 +25,13 @@ public class PngCrc
     private boolean crc_table_computed = false;
 
     /* Make the table for a fast CRC. */
-    private void make_crc_table()
-    {
+    private void make_crc_table() {
         long c;
         int n, k;
 
-        for (n = 0; n < 256; n++)
-        {
+        for (n = 0; n < 256; n++) {
             c = n;
-            for (k = 0; k < 8; k++)
-            {
+            for (k = 0; k < 8; k++) {
                 if ((c & 1) != 0)
 
                     c = 0xedb88320L ^ (c >> 1);
@@ -47,21 +43,21 @@ public class PngCrc
         crc_table_computed = true;
     }
 
-    /* Update a running CRC with the bytes buf[0..len-1]--the CRC
-     should be initialized to all 1's, and the transmitted value
-     is the 1's complement of the final running CRC (see the
-     crc() routine below)). */
+    /*
+     * Update a running CRC with the bytes buf[0..len-1]--the CRC should be
+     * initialized to all 1's, and the transmitted value is the 1's complement
+     * of the final running CRC (see the crc() routine below)).
+     */
 
-    private final long update_crc(long crc, byte buf[])
-    {
+    private final long update_crc(long crc, byte buf[]) {
         long c = crc;
         int n;
 
         if (!crc_table_computed)
             make_crc_table();
-        for (n = 0; n < buf.length; n++)
-        {
-            //            Debug.debug("crc[" + n + "]", c + " (" + Long.toHexString(c) + ")");
+        for (n = 0; n < buf.length; n++) {
+            // Debug.debug("crc[" + n + "]", c + " (" + Long.toHexString(c) +
+            // ")");
 
             c = crc_table[(int) ((c ^ buf[n]) & 0xff)] ^ (c >> 8);
         }
@@ -69,23 +65,19 @@ public class PngCrc
     }
 
     /* Return the CRC of the bytes buf[0..len-1]. */
-    public final int crc(byte buf[], int len)
-    {
+    public final int crc(byte buf[], int len) {
         return (int) (update_crc(0xffffffffL, buf) ^ 0xffffffffL);
     }
 
-    public final long start_partial_crc(byte buf[], int len)
-    {
+    public final long start_partial_crc(byte buf[], int len) {
         return update_crc(0xffffffffL, buf);
     }
 
-    public final long continue_partial_crc(long old_crc, byte buf[], int len)
-    {
+    public final long continue_partial_crc(long old_crc, byte buf[], int len) {
         return update_crc(old_crc, buf);
     }
 
-    public final long finish_partial_crc(long old_crc)
-    {
+    public final long finish_partial_crc(long old_crc) {
         return (old_crc ^ 0xffffffffL);
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageInfo.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageInfo.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageInfo.java Sat May 26 21:19:03 2012
@@ -22,8 +22,7 @@ import java.util.List;
 import org.apache.commons.imaging.ImageFormat;
 import org.apache.commons.imaging.ImageInfo;
 
-public class PngImageInfo extends ImageInfo
-{
+public class PngImageInfo extends ImageInfo {
     private final List<PngText> textChunks;
 
     public PngImageInfo(String formatDetails, int bitsPerPixel,
@@ -32,8 +31,8 @@ public class PngImageInfo extends ImageI
             int physicalHeightDpi, float physicalHeightInch,
             int physicalWidthDpi, float physicalWidthInch, int width,
             boolean isProgressive, boolean isTransparent, boolean usesPalette,
-            int colorType, String compressionAlgorithm, final List<PngText> textChunks)
-    {
+            int colorType, String compressionAlgorithm,
+            final List<PngText> textChunks) {
         super(formatDetails, bitsPerPixel, comments, format, formatName,
                 height, mimeType, numberOfImages, physicalHeightDpi,
                 physicalHeightInch, physicalWidthDpi, physicalWidthInch, width,
@@ -43,8 +42,7 @@ public class PngImageInfo extends ImageI
         this.textChunks = textChunks;
     }
 
-    public List<PngText> getTextChunks()
-    {
+    public List<PngText> getTextChunks() {
         return new ArrayList<PngText>(textChunks);
     }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java Sat May 26 21:19:03 2012
@@ -62,23 +62,19 @@ import org.apache.commons.imaging.icc.Ic
 import org.apache.commons.imaging.util.Debug;
 import org.apache.commons.imaging.util.ParamMap;
 
-public class PngImageParser extends ImageParser implements PngConstants
-{
+public class PngImageParser extends ImageParser implements PngConstants {
 
-    public PngImageParser()
-    {
+    public PngImageParser() {
         // setDebug(true);
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "Png-Custom";
     }
 
     @Override
-    public String getDefaultExtension()
-    {
+    public String getDefaultExtension() {
         return DEFAULT_EXTENSION;
     }
 
@@ -87,14 +83,12 @@ public class PngImageParser extends Imag
     private static final String ACCEPTED_EXTENSIONS[] = { DEFAULT_EXTENSION, };
 
     @Override
-    protected String[] getAcceptedExtensions()
-    {
+    protected String[] getAcceptedExtensions() {
         return ACCEPTED_EXTENSIONS;
     }
 
     @Override
-    protected ImageFormat[] getAcceptedTypes()
-    {
+    protected ImageFormat[] getAcceptedTypes() {
         return new ImageFormat[] { ImageFormat.IMAGE_FORMAT_PNG, //
         };
     }
@@ -113,22 +107,22 @@ public class PngImageParser extends Imag
     /**
      * @return List of String-formatted chunk types, ie. "tRNs".
      */
-    public List<String> getChuckTypes(InputStream is) throws ImageReadException, IOException {
+    public List<String> getChuckTypes(InputStream is)
+            throws ImageReadException, IOException {
         List<PngChunk> chunks = readChunks(is, null, false);
         List<String> chunkTypes = new ArrayList<String>();
-        for (int i=0; i<chunks.size(); i++) {
+        for (int i = 0; i < chunks.size(); i++) {
             PngChunk chunk = chunks.get(i);
             chunkTypes.add(getChunkTypeName(chunk.chunkType));
         }
         return chunkTypes;
     }
 
-    public boolean hasChuckType(ByteSource byteSource, int chunkType) throws ImageReadException, IOException
-    {
+    public boolean hasChuckType(ByteSource byteSource, int chunkType)
+            throws ImageReadException, IOException {
         InputStream is = null;
 
-        try
-        {
+        try {
             is = byteSource.getInputStream();
 
             List<PngChunk> chunks = null;
@@ -136,58 +130,48 @@ public class PngImageParser extends Imag
             readSignature(is);
             chunks = readChunks(is, new int[] { chunkType, }, true);
             return chunks.size() > 0;
-        } 
-        finally
-        {
-            try
-            {
+        } finally {
+            try {
                 if (is != null) {
                     is.close();
                 }
-            } catch (Exception e)
-            {
+            } catch (Exception e) {
                 Debug.debug(e);
             }
         }
     }
 
-
-    private boolean keepChunk(int ChunkType, int chunkTypes[])
-    {
+    private boolean keepChunk(int ChunkType, int chunkTypes[]) {
         // System.out.println("keepChunk: ");
         if (chunkTypes == null)
             return true;
 
-        for (int i = 0; i < chunkTypes.length; i++)
-        {
+        for (int i = 0; i < chunkTypes.length; i++) {
             if (chunkTypes[i] == ChunkType)
                 return true;
         }
         return false;
     }
 
-    private List<PngChunk> readChunks(InputStream is, int chunkTypes[], boolean returnAfterFirst) throws ImageReadException, IOException
-    {
+    private List<PngChunk> readChunks(InputStream is, int chunkTypes[],
+            boolean returnAfterFirst) throws ImageReadException, IOException {
         List<PngChunk> result = new ArrayList<PngChunk>();
 
-        while (true)
-        {
+        while (true) {
             if (debug)
                 System.out.println("");
 
             int length = read4Bytes("Length", is, "Not a Valid PNG File");
             int chunkType = read4Bytes("ChunkType", is, "Not a Valid PNG File");
 
-            if (debug)
-            {
+            if (debug) {
                 printCharQuad("ChunkType", chunkType);
                 debugNumber("Length", length, 4);
             }
             boolean keep = keepChunk(chunkType, chunkTypes);
 
             byte bytes[] = null;
-            if (keep)
-            {
+            if (keep) {
                 bytes = readByteArray("Chunk Data", length, is,
                         "Not a Valid PNG File: Couldn't read Chunk Data.");
             } else
@@ -199,8 +183,7 @@ public class PngImageParser extends Imag
 
             int CRC = read4Bytes("CRC", is, "Not a Valid PNG File");
 
-            if (keep)
-            {
+            if (keep) {
                 if (chunkType == iCCP)
                     result.add(new PngChunkIccp(length, chunkType, CRC, bytes));
                 else if (chunkType == tEXt)
@@ -236,35 +219,28 @@ public class PngImageParser extends Imag
     }
 
     public void readSignature(InputStream is) throws ImageReadException,
-            IOException
-    {
+            IOException {
         readAndVerifyBytes(is, PNG_Signature,
                 "Not a Valid PNG Segment: Incorrect Signature");
 
     }
 
     private List<PngChunk> readChunks(ByteSource byteSource, int chunkTypes[],
-            boolean returnAfterFirst) throws ImageReadException, IOException
-    {
+            boolean returnAfterFirst) throws ImageReadException, IOException {
         InputStream is = null;
 
-        try
-        {
+        try {
             is = byteSource.getInputStream();
 
             readSignature(is);
-            
+
             return readChunks(is, chunkTypes, returnAfterFirst);
-        }
-        finally
-        {
-            try
-            {
+        } finally {
+            try {
                 if (is != null) {
                     is.close();
                 }
-            } catch (Exception e)
-            {
+            } catch (Exception e) {
                 Debug.debug(e);
             }
         }
@@ -272,12 +248,11 @@ public class PngImageParser extends Imag
 
     @Override
     public byte[] getICCProfileBytes(ByteSource byteSource, Map params)
-            throws ImageReadException, IOException
-    {
-        List<PngChunk> chunks = readChunks(byteSource, new int[] { iCCP, }, true);
+            throws ImageReadException, IOException {
+        List<PngChunk> chunks = readChunks(byteSource, new int[] { iCCP, },
+                true);
 
-        if ((chunks == null) || (chunks.size() < 1))
-        {
+        if ((chunks == null) || (chunks.size() < 1)) {
             // throw new ImageReadException("Png: No chunks");
             return null;
         }
@@ -294,9 +269,9 @@ public class PngImageParser extends Imag
 
     @Override
     public Dimension getImageSize(ByteSource byteSource, Map params)
-            throws ImageReadException, IOException
-    {
-        List<PngChunk> chunks = readChunks(byteSource, new int[] { IHDR, }, true);
+            throws ImageReadException, IOException {
+        List<PngChunk> chunks = readChunks(byteSource, new int[] { IHDR, },
+                true);
 
         if ((chunks == null) || (chunks.size() < 1))
             throw new ImageReadException("Png: No chunks");
@@ -309,30 +284,27 @@ public class PngImageParser extends Imag
         return new Dimension(pngChunkIHDR.width, pngChunkIHDR.height);
     }
 
-    public byte[] embedICCProfile(byte image[], byte profile[])
-    {
+    public byte[] embedICCProfile(byte image[], byte profile[]) {
         return null;
     }
 
     @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
-    {
-        List<PngChunk> chunks = readChunks(byteSource, new int[] { tEXt, zTXt, }, true);
+            throws ImageReadException, IOException {
+        List<PngChunk> chunks = readChunks(byteSource,
+                new int[] { tEXt, zTXt, }, true);
 
         if ((chunks == null) || (chunks.size() < 1))
             return null;
 
         ImageMetadata result = new ImageMetadata();
 
-        for (int i = 0; i < chunks.size(); i++)
-        {
+        for (int i = 0; i < chunks.size(); i++) {
             PngTextChunk chunk = (PngTextChunk) chunks.get(i);
 
             result.add(chunk.getKeyword(), chunk.getText());
@@ -341,8 +313,7 @@ public class PngImageParser extends Imag
         return result;
     }
 
-    private boolean isGrayscale(int colorType) throws ImageReadException
-    {
+    private boolean isGrayscale(int colorType) throws ImageReadException {
         // Color type is a single-byte integer that describes the interpretation
         // of the
         // image data. Color type codes represent sums of the following values:
@@ -371,8 +342,7 @@ public class PngImageParser extends Imag
         //
         // 6 8,16 Each pixel is an R,G,B triple,
         // followed by an alpha sample.
-        switch (colorType)
-        {
+        switch (colorType) {
         case COLOR_TYPE_GREYSCALE:
             return true;
         case COLOR_TYPE_TRUE_COLOR:
@@ -389,8 +359,7 @@ public class PngImageParser extends Imag
         throw new ImageReadException("PNG: unknown color type: " + colorType);
     }
 
-    private int samplesPerPixel(int colorType) throws ImageReadException
-    {
+    private int samplesPerPixel(int colorType) throws ImageReadException {
         // Color type is a single-byte integer that describes the interpretation
         // of the
         // image data. Color type codes represent sums of the following values:
@@ -419,8 +388,7 @@ public class PngImageParser extends Imag
         //
         // 6 8,16 Each pixel is an R,G,B triple,
         // followed by an alpha sample.
-        switch (colorType)
-        {
+        switch (colorType) {
         case COLOR_TYPE_GREYSCALE:
             return 1;
         case COLOR_TYPE_TRUE_COLOR:
@@ -437,12 +405,10 @@ public class PngImageParser extends Imag
         throw new ImageReadException("PNG: unknown color type: " + colorType);
     }
 
-    private List<PngChunk> filterChunks(List<PngChunk> v, int type)
-    {
+    private List<PngChunk> filterChunks(List<PngChunk> v, int type) {
         List<PngChunk> result = new ArrayList<PngChunk>();
 
-        for (int i = 0; i < v.size(); i++)
-        {
+        for (int i = 0; i < v.size(); i++) {
             PngChunk chunk = v.get(i);
             if (chunk.chunkType == type)
                 result.add(chunk);
@@ -451,10 +417,8 @@ public class PngImageParser extends Imag
         return result;
     }
 
-    private boolean hasAlphaChannel(int ColorType) throws ImageReadException
-    {
-        switch (ColorType)
-        {
+    private boolean hasAlphaChannel(int ColorType) throws ImageReadException {
+        switch (ColorType) {
         case COLOR_TYPE_GREYSCALE: // 1,2,4,8,16 Each pixel is a grayscale
             // sample.
         case COLOR_TYPE_TRUE_COLOR: // 8,16 Each pixel is an R,G,B triple.
@@ -473,10 +437,8 @@ public class PngImageParser extends Imag
         }
     }
 
-    private String getColorTypeDescription(int ColorType)
-    {
-        switch (ColorType)
-        {
+    private String getColorTypeDescription(int ColorType) {
+        switch (ColorType) {
         case COLOR_TYPE_GREYSCALE: // 1,2,4,8,16 Each pixel is a grayscale
             // sample.
             return "grayscale";
@@ -502,13 +464,11 @@ public class PngImageParser extends Imag
     // I may not have always preserved byte order correctly.
 
     private TransparencyFilter getTransparencyFilter(int ColorType,
-            PngChunk pngChunktRNS) throws ImageReadException, IOException
-    {
+            PngChunk pngChunktRNS) throws ImageReadException, IOException {
         // this.printCharQuad("pngChunktRNS.ChunkType", pngChunktRNS.ChunkType);
         // this.debugNumber("pngChunktRNS.Length", pngChunktRNS.Length);
 
-        switch (ColorType)
-        {
+        switch (ColorType) {
         case COLOR_TYPE_GREYSCALE: // 1,2,4,8,16 Each pixel is a grayscale
             // sample.
             return new TransparencyFilterGrayscale(pngChunktRNS.bytes);
@@ -529,9 +489,9 @@ public class PngImageParser extends Imag
 
     @Override
     public ImageInfo getImageInfo(ByteSource byteSource, Map params)
-            throws ImageReadException, IOException
-    {
-        List<PngChunk> chunks = readChunks(byteSource, new int[] { IHDR, pHYs, tEXt, zTXt, tRNS, PLTE, iTXt, }, false);
+            throws ImageReadException, IOException {
+        List<PngChunk> chunks = readChunks(byteSource, new int[] { IHDR, pHYs,
+                tEXt, zTXt, tRNS, PLTE, iTXt, }, false);
 
         // if(chunks!=null)
         // System.out.println("chunks: " + chunks.size());
@@ -549,8 +509,7 @@ public class PngImageParser extends Imag
         boolean isTransparent = false;
 
         List<PngChunk> tRNSs = filterChunks(chunks, tRNS);
-        if (tRNSs.size() > 0)
-        {
+        if (tRNSs.size() > 0) {
             isTransparent = true;
             pngChunktRNS = IHDRs.get(0);
         } else {
@@ -576,20 +535,17 @@ public class PngImageParser extends Imag
             List<String> comments = new ArrayList<String>();
             List<PngText> textChunks = new ArrayList<PngText>();
 
-            for (int i = 0; i < tEXts.size(); i++)
-            {
+            for (int i = 0; i < tEXts.size(); i++) {
                 PngChunkText pngChunktEXt = (PngChunkText) tEXts.get(i);
                 comments.add(pngChunktEXt.keyword + ": " + pngChunktEXt.text);
                 textChunks.add(pngChunktEXt.getContents());
             }
-            for (int i = 0; i < zTXts.size(); i++)
-            {
+            for (int i = 0; i < zTXts.size(); i++) {
                 PngChunkZtxt pngChunkzTXt = (PngChunkZtxt) zTXts.get(i);
                 comments.add(pngChunkzTXt.keyword + ": " + pngChunkzTXt.text);
                 textChunks.add(pngChunkzTXt.getContents());
             }
-            for (int i = 0; i < iTXts.size(); i++)
-            {
+            for (int i = 0; i < iTXts.size(); i++) {
                 PngChunkItxt pngChunkiTXt = (PngChunkItxt) iTXts.get(i);
                 comments.add(pngChunkiTXt.keyword + ": " + pngChunkiTXt.text);
                 textChunks.add(pngChunkiTXt.getContents());
@@ -626,13 +582,11 @@ public class PngImageParser extends Imag
                 PhysicalWidthDpi = (int) Math
                         .round(pngChunkpHYs.PixelsPerUnitXAxis
                                 * meters_per_inch);
-                PhysicalWidthInch = (float) ((double) Width
-                        / ((double) pngChunkpHYs.PixelsPerUnitXAxis * meters_per_inch));
+                PhysicalWidthInch = (float) ((double) Width / ((double) pngChunkpHYs.PixelsPerUnitXAxis * meters_per_inch));
                 PhysicalHeightDpi = (int) Math
                         .round(pngChunkpHYs.PixelsPerUnitYAxis
                                 * meters_per_inch);
-                PhysicalHeightInch = (float) ((double) Height
-                        / ((double) pngChunkpHYs.PixelsPerUnitYAxis * meters_per_inch));
+                PhysicalHeightInch = (float) ((double) Height / ((double) pngChunkpHYs.PixelsPerUnitYAxis * meters_per_inch));
             }
 
             String FormatDetails = "Png";
@@ -644,8 +598,7 @@ public class PngImageParser extends Imag
                 usesPalette = true;
 
             int ColorType;
-            switch (pngChunkIHDR.colorType)
-            {
+            switch (pngChunkIHDR.colorType) {
             case COLOR_TYPE_GREYSCALE: // 1,2,4,8,16 Each pixel is a grayscale
                 // sample.
             case COLOR_TYPE_GREYSCALE_WITH_ALPHA: // 8,16 Each pixel is a
@@ -668,19 +621,17 @@ public class PngImageParser extends Imag
 
             String compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_PNG_FILTER;
 
-            return new PngImageInfo(FormatDetails, BitsPerPixel,
-                    comments, Format, FormatName, Height, MimeType,
-                    NumberOfImages, PhysicalHeightDpi, PhysicalHeightInch,
-                    PhysicalWidthDpi, PhysicalWidthInch, Width, isProgressive,
-                    isTransparent, usesPalette, ColorType,
-                    compressionAlgorithm, textChunks);
+            return new PngImageInfo(FormatDetails, BitsPerPixel, comments,
+                    Format, FormatName, Height, MimeType, NumberOfImages,
+                    PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi,
+                    PhysicalWidthInch, Width, isProgressive, isTransparent,
+                    usesPalette, ColorType, compressionAlgorithm, textChunks);
         }
     }
 
     @Override
     public BufferedImage getBufferedImage(ByteSource byteSource, Map params)
-            throws ImageReadException, IOException
-    {
+            throws ImageReadException, IOException {
         boolean verbose = ParamMap.getParamBoolean(params, PARAM_KEY_VERBOSE,
                 false);
 
@@ -692,8 +643,8 @@ public class PngImageParser extends Imag
         // throw new ImageWriteException("Unknown parameter: " + firstKey);
         // }
 
-        List<PngChunk> chunks = readChunks(byteSource, new int[] { IHDR, PLTE, IDAT,
-                tRNS, iCCP, gAMA, sRGB, }, false);
+        List<PngChunk> chunks = readChunks(byteSource, new int[] { IHDR, PLTE,
+                IDAT, tRNS, iCCP, gAMA, sRGB, }, false);
 
         if ((chunks == null) || (chunks.size() < 1))
             throw new ImageReadException("PNG: no chunks");
@@ -719,8 +670,7 @@ public class PngImageParser extends Imag
             throw new ImageReadException("PNG missing image data");
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        for (int i = 0; i < IDATs.size(); i++)
-        {
+        for (int i = 0; i < IDATs.size(); i++) {
             PngChunkIdat pngChunkIDAT = (PngChunkIdat) IDATs.get(i);
             byte bytes[] = pngChunkIDAT.bytes;
             // System.out.println(i + ": bytes: " + bytes.length);
@@ -734,8 +684,7 @@ public class PngImageParser extends Imag
         TransparencyFilter transparencyFilter = null;
 
         List<PngChunk> tRNSs = filterChunks(chunks, tRNS);
-        if (tRNSs.size() > 0)
-        {
+        if (tRNSs.size() > 0) {
             PngChunk pngChunktRNS = tRNSs.get(0);
             transparencyFilter = getTransparencyFilter(pngChunkIHDR.colorType,
                     pngChunktRNS);
@@ -754,13 +703,11 @@ public class PngImageParser extends Imag
             if (iCCPs.size() > 1)
                 throw new ImageReadException("PNG: unexpected iCCP chunk");
 
-            if (sRGBs.size() == 1)
-            {
+            if (sRGBs.size() == 1) {
                 // no color management neccesary.
                 if (debug)
                     System.out.println("sRGB, no color management neccesary.");
-            } else if (iCCPs.size() == 1)
-            {
+            } else if (iCCPs.size() == 1) {
                 if (debug)
                     System.out.println("iCCP.");
 
@@ -768,8 +715,7 @@ public class PngImageParser extends Imag
                 byte bytes[] = pngChunkiCCP.UncompressedProfile;
 
                 icc_profile = ICC_Profile.getInstance(bytes);
-            } else if (gAMAs.size() == 1)
-            {
+            } else if (gAMAs.size() == 1) {
                 PngChunkGama pngChunkgAMA = (PngChunkGama) gAMAs.get(0);
                 double gamma = pngChunkgAMA.getGamma();
 
@@ -834,11 +780,9 @@ public class PngImageParser extends Imag
 
             scanExpediter.drive();
 
-            if (icc_profile != null)
-            {
+            if (icc_profile != null) {
                 Boolean is_srgb = new IccProfileParser().issRGB(icc_profile);
-                if (is_srgb == null || !is_srgb.booleanValue())
-                {
+                if (is_srgb == null || !is_srgb.booleanValue()) {
                     ICC_ColorSpace cs = new ICC_ColorSpace(icc_profile);
 
                     ColorModel srgbCM = ColorModel.getRGBdefault();
@@ -857,8 +801,7 @@ public class PngImageParser extends Imag
 
     @Override
     public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
-            throws ImageReadException, IOException
-    {
+            throws ImageReadException, IOException {
         ImageInfo imageInfo = getImageInfo(byteSource);
         if (imageInfo == null)
             return false;
@@ -869,8 +812,7 @@ public class PngImageParser extends Imag
             List<PngChunk> chunks = readChunks(byteSource, null, false);
             {
                 List<PngChunk> IHDRs = filterChunks(chunks, IHDR);
-                if (IHDRs.size() != 1)
-                {
+                if (IHDRs.size() != 1) {
                     if (debug)
                         System.out.println("PNG contains more than one Header");
                     return false;
@@ -885,8 +827,7 @@ public class PngImageParser extends Imag
             if ((chunks.size() < 1))
                 return false;
 
-            for (int i = 0; i < chunks.size(); i++)
-            {
+            for (int i = 0; i < chunks.size(); i++) {
                 PngChunk chunk = chunks.get(i);
                 printCharQuad(pw, "\t" + i + ": ", chunk.chunkType);
             }
@@ -901,15 +842,14 @@ public class PngImageParser extends Imag
 
     @Override
     public void writeImage(BufferedImage src, OutputStream os, Map params)
-            throws ImageWriteException, IOException
-    {
+            throws ImageWriteException, IOException {
         new PngWriter(params).writeImage(src, os, params);
     }
 
     /**
      * Extracts embedded XML metadata as XML string.
      * <p>
-     *
+     * 
      * @param byteSource
      *            File containing image data.
      * @param params
@@ -918,17 +858,16 @@ public class PngImageParser extends Imag
      */
     @Override
     public String getXmpXml(ByteSource byteSource, Map params)
-            throws ImageReadException, IOException
-    {
+            throws ImageReadException, IOException {
 
-        List<PngChunk> chunks = readChunks(byteSource, new int[] { iTXt, }, false);
+        List<PngChunk> chunks = readChunks(byteSource, new int[] { iTXt, },
+                false);
 
         if ((chunks == null) || (chunks.size() < 1))
             return null;
 
         List<PngChunkItxt> xmpChunks = new ArrayList<PngChunkItxt>();
-        for (int i = 0; i < chunks.size(); i++)
-        {
+        for (int i = 0; i < chunks.size(); i++) {
             PngChunkItxt chunk = (PngChunkItxt) chunks.get(i);
             if (!chunk.getKeyword().equals(XMP_KEYWORD))
                 continue;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngText.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngText.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngText.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngText.java Sat May 26 21:19:03 2012
@@ -16,34 +16,27 @@
  */
 package org.apache.commons.imaging.formats.png;
 
-public abstract class PngText
-{
-    public PngText(String keyword, String text)
-    {
+public abstract class PngText {
+    public PngText(String keyword, String text) {
         this.keyword = keyword;
         this.text = text;
     }
 
     public final String keyword, text;
 
-    public static class tEXt extends PngText
-    {
-        public tEXt(String keyword, String text)
-        {
+    public static class tEXt extends PngText {
+        public tEXt(String keyword, String text) {
             super(keyword, text);
         }
     }
 
-    public static class zTXt extends PngText
-    {
-        public zTXt(String keyword, String text)
-        {
+    public static class zTXt extends PngText {
+        public zTXt(String keyword, String text) {
             super(keyword, text);
         }
     }
 
-    public static class iTXt extends PngText
-    {
+    public static class iTXt extends PngText {
 
         /*
          * The language tag defined in [RFC-3066] indicates the human language
@@ -60,8 +53,7 @@ public abstract class PngText
         public final String translatedKeyword;
 
         public iTXt(String keyword, String text, String languageTag,
-                String translatedKeyword)
-        {
+                String translatedKeyword) {
             super(keyword, text);
             this.languageTag = languageTag;
             this.translatedKeyword = translatedKeyword;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java Sat May 26 21:19:03 2012
@@ -35,17 +35,14 @@ import org.apache.commons.imaging.util.D
 import org.apache.commons.imaging.util.ParamMap;
 import org.apache.commons.imaging.util.UnicodeUtils;
 
-public class PngWriter implements PngConstants
-{
+public class PngWriter implements PngConstants {
     private final boolean verbose;
 
-    public PngWriter(boolean verbose)
-    {
+    public PngWriter(boolean verbose) {
         this.verbose = verbose;
     }
 
-    public PngWriter(Map params)
-    {
+    public PngWriter(Map params) {
         this.verbose = ParamMap.getParamBoolean(params, PARAM_KEY_VERBOSE,
                 false);
     }
@@ -55,10 +52,10 @@ public class PngWriter implements PngCon
      * PLTE: palette table associated with indexed PNG images. 3. IDAT: image
      * data chunks. 4. IEND: image trailer, which is the last chunk in a PNG
      * datastream.
-     *
+     * 
      * The remaining 14 chunk types are termed ancillary chunk types, which
      * encoders may generate and decoders may interpret.
-     *
+     * 
      * 1. Transparency information: tRNS (see 11.3.2: Transparency information).
      * 2. Colour space information: cHRM, gAMA, iCCP, sBIT, sRGB (see 11.3.3:
      * Colour space information). 3. Textual information: iTXt, tEXt, zTXt (see
@@ -67,8 +64,7 @@ public class PngWriter implements PngCon
      * tIME (see 11.3.6: Time stamp information).
      */
 
-    private final void writeInt(OutputStream os, int value) throws IOException
-    {
+    private final void writeInt(OutputStream os, int value) throws IOException {
         os.write(0xff & (value >> 24));
         os.write(0xff & (value >> 16));
         os.write(0xff & (value >> 8));
@@ -76,8 +72,7 @@ public class PngWriter implements PngCon
     }
 
     private final void writeChunk(OutputStream os, byte chunkType[],
-            byte data[]) throws IOException
-    {
+            byte data[]) throws IOException {
         int dataLength = data == null ? 0 : data.length;
         writeInt(os, dataLength);
         os.write(chunkType);
@@ -106,8 +101,7 @@ public class PngWriter implements PngCon
         }
     }
 
-    private static class ImageHeader
-    {
+    private static class ImageHeader {
         public final int width;
         public final int height;
         public final byte bit_depth;
@@ -118,8 +112,7 @@ public class PngWriter implements PngCon
 
         public ImageHeader(int width, int height, byte bit_depth,
                 byte colorType, byte compressionMethod, byte filterMethod,
-                byte interlaceMethod)
-        {
+                byte interlaceMethod) {
             this.width = width;
             this.height = height;
             this.bit_depth = bit_depth;
@@ -132,8 +125,7 @@ public class PngWriter implements PngCon
     }
 
     private void writeChunkIHDR(OutputStream os, ImageHeader value)
-            throws IOException
-    {
+            throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         writeInt(baos, value.width);
         writeInt(baos, value.height);
@@ -149,8 +141,7 @@ public class PngWriter implements PngCon
     }
 
     private void writeChunkiTXt(OutputStream os, PngText.iTXt text)
-            throws IOException, ImageWriteException
-    {
+            throws IOException, ImageWriteException {
         if (!UnicodeUtils.isValidISO_8859_1(text.keyword))
             throw new ImageWriteException(
                     "Png tEXt chunk keyword is not ISO-8859-1: " + text.keyword);
@@ -182,8 +173,7 @@ public class PngWriter implements PngCon
     }
 
     private void writeChunkzTXt(OutputStream os, PngText.zTXt text)
-            throws IOException, ImageWriteException
-    {
+            throws IOException, ImageWriteException {
         if (!UnicodeUtils.isValidISO_8859_1(text.keyword))
             throw new ImageWriteException(
                     "Png zTXt chunk keyword is not ISO-8859-1: " + text.keyword);
@@ -201,16 +191,13 @@ public class PngWriter implements PngCon
         baos.write(PngConstants.COMPRESSION_DEFLATE_INFLATE);
 
         // text
-        baos
-                .write(new ZLibUtils().deflate(text.text
-                        .getBytes("ISO-8859-1")));
+        baos.write(new ZLibUtils().deflate(text.text.getBytes("ISO-8859-1")));
 
         writeChunk(os, zTXt_CHUNK_TYPE.toByteArray(), baos.toByteArray());
     }
 
     private void writeChunktEXt(OutputStream os, PngText.tEXt text)
-            throws IOException, ImageWriteException
-    {
+            throws IOException, ImageWriteException {
         if (!UnicodeUtils.isValidISO_8859_1(text.keyword))
             throw new ImageWriteException(
                     "Png tEXt chunk keyword is not ISO-8859-1: " + text.keyword);
@@ -231,8 +218,7 @@ public class PngWriter implements PngCon
     }
 
     private void writeChunkXmpiTXt(OutputStream os, String xmpXml)
-            throws IOException
-    {
+            throws IOException {
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
@@ -255,14 +241,12 @@ public class PngWriter implements PngCon
     }
 
     private void writeChunkPLTE(OutputStream os, Palette palette)
-            throws IOException
-    {
+            throws IOException {
         int length = palette.length();
         byte bytes[] = new byte[length * 3];
 
         // Debug.debug("length", length);
-        for (int i = 0; i < length; i++)
-        {
+        for (int i = 0; i < length; i++) {
             int rgb = palette.getEntry(i);
             int index = i * 3;
             // Debug.debug("index", index);
@@ -274,20 +258,17 @@ public class PngWriter implements PngCon
         writeChunk(os, PLTE_CHUNK_TYPE.toByteArray(), bytes);
     }
 
-    private void writeChunkIEND(OutputStream os) throws IOException
-    {
+    private void writeChunkIEND(OutputStream os) throws IOException {
         writeChunk(os, IEND_CHUNK_TYPE.toByteArray(), null);
     }
 
     private void writeChunkIDAT(OutputStream os, byte bytes[])
-            throws IOException
-    {
+            throws IOException {
         writeChunk(os, IDAT_CHUNK_TYPE.toByteArray(), bytes);
     }
-    
+
     private void writeChunkPHYS(OutputStream os, int xPPU, int yPPU, byte units)
-            throws IOException
-    {
+            throws IOException {
         byte[] bytes = new byte[9];
         bytes[0] = (byte) (0xff & (xPPU >> 24));
         bytes[1] = (byte) (0xff & (xPPU >> 16));
@@ -301,16 +282,14 @@ public class PngWriter implements PngCon
         writeChunk(os, IPHYS_CHUNK_TYPE.toByteArray(), bytes);
     }
 
-    private byte getColourType(boolean hasAlpha, boolean isGrayscale)
-    {
+    private byte getColourType(boolean hasAlpha, boolean isGrayscale) {
         byte result;
 
         boolean index = false; // charles
 
         if (index)
             result = COLOR_TYPE_INDEXED_COLOR;
-        else if (isGrayscale)
-        {
+        else if (isGrayscale) {
             if (hasAlpha)
                 result = COLOR_TYPE_GREYSCALE_WITH_ALPHA;
             else
@@ -323,16 +302,13 @@ public class PngWriter implements PngCon
         return result;
     }
 
-    private byte getBitDepth(final byte colorType, Map params)
-    {
+    private byte getBitDepth(final byte colorType, Map params) {
         byte result = 8;
 
         Object o = params.get(PARAM_KEY_PNG_BIT_DEPTH);
-        if (o != null && o instanceof Number)
-        {
+        if (o != null && o instanceof Number) {
             int value = ((Number) o).intValue();
-            switch (value)
-            {
+            switch (value) {
             case 1:
             case 2:
             case 4:
@@ -342,8 +318,7 @@ public class PngWriter implements PngCon
                 break;
             default:
             }
-            switch (colorType)
-            {
+            switch (colorType) {
             case COLOR_TYPE_GREYSCALE:
                 break;
             case COLOR_TYPE_INDEXED_COLOR:
@@ -378,8 +353,7 @@ public class PngWriter implements PngCon
      */
 
     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 = new HashMap(params);
 
@@ -402,8 +376,7 @@ public class PngWriter implements PngCon
         if (params.containsKey(PARAM_KEY_PNG_TEXT_CHUNKS))
             params.remove(PARAM_KEY_PNG_TEXT_CHUNKS);
         params.remove(PARAM_KEY_PIXEL_DENSITY);
-        if (params.size() > 0)
-        {
+        if (params.size() > 0) {
             Object firstKey = params.keySet().iterator().next();
             throw new ImageWriteException("Unknown parameter: " + firstKey);
         }
@@ -431,11 +404,9 @@ public class PngWriter implements PngCon
             if (forceIndexedColor && forceTrueColor)
                 throw new ImageWriteException(
                         "Params: Cannot force both indexed and true color modes");
-            else if (forceIndexedColor)
-            {
+            else if (forceIndexedColor) {
                 colorType = COLOR_TYPE_INDEXED_COLOR;
-            } else if (forceTrueColor)
-            {
+            } else if (forceTrueColor) {
                 colorType = (byte) (hasAlpha ? COLOR_TYPE_TRUE_COLOR_WITH_ALPHA
                         : COLOR_TYPE_TRUE_COLOR);
                 isGrayscale = false;
@@ -481,8 +452,7 @@ public class PngWriter implements PngCon
         }
 
         Palette palette = null;
-        if (colorType == COLOR_TYPE_INDEXED_COLOR)
-        {
+        if (colorType == COLOR_TYPE_INDEXED_COLOR) {
             // PLTE No Before first IDAT
 
             int max_colors = hasAlpha ? 255 : 256;
@@ -496,31 +466,32 @@ public class PngWriter implements PngCon
 
             writeChunkPLTE(os, palette);
         }
-        
+
         Object pixelDensityObj = params.get(PARAM_KEY_PIXEL_DENSITY);
-        if (pixelDensityObj instanceof PixelDensity)
-        {
-            PixelDensity pixelDensity = (PixelDensity)pixelDensityObj;
+        if (pixelDensityObj instanceof PixelDensity) {
+            PixelDensity pixelDensity = (PixelDensity) pixelDensityObj;
             if (pixelDensity.isUnitless()) {
-                writeChunkPHYS(os, (int)Math.round(pixelDensity.getRawHorizontalDensity()),
-                        (int)Math.round(pixelDensity.getRawVerticalDensity()), (byte)0);
+                writeChunkPHYS(os, (int) Math.round(pixelDensity
+                        .getRawHorizontalDensity()),
+                        (int) Math.round(pixelDensity.getRawVerticalDensity()),
+                        (byte) 0);
             } else {
-                writeChunkPHYS(os, (int)Math.round(pixelDensity.horizontalDensityMetres()),
-                        (int)Math.round(pixelDensity.verticalDensityMetres()), (byte)1);
+                writeChunkPHYS(os, (int) Math.round(pixelDensity
+                        .horizontalDensityMetres()),
+                        (int) Math.round(pixelDensity.verticalDensityMetres()),
+                        (byte) 1);
             }
         }
 
-        if (params.containsKey(PARAM_KEY_XMP_XML))
-        {
+        if (params.containsKey(PARAM_KEY_XMP_XML)) {
             String xmpXml = (String) params.get(PARAM_KEY_XMP_XML);
             writeChunkXmpiTXt(os, xmpXml);
         }
 
-        if (params.containsKey(PARAM_KEY_PNG_TEXT_CHUNKS))
-        {
-            List<PngText> outputTexts = (List<PngText>) params.get(PARAM_KEY_PNG_TEXT_CHUNKS);
-            for (int i = 0; i < outputTexts.size(); i++)
-            {
+        if (params.containsKey(PARAM_KEY_PNG_TEXT_CHUNKS)) {
+            List<PngText> outputTexts = (List<PngText>) params
+                    .get(PARAM_KEY_PNG_TEXT_CHUNKS);
+            for (int i = 0; i < outputTexts.size(); i++) {
                 PngText text = outputTexts.get(i);
                 if (text instanceof PngText.tEXt)
                     writeChunktEXt(os, (PngText.tEXt) text);
@@ -547,30 +518,25 @@ public class PngWriter implements PngCon
                         || colorType == COLOR_TYPE_TRUE_COLOR_WITH_ALPHA;
 
                 int row[] = new int[width];
-                for (int y = 0; y < height; y++)
-                {
+                for (int y = 0; y < height; y++) {
                     // Debug.debug("y", y + "/" + height);
                     src.getRGB(0, y, width, 1, row, 0, width);
 
                     byte filter_type = FILTER_TYPE_NONE;
                     baos.write(filter_type);
-                    for (int x = 0; x < width; x++)
-                    {
+                    for (int x = 0; x < width; x++) {
                         int argb = row[x];
 
-                        if (palette != null)
-                        {
+                        if (palette != null) {
                             int index = palette.getPaletteIndex(argb);
                             baos.write(0xff & index);
-                        } else
-                        {
+                        } else {
                             int alpha = 0xff & (argb >> 24);
                             int red = 0xff & (argb >> 16);
                             int green = 0xff & (argb >> 8);
                             int blue = 0xff & (argb >> 0);
 
-                            if (isGrayscale)
-                            {
+                            if (isGrayscale) {
                                 int gray = (red + green + blue) / 3;
                                 // if(y==0)
                                 // {
@@ -585,8 +551,7 @@ public class PngWriter implements PngCon
                                 // Debug.debug();
                                 // }
                                 baos.write(gray);
-                            } else
-                            {
+                            } else {
                                 baos.write(red);
                                 baos.write(green);
                                 baos.write(blue);
@@ -604,8 +569,7 @@ public class PngWriter implements PngCon
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             DeflaterOutputStream dos = new DeflaterOutputStream(baos);
             int chunk_size = 256 * 1024;
-            for (int index = 0; index < uncompressed.length; index += chunk_size)
-            {
+            for (int index = 0; index < uncompressed.length; index += chunk_size) {
                 int end = Math.min(uncompressed.length, index + chunk_size);
                 int length = end - index;
 
@@ -615,8 +579,7 @@ public class PngWriter implements PngCon
 
                 byte compressed[] = baos.toByteArray();
                 baos.reset();
-                if (compressed.length > 0)
-                {
+                if (compressed.length > 0) {
                     // Debug.debug("compressed", compressed.length);
                     writeChunkIDAT(os, compressed);
                 }
@@ -625,8 +588,7 @@ public class PngWriter implements PngCon
             {
                 dos.finish();
                 byte compressed[] = baos.toByteArray();
-                if (compressed.length > 0)
-                {
+                if (compressed.length > 0) {
                     // Debug.debug("compressed final", compressed.length);
                     writeChunkIDAT(os, compressed);
                 }
@@ -653,6 +615,6 @@ public class PngWriter implements PngCon
 
         os.close();
     } // todo: filter types
-    // proper colour types
-    // srgb, etc.
+      // proper colour types
+      // srgb, etc.
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediter.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediter.java Sat May 26 21:19:03 2012
@@ -31,8 +31,7 @@ import org.apache.commons.imaging.format
 import org.apache.commons.imaging.formats.png.scanlinefilters.ScanlineFilterUp;
 import org.apache.commons.imaging.formats.transparencyfilters.TransparencyFilter;
 
-public abstract class ScanExpediter extends BinaryFileParser
-{
+public abstract class ScanExpediter extends BinaryFileParser {
     protected final int width;
     protected final int height;
     protected final InputStream is;
@@ -64,41 +63,35 @@ public abstract class ScanExpediter exte
         this.transparencyFilter = transparencyFilter;
     }
 
-    protected int getBitsToBytesRoundingUp(int bits)
-    {
+    protected int getBitsToBytesRoundingUp(int bits) {
         int bytes = bits / 8;
         if ((bits % 8 > 0))
             bytes++;
         return bytes;
     }
 
-    protected final int getPixelARGB(int alpha, int red, int green, int blue)
-    {
+    protected final int getPixelARGB(int alpha, int red, int green, int blue) {
         int rgb = ((0xff & alpha) << 24) | ((0xff & red) << 16)
                 | ((0xff & green) << 8) | ((0xff & blue) << 0);
 
         return rgb;
     }
 
-    protected final int getPixelRGB(int red, int green, int blue)
-    {
+    protected final int getPixelRGB(int red, int green, int blue) {
         return getPixelARGB(0xff, red, green, blue);
     }
 
     public abstract void drive() throws ImageReadException, IOException;
 
     protected int getRGB(BitParser bitParser, int pixelIndexInScanline)
-            throws ImageReadException, IOException
-    {
+            throws ImageReadException, IOException {
 
-        switch (colorType)
-        {
+        switch (colorType) {
         case 0: // 1,2,4,8,16 Each pixel is a grayscale sample.
         {
             int sample = bitParser.getSampleAsByte(pixelIndexInScanline, 0);
 
-            if (gammaCorrection != null)
-            {
+            if (gammaCorrection != null) {
                 sample = gammaCorrection.correctSample(sample);
             }
 
@@ -121,8 +114,7 @@ public abstract class ScanExpediter exte
             if (transparencyFilter != null)
                 rgb = transparencyFilter.filter(rgb, -1);
 
-            if (gammaCorrection != null)
-            {
+            if (gammaCorrection != null) {
                 int alpha = (0xff000000 & rgb) >> 24; // make sure to preserve
                 // transparency
                 red = gammaCorrection.correctSample(red);
@@ -133,7 +125,7 @@ public abstract class ScanExpediter exte
 
             return rgb;
         }
-            //
+        //
         case 3: // 1,2,4,8 Each pixel is a palette index;
             // a PLTE chunk must appear.
         {
@@ -166,8 +158,7 @@ public abstract class ScanExpediter exte
             int blue = bitParser.getSampleAsByte(pixelIndexInScanline, 2);
             int alpha = bitParser.getSampleAsByte(pixelIndexInScanline, 3);
 
-            if (gammaCorrection != null)
-            {
+            if (gammaCorrection != null) {
                 red = gammaCorrection.correctSample(red);
                 green = gammaCorrection.correctSample(green);
                 blue = gammaCorrection.correctSample(blue);
@@ -183,12 +174,10 @@ public abstract class ScanExpediter exte
     }
 
     protected ScanlineFilter getScanlineFilter(int filter_type,
-            int BytesPerPixel) throws ImageReadException
-    {
+            int BytesPerPixel) throws ImageReadException {
         ScanlineFilter filter;
 
-        switch (filter_type)
-        {
+        switch (filter_type) {
         case 0: // None
             filter = new ScanlineFilterNone();
             break;
@@ -219,8 +208,7 @@ public abstract class ScanExpediter exte
     }
 
     protected byte[] unfilterScanline(int filter_type, byte src[], byte prev[],
-            int BytesPerPixel) throws ImageReadException, IOException
-    {
+            int BytesPerPixel) throws ImageReadException, IOException {
         ScanlineFilter filter = getScanlineFilter(filter_type, BytesPerPixel);
 
         byte dst[] = new byte[src.length];
@@ -229,8 +217,7 @@ public abstract class ScanExpediter exte
     }
 
     protected byte[] getNextScanline(InputStream is, int length, byte prev[],
-            int BytesPerPixel) throws ImageReadException, IOException
-    {
+            int BytesPerPixel) throws ImageReadException, IOException {
         int filterType = is.read();
         if (filterType < 0)
             throw new ImageReadException("PNG: missing filter type");
@@ -244,4 +231,4 @@ public abstract class ScanExpediter exte
         return unfiltered;
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediterInterlaced.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediterInterlaced.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediterInterlaced.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/png/ScanExpediterInterlaced.java Sat May 26 21:19:03 2012
@@ -24,8 +24,7 @@ import org.apache.commons.imaging.ImageR
 import org.apache.commons.imaging.formats.png.chunks.PngChunkPlte;
 import org.apache.commons.imaging.formats.transparencyfilters.TransparencyFilter;
 
-public class ScanExpediterInterlaced extends ScanExpediter
-{
+public class ScanExpediterInterlaced extends ScanExpediter {
     public ScanExpediterInterlaced(int width, int height, InputStream is,
             BufferedImage bi, int color_type, int BitDepth, int bits_per_pixel,
             PngChunkPlte fPNGChunkPLTE, GammaCorrection fGammaCorrection,
@@ -39,60 +38,43 @@ public class ScanExpediterInterlaced ext
     private void visit(int x, int y, BufferedImage bi, BitParser fBitParser,
             int color_type, int pixel_index_in_scanline,
             PngChunkPlte fPNGChunkPLTE, GammaCorrection fGammaCorrection)
-            throws ImageReadException, IOException
-    {
+            throws ImageReadException, IOException {
         int rgb = getRGB(fBitParser,
-        //                    color_type,
+        // color_type,
                 pixel_index_in_scanline
-        //                    ,
-        //                    fPNGChunkPLTE, fGammaCorrection
+        // ,
+        // fPNGChunkPLTE, fGammaCorrection
         );
 
         bi.setRGB(x, y, rgb);
 
-        //                buffer.setElem(y * width +x , rgb);
+        // buffer.setElem(y * width +x , rgb);
 
     }
 
-    private static final int Starting_Row[] = {
-            0, 0, 4, 0, 2, 0, 1
-    };
-    private static final int Starting_Col[] = {
-            0, 4, 0, 2, 0, 1, 0
-    };
-    private static final int Row_Increment[] = {
-            8, 8, 8, 4, 4, 2, 2
-    };
-    private static final int Col_Increment[] = {
-            8, 8, 4, 4, 2, 2, 1
-    };
-    private static final int Block_Height[] = {
-            8, 8, 4, 4, 2, 2, 1
-    };
-    private static final int Block_Width[] = {
-            8, 4, 4, 2, 2, 1, 1
-    };
+    private static final int Starting_Row[] = { 0, 0, 4, 0, 2, 0, 1 };
+    private static final int Starting_Col[] = { 0, 4, 0, 2, 0, 1, 0 };
+    private static final int Row_Increment[] = { 8, 8, 8, 4, 4, 2, 2 };
+    private static final int Col_Increment[] = { 8, 8, 4, 4, 2, 2, 1 };
+    private static final int Block_Height[] = { 8, 8, 4, 4, 2, 2, 1 };
+    private static final int Block_Width[] = { 8, 4, 4, 2, 2, 1, 1 };
 
     @Override
-    public void drive() throws ImageReadException, IOException
-    {
+    public void drive() throws ImageReadException, IOException {
 
         int pass = 1;
-        while (pass <= 7)
-        {
+        while (pass <= 7) {
             byte prev[] = null;
 
             int y = Starting_Row[pass - 1];
-            //                int y_stride = Row_Increment[pass - 1];
+            // int y_stride = Row_Increment[pass - 1];
             boolean rows_in_pass = (y < height);
-            while (y < height)
-            {
+            while (y < height) {
                 int x = Starting_Col[pass - 1];
                 int pixel_index_in_scanline = 0;
 
-                if (x < width)
-                {
-                    //                         only get data if there are pixels in this scanline/pass
+                if (x < width) {
+                    // only get data if there are pixels in this scanline/pass
                     int ColumnsInRow = 1 + ((width - Starting_Col[pass - 1] - 1) / Col_Increment[pass - 1]);
                     int bitsPerScanLine = bitsPerPixel * ColumnsInRow;
                     int pixel_bytes_per_scan_line = getBitsToBytesRoundingUp(bitsPerScanLine);
@@ -105,8 +87,7 @@ public class ScanExpediterInterlaced ext
                     BitParser fBitParser = new BitParser(unfiltered,
                             bitsPerPixel, bitDepth);
 
-                    while (x < width)
-                    {
+                    while (x < width) {
                         visit(x, y, bi, fBitParser, colorType,
                                 pixel_index_in_scanline, pngChunkPLTE,
                                 gammaCorrection);
@@ -120,4 +101,4 @@ public class ScanExpediterInterlaced ext
             pass = pass + 1;
         }
     }
-}
\ No newline at end of file
+}



Mime
View raw message