pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1805453 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
Date Fri, 18 Aug 2017 17:54:49 GMT
Author: tilman
Date: Fri Aug 18 17:54:49 2017
New Revision: 1805453

URL: http://svn.apache.org/viewvc?rev=1805453&view=rev
Log:
PDFBOX-3900: optimize with lazy initialized map

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java?rev=1805453&r1=1805452&r2=1805453&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
Fri Aug 18 17:54:49 2017
@@ -54,6 +54,14 @@ public class PDSeparation extends PDSpec
     private PDFunction tintTransform = null;
 
     /**
+     * Map used to speed up {@link #toRGB(float[])}. Note that this class contains three
maps (this
+     * and the two in {@link #toRGBImage(java.awt.image.WritableRaster) } and {@link #toRGBImage2(java.awt.image.WritableRaster)
+     * }. The maps use different key intervals. This map here is needed for shading, which
produce
+     * more than 256 different float values, which we cast to int so that the map can work.
+     */
+    private Map<Integer, float[]> toRGBMap = null;
+
+    /**
      * Creates a new Separation color space.
      */
     public PDSeparation()
@@ -105,8 +113,20 @@ public class PDSeparation extends PDSpec
     @Override
     public float[] toRGB(float[] value) throws IOException
     {
+        if (toRGBMap == null)
+        {
+            toRGBMap = new HashMap<>();
+        }
+        int key = (int) (value[0] * 255);
+        float[] retval = toRGBMap.get(key);
+        if (retval != null)
+        {
+            return retval;
+        }
         float[] altColor = tintTransform.eval(value);
-        return alternateColorSpace.toRGB(altColor);
+        retval = alternateColorSpace.toRGB(altColor);
+        toRGBMap.put(key, retval);
+        return retval;
     }
 
     //



Mime
View raw message