commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1342914 [4/5] - in /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging: ./ color/ common/ common/bytesource/ common/itu_t4/ common/mylzw/
Date Sat, 26 May 2012 15:35:06 GMT
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageMetadata.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageMetadata.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageMetadata.java Sat May 26 15:35:04 2012
@@ -19,85 +19,72 @@ package org.apache.commons.imaging.commo
 import java.util.ArrayList;
 import java.util.List;
 
-public class ImageMetadata implements IImageMetadata
-{
+public class ImageMetadata implements IImageMetadata {
     private final List<IImageMetadataItem> items = new ArrayList<IImageMetadataItem>();
 
-    public void add(String keyword, String text)
-    {
+    public void add(String keyword, String text) {
         add(new Item(keyword, text));
     }
 
-    public void add(IImageMetadataItem item)
-    {
+    public void add(IImageMetadataItem item) {
         items.add(item);
     }
 
-    public List<? extends IImageMetadataItem> getItems()
-    {
+    public List<? extends IImageMetadataItem> getItems() {
         return new ArrayList<IImageMetadataItem>(items);
     }
 
-    protected static final String newline = System.getProperty("line.separator");
+    protected static final String newline = System
+            .getProperty("line.separator");
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return toString(null);
     }
 
-    public String toString(String prefix)
-    {
+    public String toString(String prefix) {
         if (null == prefix)
             prefix = "";
 
         StringBuffer result = new StringBuffer();
-        for (int i = 0; i < items.size(); i++)
-        {
+        for (int i = 0; i < items.size(); i++) {
             if (i > 0)
                 result.append(newline);
-            //            if (null != prefix)
-            //                result.append(prefix);
+            // if (null != prefix)
+            // result.append(prefix);
 
-            ImageMetadata.IImageMetadataItem item = items
-                    .get(i);
+            ImageMetadata.IImageMetadataItem item = items.get(i);
             result.append(item.toString(prefix + "\t"));
 
-            //            Debug.debug("prefix", prefix);
-            //            Debug.debug("item", items.get(i));
-            //            Debug.debug();
+            // Debug.debug("prefix", prefix);
+            // Debug.debug("item", items.get(i));
+            // Debug.debug();
         }
         return result.toString();
     }
 
-    public static class Item implements IImageMetadataItem
-    {
+    public static class Item implements IImageMetadataItem {
         private final String keyword, text;
 
-        public Item(String keyword, String text)
-        {
+        public Item(String keyword, String text) {
             this.keyword = keyword;
             this.text = text;
         }
 
-        public String getKeyword()
-        {
+        public String getKeyword() {
             return keyword;
         }
 
-        public String getText()
-        {
+        public String getText() {
             return text;
         }
 
         @Override
-        public String toString()
-        {
+        public String toString() {
             return toString(null);
         }
 
-        public String toString(String prefix)
-        {
+        public String toString(String prefix) {
             String result = keyword + ": " + text;
             if (null != prefix)
                 result = prefix + result;
@@ -105,4 +92,4 @@ public class ImageMetadata implements II
         }
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java Sat May 26 15:35:04 2012
@@ -24,16 +24,14 @@ public class MyByteArrayOutputStream ext
 {
     private final byte bytes[];
 
-    public MyByteArrayOutputStream(int length)
-    {
+    public MyByteArrayOutputStream(int length) {
         bytes = new byte[length];
     }
 
     private int count = 0;
 
     @Override
-    public void write(int value) throws IOException
-    {
+    public void write(int value) throws IOException {
         if (count >= bytes.length)
             throw new IOException("Write exceeded expected length (" + count
                     + ", " + bytes.length + ")");
@@ -42,10 +40,8 @@ public class MyByteArrayOutputStream ext
         count++;
     }
 
-    public byte[] toByteArray()
-    {
-        if (count < bytes.length)
-        {
+    public byte[] toByteArray() {
+        if (count < bytes.length) {
             byte result[] = new byte[count];
             System.arraycopy(bytes, 0, result, 0, count);
             return result;
@@ -53,8 +49,7 @@ public class MyByteArrayOutputStream ext
         return bytes;
     }
 
-    public int getBytesWritten()
-    {
+    public int getBytesWritten() {
         return count;
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java Sat May 26 15:35:04 2012
@@ -21,22 +21,20 @@ import java.io.IOException;
 
 import org.apache.commons.imaging.ImageReadException;
 
-public class PackBits
-{
+public class PackBits {
 
     public byte[] decompress(byte bytes[], int expected)
-            throws ImageReadException
-    {
+            throws ImageReadException {
         int total = 0;
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
-        //    Loop until you get the number of unpacked bytes you are expecting:
+        // Loop until you get the number of unpacked bytes you are expecting:
         int i = 0;
         while (total < expected)
 
         {
-            //        Read the next source byte into n.
+            // Read the next source byte into n.
             if (i >= bytes.length)
                 throw new ImageReadException(
                         "Tiff: Unpack bits source exhausted: " + i
@@ -44,9 +42,9 @@ public class PackBits
                                 + expected);
 
             int n = bytes[i++];
-            //                If n is between 0 and 127 inclusive, copy the next n+1 bytes literally.
-            if ((n >= 0) && (n <= 127))
-            {
+            // If n is between 0 and 127 inclusive, copy the next n+1 bytes
+            // literally.
+            if ((n >= 0) && (n <= 127)) {
 
                 int count = n + 1;
 
@@ -54,23 +52,23 @@ public class PackBits
                 for (int j = 0; j < count; j++)
                     baos.write(bytes[i++]);
             }
-            //                Else if n is between -127 and -1 inclusive, copy the next byte -n+1
-            //                times.
-            else if ((n >= -127) && (n <= -1))
-            {
+            // Else if n is between -127 and -1 inclusive, copy the next byte
+            // -n+1
+            // times.
+            else if ((n >= -127) && (n <= -1)) {
                 int b = bytes[i++];
                 int count = -n + 1;
 
                 total += count;
                 for (int j = 0; j < count; j++)
                     baos.write(b);
-            }
-            else if (n == -128)
+            } else if (n == -128)
                 throw new ImageReadException("Packbits: " + n);
-            //                Else if n is between -127 and -1 inclusive, copy the next byte -n+1
-            //                times.
-            //        else
-            //                Else if n is -128, noop.
+            // Else if n is between -127 and -1 inclusive, copy the next byte
+            // -n+1
+            // times.
+            // else
+            // Else if n is -128, noop.
         }
         byte result[] = baos.toByteArray();
 
@@ -78,16 +76,14 @@ public class PackBits
 
     }
 
-    private int findNextDuplicate(byte bytes[], int start)
-    {
-        //        int last = -1;
+    private int findNextDuplicate(byte bytes[], int start) {
+        // int last = -1;
         if (start >= bytes.length)
             return -1;
 
         byte prev = bytes[start];
 
-        for (int i = start + 1; i < bytes.length; i++)
-        {
+        for (int i = start + 1; i < bytes.length; i++) {
             byte b = bytes[i];
 
             if (b == prev)
@@ -99,27 +95,27 @@ public class PackBits
         return -1;
     }
 
-    private int findRunLength(byte bytes[], int start)
-    {
+    private int findRunLength(byte bytes[], int start) {
         byte b = bytes[start];
 
         int i;
 
-        for (i = start + 1; (i < bytes.length) && (bytes[i] == b); i++)
-        { /* do nothing */ }
+        for (i = start + 1; (i < bytes.length) && (bytes[i] == b); i++) { /*
+                                                                           * do
+                                                                           * nothing
+                                                                           */
+        }
 
         return i - start;
     }
 
-    public byte[] compress(byte bytes[]) throws IOException
-    {
+    public byte[] compress(byte bytes[]) throws IOException {
         MyByteArrayOutputStream baos = new MyByteArrayOutputStream(
                 bytes.length * 2); // max length 1 extra byte for every 128
 
         int ptr = 0;
         int count = 0;
-        while (ptr < bytes.length)
-        {
+        while (ptr < bytes.length) {
             count++;
             int dup = findNextDuplicate(bytes, ptr);
 
@@ -130,13 +126,10 @@ public class PackBits
                 baos.write(-(actual_len - 1));
                 baos.write(bytes[ptr]);
                 ptr += actual_len;
-            }
-            else
-            { // write literals
+            } else { // write literals
                 int len = dup - ptr;
 
-                if (dup > 0)
-                {
+                if (dup > 0) {
                     int runlen = findRunLength(bytes, dup);
                     if (runlen < 3) // may want to discard next run.
                     {
@@ -155,8 +148,7 @@ public class PackBits
                 int actual_len = Math.min(len, 128);
 
                 baos.write(actual_len - 1);
-                for (int i = 0; i < actual_len; i++)
-                {
+                for (int i = 0; i < actual_len; i++) {
                     baos.write(bytes[ptr]);
                     ptr++;
                 }
@@ -167,4 +159,4 @@ public class PackBits
         return result;
 
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumber.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumber.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumber.java Sat May 26 15:35:04 2012
@@ -19,31 +19,26 @@ package org.apache.commons.imaging.commo
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 
-public class RationalNumber extends Number
-{
+public class RationalNumber extends Number {
     private static final long serialVersionUID = -1;
 
     public final int numerator;
     public final int divisor;
 
-    public RationalNumber(int numerator, int divisor)
-    {
+    public RationalNumber(int numerator, int divisor) {
         this.numerator = numerator;
         this.divisor = divisor;
     }
 
-    public static final RationalNumber factoryMethod(long n, long d)
-    {
+    public static final RationalNumber factoryMethod(long n, long d) {
         // safer than constructor - handles values outside min/max range.
         // also does some simple finding of common denominators.
 
         if (n > Integer.MAX_VALUE || n < Integer.MIN_VALUE
-                || d > Integer.MAX_VALUE || d < Integer.MIN_VALUE)
-        {
+                || d > Integer.MAX_VALUE || d < Integer.MIN_VALUE) {
             while ((n > Integer.MAX_VALUE || n < Integer.MIN_VALUE
                     || d > Integer.MAX_VALUE || d < Integer.MIN_VALUE)
-                    && (Math.abs(n) > 1) && (Math.abs(d) > 1))
-            {
+                    && (Math.abs(n) > 1) && (Math.abs(d) > 1)) {
                 // brutal, inprecise truncation =(
                 // use the sign-preserving right shift operator.
                 n >>= 1;
@@ -65,8 +60,7 @@ public class RationalNumber extends Numb
     /**
      * Return the greatest common divisor
      */
-    private static long gcd(long a, long b)
-    {
+    private static long gcd(long a, long b) {
 
         if (b == 0)
             return a;
@@ -74,45 +68,38 @@ public class RationalNumber extends Numb
             return gcd(b, a % b);
     }
 
-    public RationalNumber negate()
-    {
+    public RationalNumber negate() {
         return new RationalNumber(-numerator, divisor);
     }
 
     @Override
-    public double doubleValue()
-    {
+    public double doubleValue() {
         return (double) numerator / (double) divisor;
     }
 
     @Override
-    public float floatValue()
-    {
+    public float floatValue() {
         return (float) numerator / (float) divisor;
     }
 
     @Override
-    public int intValue()
-    {
+    public int intValue() {
         return numerator / divisor;
     }
 
     @Override
-    public long longValue()
-    {
+    public long longValue() {
         return (long) numerator / (long) divisor;
     }
 
-    public boolean isValid()
-    {
+    public boolean isValid() {
         return divisor != 0;
     }
 
     private static final NumberFormat nf = DecimalFormat.getInstance();
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         if (divisor == 0)
             return "Invalid rational (" + numerator + "/" + divisor + ")";
         if ((numerator % divisor) == 0)
@@ -121,12 +108,11 @@ public class RationalNumber extends Numb
                 + nf.format((double) numerator / divisor) + ")";
     }
 
-    public String toDisplayString()
-    {
+    public String toDisplayString() {
         if ((numerator % divisor) == 0)
             return "" + (numerator / divisor);
         NumberFormat nf = DecimalFormat.getInstance();
         nf.setMaximumFractionDigits(3);
         return nf.format((double) numerator / (double) divisor);
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumberUtilities.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumberUtilities.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumberUtilities.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumberUtilities.java Sat May 26 15:35:04 2012
@@ -16,31 +16,25 @@
  */
 package org.apache.commons.imaging.common;
 
-public abstract class RationalNumberUtilities extends Number
-{
+public abstract class RationalNumberUtilities extends Number {
 
-    private static class Option
-    {
+    private static class Option {
         public final RationalNumber rationalNumber;
         public final double error;
 
-        private Option(final RationalNumber rationalNumber, final double error)
-        {
+        private Option(final RationalNumber rationalNumber, final double error) {
             this.rationalNumber = rationalNumber;
             this.error = error;
         }
 
         public static final Option factory(final RationalNumber rationalNumber,
-                final double value)
-        {
+                final double value) {
             return new Option(rationalNumber, Math.abs(rationalNumber
-                    .doubleValue()
-                    - value));
+                    .doubleValue() - value));
         }
 
         @Override
-        public String toString()
-        {
+        public String toString() {
             return rationalNumber.toString();
         }
     }
@@ -51,16 +45,14 @@ public abstract class RationalNumberUtil
     //
     // calculate rational number using successive approximations.
     //
-    public static final RationalNumber getRationalNumber(double value)
-    {
+    public static final RationalNumber getRationalNumber(double value) {
         if (value >= Integer.MAX_VALUE)
             return new RationalNumber(Integer.MAX_VALUE, 1);
         else if (value <= -Integer.MAX_VALUE)
             return new RationalNumber(-Integer.MAX_VALUE, 1);
 
         boolean negative = false;
-        if (value < 0)
-        {
+        if (value < 0) {
             negative = true;
             value = Math.abs(value);
         }
@@ -72,30 +64,21 @@ public abstract class RationalNumberUtil
 
             if (value == 0)
                 return new RationalNumber(0, 1);
-            else if (value >= 1)
-            {
+            else if (value >= 1) {
                 int approx = (int) value;
-                if (approx < value)
-                {
+                if (approx < value) {
                     l = new RationalNumber(approx, 1);
                     h = new RationalNumber(approx + 1, 1);
-                }
-                else
-                {
+                } else {
                     l = new RationalNumber(approx - 1, 1);
                     h = new RationalNumber(approx, 1);
                 }
-            }
-            else
-            {
+            } else {
                 int approx = (int) (1.0 / value);
-                if ((1.0 / approx) < value)
-                {
+                if ((1.0 / approx) < value) {
                     l = new RationalNumber(1, approx);
                     h = new RationalNumber(1, approx - 1);
-                }
-                else
-                {
+                } else {
                     l = new RationalNumber(1, approx + 1);
                     h = new RationalNumber(1, approx);
                 }
@@ -106,13 +89,13 @@ public abstract class RationalNumberUtil
 
         Option bestOption = (low.error < high.error) ? low : high;
 
-        final int MAX_ITERATIONS = 100; // value is quite high, actually.  shouldn't matter.
+        final int MAX_ITERATIONS = 100; // value is quite high, actually.
+                                        // shouldn't matter.
         for (int count = 0; bestOption.error > TOLERANCE
-                && count < MAX_ITERATIONS; count++)
-        {
-            //            Debug.debug("bestOption: " + bestOption + ", left: " + low
-            //                    + ", right: " + high + ", value: " + value + ", error: "
-            //                    + bestOption.error);
+                && count < MAX_ITERATIONS; count++) {
+            // Debug.debug("bestOption: " + bestOption + ", left: " + low
+            // + ", right: " + high + ", value: " + value + ", error: "
+            // + bestOption.error);
 
             RationalNumber mediant = RationalNumber.factoryMethod(
                     (long) low.rationalNumber.numerator
@@ -121,15 +104,12 @@ public abstract class RationalNumberUtil
                             + (long) high.rationalNumber.divisor);
             Option mediantOption = Option.factory(mediant, value);
 
-            if (value < mediant.doubleValue())
-            {
+            if (value < mediant.doubleValue()) {
                 if (high.error <= mediantOption.error)
                     break;
 
                 high = mediantOption;
-            }
-            else
-            {
+            } else {
                 if (low.error <= mediantOption.error)
                     break;
 
@@ -140,9 +120,8 @@ public abstract class RationalNumberUtil
                 bestOption = mediantOption;
         }
 
-        return negative
-                ? bestOption.rationalNumber.negate()
+        return negative ? bestOption.rationalNumber.negate()
                 : bestOption.rationalNumber;
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RgbBufferedImageFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RgbBufferedImageFactory.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RgbBufferedImageFactory.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RgbBufferedImageFactory.java Sat May 26 15:35:04 2012
@@ -19,19 +19,16 @@ package org.apache.commons.imaging.commo
 
 import java.awt.image.BufferedImage;
 
-public class RgbBufferedImageFactory implements IBufferedImageFactory
-{
+public class RgbBufferedImageFactory implements IBufferedImageFactory {
     public BufferedImage getColorBufferedImage(int width, int height,
-            boolean hasAlpha)
-    {
+            boolean hasAlpha) {
         if (hasAlpha)
             return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
         return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     }
 
     public BufferedImage getGrayscaleBufferedImage(int width, int height,
-            boolean hasAlpha)
-    {
+            boolean hasAlpha) {
         // always use color.
         return getColorBufferedImage(width, height, hasAlpha);
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/SimpleBufferedImageFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/SimpleBufferedImageFactory.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/SimpleBufferedImageFactory.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/SimpleBufferedImageFactory.java Sat May 26 15:35:04 2012
@@ -19,19 +19,16 @@ package org.apache.commons.imaging.commo
 
 import java.awt.image.BufferedImage;
 
-public class SimpleBufferedImageFactory implements IBufferedImageFactory
-{
+public class SimpleBufferedImageFactory implements IBufferedImageFactory {
     public BufferedImage getColorBufferedImage(int width, int height,
-            boolean hasAlpha)
-    {
+            boolean hasAlpha) {
         if (hasAlpha)
             return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
         return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     }
 
     public BufferedImage getGrayscaleBufferedImage(int width, int height,
-            boolean hasAlpha)
-    {
+            boolean hasAlpha) {
         if (hasAlpha)
             return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ZLibUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ZLibUtils.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ZLibUtils.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ZLibUtils.java Sat May 26 15:35:04 2012
@@ -22,8 +22,7 @@ import java.io.IOException;
 import java.util.zip.DeflaterOutputStream;
 import java.util.zip.InflaterInputStream;
 
-public class ZLibUtils extends BinaryFileFunctions
-{
+public class ZLibUtils extends BinaryFileFunctions {
     public final byte[] inflate(byte bytes[]) throws IOException
     // slow, probably.
     {
@@ -32,8 +31,7 @@ public class ZLibUtils extends BinaryFil
         return getStreamBytes(zIn);
     }
 
-    public final byte[] deflate(byte bytes[]) throws IOException
-    {
+    public final byte[] deflate(byte bytes[]) throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         DeflaterOutputStream dos = new DeflaterOutputStream(baos);
         dos.write(bytes);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSource.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSource.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSource.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSource.java Sat May 26 15:35:04 2012
@@ -21,17 +21,14 @@ import java.io.InputStream;
 
 import org.apache.commons.imaging.common.BinaryFileFunctions;
 
-public abstract class ByteSource extends BinaryFileFunctions
-{
+public abstract class ByteSource extends BinaryFileFunctions {
     protected final String filename;
 
-    public ByteSource(final String filename)
-    {
+    public ByteSource(final String filename) {
         this.filename = filename;
     }
 
-    public final InputStream getInputStream(int start) throws IOException
-    {
+    public final InputStream getInputStream(int start) throws IOException {
         InputStream is = null;
         boolean succeeded = false;
         try {
@@ -55,22 +52,20 @@ public abstract class ByteSource extends
     public abstract byte[] getAll() throws IOException;
 
     /*
-     * This operation can be VERY expensive; for inputstream
-     * byte sources, the entire stream must be drained to
-     * determine its length.
+     * This operation can be VERY expensive; for inputstream byte sources, the
+     * entire stream must be drained to determine its length.
      */
     public abstract long getLength() throws IOException;
 
     //
-    //    public byte[] getAll() throws IOException
-    //    {
-    //        return getBlock(0, (int) getLength());
-    //    }
+    // public byte[] getAll() throws IOException
+    // {
+    // return getBlock(0, (int) getLength());
+    // }
 
     public abstract String getDescription();
 
-    public final String getFilename()
-    {
+    public final String getFilename() {
         return filename;
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceArray.java Sat May 26 15:35:04 2012
@@ -20,33 +20,29 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-public class ByteSourceArray extends ByteSource
-{
+public class ByteSourceArray extends ByteSource {
     private final byte bytes[];
 
-    public ByteSourceArray(String filename, byte bytes[])
-    {
+    public ByteSourceArray(String filename, byte bytes[]) {
         super(filename);
         this.bytes = bytes;
     }
 
-    public ByteSourceArray(byte bytes[])
-    {
+    public ByteSourceArray(byte bytes[]) {
         super(null);
         this.bytes = bytes;
     }
 
     @Override
-    public InputStream getInputStream()
-    {
+    public InputStream getInputStream() {
         return new ByteArrayInputStream(bytes);
     }
 
     @Override
-    public byte[] getBlock(int start, int length) throws IOException
-    {
+    public byte[] getBlock(int start, int length) throws IOException {
         // We include a separate check for int overflow.
-        if ((start < 0) || (length < 0) || (start + length < 0) || (start + length > bytes.length)) {
+        if ((start < 0) || (length < 0) || (start + length < 0)
+                || (start + length > bytes.length)) {
             throw new IOException("Could not read block (block start: " + start
                     + ", block length: " + length + ", data length: "
                     + bytes.length + ").");
@@ -58,21 +54,18 @@ public class ByteSourceArray extends Byt
     }
 
     @Override
-    public long getLength()
-    {
+    public long getLength() {
         return bytes.length;
     }
 
     @Override
-    public byte[] getAll() throws IOException
-    {
+    public byte[] getAll() throws IOException {
         return bytes;
     }
 
     @Override
-    public String getDescription()
-    {
+    public String getDescription() {
         return bytes.length + " byte array";
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceFile.java Sat May 26 15:35:04 2012
@@ -26,19 +26,16 @@ import java.io.RandomAccessFile;
 
 import org.apache.commons.imaging.util.Debug;
 
-public class ByteSourceFile extends ByteSource
-{
+public class ByteSourceFile extends ByteSource {
     private final File file;
 
-    public ByteSourceFile(File file)
-    {
+    public ByteSourceFile(File file) {
         super(file.getName());
         this.file = file;
     }
 
     @Override
-    public InputStream getInputStream() throws IOException
-    {
+    public InputStream getInputStream() throws IOException {
         FileInputStream is = null;
         BufferedInputStream bis = null;
         is = new FileInputStream(file);
@@ -47,34 +44,28 @@ public class ByteSourceFile extends Byte
     }
 
     @Override
-    public byte[] getBlock(int start, int length) throws IOException
-    {
+    public byte[] getBlock(int start, int length) throws IOException {
 
         RandomAccessFile raf = null;
-        try
-        {
+        try {
             raf = new RandomAccessFile(file, "r");
 
             // We include a separate check for int overflow.
-            if ((start < 0) || (length < 0) || (start + length < 0) || (start + length > raf.length())) {
-                throw new IOException("Could not read block (block start: " + start
-                        + ", block length: " + length + ", data length: "
-                        + raf.length() + ").");
+            if ((start < 0) || (length < 0) || (start + length < 0)
+                    || (start + length > raf.length())) {
+                throw new IOException("Could not read block (block start: "
+                        + start + ", block length: " + length
+                        + ", data length: " + raf.length() + ").");
             }
 
             return getRAFBytes(raf, start, length,
                     "Could not read value from file");
-        }
-        finally
-        {
-            try
-            {
+        } finally {
+            try {
                 if (raf != null) {
                     raf.close();
                 }
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 Debug.debug(e);
             }
 
@@ -82,47 +73,37 @@ public class ByteSourceFile extends Byte
     }
 
     @Override
-    public long getLength()
-    {
+    public long getLength() {
         return file.length();
     }
 
     @Override
-    public byte[] getAll() throws IOException
-    {
+    public byte[] getAll() throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
         InputStream is = null;
-        try
-        {
+        try {
             is = new FileInputStream(file);
             is = new BufferedInputStream(is);
             byte buffer[] = new byte[1024];
             int read;
-            while ((read = is.read(buffer)) > 0)
-            {
+            while ((read = is.read(buffer)) > 0) {
                 baos.write(buffer, 0, read);
             }
             return baos.toByteArray();
-        }
-        finally
-        {
-            try
-            {
+        } finally {
+            try {
                 if (null != is)
                     is.close();
-            }
-            catch (IOException e)
-            {
-                //                Debug.d
+            } catch (IOException e) {
+                // Debug.d
             }
         }
     }
 
     @Override
-    public String getDescription()
-    {
+    public String getDescription() {
         return "File: '" + file.getAbsolutePath() + "'";
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java Sat May 26 15:35:04 2012
@@ -21,31 +21,26 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-public class ByteSourceInputStream extends ByteSource
-{
+public class ByteSourceInputStream extends ByteSource {
     private final InputStream is;
     private CacheBlock cacheHead = null;
     private static final int BLOCK_SIZE = 1024;
 
-    public ByteSourceInputStream(InputStream is, String filename)
-    {
+    public ByteSourceInputStream(InputStream is, String filename) {
         super(filename);
         this.is = new BufferedInputStream(is);
     }
 
-    private class CacheBlock
-    {
+    private class CacheBlock {
         public final byte bytes[];
         private CacheBlock next = null;
         private boolean triedNext = false;
 
-        public CacheBlock(final byte[] bytes)
-        {
+        public CacheBlock(final byte[] bytes) {
             this.bytes = bytes;
         }
 
-        public CacheBlock getNext() throws IOException
-        {
+        public CacheBlock getNext() throws IOException {
             if (null != next)
                 return next;
             if (triedNext)
@@ -59,23 +54,19 @@ public class ByteSourceInputStream exten
 
     private byte readBuffer[] = null;
 
-    private CacheBlock readBlock() throws IOException
-    {
+    private CacheBlock readBlock() throws IOException {
         if (null == readBuffer)
             readBuffer = new byte[BLOCK_SIZE];
 
         int read = is.read(readBuffer);
         if (read < 1)
             return null;
-        else if (read < BLOCK_SIZE)
-        {
+        else if (read < BLOCK_SIZE) {
             // return a copy.
             byte result[] = new byte[read];
             System.arraycopy(readBuffer, 0, result, 0, read);
             return new CacheBlock(result);
-        }
-        else
-        {
+        } else {
             // return current buffer.
             byte result[] = readBuffer;
             readBuffer = null;
@@ -83,32 +74,27 @@ public class ByteSourceInputStream exten
         }
     }
 
-    private CacheBlock getFirstBlock() throws IOException
-    {
+    private CacheBlock getFirstBlock() throws IOException {
         if (null == cacheHead)
             cacheHead = readBlock();
         return cacheHead;
     }
 
-    private class CacheReadingInputStream extends InputStream
-    {
+    private class CacheReadingInputStream extends InputStream {
         private CacheBlock block = null;
         private boolean readFirst = false;
         private int blockIndex = 0;
 
         @Override
-        public int read() throws IOException
-        {
-            if (null == block)
-            {
+        public int read() throws IOException {
+            if (null == block) {
                 if (readFirst)
                     return -1;
                 block = getFirstBlock();
                 readFirst = true;
             }
 
-            if (block != null && blockIndex >= block.bytes.length)
-            {
+            if (block != null && blockIndex >= block.bytes.length) {
                 block = block.getNext();
                 blockIndex = 0;
             }
@@ -123,8 +109,7 @@ public class ByteSourceInputStream exten
         }
 
         @Override
-        public int read(byte b[], int off, int len) throws IOException
-        {
+        public int read(byte b[], int off, int len) throws IOException {
             // first section copied verbatim from InputStream
             if (b == null)
                 throw new NullPointerException();
@@ -136,16 +121,14 @@ public class ByteSourceInputStream exten
 
             // optimized block read
 
-            if (null == block)
-            {
+            if (null == block) {
                 if (readFirst)
                     return -1;
                 block = getFirstBlock();
                 readFirst = true;
             }
 
-            if (block != null && blockIndex >= block.bytes.length)
-            {
+            if (block != null && blockIndex >= block.bytes.length) {
                 block = block.getNext();
                 blockIndex = 0;
             }
@@ -165,22 +148,19 @@ public class ByteSourceInputStream exten
     }
 
     @Override
-    public InputStream getInputStream() throws IOException
-    {
+    public InputStream getInputStream() throws IOException {
         return new CacheReadingInputStream();
     }
 
     @Override
-    public byte[] getBlock(int blockStart, int blockLength) throws IOException
-    {
+    public byte[] getBlock(int blockStart, int blockLength) throws IOException {
         // We include a separate check for int overflow.
-        if ((blockStart < 0)
-                || (blockLength < 0)
+        if ((blockStart < 0) || (blockLength < 0)
                 || (blockStart + blockLength < 0)
                 || (blockStart + blockLength > streamLength.longValue())) {
-            throw new IOException("Could not read block (block start: " + blockStart
-                    + ", block length: " + blockLength + ", data length: "
-                    + streamLength + ").");
+            throw new IOException("Could not read block (block start: "
+                    + blockStart + ", block length: " + blockLength
+                    + ", data length: " + streamLength + ").");
         }
 
         InputStream is = getInputStream();
@@ -188,8 +168,7 @@ public class ByteSourceInputStream exten
 
         byte bytes[] = new byte[blockLength];
         int total = 0;
-        while (true)
-        {
+        while (true) {
             int read = is.read(bytes, total, bytes.length - total);
             if (read < 1)
                 throw new IOException("Could not read block.");
@@ -202,8 +181,7 @@ public class ByteSourceInputStream exten
     private Long streamLength = null;
 
     @Override
-    public long getLength() throws IOException
-    {
+    public long getLength() throws IOException {
         if (streamLength != null)
             return streamLength.longValue();
 
@@ -217,13 +195,11 @@ public class ByteSourceInputStream exten
     }
 
     @Override
-    public byte[] getAll() throws IOException
-    {
+    public byte[] getAll() throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
         CacheBlock block = getFirstBlock();
-        while (block != null)
-        {
+        while (block != null) {
             baos.write(block.bytes);
             block = block.getNext();
         }
@@ -231,9 +207,8 @@ public class ByteSourceInputStream exten
     }
 
     @Override
-    public String getDescription()
-    {
+    public String getDescription() {
         return "Inputstream: '" + filename + "'";
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTree.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTree.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTree.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTree.java Sat May 26 15:35:04 2012
@@ -30,15 +30,17 @@ class HuffmanTree {
         boolean isEmpty = true;
         Object value = null;
     }
+
     private List<Node> nodes = new ArrayList<Node>();
 
-    public final void insert(String pattern, Object value) throws HuffmanTreeException {
+    public final void insert(String pattern, Object value)
+            throws HuffmanTreeException {
         int position = 0;
         Node node = growAndGetNode(position);
         if (node.value != null) {
             throw new HuffmanTreeException("Can't add child to a leaf");
         }
-        for(int patternPosition = 0; patternPosition < pattern.length(); patternPosition++) {
+        for (int patternPosition = 0; patternPosition < pattern.length(); patternPosition++) {
             char nextChar = pattern.charAt(patternPosition);
             if (nextChar == '0') {
                 position = (position << 1) + 1;
@@ -52,7 +54,7 @@ class HuffmanTree {
         }
         node.value = value;
     }
-    
+
     private Node growAndGetNode(int position) {
         while (position >= nodes.size()) {
             nodes.add(new Node());
@@ -61,8 +63,9 @@ class HuffmanTree {
         node.isEmpty = false;
         return node;
     }
-    
-    public final Object decode(BitInputStreamFlexible bitStream) throws HuffmanTreeException {
+
+    public final Object decode(BitInputStreamFlexible bitStream)
+            throws HuffmanTreeException {
         int position = 0;
         Node node = nodes.get(0);
         while (node.value == null) {
@@ -70,7 +73,8 @@ class HuffmanTree {
             try {
                 nextBit = bitStream.readBits(1);
             } catch (IOException ioEx) {
-                throw new HuffmanTreeException("Error reading stream for huffman tree", ioEx);
+                throw new HuffmanTreeException(
+                        "Error reading stream for huffman tree", ioEx);
             }
             if (nextBit == 0) {
                 position = (position << 1) + 1;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTreeException.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTreeException.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTreeException.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/HuffmanTreeException.java Sat May 26 15:35:04 2012
@@ -22,7 +22,7 @@ class HuffmanTreeException extends Excep
     public HuffmanTreeException(String message) {
         super(message);
     }
-    
+
     public HuffmanTreeException(String message, Throwable throwable) {
         super(message, throwable);
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java Sat May 26 15:35:04 2012
@@ -24,15 +24,14 @@ import org.apache.commons.imaging.ImageW
 import org.apache.commons.imaging.common.BitArrayOutputStream;
 import org.apache.commons.imaging.common.BitInputStreamFlexible;
 
-
 public class T4AndT6Compression {
     private static final HuffmanTree whiteRunLengths = new HuffmanTree();
     private static final HuffmanTree blackRunLengths = new HuffmanTree();
     private static final HuffmanTree controlCodes = new HuffmanTree();
-    
+
     private static final int WHITE = 0;
     private static final int BLACK = 1;
-    
+
     static {
         try {
             for (int i = 0; i < T4_T6_Tables.whiteTerminatingCodes.length; i++) {
@@ -57,13 +56,20 @@ public class T4AndT6Compression {
                 blackRunLengths.insert(entry.bitString, entry.value);
             }
             controlCodes.insert(T4_T6_Tables.EOL.bitString, T4_T6_Tables.EOL);
-            controlCodes.insert(T4_T6_Tables.EOL13.bitString, T4_T6_Tables.EOL13);
-            controlCodes.insert(T4_T6_Tables.EOL14.bitString, T4_T6_Tables.EOL14);
-            controlCodes.insert(T4_T6_Tables.EOL15.bitString, T4_T6_Tables.EOL15);
-            controlCodes.insert(T4_T6_Tables.EOL16.bitString, T4_T6_Tables.EOL16);
-            controlCodes.insert(T4_T6_Tables.EOL17.bitString, T4_T6_Tables.EOL17);
-            controlCodes.insert(T4_T6_Tables.EOL18.bitString, T4_T6_Tables.EOL18);
-            controlCodes.insert(T4_T6_Tables.EOL19.bitString, T4_T6_Tables.EOL19);
+            controlCodes.insert(T4_T6_Tables.EOL13.bitString,
+                    T4_T6_Tables.EOL13);
+            controlCodes.insert(T4_T6_Tables.EOL14.bitString,
+                    T4_T6_Tables.EOL14);
+            controlCodes.insert(T4_T6_Tables.EOL15.bitString,
+                    T4_T6_Tables.EOL15);
+            controlCodes.insert(T4_T6_Tables.EOL16.bitString,
+                    T4_T6_Tables.EOL16);
+            controlCodes.insert(T4_T6_Tables.EOL17.bitString,
+                    T4_T6_Tables.EOL17);
+            controlCodes.insert(T4_T6_Tables.EOL18.bitString,
+                    T4_T6_Tables.EOL18);
+            controlCodes.insert(T4_T6_Tables.EOL19.bitString,
+                    T4_T6_Tables.EOL19);
             controlCodes.insert(T4_T6_Tables.P.bitString, T4_T6_Tables.P);
             controlCodes.insert(T4_T6_Tables.H.bitString, T4_T6_Tables.H);
             controlCodes.insert(T4_T6_Tables.V0.bitString, T4_T6_Tables.V0);
@@ -76,9 +82,10 @@ public class T4AndT6Compression {
         } catch (HuffmanTreeException cannotHappen) {
         }
     }
-    
-    private static void compress1DLine(BitInputStreamFlexible inputStream, BitArrayOutputStream outputStream,
-            int[] referenceLine, int width) throws ImageWriteException {
+
+    private static void compress1DLine(BitInputStreamFlexible inputStream,
+            BitArrayOutputStream outputStream, int[] referenceLine, int width)
+            throws ImageWriteException {
         int color = WHITE;
         int runLength = 0;
         for (int x = 0; x < width; x++) {
@@ -95,22 +102,26 @@ public class T4AndT6Compression {
                     runLength = 1;
                 }
             } catch (IOException ioException) {
-                throw new ImageWriteException("Error reading image to compress", ioException);
+                throw new ImageWriteException(
+                        "Error reading image to compress", ioException);
             }
         }
         writeRunLength(outputStream, runLength, color);
     }
-    
+
     /**
-     * Compressed with the "Modified Huffman" encoding of section 10 in the TIFF6 specification.
-     * No EOLs, no RTC, rows are padded to end on a byte boundary.
+     * Compressed with the "Modified Huffman" encoding of section 10 in the
+     * TIFF6 specification. No EOLs, no RTC, rows are padded to end on a byte
+     * boundary.
+     * 
      * @param uncompressed
      * @param width
      * @param height
      * @return the compressed data
      * @throws ImageReadException
      */
-    public static byte[] compressModifiedHuffman(byte[] uncompressed, int width, int height) throws ImageWriteException {
+    public static byte[] compressModifiedHuffman(byte[] uncompressed,
+            int width, int height) throws ImageWriteException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(uncompressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -121,17 +132,20 @@ public class T4AndT6Compression {
         }
         return outputStream.toByteArray();
     }
-    
+
     /**
-     * Decompresses the "Modified Huffman" encoding of section 10 in the TIFF6 specification.
-     * No EOLs, no RTC, rows are padded to end on a byte boundary.
+     * Decompresses the "Modified Huffman" encoding of section 10 in the TIFF6
+     * specification. No EOLs, no RTC, rows are padded to end on a byte
+     * boundary.
+     * 
      * @param compressed
      * @param width
      * @param height
      * @return the decompressed data
      * @throws ImageReadException
      */
-    public static byte[] decompressModifiedHuffman(byte[] compressed, int width, int height) throws ImageReadException {
+    public static byte[] decompressModifiedHuffman(byte[] compressed,
+            int width, int height) throws ImageReadException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(compressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -146,18 +160,20 @@ public class T4AndT6Compression {
                 color = 1 - color;
                 rowLength += runLength;
             }
-            
+
             if (rowLength == width) {
                 inputStream.flushCache();
                 outputStream.flush();
             } else if (rowLength > width) {
-                throw new ImageReadException("Unrecoverable row length error in image row " + y);
+                throw new ImageReadException(
+                        "Unrecoverable row length error in image row " + y);
             }
         }
         return outputStream.toByteArray();
     }
 
-    public static byte[] compressT4_1D(byte[] uncompressed, int width, int height, boolean hasFill) throws ImageWriteException {
+    public static byte[] compressT4_1D(byte[] uncompressed, int width,
+            int height, boolean hasFill) throws ImageWriteException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(uncompressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -169,7 +185,8 @@ public class T4AndT6Compression {
         for (int y = 0; y < height; y++) {
             compress1DLine(inputStream, outputStream, null, width);
             if (hasFill) {
-                int bitsAvailable = outputStream.getBitsAvailableInCurrentByte();
+                int bitsAvailable = outputStream
+                        .getBitsAvailableInCurrentByte();
                 if (bitsAvailable < 4) {
                     outputStream.flush();
                     bitsAvailable = 8;
@@ -183,17 +200,19 @@ public class T4AndT6Compression {
         }
         return outputStream.toByteArray();
     }
-    
+
     /**
-     * Decompresses T.4 1D encoded data. EOL at the beginning and after each row,
-     * can be preceded by fill bits to fit on a byte boundary, no RTC.
+     * Decompresses T.4 1D encoded data. EOL at the beginning and after each
+     * row, can be preceded by fill bits to fit on a byte boundary, no RTC.
+     * 
      * @param compressed
      * @param width
      * @param height
      * @return the decompressed data
      * @throws ImageReadException
      */
-    public static byte[] decompressT4_1D(byte[] compressed, int width, int height, boolean hasFill) throws ImageReadException {
+    public static byte[] decompressT4_1D(byte[] compressed, int width,
+            int height, boolean hasFill) throws ImageReadException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(compressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -215,19 +234,23 @@ public class T4AndT6Compression {
                     rowLength += runLength;
                 }
             } catch (HuffmanTreeException huffmanException) {
-                throw new ImageReadException("Decompression error", huffmanException);
+                throw new ImageReadException("Decompression error",
+                        huffmanException);
             }
-            
+
             if (rowLength == width) {
                 outputStream.flush();
             } else if (rowLength > width) {
-                throw new ImageReadException("Unrecoverable row length error in image row " + y);
+                throw new ImageReadException(
+                        "Unrecoverable row length error in image row " + y);
             }
         }
         return outputStream.toByteArray();
     }
 
-    public static byte[] compressT4_2D(byte[] uncompressed, int width, int height, boolean hasFill, int parameterK) throws ImageWriteException {
+    public static byte[] compressT4_2D(byte[] uncompressed, int width,
+            int height, boolean hasFill, int parameterK)
+            throws ImageWriteException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(uncompressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -247,15 +270,17 @@ public class T4AndT6Compression {
                     try {
                         codingLine[i] = inputStream.readBits(1);
                     } catch (IOException ioException) {
-                        throw new ImageWriteException("Error reading image to compress", ioException);
+                        throw new ImageWriteException(
+                                "Error reading image to compress", ioException);
                     }
                 }
                 int codingA0Color = WHITE;
                 int referenceA0Color = WHITE;
                 int a1 = nextChangingElement(codingLine, codingA0Color, 0);
                 int b1 = nextChangingElement(referenceLine, referenceA0Color, 0);
-                int b2 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
-                for (int a0 = 0; a0 < width; ) {
+                int b2 = nextChangingElement(referenceLine,
+                        1 - referenceA0Color, b1 + 1);
+                for (int a0 = 0; a0 < width;) {
                     if (b2 < a1) {
                         T4_T6_Tables.P.writeBits(outputStream);
                         a0 = b2;
@@ -282,24 +307,30 @@ public class T4AndT6Compression {
                             codingA0Color = 1 - codingA0Color;
                             a0 = a1;
                         } else {
-                            int a2 = nextChangingElement(codingLine, 1 - codingA0Color, a1 + 1);
+                            int a2 = nextChangingElement(codingLine,
+                                    1 - codingA0Color, a1 + 1);
                             int a0a1 = a1 - a0;
                             int a1a2 = a2 - a1;
                             T4_T6_Tables.H.writeBits(outputStream);
                             writeRunLength(outputStream, a0a1, codingA0Color);
-                            writeRunLength(outputStream, a1a2, 1 - codingA0Color);
+                            writeRunLength(outputStream, a1a2,
+                                    1 - codingA0Color);
                             a0 = a2;
                         }
                     }
                     referenceA0Color = changingElementAt(referenceLine, a0);
                     a1 = nextChangingElement(codingLine, codingA0Color, a0 + 1);
                     if (codingA0Color == referenceA0Color) {
-                        b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
+                        b1 = nextChangingElement(referenceLine,
+                                referenceA0Color, a0 + 1);
                     } else {
-                        b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
-                        b1 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
+                        b1 = nextChangingElement(referenceLine,
+                                referenceA0Color, a0 + 1);
+                        b1 = nextChangingElement(referenceLine,
+                                1 - referenceA0Color, b1 + 1);
                     }
-                    b2 = nextChangingElement(referenceLine, 1 - codingA0Color, b1 + 1);
+                    b2 = nextChangingElement(referenceLine, 1 - codingA0Color,
+                            b1 + 1);
                 }
                 int[] swap = referenceLine;
                 referenceLine = codingLine;
@@ -310,7 +341,8 @@ public class T4AndT6Compression {
                 compress1DLine(inputStream, outputStream, referenceLine, width);
             }
             if (hasFill) {
-                int bitsAvailable = outputStream.getBitsAvailableInCurrentByte();
+                int bitsAvailable = outputStream
+                        .getBitsAvailableInCurrentByte();
                 if (bitsAvailable < 4) {
                     outputStream.flush();
                     bitsAvailable = 8;
@@ -328,19 +360,21 @@ public class T4AndT6Compression {
         }
         return outputStream.toByteArray();
     }
-    
+
     /**
-     * Decompressed T.4 2D encoded data. EOL at the beginning and after each row,
-     * can be preceded by fill bits to fit on a byte boundary, and is succeeded
-     * by a tag bit determining whether the next line is encoded using 1D or 2D.
-     * No RTC.
+     * Decompressed T.4 2D encoded data. EOL at the beginning and after each
+     * row, can be preceded by fill bits to fit on a byte boundary, and is
+     * succeeded by a tag bit determining whether the next line is encoded using
+     * 1D or 2D. No RTC.
+     * 
      * @param compressed
      * @param width
      * @param height
      * @return the decompressed data
      * @throws ImageReadException
      */
-    public static byte[] decompressT4_2D(byte[] compressed, int width, int height, boolean hasFill) throws ImageReadException {
+    public static byte[] decompressT4_2D(byte[] compressed, int width,
+            int height, boolean hasFill) throws ImageReadException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(compressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -358,21 +392,29 @@ public class T4AndT6Compression {
                     // 2D
                     int codingA0Color = WHITE;
                     int referenceA0Color = WHITE;
-                    int b1 = nextChangingElement(referenceLine, referenceA0Color, 0);
-                    int b2 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
-                    for (int a0 = 0; a0 < width; ) {
+                    int b1 = nextChangingElement(referenceLine,
+                            referenceA0Color, 0);
+                    int b2 = nextChangingElement(referenceLine,
+                            1 - referenceA0Color, b1 + 1);
+                    for (int a0 = 0; a0 < width;) {
                         int a1, a2;
-                        entry = (T4_T6_Tables.Entry) controlCodes.decode(inputStream);
+                        entry = (T4_T6_Tables.Entry) controlCodes
+                                .decode(inputStream);
                         if (entry == T4_T6_Tables.P) {
-                            fillRange(outputStream, referenceLine, a0, b2, codingA0Color);
+                            fillRange(outputStream, referenceLine, a0, b2,
+                                    codingA0Color);
                             a0 = b2;
                         } else if (entry == T4_T6_Tables.H) {
-                            int a0a1 = readTotalRunLength(inputStream, codingA0Color);
+                            int a0a1 = readTotalRunLength(inputStream,
+                                    codingA0Color);
                             a1 = a0 + a0a1;
-                            fillRange(outputStream, referenceLine, a0, a1, codingA0Color);
-                            int a1a2 = readTotalRunLength(inputStream, 1 - codingA0Color);
+                            fillRange(outputStream, referenceLine, a0, a1,
+                                    codingA0Color);
+                            int a1a2 = readTotalRunLength(inputStream,
+                                    1 - codingA0Color);
                             a2 = a1 + a1a2;
-                            fillRange(outputStream, referenceLine, a1, a2, 1 - codingA0Color);
+                            fillRange(outputStream, referenceLine, a1, a2,
+                                    1 - codingA0Color);
                             a0 = a2;
                         } else {
                             int a1b1;
@@ -391,21 +433,28 @@ public class T4AndT6Compression {
                             } else if (entry == T4_T6_Tables.VR3) {
                                 a1b1 = 3;
                             } else {
-                                throw new ImageReadException("Invalid/unknown T.4 control code " + entry.bitString);
+                                throw new ImageReadException(
+                                        "Invalid/unknown T.4 control code "
+                                                + entry.bitString);
                             }
                             a1 = b1 + a1b1;
-                            fillRange(outputStream, referenceLine, a0, a1, codingA0Color);
+                            fillRange(outputStream, referenceLine, a0, a1,
+                                    codingA0Color);
                             a0 = a1;
                             codingA0Color = 1 - codingA0Color;
                         }
                         referenceA0Color = changingElementAt(referenceLine, a0);
                         if (codingA0Color == referenceA0Color) {
-                            b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
+                            b1 = nextChangingElement(referenceLine,
+                                    referenceA0Color, a0 + 1);
                         } else {
-                            b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
-                            b1 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
+                            b1 = nextChangingElement(referenceLine,
+                                    referenceA0Color, a0 + 1);
+                            b1 = nextChangingElement(referenceLine,
+                                    1 - referenceA0Color, b1 + 1);
                         }
-                        b2 = nextChangingElement(referenceLine, 1 - codingA0Color, b1 + 1);
+                        b2 = nextChangingElement(referenceLine,
+                                1 - codingA0Color, b1 + 1);
                         rowLength = a0;
                     }
                 } else {
@@ -424,19 +473,22 @@ public class T4AndT6Compression {
             } catch (IOException ioException) {
                 throw new ImageReadException("Decompression error", ioException);
             } catch (HuffmanTreeException huffmanException) {
-                throw new ImageReadException("Decompression error", huffmanException);
+                throw new ImageReadException("Decompression error",
+                        huffmanException);
             }
-            
+
             if (rowLength == width) {
                 outputStream.flush();
             } else if (rowLength > width) {
-                throw new ImageReadException("Unrecoverable row length error in image row " + y);
+                throw new ImageReadException(
+                        "Unrecoverable row length error in image row " + y);
             }
         }
         return outputStream.toByteArray();
     }
 
-    public static byte[] compressT6(byte[] uncompressed, int width, int height) throws ImageWriteException {
+    public static byte[] compressT6(byte[] uncompressed, int width, int height)
+            throws ImageWriteException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(uncompressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -447,15 +499,17 @@ public class T4AndT6Compression {
                 try {
                     codingLine[i] = inputStream.readBits(1);
                 } catch (IOException ioException) {
-                    throw new ImageWriteException("Error reading image to compress", ioException);
+                    throw new ImageWriteException(
+                            "Error reading image to compress", ioException);
                 }
             }
             int codingA0Color = WHITE;
             int referenceA0Color = WHITE;
             int a1 = nextChangingElement(codingLine, codingA0Color, 0);
             int b1 = nextChangingElement(referenceLine, referenceA0Color, 0);
-            int b2 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
-            for (int a0 = 0; a0 < width; ) {
+            int b2 = nextChangingElement(referenceLine, 1 - referenceA0Color,
+                    b1 + 1);
+            for (int a0 = 0; a0 < width;) {
                 if (b2 < a1) {
                     T4_T6_Tables.P.writeBits(outputStream);
                     a0 = b2;
@@ -482,7 +536,8 @@ public class T4AndT6Compression {
                         codingA0Color = 1 - codingA0Color;
                         a0 = a1;
                     } else {
-                        int a2 = nextChangingElement(codingLine, 1 - codingA0Color, a1 + 1);
+                        int a2 = nextChangingElement(codingLine,
+                                1 - codingA0Color, a1 + 1);
                         int a0a1 = a1 - a0;
                         int a1a2 = a2 - a1;
                         T4_T6_Tables.H.writeBits(outputStream);
@@ -494,12 +549,16 @@ public class T4AndT6Compression {
                 referenceA0Color = changingElementAt(referenceLine, a0);
                 a1 = nextChangingElement(codingLine, codingA0Color, a0 + 1);
                 if (codingA0Color == referenceA0Color) {
-                    b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
+                    b1 = nextChangingElement(referenceLine, referenceA0Color,
+                            a0 + 1);
                 } else {
-                    b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
-                    b1 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
+                    b1 = nextChangingElement(referenceLine, referenceA0Color,
+                            a0 + 1);
+                    b1 = nextChangingElement(referenceLine,
+                            1 - referenceA0Color, b1 + 1);
                 }
-                b2 = nextChangingElement(referenceLine, 1 - codingA0Color, b1 + 1);
+                b2 = nextChangingElement(referenceLine, 1 - codingA0Color,
+                        b1 + 1);
             }
             int[] swap = referenceLine;
             referenceLine = codingLine;
@@ -511,17 +570,20 @@ public class T4AndT6Compression {
         T4_T6_Tables.EOL.writeBits(outputStream);
         return outputStream.toByteArray();
     }
-    
+
     /**
-     * Decompress T.6 encoded data. No EOLs, except for 2 consecutive ones at the end
-     * (the EOFB, end of fax block). No RTC. No fill bits anywhere. All data is 2D encoded.
+     * Decompress T.6 encoded data. No EOLs, except for 2 consecutive ones at
+     * the end (the EOFB, end of fax block). No RTC. No fill bits anywhere. All
+     * data is 2D encoded.
+     * 
      * @param compressed
      * @param width
      * @param height
      * @return the decompressed data
      * @throws ImageReadException
      */
-    public static byte[] decompressT6(byte[] compressed, int width, int height) throws ImageReadException {
+    public static byte[] decompressT6(byte[] compressed, int width, int height)
+            throws ImageReadException {
         BitInputStreamFlexible inputStream = new BitInputStreamFlexible(
                 new ByteArrayInputStream(compressed));
         BitArrayOutputStream outputStream = new BitArrayOutputStream();
@@ -533,20 +595,27 @@ public class T4AndT6Compression {
                 int codingA0Color = WHITE;
                 int referenceA0Color = WHITE;
                 int b1 = nextChangingElement(referenceLine, referenceA0Color, 0);
-                int b2 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
-                for (int a0 = 0; a0 < width; ) {
+                int b2 = nextChangingElement(referenceLine,
+                        1 - referenceA0Color, b1 + 1);
+                for (int a0 = 0; a0 < width;) {
                     int a1, a2;
-                    entry = (T4_T6_Tables.Entry) controlCodes.decode(inputStream);
+                    entry = (T4_T6_Tables.Entry) controlCodes
+                            .decode(inputStream);
                     if (entry == T4_T6_Tables.P) {
-                        fillRange(outputStream, referenceLine, a0, b2, codingA0Color);
+                        fillRange(outputStream, referenceLine, a0, b2,
+                                codingA0Color);
                         a0 = b2;
                     } else if (entry == T4_T6_Tables.H) {
-                        int a0a1 = readTotalRunLength(inputStream, codingA0Color);
+                        int a0a1 = readTotalRunLength(inputStream,
+                                codingA0Color);
                         a1 = a0 + a0a1;
-                        fillRange(outputStream, referenceLine, a0, a1, codingA0Color);
-                        int a1a2 = readTotalRunLength(inputStream, 1 - codingA0Color);
+                        fillRange(outputStream, referenceLine, a0, a1,
+                                codingA0Color);
+                        int a1a2 = readTotalRunLength(inputStream,
+                                1 - codingA0Color);
                         a2 = a1 + a1a2;
-                        fillRange(outputStream, referenceLine, a1, a2, 1 - codingA0Color);
+                        fillRange(outputStream, referenceLine, a1, a2,
+                                1 - codingA0Color);
                         a0 = a2;
                     } else {
                         int a1b1;
@@ -565,54 +634,63 @@ public class T4AndT6Compression {
                         } else if (entry == T4_T6_Tables.VR3) {
                             a1b1 = 3;
                         } else {
-                            throw new ImageReadException("Invalid/unknown T.6 control code " + entry.bitString);
+                            throw new ImageReadException(
+                                    "Invalid/unknown T.6 control code "
+                                            + entry.bitString);
                         }
                         a1 = b1 + a1b1;
-                        fillRange(outputStream, referenceLine, a0, a1, codingA0Color);
+                        fillRange(outputStream, referenceLine, a0, a1,
+                                codingA0Color);
                         a0 = a1;
                         codingA0Color = 1 - codingA0Color;
                     }
                     referenceA0Color = changingElementAt(referenceLine, a0);
                     if (codingA0Color == referenceA0Color) {
-                        b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
+                        b1 = nextChangingElement(referenceLine,
+                                referenceA0Color, a0 + 1);
                     } else {
-                        b1 = nextChangingElement(referenceLine, referenceA0Color, a0 + 1);
-                        b1 = nextChangingElement(referenceLine, 1 - referenceA0Color, b1 + 1);
+                        b1 = nextChangingElement(referenceLine,
+                                referenceA0Color, a0 + 1);
+                        b1 = nextChangingElement(referenceLine,
+                                1 - referenceA0Color, b1 + 1);
                     }
-                    b2 = nextChangingElement(referenceLine, 1 - codingA0Color, b1 + 1);
+                    b2 = nextChangingElement(referenceLine, 1 - codingA0Color,
+                            b1 + 1);
                     rowLength = a0;
                 }
             } catch (HuffmanTreeException huffmanException) {
-                throw new ImageReadException("Decompression error", huffmanException);
+                throw new ImageReadException("Decompression error",
+                        huffmanException);
             }
-            
+
             if (rowLength == width) {
                 outputStream.flush();
             } else if (rowLength > width) {
-                throw new ImageReadException("Unrecoverable row length error in image row " + y);
+                throw new ImageReadException(
+                        "Unrecoverable row length error in image row " + y);
             }
         }
         return outputStream.toByteArray();
     }
-    
+
     private static boolean isEOL(T4_T6_Tables.Entry entry, boolean hasFill) {
         if (entry == T4_T6_Tables.EOL) {
             return true;
         }
         if (hasFill) {
-            return entry == T4_T6_Tables.EOL13 ||
-                    entry == T4_T6_Tables.EOL14 ||
-                    entry == T4_T6_Tables.EOL15 ||
-                    entry == T4_T6_Tables.EOL16 ||
-                    entry == T4_T6_Tables.EOL17 ||
-                    entry == T4_T6_Tables.EOL18 ||
-                    entry == T4_T6_Tables.EOL19;            
+            return entry == T4_T6_Tables.EOL13 || entry == T4_T6_Tables.EOL14
+                    || entry == T4_T6_Tables.EOL15
+                    || entry == T4_T6_Tables.EOL16
+                    || entry == T4_T6_Tables.EOL17
+                    || entry == T4_T6_Tables.EOL18
+                    || entry == T4_T6_Tables.EOL19;
         } else {
             return false;
         }
     }
-    
-    private static void writeRunLength(BitArrayOutputStream bitStream, int runLength, int color) {
+
+    private static void writeRunLength(BitArrayOutputStream bitStream,
+            int runLength, int color) {
         final T4_T6_Tables.Entry[] makeUpCodes;
         final T4_T6_Tables.Entry[] terminatingCodes;
         if (color == WHITE) {
@@ -623,7 +701,8 @@ public class T4AndT6Compression {
             terminatingCodes = T4_T6_Tables.blackTerminatingCodes;
         }
         while (runLength >= 1792) {
-            T4_T6_Tables.Entry entry = lowerBound(T4_T6_Tables.additionalMakeUpCodes, runLength);
+            T4_T6_Tables.Entry entry = lowerBound(
+                    T4_T6_Tables.additionalMakeUpCodes, runLength);
             entry.writeBits(bitStream);
             runLength -= entry.value.intValue();
         }
@@ -635,14 +714,16 @@ public class T4AndT6Compression {
         T4_T6_Tables.Entry terminatingEntry = terminatingCodes[runLength];
         terminatingEntry.writeBits(bitStream);
     }
-    
-    private static T4_T6_Tables.Entry lowerBound(T4_T6_Tables.Entry[] entries, int value) {
+
+    private static T4_T6_Tables.Entry lowerBound(T4_T6_Tables.Entry[] entries,
+            int value) {
         int first = 0;
         int last = entries.length - 1;
         do {
             int middle = (first + last) >>> 2;
-            if (entries[middle].value.intValue() <= value &&
-                    ((middle + 1) >= entries.length || value < entries[middle + 1].value.intValue())) {
+            if (entries[middle].value.intValue() <= value
+                    && ((middle + 1) >= entries.length || value < entries[middle + 1].value
+                            .intValue())) {
                 return entries[middle];
             } else if (entries[middle].value.intValue() > value) {
                 last = middle - 1;
@@ -652,42 +733,46 @@ public class T4AndT6Compression {
         } while (first < last);
         return entries[first];
     }
-    
-    private static int readTotalRunLength(BitInputStreamFlexible bitStream, int color) throws ImageReadException {
+
+    private static int readTotalRunLength(BitInputStreamFlexible bitStream,
+            int color) throws ImageReadException {
         try {
             int totalLength = 0;
             Integer runLength;
             do {
                 if (color == WHITE) {
-                    runLength = (Integer)whiteRunLengths.decode(bitStream);
+                    runLength = (Integer) whiteRunLengths.decode(bitStream);
                 } else {
-                    runLength = (Integer)blackRunLengths.decode(bitStream);
+                    runLength = (Integer) blackRunLengths.decode(bitStream);
                 }
                 totalLength += runLength.intValue();
             } while (runLength.intValue() > 63);
             return totalLength;
         } catch (HuffmanTreeException huffmanException) {
-            throw new ImageReadException("Decompression error", huffmanException);
+            throw new ImageReadException("Decompression error",
+                    huffmanException);
         }
     }
-    
+
     private static int changingElementAt(int[] line, int position) {
         if (position < 0 || position >= line.length) {
             return WHITE;
         }
         return line[position];
     }
-    
-    private static int nextChangingElement(int[] line, int currentColour, int start) {
+
+    private static int nextChangingElement(int[] line, int currentColour,
+            int start) {
         int position;
-        for (position = start; position < line.length && line[position] == currentColour; position++) {
+        for (position = start; position < line.length
+                && line[position] == currentColour; position++) {
             // noop
         }
         return position < line.length ? position : line.length;
     }
-    
-    private static void fillRange(BitArrayOutputStream outputStream, int[] referenceRow,
-            int a0, int end, int color) {
+
+    private static void fillRange(BitArrayOutputStream outputStream,
+            int[] referenceRow, int a0, int end, int color) {
         for (int i = a0; i < end; i++) {
             referenceRow[i] = color;
             outputStream.writeBit(color);



Mime
View raw message