diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2014-07-11 17:30:10 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2014-07-11 17:30:10 +0000 |
commit | f9e61a81288b2374ae30a91da3895c7949a83de9 (patch) | |
tree | 09c9cd56e3157e41532d40ea0e5e601a81a661c8 /src/java/org/apache/fop/render | |
parent | 1ead2b6ba0e8eda9eb06da4fab5ed9bf1cd8611e (diff) | |
download | xmlgraphics-fop-f9e61a81288b2374ae30a91da3895c7949a83de9.tar.gz xmlgraphics-fop-f9e61a81288b2374ae30a91da3895c7949a83de9.zip |
Avoid unnecessary conversion to List of Double by keeping the original float[] array for colors
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609750 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
3 files changed, 16 insertions, 135 deletions
diff --git a/src/java/org/apache/fop/render/shading/Function.java b/src/java/org/apache/fop/render/shading/Function.java index f54d36680..75a041d72 100644 --- a/src/java/org/apache/fop/render/shading/Function.java +++ b/src/java/org/apache/fop/render/shading/Function.java @@ -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; } diff --git a/src/java/org/apache/fop/render/shading/FunctionPattern.java b/src/java/org/apache/fop/render/shading/FunctionPattern.java index 7ca9855b5..f7b735dd1 100644 --- a/src/java/org/apache/fop/render/shading/FunctionPattern.java +++ b/src/java/org/apache/fop/render/shading/FunctionPattern.java @@ -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"); } diff --git a/src/java/org/apache/fop/render/shading/GradientFactory.java b/src/java/org/apache/fop/render/shading/GradientFactory.java index f17a0e74c..5cc33c62d 100644 --- a/src/java/org/apache/fop/render/shading/GradientFactory.java +++ b/src/java/org/apache/fop/render/shading/GradientFactory.java @@ -125,8 +125,8 @@ public abstract class GradientFactory<P extends Pattern> { 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 extends Pattern> { 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; - } } |