commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1441744 - in /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging: common/ formats/bmp/pixelparsers/ formats/psd/datareaders/
Date Sat, 02 Feb 2013 13:46:16 GMT
Author: damjan
Date: Sat Feb  2 13:46:16 2013
New Revision: 1441744

URL: http://svn.apache.org/viewvc?rev=1441744&view=rev
Log:
Cleanups.


Modified:
    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/formats/bmp/pixelparsers/PixelParser.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserBitFields.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRgb.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java

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=1441744&r1=1441743&r2=1441744&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
Sat Feb  2 13:46:16 2013
@@ -29,11 +29,11 @@ public class BinaryFileParser {
     private ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
     protected boolean debug = false;
 
-    public BinaryFileParser(final ByteOrder byteOrder) {
+    protected BinaryFileParser(final ByteOrder byteOrder) {
         this.byteOrder = byteOrder;
     }
 
-    public BinaryFileParser() {
+    protected BinaryFileParser() {
     }
 
     protected void setByteOrder(final ByteOrder byteOrder) {
@@ -68,114 +68,114 @@ public class BinaryFileParser {
         return ByteConversions.toUInt16(bytes, byteOrder);
     }
 
-    public final int toUInt16(final byte bytes[], final int start) {
+    protected final int toUInt16(final byte bytes[], final int start) {
         return ByteConversions.toUInt16(bytes, start, byteOrder);
     }
 
-    public byte[] getStreamBytes(final InputStream is) throws IOException {
+    protected byte[] getStreamBytes(final InputStream is) throws IOException {
         return BinaryFunctions.getStreamBytes(is);
     }
     
-    public final int read4Bytes(final String name, final InputStream is, final String exception)
+    protected final int read4Bytes(final String name, final InputStream is, final String
exception)
             throws IOException {
         return BinaryFunctions.read4Bytes(name, is, exception, byteOrder);
     }
 
-    public final int read3Bytes(final String name, final InputStream is, final String exception)
+    protected final int read3Bytes(final String name, final InputStream is, final String
exception)
             throws IOException {
         return BinaryFunctions.read3Bytes(name, is, exception, byteOrder);
     }
 
-    public final int read2Bytes(final String name, final InputStream is, final String exception)
+    protected final int read2Bytes(final String name, final InputStream is, final String
exception)
             throws IOException {
         return BinaryFunctions.read2Bytes(name, is, exception, byteOrder);
     }
     
-    public final byte readByte(final String name, final InputStream is, final String exception)
+    protected final byte readByte(final String name, final InputStream is, final String exception)
             throws IOException {
         return BinaryFunctions.readByte(name, is, exception);
     }
     
-    public final byte[] readByteArray(final String name, final int length, final InputStream
is,
+    protected final byte[] readByteArray(final String name, final int length, final InputStream
is,
             final String exception) throws IOException {
         return BinaryFunctions.readByteArray(name, length, is, exception);
     }
     
-    public final byte[] readByteArray(final String name, final int length, final InputStream
is)
+    protected final byte[] readByteArray(final String name, final int length, final InputStream
is)
             throws IOException {
         return BinaryFunctions.readByteArray(name, length, is);
     }
     
-    public byte[] readBytearray(final String name, final byte bytes[], final int start,
+    protected byte[] readBytearray(final String name, final byte bytes[], final int start,
             final int count) throws ImageReadException {
         return BinaryFunctions.readBytearray(name, bytes, start, count);
     }
     
-    public final byte[] readBytes(final InputStream is, final int count) throws IOException
{
+    protected final byte[] readBytes(final InputStream is, final int count) throws IOException
{
         return BinaryFunctions.readBytes(is, count);
     }
     
-    public final void readAndVerifyBytes(final InputStream is,
+    protected final void readAndVerifyBytes(final InputStream is,
             final BinaryConstant expected, final String exception)
                     throws IOException, ImageReadException {
         BinaryFunctions.readAndVerifyBytes(is, expected, exception);
     }
     
-    public final void readAndVerifyBytes(final InputStream is, final byte expected[],
+    protected final void readAndVerifyBytes(final InputStream is, final byte expected[],
             final String exception) throws ImageReadException, IOException {
         BinaryFunctions.readAndVerifyBytes(is, expected, exception);
     }
     
-    public final void skipBytes(final InputStream is, final int length)
+    protected final void skipBytes(final InputStream is, final int length)
             throws IOException {
         BinaryFunctions.skipBytes(is, length);
     }
     
-    public final void skipBytes(final InputStream is, final int length, final String exception)
+    protected final void skipBytes(final InputStream is, final int length, final String exception)
             throws IOException {
         BinaryFunctions.skipBytes(is, length, exception);
     }
     
-    public final byte[] getByteArrayTail(final String name, final byte bytes[], final int
count)
+    protected final byte[] getByteArrayTail(final String name, final byte bytes[], final
int count)
             throws ImageReadException {
         return BinaryFunctions.getByteArrayTail(name, bytes, count);
     }
     
-    public final int findNull(final byte src[]) {
+    protected final int findNull(final byte src[]) {
         return BinaryFunctions.findNull(src);
     }
     
-    public final int findNull(final byte src[], final int start) {
+    protected final int findNull(final byte src[], final int start) {
         return BinaryFunctions.findNull(src, start);
     }
     
-    public void printByteBits(final String msg, final byte i) {
+    protected void printByteBits(final String msg, final byte i) {
         BinaryFunctions.printByteBits(msg, i);
     }
     
-    public void printCharQuad(final String msg, final int i) {
+    protected void printCharQuad(final String msg, final int i) {
         BinaryFunctions.printCharQuad(msg, i);
     }
 
-    public final void printCharQuad(final PrintWriter pw, final String msg, final int i)
{
+    protected final void printCharQuad(final PrintWriter pw, final String msg, final int
i) {
         BinaryFunctions.printCharQuad(pw, msg, i);
     }
     
-    public final void debugNumber(final String msg, final int data) {
+    protected final void debugNumber(final String msg, final int data) {
         debugNumber(msg, data, 1);
     }
 
-    public final void debugNumber(final String msg, final int data, final int bytes) {
+    protected final void debugNumber(final String msg, final int data, final int bytes) {
         final PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
         debugNumber(pw, msg, data, bytes);
         pw.flush();
     }
 
-    public final void debugNumber(final PrintWriter pw, final String msg, final int data)
{
+    protected final void debugNumber(final PrintWriter pw, final String msg, final int data)
{
         debugNumber(pw, msg, data, 1);
     }
 
-    public final void debugNumber(final PrintWriter pw, final String msg, final int data,
+    protected final void debugNumber(final PrintWriter pw, final String msg, final int data,
             final int bytes) {
         pw.print(msg + ": " + data + " (");
         int byteData = data;
@@ -192,7 +192,7 @@ public class BinaryFileParser {
         pw.flush();
     }
 
-    public final void debugByteArray(final String name, final byte bytes[]) {
+    protected final void debugByteArray(final String name, final byte bytes[]) {
         System.out.println(name + ": " + bytes.length);
 
         for (int i = 0; ((i < bytes.length) && (i < 50)); i++) {
@@ -200,7 +200,7 @@ public class BinaryFileParser {
         }
     }
 
-    public final void debugNumberArray(final String name, final int numbers[], final int
length) {
+    protected final void debugNumberArray(final String name, final int numbers[], final int
length) {
         System.out.println(name + ": " + numbers.length);
 
         for (int i = 0; ((i < numbers.length) && (i < 50)); i++) {
@@ -208,12 +208,12 @@ public class BinaryFileParser {
         }
     }
 
-    public final boolean compareByteArrays(final byte a[], final int aStart, final byte b[],
+    protected final boolean compareByteArrays(final byte a[], final int aStart, final byte
b[],
             final int bStart, final int length) {
         return BinaryFunctions.compareByteArrays(a, aStart, b, bStart, length);
     }
     
-    public static boolean startsWith(final byte haystack[], final BinaryConstant needle)
{
+    protected static boolean startsWith(final byte haystack[], final BinaryConstant needle)
{
         if ((haystack == null) || (haystack.length < needle.size())) {
             return false;
         }
@@ -227,7 +227,7 @@ public class BinaryFileParser {
         return true;
     }
 
-    public static boolean startsWith(final byte haystack[], final byte needle[]) {
+    protected static boolean startsWith(final byte haystack[], final byte needle[]) {
         return BinaryFunctions.startsWith(haystack, needle);
     }
 }

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=1441744&r1=1441743&r2=1441744&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
Sat Feb  2 13:46:16 2013
@@ -192,11 +192,21 @@ public class BinaryInputStream extends I
         return BinaryFunctions.read3Bytes(name, is, exception, byteOrder);
     }
 
+    public final int read3Bytes(final String name, final String exception)
+            throws IOException {
+        return BinaryFunctions.read3Bytes(name, is, exception, byteOrder);
+    }
+
     protected final int read2Bytes(final String name, final String exception, final ByteOrder
byteOrder)
             throws IOException {
         return BinaryFunctions.read2Bytes(name, is, exception, byteOrder);
     }
-    
+
+    public final int read2Bytes(final String name, final String exception)
+            throws IOException {
+        return BinaryFunctions.read2Bytes(name, is, exception, byteOrder);
+    }
+
     public final int read2Bytes(final String exception) throws IOException {
         return BinaryFunctions.read2Bytes("", is, exception, byteOrder);
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java?rev=1441744&r1=1441743&r2=1441744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParser.java
Sat Feb  2 13:46:16 2013
@@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 
 import org.apache.commons.imaging.ImageReadException;
-import org.apache.commons.imaging.common.BinaryFileParser;
+import org.apache.commons.imaging.common.BinaryInputStream;
 import org.apache.commons.imaging.common.ByteOrder;
 import org.apache.commons.imaging.common.ImageBuilder;
 import org.apache.commons.imaging.formats.bmp.BmpHeaderInfo;
@@ -30,16 +30,14 @@ public abstract class PixelParser {
     public final byte colorTable[];
     public final byte imageData[];
 
-    protected final BinaryFileParser bfp;
-    protected final ByteArrayInputStream is;
+    protected final BinaryInputStream is;
 
     public PixelParser(final BmpHeaderInfo bhi, final byte ColorTable[], final byte ImageData[])
{
         this.bhi = bhi;
         this.colorTable = ColorTable;
         this.imageData = ImageData;
 
-        bfp = new BinaryFileParser(ByteOrder.INTEL);
-        is = new ByteArrayInputStream(ImageData);
+        is = new BinaryInputStream(new ByteArrayInputStream(ImageData), ByteOrder.INTEL);
     }
 
     public abstract void processImage(ImageBuilder imageBuilder)

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserBitFields.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserBitFields.java?rev=1441744&r1=1441743&r2=1441744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserBitFields.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserBitFields.java
Sat Feb  2 13:46:16 2013
@@ -76,13 +76,13 @@ public class PixelParserBitFields extend
             data = 0xff & imageData[bytecount + 0];
             bytecount += 1;
         } else if (bhi.bitsPerPixel == 24) {
-            data = bfp.read3Bytes("Pixel", is, "BMP Image Data");
+            data = is.read3Bytes("Pixel", "BMP Image Data");
             bytecount += 3;
         } else if (bhi.bitsPerPixel == 32) {
-            data = bfp.read4Bytes("Pixel", is, "BMP Image Data");
+            data = is.read4Bytes("Pixel", "BMP Image Data");
             bytecount += 4;
         } else if (bhi.bitsPerPixel == 16) {
-            data = bfp.read2Bytes("Pixel", is, "BMP Image Data");
+            data = is.read2Bytes("Pixel", "BMP Image Data");
             bytecount += 2;
         } else {
             throw new ImageReadException("Unknown BitsPerPixel: "
@@ -107,7 +107,7 @@ public class PixelParserBitFields extend
     @Override
     public void newline() throws ImageReadException, IOException {
         while (((bytecount) % 4) != 0) {
-            bfp.readByte("Pixel", is, "BMP Image Data");
+            is.readByte("Pixel", "BMP Image Data");
             bytecount++;
         }
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRgb.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRgb.java?rev=1441744&r1=1441743&r2=1441744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRgb.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRgb.java
Sat Feb  2 13:46:16 2013
@@ -67,7 +67,7 @@ public class PixelParserRgb extends Pixe
 
             return rgb;
         } else if (bhi.bitsPerPixel == 16) {
-            final int data = bfp.read2Bytes("Pixel", is, "BMP Image Data");
+            final int data = is.read2Bytes("Pixel", "BMP Image Data");
 
             final int blue = (0x1f & (data >> 0)) << 3;
             final int green = (0x1f & (data >> 5)) << 3;
@@ -112,7 +112,7 @@ public class PixelParserRgb extends Pixe
         cached_bit_count = 0;
 
         while (((bytecount) % 4) != 0) {
-            bfp.readByte("Pixel", is, "BMP Image Data");
+            is.readByte("Pixel", "BMP Image Data");
             bytecount++;
         }
     }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java?rev=1441744&r1=1441743&r2=1441744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java
Sat Feb  2 13:46:16 2013
@@ -95,9 +95,9 @@ public class PixelParserRle extends Pixe
 
         boolean done = false;
         while (!done) {
-            final int a = 0xff & bfp.readByte("RLE (" + x + "," + y + ") a", is,
+            final int a = 0xff & is.readByte("RLE (" + x + "," + y + ") a",
                     "BMP: Bad RLE");
-            final int b = 0xff & bfp.readByte("RLE (" + x + "," + y + ") b", is,
+            final int b = 0xff & is.readByte("RLE (" + x + "," + y + ") b",
                     "BMP: Bad RLE");
 
             if (a == 0) {
@@ -113,8 +113,8 @@ public class PixelParserRle extends Pixe
                     done = true;
                     break;
                 case 2: {
-                    final int deltaX = 0xff & bfp.readByte("RLE deltaX", is, "BMP: Bad
RLE");
-                    final int deltaY = 0xff & bfp.readByte("RLE deltaY", is, "BMP: Bad
RLE");
+                    final int deltaX = 0xff & is.readByte("RLE deltaX", "BMP: Bad RLE");
+                    final int deltaY = 0xff & is.readByte("RLE deltaY", "BMP: Bad RLE");
                     x += deltaX;
                     y -= deltaY;
                     break;
@@ -133,7 +133,7 @@ public class PixelParserRle extends Pixe
                     // System.out.println("size: " + size);
                     // System.out.println("SamplesPerByte: " + SamplesPerByte);
 
-                    final byte bytes[] = bfp.readByteArray("bytes", size, is,
+                    final byte bytes[] = is.readByteArray("bytes", size,
                             "RLE: Absolute Mode");
 
                     int remaining = b;

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java?rev=1441744&r1=1441743&r2=1441744&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/psd/datareaders/CompressedDataReader.java
Sat Feb  2 13:46:16 2013
@@ -23,6 +23,7 @@ import java.io.InputStream;
 
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.common.BinaryFileParser;
+import org.apache.commons.imaging.common.BinaryFunctions;
 import org.apache.commons.imaging.common.ByteOrder;
 import org.apache.commons.imaging.common.PackBits;
 import org.apache.commons.imaging.common.mylzw.BitsToByteInputStream;
@@ -49,8 +50,8 @@ public class CompressedDataReader extend
         final int scanline_count = height * header.Channels;
         final int scanline_bytecounts[] = new int[scanline_count];
         for (int i = 0; i < scanline_count; i++) {
-            scanline_bytecounts[i] = bfp.read2Bytes("scanline_bytecount[" + i
-                    + "]", is, "PSD: bad Image Data");
+            scanline_bytecounts[i] = BinaryFunctions.read2Bytes("scanline_bytecount[" + i
+                    + "]", is, "PSD: bad Image Data", bfp.getByteOrder());
         }
         bfp.setDebug(false);
         // System.out.println("fImageContents.Compression: "
@@ -64,7 +65,7 @@ public class CompressedDataReader extend
         for (int channel = 0; channel < channel_count; channel++) {
             for (int y = 0; y < height; y++) {
                 final int index = channel * height + y;
-                final byte packed[] = bfp.readByteArray("scanline",
+                final byte packed[] = BinaryFunctions.readByteArray("scanline",
                         scanline_bytecounts[index], is,
                         "PSD: Missing Image Data");
 



Mime
View raw message