commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1335936 - in /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff: TiffElement.java TiffImageData.java TiffReader.java datareaders/DataReaderStrips.java datareaders/DataReaderTiled.java
Date Wed, 09 May 2012 05:58:10 GMT
Author: damjan
Date: Wed May  9 05:58:09 2012
New Revision: 1335936

URL: http://svn.apache.org/viewvc?rev=1335936&view=rev
Log:
Reduce memory usage when reading TIFF files.

Jira issue key: IMAGING-70
Submitted by: Gary Lucas <gwlucas at sonalysts dot com>


Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageData.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java?rev=1335936&r1=1335935&r2=1335936&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java
Wed May  9 05:58:09 2012
@@ -54,6 +54,10 @@ public abstract class TiffElement
 
             this.data = data;
         }
+        
+        public byte []getData(){
+            return data;
+        }
 
     }
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageData.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageData.java?rev=1335936&r1=1335935&r2=1335936&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageData.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageData.java
Wed May  9 05:58:09 2012
@@ -20,6 +20,7 @@ package org.apache.commons.imaging.forma
 import java.io.IOException;
 
 import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
 import org.apache.commons.imaging.formats.tiff.datareaders.DataReader;
 import org.apache.commons.imaging.formats.tiff.datareaders.DataReaderStrips;
 import org.apache.commons.imaging.formats.tiff.datareaders.DataReaderTiled;
@@ -141,4 +142,30 @@ public abstract class TiffImageData
         }
 
     }
+    
+        public static class ByteSourceData extends  Data 
+    {
+        ByteSourceFile byteSourceFile ;
+        public ByteSourceData(int offset, int length, ByteSourceFile byteSource)
+        {
+            super(offset, length, new byte[0]);
+            byteSourceFile = byteSource;
+        }
+
+        @Override
+        public String getElementDescription(boolean verbose)
+        {
+            return "Tiff image data: " + data.length + " bytes";
+        }
+
+        
+        public byte[] getData()
+        {
+            try {
+                return byteSourceFile.getBlock(offset, length);
+            } catch (IOException ioex) {
+            }
+            return new byte[0];
+        }
+    }
 }
\ No newline at end of file

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java?rev=1335936&r1=1335935&r2=1335936&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
Wed May  9 05:58:09 2012
@@ -26,6 +26,7 @@ import org.apache.commons.imaging.Format
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.common.BinaryFileParser;
 import org.apache.commons.imaging.common.bytesource.ByteSource;
+import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
 import org.apache.commons.imaging.formats.tiff.TiffDirectory.ImageDataElement;
 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
 import org.apache.commons.imaging.formats.tiff.constants.TiffConstants;
@@ -468,14 +469,25 @@ public class TiffReader extends BinaryFi
             TiffDirectory directory) throws ImageReadException, IOException
     {
 
+     
         List<ImageDataElement> elements = directory.getTiffRawImageDataElements();
         TiffImageData.Data data[] = new TiffImageData.Data[elements.size()];
-        for (int i = 0; i < elements.size(); i++)
-        {
-            TiffDirectory.ImageDataElement element = elements.get(i);
-            byte bytes[] = byteSource.getBlock(element.offset, element.length);
-            data[i] = new TiffImageData.Data(element.offset, element.length,
-                    bytes);
+        
+        if (byteSource instanceof ByteSourceFile) {
+            ByteSourceFile bsf = (ByteSourceFile) byteSource;
+            for (int i = 0; i < elements.size(); i++) {
+                TiffDirectory.ImageDataElement element = elements.get(i);          
+                data[i] = new TiffImageData.ByteSourceData(
+                        element.offset, element.length,
+                        bsf);
+            }
+        } else {
+            for (int i = 0; i < elements.size(); i++) {
+                TiffDirectory.ImageDataElement element = elements.get(i);
+                byte bytes[] = byteSource.getBlock(element.offset, element.length);
+                data[i] = new TiffImageData.Data(element.offset, element.length,
+                        bytes);
+            }
         }
 
         if (directory.imageDataInStrips())

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java?rev=1335936&r1=1335935&r2=1335936&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
Wed May  9 05:58:09 2012
@@ -99,7 +99,7 @@ public final class DataReaderStrips exte
             long bytesPerStrip = rowsInThisStrip * bytesPerRow;
             long pixelsPerStrip = rowsInThisStrip * width;
 
-            byte compressed[] = imageData.strips[strip].data;
+            byte compressed[] = imageData.strips[strip].getData();
 
             byte decompressed[] = decompress(compressed, compression,
                     (int)bytesPerStrip, width, (int)rowsInThisStrip);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java?rev=1335936&r1=1335935&r2=1335936&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java
Wed May  9 05:58:09 2012
@@ -107,7 +107,7 @@ public final class DataReaderTiled exten
 
         for (int tile = 0; tile < imageData.tiles.length; tile++)
         {
-            byte compressed[] = imageData.tiles[tile].data;
+            byte compressed[] = imageData.tiles[tile].getData();
 
             byte decompressed[] = decompress(compressed, compression,
                     bytesPerTile, tileWidth, tileLength);



Mime
View raw message