pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1801188 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
Date Fri, 07 Jul 2017 16:17:16 GMT
Author: tilman
Date: Fri Jul  7 16:17:16 2017
New Revision: 1801188

URL: http://svn.apache.org/viewvc?rev=1801188&view=rev
Log:
PDFBOX-3858: add cache for single component colorspaces

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java?rev=1801188&r1=1801187&r2=1801188&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
Fri Jul  7 16:17:16 2017
@@ -24,6 +24,7 @@ import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -281,6 +282,10 @@ public class PDDeviceN extends PDSpecial
     //
     private BufferedImage toRGBWithTintTransform(WritableRaster raster) throws IOException
     {
+        // map only in use if one color component
+        Map<Float,int[]> map1 = new HashMap<>();
+        float key = 0;
+
         int width = raster.getWidth();
         int height = raster.getHeight();
 
@@ -296,6 +301,20 @@ public class PDDeviceN extends PDSpecial
             for (int x = 0; x < width; x++)
             {
                 raster.getPixel(x, y, src);
+                if (numSrcComponents == 1)
+                {
+                    int[] pxl = map1.get(src[0]);
+                    if (pxl != null)
+                    {
+                        rgbRaster.setPixel(x, y, pxl);
+                        continue;
+                    }
+                    else
+                    {
+                        // need to remember key bevause src is modified
+                        key = src[0];
+                    }
+                }
 
                 int[] intSrc = new int[numSrcComponents];
                 raster.getPixel(x, y, intSrc);
@@ -318,6 +337,12 @@ public class PDDeviceN extends PDSpecial
                     rgb[s] = (int) (rgbFloat[s] * 255f);
                 }                
 
+                if (numSrcComponents == 1)
+                {
+                    // must clone because rgb is reused
+                    map1.put(key, rgb.clone());
+                }
+
                 rgbRaster.setPixel(x, y, rgb);
             }
         }



Mime
View raw message