pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1601689 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image: PDImageXObject.java SampledImageReader.java
Date Tue, 10 Jun 2014 17:12:38 GMT
Author: lehmi
Date: Tue Jun 10 17:12:37 2014
New Revision: 1601689

URL: http://svn.apache.org/r1601689
Log:
PDFBOX-2127: optimize calls of getPixel by reusing the pixel array as proposed by Petr Slaby

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
    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/PDImageXObject.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java?rev=1601689&r1=1601688&r2=1601689&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
Tue Jun 10 17:12:37 2014
@@ -264,6 +264,7 @@ public final class PDImageXObject extend
 
         float[] rgb = new float[3];
         float[] rgba = new float[4];
+        float[] alphaPixel = null;
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
@@ -273,14 +274,15 @@ public final class PDImageXObject extend
                 rgba[0] = rgb[0];
                 rgba[1] = rgb[1];
                 rgba[2] = rgb[2];
-
+                
+                alphaPixel = alpha.getPixel(x, y, alphaPixel);
                 if (isSoft)
                 {
-                    rgba[3] = alpha.getPixel(x, y, (float[])null)[0];
+                    rgba[3] = alphaPixel[0];
                 }
                 else
                 {
-                    rgba[3] = 255 - alpha.getPixel(x, y, (float[])null)[0];
+                    rgba[3] = 255 - alphaPixel[0];
                 }
 
                 dest.setPixel(x, y, rgba);

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=1601689&r1=1601688&r2=1601689&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
Tue Jun 10 17:12:37 2014
@@ -79,22 +79,17 @@ final class SampledImageReader
         WritableRaster raster = masked.getRaster();
         WritableRaster alpha = mask.getRaster();
 
-        float[] rgba = new float[4];
         final float[] transparent = new float[4];
+        float[] alphaPixel = null;
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
             {
-                raster.getPixel(x, y, rgba);
-
-                if (alpha.getPixel(x, y, (float[])null)[0] == 255)
+                alphaPixel = alpha.getPixel(x, y, alphaPixel);
+                if (alphaPixel[0] == 255)
                 {
                     raster.setPixel(x, y, transparent);
                 }
-                else
-                {
-                    raster.setPixel(x, y, rgba);
-                }
             }
         }
 
@@ -246,11 +241,11 @@ final class SampledImageReader
             final int width = pdImage.getWidth();
             final int height = pdImage.getHeight();
             final int numComponents = pdImage.getColorSpace().getNumberOfComponents();
+            int max = width * height;
 
             for (int c = 0; c < numComponents; c++)
             {
                 int sourceOffset = c;
-                int max = width * height;
                 for (int i = 0; i < max; i++)
                 {
                     banks[c][i] = source[sourceOffset];
@@ -397,6 +392,7 @@ final class SampledImageReader
 
         float[] rgb = new float[3];
         float[] rgba = new float[4];
+        float[] alphaPixel = null;
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
@@ -406,7 +402,8 @@ final class SampledImageReader
                 rgba[0] = rgb[0];
                 rgba[1] = rgb[1];
                 rgba[2] = rgb[2];
-                rgba[3] = 255 - alpha.getPixel(x, y, (float[])null)[0];
+                alphaPixel = alpha.getPixel(x, y, alphaPixel);
+                rgba[3] = 255 - alphaPixel[0];
 
                 dest.setPixel(x, y, rgba);
             }



Mime
View raw message