pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1821403 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
Date Wed, 17 Jan 2018 17:42:29 GMT
Author: lehmi
Date: Wed Jan 17 17:42:29 2018
New Revision: 1821403

URL: http://svn.apache.org/viewvc?rev=1821403&view=rev
Log:
PDFBOX-4060: enable caching for all numbers of input colors

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=1821403&r1=1821402&r2=1821403&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
Wed Jan 17 17:42:29 2018
@@ -280,9 +280,9 @@ 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;
+        // cache color mappings
+        Map<String, int[]> map1 = new HashMap<String, int[]>();
+        String key = null;
 
         int width = raster.getWidth();
         int height = raster.getHeight();
@@ -299,21 +299,18 @@ public class PDDeviceN extends PDSpecial
             for (int x = 0; x < width; x++)
             {
                 raster.getPixel(x, y, src);
-                if (numSrcComponents == 1)
+                // use a string representation as key
+                key = Float.toString(src[0]);
+                for (int s = 1; s < numSrcComponents; s++)
                 {
-                    int[] pxl = map1.get(src[0]);
-                    if (pxl != null)
-                    {
-                        rgbRaster.setPixel(x, y, pxl);
-                        continue;
-                    }
-                    else
-                    {
-                        // need to remember key because src is modified
-                        key = src[0];
-                    }
+                    key += "#" + Float.toString(src[s]);
+                }
+                int[] pxl = map1.get(key);
+                if (pxl != null)
+                {
+                    rgbRaster.setPixel(x, y, pxl);
+                    continue;
                 }
-
                 // scale to 0..1
                 for (int s = 0; s < numSrcComponents; s++)
                 {
@@ -331,12 +328,8 @@ public class PDDeviceN extends PDSpecial
                     // scale to 0..255
                     rgb[s] = (int) (rgbFloat[s] * 255f);
                 }                
-
-                if (numSrcComponents == 1)
-                {
-                    // must clone because rgb is reused
-                    map1.put(key, rgb.clone());
-                }
+                // must clone because rgb is reused
+                map1.put(key, rgb.clone());
 
                 rgbRaster.setPixel(x, y, rgb);
             }



Mime
View raw message