You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2014/07/11 19:30:10 UTC

svn commit: r1609750 - in /xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop: pdf/PDFFactory.java pdf/PDFFunction.java render/shading/Function.java render/shading/FunctionPattern.java render/shading/GradientFactory.java

Author: vhennebert
Date: Fri Jul 11 17:30:10 2014
New Revision: 1609750

URL: http://svn.apache.org/r1609750
Log:
Avoid unnecessary conversion to List of Double by keeping the original float[] array for colors

Modified:
    xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFactory.java
    xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFunction.java
    xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/Function.java
    xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/FunctionPattern.java
    xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java

Modified: xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFactory.java?rev=1609750&r1=1609749&r2=1609750&view=diff
==============================================================================
--- xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFactory.java Fri Jul 11 17:30:10 2014
@@ -26,7 +26,6 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.DecimalFormat;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Iterator;
@@ -268,8 +267,8 @@ public class PDFFactory {
      * @return the PDF function that was created
      */
     public PDFFunction makeFunction(int theFunctionType, List theDomain,
-                                    List theRange, List theCZero,
-                                    List theCOne,
+                                    List theRange, float[] theCZero,
+                                    float[] theCOne,
                                     double theInterpolationExponentN) {    // type 2
         PDFFunction function = new PDFFunction(theFunctionType, theDomain,
                                                theRange, theCZero, theCOne,
@@ -1367,14 +1366,9 @@ public class PDFFactory {
         final Double one = new Double(1d);
         List theDomain = Arrays.asList(new Double[] {zero, one});
         List theRange = Arrays.asList(new Double[] {zero, one, zero, one, zero, one});
-        List theCZero = Arrays.asList(new Double[] {one, one, one});
-        List theCOne = new ArrayList();
-        float[] comps = ncs.getRGBColor().getColorComponents(null);
-        for (int i = 0, c = comps.length; i < c; i++) {
-            theCOne.add(new Double(comps[i]));
-        }
-        PDFFunction tintFunction = makeFunction(2, theDomain, theRange,
-                theCZero, theCOne, 1.0d);
+        float[] cZero = new float[] {1f, 1f, 1f};
+        float[] cOne = ncs.getRGBColor().getColorComponents(null);
+        PDFFunction tintFunction = makeFunction(2, theDomain, theRange, cZero, cOne, 1.0d);
         PDFSeparationColorSpace cs = new PDFSeparationColorSpace(colorName, tintFunction);
         getDocument().registerObject(cs);
         if (res != null) {

Modified: xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFunction.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFunction.java?rev=1609750&r1=1609749&r2=1609750&view=diff
==============================================================================
--- xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFunction.java (original)
+++ xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/pdf/PDFFunction.java Fri Jul 11 17:30:10 2014
@@ -20,6 +20,7 @@
 package org.apache.fop.pdf;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -71,7 +72,7 @@ public class PDFFunction extends PDFObje
      * @param theFunctionType The type of the function, which should be 2.
      */
     public PDFFunction(int theFunctionType, List<Double> theDomain,
-                       List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
+                       List<Double> theRange, float[] theCZero, float[] theCOne,
                        double theInterpolationExponentN) {
         this(new Function(theFunctionType, theDomain, theRange,
                 theCZero, theCOne, theInterpolationExponentN));
@@ -190,18 +191,10 @@ public class PDFFunction extends PDFObje
         } else if (func.getFilter() != null) {
             return false;
         }
-        if (function.getCZero() != null) {
-            if (!function.getCZero().equals(func.getCZero())) {
-                return false;
-            }
-        } else if (func.getCZero() != null) {
+        if (!Arrays.equals(function.getCZero(), func.getCZero())) {
             return false;
         }
-        if (function.getCOne() != null) {
-            if (!function.getCOne().equals(func.getCOne())) {
-                return false;
-            }
-        } else if (func.getCOne() != null) {
+        if (!Arrays.equals(function.getCOne(), func.getCOne())) {
             return false;
         }
         if (!pdfFunctions.equals(((PDFFunction) obj).pdfFunctions)) {

Modified: xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/Function.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/Function.java?rev=1609750&r1=1609749&r2=1609750&view=diff
==============================================================================
--- xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/Function.java (original)
+++ xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/Function.java Fri Jul 11 17:30:10 2014
@@ -99,13 +99,13 @@ public class Function {
      * Required For Type 2: An Array of n Doubles defining
      * the function result when x=0. Default is [0].
      */
-    protected List<Double> cZero = null;
+    protected float[] cZero;
 
     /**
      * Required For Type 2: An Array of n Doubles defining
      * the function result when x=1. Default is [1].
      */
-    protected List<Double> cOne = null;
+    protected float[] cOne;
 
     /**
      * Required for Type 2: The interpolation exponent.
@@ -137,82 +137,6 @@ public class Function {
     protected List<Double> bounds = null;
 
     /**
-     * create an complete Function object of Type 0, A Sampled function.
-     *
-     * Use null for an optional object parameter if you choose not to use it.
-     * For optional int parameters, pass the default.
-     * @param theFunctionType This is the type of function (0,2,3, or 4).
-     * It should be 0 as this is the constructor for sampled functions.
-     * @param theDomain List objects of Double objects.
-     * This is the domain of the function.
-     * See page 264 of the PDF 1.3 Spec.
-     * @param theRange List objects of Double objects.
-     * This is the Range of the function.
-     * See page 264 of the PDF 1.3 Spec.
-     * @param theSize A List object of Integer objects.
-     * This is the number of samples in each input dimension.
-     * I can't imagine there being more or less than two input dimensions,
-     * so maybe this should be an array of length 2.
-     *
-     * See page 265 of the PDF 1.3 Spec.
-     * @param theBitsPerSample An int specifying the number of bits
-                               used to represent each sample value.
-     * Limited to 1,2,4,8,12,16,24 or 32.
-     * See page 265 of the 1.3 PDF Spec.
-     * @param theOrder The order of interpolation between samples. Default is 1 (one). Limited
-     * to 1 (one) or 3, which means linear or cubic-spline interpolation.
-     *
-     * This attribute is optional.
-     *
-     * See page 265 in the PDF 1.3 spec.
-     * @param theEncode List objects of Double objects.
-     * This is the linear mapping of input values intop the domain
-     * of the function's sample table. Default is hard to represent in
-     * ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
-     * This attribute is optional.
-     *
-     * See page 265 in the PDF 1.3 spec.
-     * @param theDecode List objects of Double objects.
-     * This is a linear mapping of sample values into the range.
-     * The default is just the range.
-     *
-     * This attribute is optional.
-     * Read about it on page 265 of the PDF 1.3 spec.
-     * @param theFunctionDataStream The sample values that specify
-     *                     the function are provided in a stream.
-     *
-     * This is optional, but is almost always used.
-     *
-     * Page 265 of the PDF 1.3 spec has more.
-     * @param theFilter This is a vector of String objects which are the various filters that
-     * have are to be applied to the stream to make sense of it. Order matters,
-     * so watch out.
-     *
-     * This is not documented in the Function section of the PDF 1.3 spec,
-     * it was deduced from samples that this is sometimes used, even if we may never
-     * use it in FOP. It is added for completeness sake.
-     */
-    public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
-                       List<Double> theSize, int theBitsPerSample, int theOrder,
-                       List<Double> theEncode, List<Double> theDecode, StringBuffer theFunctionDataStream,
-                       List<String> theFilter) {
-        this.functionType = 0;      // dang well better be 0;
-        this.size = theSize;
-        this.bitsPerSample = theBitsPerSample;
-        this.order = theOrder;      // int
-        this.encode = theEncode;    // vector of int
-        this.decode = theDecode;    // vector of int
-        this.functionDataStream = theFunctionDataStream;
-        this.filter = theFilter;    // vector of Strings
-
-        // the domain and range are actually two dimensional arrays.
-        // so if there's not an even number of items, bad stuff
-        // happens.
-        this.domain = theDomain;
-        this.range = theRange;
-    }
-
-    /**
      * create an complete Function object of Type 2, an Exponential Interpolation function.
      *
      * Use null for an optional object parameter if you choose not to use it.
@@ -228,7 +152,7 @@ public class Function {
      *
      * This attribute is optional.
      * It's described on page 268 of the PDF 1.3 spec.
-     * @param theCOne This is a vector of Double objects which defines the function result
+     * @param cOne This is a vector of Double objects which defines the function result
      * when x=1.
      *
      * This attribute is optional.
@@ -239,11 +163,11 @@ public class Function {
      * PDF Spec page 268
      */
     public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
-                       List<Double> theCZero, List<Double> theCOne, double theInterpolationExponentN) {
+                       float[] cZero, float[] cOne, double theInterpolationExponentN) {
         this.functionType = 2;    // dang well better be 2;
 
-        this.cZero = theCZero;
-        this.cOne = theCOne;
+        this.cZero = cZero;
+        this.cOne = cOne;
         this.interpolationExponentN = theInterpolationExponentN;
 
         this.domain = theDomain;
@@ -299,38 +223,6 @@ public class Function {
     }
 
     /**
-     * create an complete Function object of Type 4, a postscript calculator function.
-     *
-     * Use null for an optional object parameter if you choose not to use it.
-     * For optional int parameters, pass the default.
-     * @param theFunctionType The type of function which should be 4, as this is
-     * a Postscript calculator function
-     * @param theDomain List object of Double objects.
-     * This is the domain of the function.
-     * See page 264 of the PDF 1.3 Spec.
-     * @param theRange List object of Double objects.
-     * This is the Range of the function.
-     * See page 264 of the PDF 1.3 Spec.
-     * @param theFunctionDataStream This is a stream of arithmetic,
-     *            boolean, and stack operators and boolean constants.
-     * I end up enclosing it in the '{' and '}' braces for you, so don't do it
-     * yourself.
-     *
-     * This attribute is required.
-     * It's described on page 269 of the PDF 1.3 spec.
-     */
-    public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
-                       StringBuffer theFunctionDataStream) {
-        this.functionType = 4;    // dang well better be 4;
-        this.functionDataStream = theFunctionDataStream;
-
-        this.domain = theDomain;
-
-        this.range = theRange;
-
-    }
-
-    /**
      * Gets the function type
      */
     public int getFunctionType() {
@@ -428,14 +320,14 @@ public class Function {
     /**
      * Gets the function C0 value (color for gradient)
      */
-    public List<Double> getCZero() {
+    public float[] getCZero() {
         return cZero;
     }
 
     /**
      * Gets the function C1 value (color for gradient)
      */
-    public List<Double> getCOne() {
+    public float[] getCOne() {
         return cOne;
     }
 

Modified: xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/FunctionPattern.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/FunctionPattern.java?rev=1609750&r1=1609749&r2=1609750&view=diff
==============================================================================
--- xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/FunctionPattern.java (original)
+++ xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/FunctionPattern.java Fri Jul 11 17:30:10 2014
@@ -190,10 +190,9 @@ public class FunctionPattern {
             // C0
             if (function.getCZero() != null) {
                 p.append("/C0 [ ");
-                vectorSize = function.getCZero().size();
-                for (tempInt = 0; tempInt < vectorSize; tempInt++) {
-                    p.append(PDFNumber.doubleOut(function.getCZero().get(tempInt))
-                             + " ");
+                for (float c : function.getCZero()) {
+                    p.append(PDFNumber.doubleOut(c));
+                    p.append(" ");
                 }
                 p.append("] \n");
             }
@@ -201,10 +200,9 @@ public class FunctionPattern {
             // C1
             if (function.getCOne() != null) {
                 p.append("/C1 [ ");
-                vectorSize = function.getCOne().size();
-                for (tempInt = 0; tempInt < vectorSize; tempInt++) {
-                    p.append(PDFNumber.doubleOut(function.getCOne().get(tempInt))
-                             + " ");
+                for (float c : function.getCOne()) {
+                    p.append(PDFNumber.doubleOut(c));
+                    p.append(" ");
                 }
                 p.append("] \n");
             }

Modified: xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java?rev=1609750&r1=1609749&r2=1609750&view=diff
==============================================================================
--- xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java (original)
+++ xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java Fri Jul 11 17:30:10 2014
@@ -125,8 +125,8 @@ public abstract class GradientFactory<P 
                 currentPosition++) {
             Color currentColor = colors.get(currentPosition);
             Color nextColor = colors.get(currentPosition + 1);
-            List<Double> c0 = toColorVector(currentColor);
-            List<Double> c1 = toColorVector(nextColor);
+            float[] c0 = currentColor.getColorComponents(null);
+            float[] c1 = nextColor.getColorComponents(null);
             Function function = new Function(2, null, null, c0, c1, 1.0);
             functions.add(function);
         }
@@ -156,13 +156,4 @@ public abstract class GradientFactory<P 
 
     public abstract P makePattern(int thePatternType, Shading theShading, List theXUID,
             StringBuffer theExtGState, List<Double> theMatrix);
-
-    private List<Double> toColorVector(Color nextColor) {
-        List<Double> vector = new java.util.ArrayList<Double>();
-        float[] comps = nextColor.getColorComponents(null);
-        for (int i = 0, c = comps.length; i < c; i++) {
-            vector.add(Double.valueOf(comps[i]));
-        }
-        return vector;
-    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org