commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1441595 - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/common/ main/java/org/apache/commons/imaging/formats/jpeg/ main/java/org/apache/commons/imaging/formats/pcx/ test/java/org/apache/commons/imaging/common/
Date Fri, 01 Feb 2013 19:31:29 GMT
Author: damjan
Date: Fri Feb  1 19:31:28 2013
New Revision: 1441595

URL: http://svn.apache.org/viewvc?rev=1441595&view=rev
Log:
Extensive cleanups and javadocs.


Added:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java
      - copied, changed from r1440856, commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java
Removed:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java
Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/PackBits.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ZLibUtils.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
    commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/BinaryFileFunctionsTest.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BasicCParser.java Fri Feb  1 19:31:28 2013
@@ -24,6 +24,10 @@ import java.util.Map;
 
 import org.apache.commons.imaging.ImageReadException;
 
+/**
+ * A rudimentary preprocessor and parser for the C programming
+ * language. 
+ */
 public class BasicCParser {
     private final PushbackInputStream is;
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryConversions.java Fri Feb  1 19:31:28 2013
@@ -390,7 +390,7 @@ public class BinaryConversions {
         final int byte1 = 0xff & bytes[offset + 1];
         final int byte2 = 0xff & bytes[offset + 2];
         final int byte3 = 0xff & bytes[offset + 3];
-        int bits;
+        final int bits;
         if (byteOrder == ByteOrder.MOTOROLA) {
             bits = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (byte3 << 0);
         } else {
@@ -430,7 +430,7 @@ public class BinaryConversions {
         final long byte5 = 0xffL & bytes[offset + 5];
         final long byte6 = 0xffL & bytes[offset + 6];
         final long byte7 = 0xffL & bytes[offset + 7];
-        long bits;
+        final long bits;
         if (byteOrder == ByteOrder.MOTOROLA) {
             bits = (byte0 << 56) | (byte1 << 48) | (byte2 << 40)
                     | (byte3 << 32) | (byte4 << 24) | (byte5 << 16)
@@ -475,8 +475,8 @@ public class BinaryConversions {
         final int byte5 = 0xff & bytes[offset + 5];
         final int byte6 = 0xff & bytes[offset + 6];
         final int byte7 = 0xff & bytes[offset + 7];
-        int numerator;
-        int divisor;
+        final int numerator;
+        final int divisor;
         if (byteOrder == ByteOrder.MOTOROLA) {
             numerator = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3;
             divisor = (byte4 << 24) | (byte5 << 16) | (byte6 << 8) | byte7;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java Fri Feb  1 19:31:28 2013
@@ -204,88 +204,6 @@ public class BinaryFileFunctions {
         return (byte) (0xff & result);
     }
 
-    protected final RationalNumber[] convertByteArrayToRationalArray(
-            final String name, final byte bytes[], final int start, final int length, final ByteOrder byteOrder) {
-        final int expectedLength = start + length * 8;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final RationalNumber result[] = new RationalNumber[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToRational(name, bytes, start + i * 8,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
-    protected final RationalNumber convertByteArrayToRational(final String name,
-            final byte bytes[], final ByteOrder byteOrder) {
-        return convertByteArrayToRational(name, bytes, 0, byteOrder);
-    }
-
-    protected final RationalNumber convertByteArrayToRational(final String name,
-            final byte bytes[], final int start, final ByteOrder byteOrder) {
-        final int numerator = convertByteArrayToInt(name, bytes, start + 0, byteOrder);
-        final int divisor = convertByteArrayToInt(name, bytes, start + 4, byteOrder);
-
-        return new RationalNumber(numerator, divisor);
-    }
-
-    protected final int convertByteArrayToInt(final String name, final byte bytes[],
-            final ByteOrder byteOrder) {
-        return convertByteArrayToInt(name, bytes, 0, byteOrder);
-    }
-
-    protected final int convertByteArrayToInt(final String name, final byte bytes[],
-            final int start, final ByteOrder byteOrder) {
-        final byte byte0 = bytes[start + 0];
-        final byte byte1 = bytes[start + 1];
-        final byte byte2 = bytes[start + 2];
-        final byte byte3 = bytes[start + 3];
-
-        int result;
-
-        if (byteOrder == ByteOrder.MOTOROLA) {
-            result = ((0xff & byte0) << 24) | ((0xff & byte1) << 16)
-                    | ((0xff & byte2) << 8) | ((0xff & byte3) << 0);
-        } else {
-            result = ((0xff & byte3) << 24) | ((0xff & byte2) << 16)
-                    | ((0xff & byte1) << 8) | ((0xff & byte0) << 0);
-        }
-
-        if (debug) {
-            debugNumber(name, result, 4);
-        }
-
-        return result;
-    }
-
-    protected final int[] convertByteArrayToIntArray(final String name, final byte bytes[],
-            final int start, final int length, final ByteOrder byteOrder) {
-        final int expectedLength = start + length * 4;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final int result[] = new int[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToInt(name, bytes, start + i * 4,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
     protected final void writeIntInToByteArray(final int value, final byte bytes[],
             final int start, final ByteOrder byteOrder) {
         if (byteOrder == ByteOrder.MOTOROLA) {
@@ -309,36 +227,6 @@ public class BinaryFileFunctions {
         }
     }
 
-    protected final byte[] convertIntArrayToByteArray(final int values[],
-            final ByteOrder byteOrder) {
-        final byte result[] = new byte[values.length * 4];
-
-        for (int i = 0; i < values.length; i++) {
-            writeIntInToByteArray(values[i], result, i * 4, byteOrder);
-        }
-
-        return result;
-    }
-
-    protected final byte[] convertShortArrayToByteArray(final int values[],
-            final ByteOrder byteOrder) {
-        final byte result[] = new byte[values.length * 2];
-
-        for (int i = 0; i < values.length; i++) {
-            final int value = values[i];
-
-            if (byteOrder == ByteOrder.MOTOROLA) {
-                result[i * 2 + 0] = (byte) (value >> 8);
-                result[i * 2 + 1] = (byte) (value >> 0);
-            } else {
-                result[i * 2 + 1] = (byte) (value >> 8);
-                result[i * 2 + 0] = (byte) (value >> 0);
-            }
-        }
-
-        return result;
-    }
-
     protected final byte[] convertShortToByteArray(final int value, final ByteOrder byteOrder) {
         final byte result[] = new byte[2];
 
@@ -371,31 +259,6 @@ public class BinaryFileFunctions {
         return result;
     }
 
-    protected final byte[] convertRationalArrayToByteArray(
-            final RationalNumber numbers[], final ByteOrder byteOrder) {
-        // Debug.debug("convertRationalArrayToByteArray 2");
-        final byte result[] = new byte[numbers.length * 8];
-
-        for (int i = 0; i < numbers.length; i++) {
-            writeIntInToByteArray(numbers[i].numerator, result, i * 8,
-                    byteOrder);
-            writeIntInToByteArray(numbers[i].divisor, result, i * 8 + 4,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
-    protected final byte[] convertRationalToByteArray(final RationalNumber number,
-            final ByteOrder byteOrder) {
-        final byte result[] = new byte[8];
-
-        writeIntInToByteArray(number.numerator, result, 0, byteOrder);
-        writeIntInToByteArray(number.divisor, result, 4, byteOrder);
-
-        return result;
-    }
-
     protected final int convertByteArrayToShort(final String name, final byte bytes[],
             final ByteOrder byteOrder) throws ImageReadException {
         return convertByteArrayToShort(name, 0, bytes, byteOrder);
@@ -427,29 +290,6 @@ public class BinaryFileFunctions {
         return result;
     }
 
-    protected final int[] convertByteArrayToShortArray(final String name,
-            final byte bytes[], final int start, final int length, final ByteOrder byteOrder)
-            throws ImageReadException
-
-    {
-        final int expectedLength = start + length * 2;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final int result[] = new int[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToShort(name, start + i * 2, bytes,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
     public final byte[] readByteArray(final String name, final int length, final InputStream is)
             throws IOException {
         final String exception = name + " could not be read.";
@@ -606,36 +446,46 @@ public class BinaryFileFunctions {
 
     protected final int read4Bytes(final String name, final InputStream is,
             final String exception, final ByteOrder byteOrder) throws IOException {
-        final int size = 4;
-        final byte bytes[] = new byte[size];
+        final int byte0 = is.read();
+        final int byte1 = is.read();
+        final int byte2 = is.read();
+        final int byte3 = is.read();
+        if ((byte0 | byte1 | byte2 | byte3) < 0) {
+            throw new IOException(exception);
+        }
 
-        int read = 0;
-        while (read < size) {
-            final int count = is.read(bytes, read, size - read);
-            if (count < 1) {
-                throw new IOException(exception);
-            }
+        final int result;
+        if (byteOrder == ByteOrder.MOTOROLA) {
+            result = (byte0 << 24) | (byte1 << 16)
+                    | (byte2 << 8) | (byte3 << 0);
+        } else {
+            result = (byte3 << 24) | (byte2 << 16)
+                    | (byte1 << 8) | (byte0 << 0);
+        }
 
-            read += count;
+        if (debug) {
+            debugNumber(name, result, 4);
         }
 
-        return convertByteArrayToInt(name, bytes, byteOrder);
+        return result;
     }
 
     protected final int read3Bytes(final String name, final InputStream is,
             final String exception, final ByteOrder byteOrder) throws IOException {
-        final byte byte0 = (byte) is.read();
-        final byte byte1 = (byte) is.read();
-        final byte byte2 = (byte) is.read();
-
-        int result;
+        final int byte0 = is.read();
+        final int byte1 = is.read();
+        final int byte2 = is.read();
+        if ((byte0 | byte1 | byte2) < 0) {
+            throw new IOException(exception);
+        }
 
+        final int result;
         if (byteOrder == ByteOrder.MOTOROLA) {
-            result = ((0xff & byte0) << 16) | ((0xff & byte1) << 8)
-                    | ((0xff & byte2) << 0);
+            result = (byte0 << 16) | (byte1 << 8)
+                    | (byte2 << 0);
         } else {
-            result = ((0xff & byte2) << 16) | ((0xff & byte1) << 8)
-                    | ((0xff & byte0) << 0);
+            result = (byte2 << 16) | (byte1 << 8)
+                    | (byte0 << 0);
         }
 
         if (debug) {
@@ -648,20 +498,24 @@ public class BinaryFileFunctions {
     protected final int read2Bytes(final String name, final InputStream is,
             final String exception, final ByteOrder byteOrder) throws ImageReadException,
             IOException {
-        final int size = 2;
-        final byte bytes[] = new byte[size];
-
-        int read = 0;
-        while (read < size) {
-            final int count = is.read(bytes, read, size - read);
-            if (count < 1) {
-                throw new IOException(exception);
-            }
-
-            read += count;
+        final int byte0 = is.read();
+        final int byte1 = is.read();
+        if ((byte0 | byte1) < 0) {
+            throw new IOException(exception);
+        }
+        
+        final int result;
+        if (byteOrder == ByteOrder.MOTOROLA) {
+            result = (byte0 << 8) | byte1;
+        } else {
+            result = (byte1 << 8) | byte0;
+        }
+        
+        if (debug) {
+            debugNumber(name, result, 2);
         }
 
-        return convertByteArrayToShort(name, bytes, byteOrder);
+        return result;
     }
 
     protected final void printCharQuad(final String msg, final int i) {
@@ -724,162 +578,6 @@ public class BinaryFileFunctions {
 
     }
 
-    protected final float convertByteArrayToFloat(final String name, final byte bytes[],
-            final ByteOrder byteOrder) {
-        return convertByteArrayToFloat(name, bytes, 0, byteOrder);
-    }
-
-    protected final float convertByteArrayToFloat(final String name, final byte bytes[],
-            final int start, final ByteOrder byteOrder) {
-        // TODO: not tested; probably wrong.
-
-        final byte byte0 = bytes[start + 0];
-        final byte byte1 = bytes[start + 1];
-        final byte byte2 = bytes[start + 2];
-        final byte byte3 = bytes[start + 3];
-
-        int bits;
-
-        if (byteOrder == ByteOrder.MOTOROLA) {
-            bits = ((0xff & byte0) << 24) | ((0xff & byte1) << 16)
-                    | ((0xff & byte2) << 8) | ((0xff & byte3) << 0);
-        } else {
-            bits = ((0xff & byte3) << 24) | ((0xff & byte2) << 16)
-                    | ((0xff & byte1) << 8) | ((0xff & byte0) << 0);
-        }
-
-        final float result = Float.intBitsToFloat(bits);
-
-        return result;
-    }
-
-    protected final float[] convertByteArrayToFloatArray(final String name,
-            final byte bytes[], final int start, final int length, final ByteOrder byteOrder) {
-        final int expectedLength = start + length * 4;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final float result[] = new float[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToFloat(name, bytes, start + i * 4,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
-    protected final byte[] convertFloatToByteArray(final float value, final ByteOrder byteOrder) {
-        final byte result[] = new byte[4];
-
-        final int bits = Float.floatToRawIntBits(value);
-
-        if (byteOrder == ByteOrder.INTEL) {
-            result[0] = (byte) (0xff & (bits >> 0));
-            result[1] = (byte) (0xff & (bits >> 8));
-            result[2] = (byte) (0xff & (bits >> 16));
-            result[3] = (byte) (0xff & (bits >> 24));
-        } else {
-            result[3] = (byte) (0xff & (bits >> 0));
-            result[2] = (byte) (0xff & (bits >> 8));
-            result[1] = (byte) (0xff & (bits >> 16));
-            result[0] = (byte) (0xff & (bits >> 24));
-        }
-
-        return result;
-    }
-
-    protected final byte[] convertDoubleArrayToByteArray(final double values[],
-            final ByteOrder byteOrder) {
-        final byte result[] = new byte[values.length * 8];
-        for (int i = 0; i < values.length; i++) {
-            final double value = values[i];
-            final long bits = Double.doubleToRawLongBits(value);
-
-            final int start = i * 8;
-            if (byteOrder == ByteOrder.INTEL) {
-                result[start + 0] = (byte) (0xff & (bits >> 0));
-                result[start + 1] = (byte) (0xff & (bits >> 8));
-                result[start + 2] = (byte) (0xff & (bits >> 16));
-                result[start + 3] = (byte) (0xff & (bits >> 24));
-                result[start + 4] = (byte) (0xff & (bits >> 32));
-                result[start + 5] = (byte) (0xff & (bits >> 40));
-                result[start + 6] = (byte) (0xff & (bits >> 48));
-                result[start + 7] = (byte) (0xff & (bits >> 56));
-            } else {
-                result[start + 7] = (byte) (0xff & (bits >> 0));
-                result[start + 6] = (byte) (0xff & (bits >> 8));
-                result[start + 5] = (byte) (0xff & (bits >> 16));
-                result[start + 4] = (byte) (0xff & (bits >> 24));
-                result[start + 3] = (byte) (0xff & (bits >> 32));
-                result[start + 2] = (byte) (0xff & (bits >> 40));
-                result[start + 1] = (byte) (0xff & (bits >> 48));
-                result[start + 0] = (byte) (0xff & (bits >> 56));
-            }
-        }
-        return result;
-    }
-
-    protected final double convertByteArrayToDouble(final String name, final byte bytes[],
-            final ByteOrder byteOrder) {
-        return convertByteArrayToDouble(name, bytes, 0, byteOrder);
-    }
-
-    protected final double convertByteArrayToDouble(final String name, final byte bytes[],
-            final int start, final ByteOrder byteOrder) {
-        final byte byte0 = bytes[start + 0];
-        final byte byte1 = bytes[start + 1];
-        final byte byte2 = bytes[start + 2];
-        final byte byte3 = bytes[start + 3];
-        final byte byte4 = bytes[start + 4];
-        final byte byte5 = bytes[start + 5];
-        final byte byte6 = bytes[start + 6];
-        final byte byte7 = bytes[start + 7];
-
-        long bits;
-
-        if (byteOrder == ByteOrder.MOTOROLA) {
-            bits = ((0xffL & byte0) << 56) | ((0xffL & byte1) << 48)
-                    | ((0xffL & byte2) << 40) | ((0xffL & byte3) << 32)
-                    | ((0xffL & byte4) << 24) | ((0xffL & byte5) << 16)
-                    | ((0xffL & byte6) << 8) | ((0xffL & byte7) << 0);
-
-        } else {
-            bits = ((0xffL & byte7) << 56) | ((0xffL & byte6) << 48)
-                    | ((0xffL & byte5) << 40) | ((0xffL & byte4) << 32)
-                    | ((0xffL & byte3) << 24) | ((0xffL & byte2) << 16)
-                    | ((0xffL & byte1) << 8) | ((0xffL & byte0) << 0);
-        }
-
-        final double result = Double.longBitsToDouble(bits);
-
-        return result;
-    }
-
-    protected final double[] convertByteArrayToDoubleArray(final String name,
-            final byte bytes[], final int start, final int length, final ByteOrder byteOrder) {
-        final int expectedLength = start + length * 8;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final double result[] = new double[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToDouble(name, bytes, start + i * 8,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
     protected void skipBytes(final InputStream is, final int length) throws IOException {
         this.skipBytes(is, length, "Couldn't skip bytes");
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java Fri Feb  1 19:31:28 2013
@@ -43,20 +43,15 @@ public class BinaryFileParser extends Bi
         return byteOrder;
     }
 
-    protected final int convertByteArrayToInt(final String name, final int start,
-            final byte bytes[]) {
-        return convertByteArrayToInt(name, bytes, start, byteOrder);
-    }
-
     protected final int convertByteArrayToInt(final String name, final byte bytes[]) {
-        return convertByteArrayToInt(name, bytes, byteOrder);
+        return BinaryConversions.toInt(bytes, byteOrder);
     }
 
-    public final int convertByteArrayToShort(final String name, final byte bytes[])
+    public final int convertByteArrayToShort(final String name, final byte[] bytes)
             throws ImageReadException {
         return convertByteArrayToShort(name, bytes, byteOrder);
     }
-
+    
     public final int convertByteArrayToShort(final String name, final int start,
             final byte bytes[]) throws ImageReadException {
         return convertByteArrayToShort(name, start, bytes, byteOrder);
@@ -104,9 +99,4 @@ public class BinaryFileParser extends Bi
 
         return true;
     }
-
-    protected final byte[] int2ToByteArray(final int value) {
-        return int2ToByteArray(value, byteOrder);
-    }
-
 }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java Fri Feb  1 19:31:28 2013
@@ -66,41 +66,11 @@ public class BinaryInputStream extends I
         return is.read();
     }
 
-    protected final int convertByteArrayToInt(final String name, final byte bytes[]) {
-        return convertByteArrayToInt(name, bytes, byteOrder);
-    }
-
-    public final int convertByteArrayToShort(final String name, final byte bytes[]) {
-        return convertByteArrayToShort(name, bytes, byteOrder);
-    }
-
-    public final int convertByteArrayToShort(final String name, final int start,
-            final byte bytes[]) {
-        return convertByteArrayToShort(name, start, bytes, byteOrder);
-    }
-
     public final int read4Bytes(final String name, final String exception)
             throws IOException {
         return read4Bytes(name, exception, byteOrder);
     }
 
-    public final int read3Bytes(final String name, final String exception)
-            throws IOException {
-        return read3Bytes(name, exception, byteOrder);
-    }
-
-    public final int read2Bytes(final String name, final String exception)
-            throws IOException {
-        return read2Bytes(name, exception, byteOrder);
-    }
-
-    protected final void readRandomBytes() throws IOException {
-
-        for (int counter = 0; counter < 100; counter++) {
-            readByte("" + counter, "Random Data");
-        }
-    }
-
     public final void debugNumber(final String msg, final int data) {
         debugNumber(msg, data, 1);
     }
@@ -195,41 +165,6 @@ public class BinaryInputStream extends I
         return (byte) (0xff & result);
     }
 
-    protected final RationalNumber[] convertByteArrayToRationalArray(
-            final String name, final byte bytes[], final int start, final int length, final ByteOrder byteOrder) {
-        final int expectedLength = start + length * 8;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final RationalNumber result[] = new RationalNumber[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToRational(name, bytes, start + i * 8,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
-    protected final RationalNumber convertByteArrayToRational(final String name,
-            final byte bytes[], final ByteOrder byteOrder) {
-        return convertByteArrayToRational(name, bytes, 0, byteOrder);
-    }
-
-    protected final RationalNumber convertByteArrayToRational(final String name,
-            final byte bytes[], final int start, final ByteOrder byteOrder) {
-        final int numerator = convertByteArrayToInt(name, bytes, start + 0, 4,
-                byteOrder);
-        final int divisor = convertByteArrayToInt(name, bytes, start + 4, 4,
-                byteOrder);
-
-        return new RationalNumber(numerator, divisor);
-    }
-
     protected final int convertByteArrayToInt(final String name, final byte bytes[],
             final ByteOrder byteOrder) {
         return convertByteArrayToInt(name, bytes, 0, 4, byteOrder);
@@ -262,26 +197,6 @@ public class BinaryInputStream extends I
         return result;
     }
 
-    protected final int[] convertByteArrayToIntArray(final String name, final byte bytes[],
-            final int start, final int length, final ByteOrder byteOrder) {
-        final int expectedLength = start + length * 4;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final int result[] = new int[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToInt(name, bytes, start + i * 4, 4,
-                    byteOrder);
-        }
-
-        return result;
-    }
-
     protected final int convertByteArrayToShort(final String name, final byte bytes[],
             final ByteOrder byteOrder) {
         return convertByteArrayToShort(name, 0, bytes, byteOrder);
@@ -307,30 +222,6 @@ public class BinaryInputStream extends I
         return result;
     }
 
-    protected final int[] convertByteArrayToShortArray(final String name,
-            final byte bytes[], final int start, final int length, final ByteOrder byteOrder) {
-        final int expectedLength = start + length * 2;
-
-        if (bytes.length < expectedLength) {
-            System.out.println(name + ": expected length: " + expectedLength
-                    + ", actual length: " + bytes.length);
-            return null;
-        }
-
-        final int result[] = new int[length];
-
-        for (int i = 0; i < length; i++) {
-            result[i] = convertByteArrayToShort(name, start + i * 2, bytes,
-                    byteOrder);
-
-            // byte byte0 = bytes[start + i * 2];
-            // byte byte1 = bytes[start + i * 2 + 1];
-            // result[i] = convertBytesToShort(name, byte0, byte1, byteOrder);
-        }
-
-        return result;
-    }
-
     public final byte[] readByteArray(final String name, final int length, final String exception)
             throws IOException {
         final byte result[] = new byte[length];

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java Fri Feb  1 19:31:28 2013
@@ -16,7 +16,13 @@
  */
 package org.apache.commons.imaging.common;
 
-public class BitArrayOutputStream {
+import java.io.OutputStream;
+
+/**
+ * Output stream writing to a byte array, and capable
+ * of writing 1 bit at a time, starting from the most significant bit.
+ */
+public class BitArrayOutputStream extends OutputStream {
     private byte[] buffer;
     private int bytesWritten = 0;
     private int cache = 0;
@@ -44,10 +50,12 @@ public class BitArrayOutputStream {
         return out;
     }
 
+    @Override
     public void close() {
         flush();
     }
 
+    @Override
     public void flush() {
         if (cacheMask != 0x80) {
             writeByte(cache);
@@ -56,6 +64,7 @@ public class BitArrayOutputStream {
         }
     }
 
+    @Override
     public void write(final int b) {
         flush();
         writeByte(b);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java Fri Feb  1 19:31:28 2013
@@ -19,6 +19,11 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.InputStream;
 
+/**
+ * Input stream reading 1-8, 16, 24 or 32 bits, starting from the most
+ * significant bit, but incapable of reading non-aligned and
+ * < 8 bit fields across byte boundaries.
+ */
 public class BitInputStream extends InputStream {
 
     private final InputStream is;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java Fri Feb  1 19:31:28 2013
@@ -19,6 +19,11 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.InputStream;
 
+/**
+ * Input stream that allows reading up to 32 bits
+ * across byte boundaries in most significant
+ * bit first order.
+ */
 public class BitInputStreamFlexible extends InputStream {
     // TODO should be byte order conscious, ie TIFF for reading
     // samples size<8 - shuoldn't that effect their order within byte?

Copied: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java (from r1440856, 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/FastByteArrayOutputStream.java?p2=commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/FastByteArrayOutputStream.java&p1=commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/MyByteArrayOutputStream.java&r1=1440856&r2=1441595&rev=1441595&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/FastByteArrayOutputStream.java Fri Feb  1 19:31:28 2013
@@ -19,11 +19,13 @@ package org.apache.commons.imaging.commo
 import java.io.IOException;
 import java.io.OutputStream;
 
-/// Some performance benefit, because not thread safe.
-public class MyByteArrayOutputStream extends OutputStream {
+/** Like ByteArrayOutputStream, but has some performance benefit,
+  * because it's not thread safe.
+  */
+public class FastByteArrayOutputStream extends OutputStream {
     private final byte bytes[];
 
-    public MyByteArrayOutputStream(final int length) {
+    public FastByteArrayOutputStream(final int length) {
         bytes = new byte[length];
     }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java Fri Feb  1 19:31:28 2013
@@ -102,7 +102,7 @@ public class ImageBuilder {
      * no bounds checking is applied.
      * @param x the X coordinate of the pixel to be read
      * @param y the Y coordinate of the pixel to be read
-     * @return 
+     * @return the RGB or ARGB pixel value
      */
     public int getRGB(final int x, final int y) {
         final int rowOffset = y * width;

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=1441595&r1=1441594&r2=1441595&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 Fri Feb  1 19:31:28 2013
@@ -106,9 +106,9 @@ public class PackBits {
     }
 
     public byte[] compress(final byte bytes[]) throws IOException {
-        MyByteArrayOutputStream baos = null;
+        FastByteArrayOutputStream baos = null;
         try {
-            baos = new MyByteArrayOutputStream(
+            baos = new FastByteArrayOutputStream(
                     bytes.length * 2); // max length 1 extra byte for every 128
 
             int ptr = 0;

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=1441595&r1=1441594&r2=1441595&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 Fri Feb  1 19:31:28 2013
@@ -19,6 +19,9 @@ package org.apache.commons.imaging.commo
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 
+/**
+ * Rational number, as used by the TIFF image format.
+ */
 public class RationalNumber extends Number {
     private static final long serialVersionUID = -1;
 

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=1441595&r1=1441594&r2=1441595&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 Fri Feb  1 19:31:28 2013
@@ -23,9 +23,7 @@ import java.util.zip.DeflaterOutputStrea
 import java.util.zip.InflaterInputStream;
 
 public class ZLibUtils extends BinaryFileFunctions {
-    public final byte[] inflate(final byte bytes[]) throws IOException
-    // slow, probably.
-    {
+    public final byte[] inflate(final byte bytes[]) throws IOException {
         final ByteArrayInputStream in = new ByteArrayInputStream(bytes);
         final InflaterInputStream zIn = new InflaterInputStream(in);
         return getStreamBytes(zIn);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java Fri Feb  1 19:31:28 2013
@@ -40,13 +40,11 @@ public class JpegUtils extends BinaryFil
         public boolean visitSegment(int marker, byte markerBytes[],
                 int segmentLength, byte segmentLengthBytes[],
                 byte segmentData[]) throws ImageReadException,
-        // ImageWriteException,
                 IOException;
     }
 
     public void traverseJFIF(final ByteSource byteSource, final Visitor visitor)
             throws ImageReadException,
-            // ImageWriteException,
             IOException {
         InputStream is = null;
 
@@ -56,8 +54,6 @@ public class JpegUtils extends BinaryFil
             readAndVerifyBytes(is, SOI,
                     "Not a Valid JPEG File: doesn't begin with 0xffd8");
 
-            final ByteOrder byteOrder = getByteOrder();
-
             int markerCount;
             for (markerCount = 0; true; markerCount++) {
                 final byte[] markerBytes = new byte[2];
@@ -70,10 +66,6 @@ public class JpegUtils extends BinaryFil
                 final int marker = ((0xff & markerBytes[0]) << 8)
                         | (0xff & markerBytes[1]);
 
-                // Debug.debug("marker", marker + " (0x" +
-                // Integer.toHexString(marker) + ")");
-                // Debug.debug("markerBytes", markerBytes);
-
                 if (marker == EOIMarker || marker == SOS_Marker) {
                     if (!visitor.beginSOS()) {
                         return;
@@ -87,18 +79,12 @@ public class JpegUtils extends BinaryFil
                 final byte segmentLengthBytes[] = readByteArray("segmentLengthBytes",
                         2, is, "segmentLengthBytes");
                 final int segmentLength = convertByteArrayToShort("segmentLength",
-                        segmentLengthBytes, byteOrder);
-
-                // Debug.debug("segmentLength", segmentLength + " (0x" +
-                // Integer.toHexString(segmentLength) + ")");
-                // Debug.debug("segmentLengthBytes", segmentLengthBytes);
+                        segmentLengthBytes);
 
                 final byte segmentData[] = readByteArray("Segment Data",
                         segmentLength - 2, is,
                         "Invalid Segment: insufficient data");
 
-                // Debug.debug("segmentLength", segmentLength);
-
                 if (!visitor.visitSegment(marker, markerBytes, segmentLength,
                         segmentLengthBytes, segmentData)) {
                     return;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java Fri Feb  1 19:31:28 2013
@@ -261,18 +261,12 @@ public class PcxImageParser extends Imag
         final int version = 0xff & pcxHeaderBytes[1];
         final int encoding = 0xff & pcxHeaderBytes[2];
         final int bitsPerPixel = 0xff & pcxHeaderBytes[3];
-        final int xMin = convertByteArrayToShort("xMin", 4, pcxHeaderBytes,
-                ByteOrder.LITTLE_ENDIAN);
-        final int yMin = convertByteArrayToShort("yMin", 6, pcxHeaderBytes,
-                ByteOrder.LITTLE_ENDIAN);
-        final int xMax = convertByteArrayToShort("xMax", 8, pcxHeaderBytes,
-                ByteOrder.LITTLE_ENDIAN);
-        final int yMax = convertByteArrayToShort("yMax", 10, pcxHeaderBytes,
-                ByteOrder.LITTLE_ENDIAN);
-        final int hDpi = convertByteArrayToShort("hDpi", 12, pcxHeaderBytes,
-                ByteOrder.LITTLE_ENDIAN);
-        final int vDpi = convertByteArrayToShort("vDpi", 14, pcxHeaderBytes,
-                ByteOrder.LITTLE_ENDIAN);
+        final int xMin = convertByteArrayToShort("xMin", 4, pcxHeaderBytes);
+        final int yMin = convertByteArrayToShort("yMin", 6, pcxHeaderBytes);
+        final int xMax = convertByteArrayToShort("xMax", 8, pcxHeaderBytes);
+        final int yMax = convertByteArrayToShort("yMax", 10, pcxHeaderBytes);
+        final int hDpi = convertByteArrayToShort("hDpi", 12, pcxHeaderBytes);
+        final int vDpi = convertByteArrayToShort("vDpi", 14, pcxHeaderBytes);
         final int[] colormap = new int[16];
         for (int i = 0; i < 16; i++) {
             colormap[i] = 0xff000000
@@ -283,13 +277,13 @@ public class PcxImageParser extends Imag
         final int reserved = 0xff & pcxHeaderBytes[64];
         final int nPlanes = 0xff & pcxHeaderBytes[65];
         final int bytesPerLine = convertByteArrayToShort("BytesPerLine", 66,
-                pcxHeaderBytes, ByteOrder.LITTLE_ENDIAN);
+                pcxHeaderBytes);
         final int paletteInfo = convertByteArrayToShort("PaletteInfo", 68,
-                pcxHeaderBytes, ByteOrder.LITTLE_ENDIAN);
+                pcxHeaderBytes);
         final int hScreenSize = convertByteArrayToShort("hScreenSize", 70,
-                pcxHeaderBytes, ByteOrder.LITTLE_ENDIAN);
+                pcxHeaderBytes);
         final int vScreenSize = convertByteArrayToShort("vScreenSize", 72,
-                pcxHeaderBytes, ByteOrder.LITTLE_ENDIAN);
+                pcxHeaderBytes);
 
         if (manufacturer != 10) {
             throw new ImageReadException(

Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/BinaryFileFunctionsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/BinaryFileFunctionsTest.java?rev=1441595&r1=1441594&r2=1441595&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/BinaryFileFunctionsTest.java (original)
+++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/common/BinaryFileFunctionsTest.java Fri Feb  1 19:31:28 2013
@@ -16,47 +16,31 @@
 package org.apache.commons.imaging.common;
 
 import org.apache.commons.imaging.ImagingTest;
-import org.apache.commons.imaging.common.BinaryFileFunctions;
 
 public class BinaryFileFunctionsTest extends ImagingTest {
-    // Work around that pesky "protected"...
-    private static class Extender extends BinaryFileFunctions {
-        public void testFloatToByteConversion() {
-            final byte[] bytesLE = convertFloatToByteArray(1.0f,
-                    ByteOrder.LITTLE_ENDIAN);
-            assertEquals(
-                    convertByteArrayToFloat("bytes", bytesLE,
-                            ByteOrder.LITTLE_ENDIAN), 1.0f, 0f);
-
-            final byte[] bytesBE = convertFloatToByteArray(1.0f,
-                    ByteOrder.BIG_ENDIAN);
-            assertEquals(
-                    convertByteArrayToFloat("bytes", bytesBE,
-                            ByteOrder.BIG_ENDIAN), 1.0f, 0f);
-        }
-
-        public void testDoubleToByteConversion() {
-            final byte[] bytesLE = BinaryConversions.toBytes(1.0,
-                    ByteOrder.LITTLE_ENDIAN);
-            assertEquals(
-                    convertByteArrayToDouble("bytes", bytesLE,
-                            ByteOrder.LITTLE_ENDIAN), 1.0, 0);
-
-            final byte[] bytesBE = BinaryConversions.toBytes(1.0,
-                    ByteOrder.BIG_ENDIAN);
-            assertEquals(
-                    convertByteArrayToDouble("bytes", bytesBE,
-                            ByteOrder.BIG_ENDIAN), 1.0, 0);
-        }
-    }
-
-    private final Extender extender = new Extender();
-
     public void testFloatToByteConversion() {
-        extender.testFloatToByteConversion();
+        final byte[] bytesLE = BinaryConversions.toBytes(1.0f,
+                ByteOrder.LITTLE_ENDIAN);
+        assertEquals(
+                BinaryConversions.toFloat(bytesLE, ByteOrder.LITTLE_ENDIAN),
+                1.0f, 0f);
+
+        final byte[] bytesBE = BinaryConversions.toBytes(1.0f,
+                ByteOrder.BIG_ENDIAN);
+        assertEquals(BinaryConversions.toFloat(bytesBE, ByteOrder.BIG_ENDIAN),
+                1.0f, 0f);
     }
 
     public void testDoubleToByteConversion() {
-        extender.testDoubleToByteConversion();
+        final byte[] bytesLE = BinaryConversions.toBytes(1.0,
+                ByteOrder.LITTLE_ENDIAN);
+        assertEquals(
+                BinaryConversions.toDouble(bytesLE, ByteOrder.LITTLE_ENDIAN),
+                1.0, 0);
+
+        final byte[] bytesBE = BinaryConversions.toBytes(1.0,
+                ByteOrder.BIG_ENDIAN);
+        assertEquals(BinaryConversions.toDouble(bytesBE, ByteOrder.BIG_ENDIAN),
+                1.0, 0);
     }
 }



Mime
View raw message