You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2017/08/18 17:54:44 UTC
svn commit: r1805452 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
Author: tilman
Date: Fri Aug 18 17:54:44 2017
New Revision: 1805452
URL: http://svn.apache.org/viewvc?rev=1805452&view=rev
Log:
PDFBOX-3900: optimize with lazy initialized map
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java?rev=1805452&r1=1805451&r2=1805452&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java Fri Aug 18 17:54:44 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<Integer, float[]>();
+ }
+ 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;
}
//