pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1737259 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java
Date Thu, 31 Mar 2016 17:00:30 GMT
Author: tilman
Date: Thu Mar 31 17:00:29 2016
New Revision: 1737259

URL: http://svn.apache.org/viewvc?rev=1737259&view=rev
Log:
PDFBOX-3297: optimize function creation

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java?rev=1737259&r1=1737258&r2=1737259&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java
Thu Mar 31 17:00:29 2016
@@ -35,6 +35,7 @@ public class PDFunctionType3 extends PDF
     private COSArray functions = null;
     private COSArray encode = null;
     private COSArray bounds = null;
+    private PDFunction[] functionsArray = null;
     
     /**
      * Constructor.
@@ -68,12 +69,20 @@ public class PDFunctionType3 extends PDF
         // clip input value to domain
         x = clipToRange(x, domain.getMin(), domain.getMax());
 
-        COSArray functionsArray = getFunctions();
-        int numberOfFunctions = functionsArray.size();
-        // This doesn't make sense but it may happen ...
-        if (numberOfFunctions == 1) 
+        if (functionsArray == null)
         {
-            function = PDFunction.create(functionsArray.get(0));
+            COSArray ar = getFunctions();
+            functionsArray = new PDFunction[ar.size()];
+            for (int i = 0; i < ar.size(); ++i)
+            {
+                functionsArray[i] = PDFunction.create(ar.getObject(i));
+            }            
+        }
+
+        if (functionsArray.length == 1) 
+        {
+            // This doesn't make sense but it may happen ...
+            function = functionsArray[0];
             PDRange encRange = getEncodeForParameter(0);
             x = interpolate(x, domain.getMin(), domain.getMax(), encRange.getMin(), encRange.getMax());
         }
@@ -94,12 +103,16 @@ public class PDFunctionType3 extends PDF
                 if ( x >= partitionValues[i] && 
                         (x < partitionValues[i+1] || (i == partitionValuesSize - 2 &&
x == partitionValues[i+1])))
                 {
-                    function = PDFunction.create(functionsArray.get(i));
+                    function = functionsArray[i];
                     PDRange encRange = getEncodeForParameter(i);
                     x = interpolate(x, partitionValues[i], partitionValues[i+1], encRange.getMin(),
encRange.getMax());
                     break;
                 }
             }
+            if (function == null)
+            {
+                throw new IOException("partition not found in type 3 function");
+            }
         }
         float[] functionValues = new float[]{x};
         // calculate the output values using the chosen function



Mime
View raw message