pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1794951 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
Date Fri, 12 May 2017 10:01:30 GMT
Author: tilman
Date: Fri May 12 10:01:30 2017
New Revision: 1794951

URL: http://svn.apache.org/viewvc?rev=1794951&view=rev
Log:
PDFBOX-3791: read image one row at a time, not one pixel at a time due to overhead in our
buffer infrastructure

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java?rev=1794951&r1=1794950&r2=1794951&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
Fri May 12 10:01:30 2017
@@ -276,21 +276,28 @@ final class SampledImageReader
             final int width = pdImage.getWidth();
             final int height = pdImage.getHeight();
             final int numComponents = pdImage.getColorSpace().getNumberOfComponents();
-            int max = width * height;
-            byte[] tempBytes = new byte[numComponents];
-            for (int i = 0; i < max; i++)
+            byte[] tempBytes = new byte[numComponents * width];
+            // compromise between memory and time usage:
+            // reading the whole image consumes too much memory
+            // reading one pixel at a time makes it slow in our buffering infrastructure

+            int i = 0;
+            for (int y = 0; y < height; ++y)
             {
                 input.read(tempBytes);
-                for (int c = 0; c < numComponents; c++)
+                for (int x = 0; x < width; ++x)
                 {
-                    banks[c][i] = tempBytes[0+c];
+                    for (int c = 0; c < numComponents; c++)
+                    {
+                        banks[c][i] = tempBytes[x * numComponents + c];
+                    }
+                    ++i;
                 }
             }
             // use the color space to convert the image to RGB
             return pdImage.getColorSpace().toRGBImage(raster);
         }
     }
-    
+
     // slower, general-purpose image conversion from any image format
     private static BufferedImage fromAny(PDImage pdImage, WritableRaster raster, COSArray
colorKey)
             throws IOException



Mime
View raw message