aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2014-07-11 17:30:10 +0000
committerVincent Hennebert <vhennebert@apache.org>2014-07-11 17:30:10 +0000
commitf9e61a81288b2374ae30a91da3895c7949a83de9 (patch)
tree09c9cd56e3157e41532d40ea0e5e601a81a661c8 /src/java/org
parent1ead2b6ba0e8eda9eb06da4fab5ed9bf1cd8611e (diff)
downloadxmlgraphics-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')
-rw-r--r--src/java/org/apache/fop/pdf/PDFFactory.java16
-rw-r--r--src/java/org/apache/fop/pdf/PDFFunction.java15
-rw-r--r--src/java/org/apache/fop/render/shading/Function.java124
-rw-r--r--src/java/org/apache/fop/render/shading/FunctionPattern.java14
-rw-r--r--src/java/org/apache/fop/render/shading/GradientFactory.java13
5 files changed, 25 insertions, 157 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java
index 29d821ad3..d7d08ce25 100644
--- a/src/java/org/apache/fop/pdf/PDFFactory.java
+++ b/src/java/org/apache/fop/pdf/PDFFactory.java
@@ -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) {
diff --git a/src/java/org/apache/fop/pdf/PDFFunction.java b/src/java/org/apache/fop/pdf/PDFFunction.java
index db14d550a..b63887186 100644
--- a/src/java/org/apache/fop/pdf/PDFFunction.java
+++ b/src/java/org/apache/fop/pdf/PDFFunction.java
@@ -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 PDFObject {
* @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 PDFObject {
} 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)) {
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;
- }
}