commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1293744 - in /commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders: DataReader.java DataReaderStrips.java DataReaderTiled.java
Date Sun, 26 Feb 2012 05:43:01 GMT
Author: damjan
Date: Sun Feb 26 05:43:00 2012
New Revision: 1293744

URL: http://svn.apache.org/viewvc?rev=1293744&view=rev
Log:
Some more TIFF performance enhancements. Make getSamplesAsBytes()
use a preallocated array instead of allocating a new one on each
pixel. Also simplifies an if statement so there's less work done
per pixel. This reduces the running time by about 20%, and shortens
the total time taken by tests run by "mvn package" by about 5%.


Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReader.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderStrips.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderTiled.java

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReader.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReader.java?rev=1293744&r1=1293743&r2=1293744&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReader.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReader.java
Sun Feb 26 05:43:00 2012
@@ -64,10 +64,15 @@ public abstract class DataReader impleme
     public abstract void readImageData(ImageBuilder imageBuilder)
             throws ImageReadException, IOException;
 
-    protected int[] getSamplesAsBytes(BitInputStream bis)
+    /**
+     * Reads samples and returns them in an int array.
+     * @param bis the stream to read from
+     * @param result the samples array to populate, must be the same length as bitsPerSample.length
+     * @throws IOException
+     */
+    protected void getSamplesAsBytes(BitInputStream bis, int[] result)
             throws IOException
     {
-        int result[] = new int[bitsPerSample.length];
         for (int i = 0; i < bitsPerSample.length; i++)
         {
             int bits = bitsPerSample[i];
@@ -85,8 +90,6 @@ public abstract class DataReader impleme
             }
             result[i] = sample;
         }
-
-        return result;
     }
 
     protected int[] applyPredictor(int samples[], int x)

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderStrips.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderStrips.java?rev=1293744&r1=1293743&r2=1293744&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderStrips.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderStrips.java
Sun Feb 26 05:43:00 2012
@@ -55,11 +55,15 @@ public final class DataReaderStrips exte
         ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
         BitInputStream bis = new BitInputStream(bais);
 
+        if (y >= height) {
+            return;
+        }
+        int[] samples = new int[bitsPerSample.length];
         for (int i = 0; i < pixels_per_strip; i++)
         {
-            int samples[] = getSamplesAsBytes(bis);
+            getSamplesAsBytes(bis, samples);
 
-            if ((x < width) && (y < height))
+            if (x < width)
             {
                 samples = applyPredictor(samples, x);
 

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderTiled.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderTiled.java?rev=1293744&r1=1293743&r2=1293744&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderTiled.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReaderTiled.java
Sun Feb 26 05:43:00 2012
@@ -65,13 +65,14 @@ public final class DataReaderTiled exten
 
         int tileX = 0, tileY = 0;
 
+        int[] samples = new int[bitsPerSample.length];
         for (int i = 0; i < pixelsPerTile; i++)
         {
 
             int x = tileX + startX;
             int y = tileY + startY;
 
-            int samples[] = getSamplesAsBytes(bis);
+            getSamplesAsBytes(bis, samples);
 
             if ((x < width) && (y < height))
             {



Mime
View raw message