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 2014/02/14 22:01:39 UTC
svn commit: r1568519 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/
Author: tilman
Date: Fri Feb 14 21:01:38 2014
New Revision: 1568519
URL: http://svn.apache.org/r1568519
Log:
PDFBOX-1914: Shading package: Move "function" methods to base class and more refactoring
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudShadingContext.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudTriangle.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType4.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType5.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType6.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType7.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudShadingContext.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudShadingContext.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudShadingContext.java Fri Feb 14 21:01:38 2014
@@ -22,7 +22,6 @@ import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
-import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
@@ -31,6 +30,8 @@ import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.imageio.stream.ImageInputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -79,11 +80,8 @@ public abstract class GouraudShadingCont
protected float[] background;
private ColorSpace shadingColorSpace;
private PDFunction shadingTinttransform;
- /**
- * color conversion function.
- */
- protected PDFunction function = null; //TODO implement common PDShadingtype for 4 and 5
- private Area area = new Area(); //TODO for later optimization
+ private final boolean hasFunction;
+ private final PDShadingResources gouraudShadingType;
/**
* Constructor creates an instance to be used for fill operations.
@@ -99,8 +97,10 @@ public abstract class GouraudShadingCont
protected GouraudShadingContext(PDShadingResources shadingType, ColorModel colorModelValue,
AffineTransform xform, Matrix ctm, int pageHeight) throws IOException
{
+ gouraudShadingType = shadingType;
triangleList = new ArrayList<GouraudTriangle>();
colorSpace = shadingType.getColorSpace();
+ hasFunction = shadingType.getFunction() != null;
LOG.debug("colorSpace: " + colorSpace);
numberOfColorComponents = colorSpace.getNumberOfComponents();
LOG.debug("numberOfColorComponents: " + numberOfColorComponents);
@@ -207,17 +207,6 @@ public abstract class GouraudShadingCont
}
/**
- * create a java area that includes all the triangles.
- */
- protected void createArea()
- {
- for (GouraudTriangle triangle : triangleList)
- {
- area.add(new Area(triangle.polygon));
- }
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -298,8 +287,19 @@ public abstract class GouraudShadingCont
continue;
}
}
+
+ if (hasFunction)
+ {
+ try
+ {
+ values = gouraudShadingType.evalFunction(values);
+ }
+ catch (IOException exception)
+ {
+ LOG.error("error while processing a function", exception);
+ }
+ }
- //TODO handle function
// convert color values from shading colorspace to RGB
if (shadingColorSpace != null)
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudTriangle.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudTriangle.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudTriangle.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/GouraudTriangle.java Fri Feb 14 21:01:38 2014
@@ -17,7 +17,6 @@
package org.apache.pdfbox.pdmodel.graphics.shading;
-import java.awt.Polygon;
import java.awt.geom.Point2D;
/**
@@ -28,10 +27,6 @@ import java.awt.geom.Point2D;
public class GouraudTriangle
{
/**
- * the polygon representing the triangle.
- */
- protected final Polygon polygon = new Polygon();
- /**
* point A of the triangle.
*/
protected final Point2D pointA;
@@ -94,10 +89,6 @@ public class GouraudTriangle
xCminusB = pointC.getX() - pointB.getX();
yCminusB = pointC.getY() - pointB.getY();
area = getArea(pointA, pointB, pointC);
-
- polygon.addPoint((int) Math.round(a.getX()), (int) Math.round(a.getY()));
- polygon.addPoint((int) Math.round(b.getX()), (int) Math.round(b.getY()));
- polygon.addPoint((int) Math.round(c.getX()), (int) Math.round(c.getY()));
}
/**
@@ -114,7 +105,7 @@ public class GouraudTriangle
// see also:
// http://math.stackexchange.com/q/51326
// http://www.gamedev.net/topic/295943-is-this-a-better-point-in-triangle-test-2d/
- // java function can't be used because polygon takes integer coordinates
+ // java function can't be used because java polygon class takes integer coordinates
double xPminusA = p.getX() - pointA.getX();
double yPminusA = p.getY() - pointA.getY();
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java Fri Feb 14 21:01:38 2014
@@ -26,6 +26,7 @@ import org.apache.pdfbox.cos.COSDictiona
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.common.COSObjectable;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.common.function.PDFunction;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
@@ -40,6 +41,8 @@ public abstract class PDShadingResources
private COSArray background = null;
private PDRectangle bBox = null;
private PDColorSpace colorspace = null;
+ private PDFunction function = null;
+ private PDFunction[] functionArray = null;
/**
* shading type 1 = function based shading.
@@ -295,4 +298,128 @@ public abstract class PDShadingResources
return shading;
}
+ /**
+ * This will set the function for the color conversion.
+ *
+ * @param newFunction The new function.
+ */
+ public void setFunction(PDFunction newFunction)
+ {
+ functionArray = null;
+ function = newFunction;
+ if (newFunction == null)
+ {
+ getCOSDictionary().removeItem(COSName.FUNCTION);
+ }
+ else
+ {
+ getCOSDictionary().setItem(COSName.FUNCTION, newFunction);
+ }
+ }
+
+ /**
+ * This will set the functions COSArray for the color conversion.
+ *
+ * @param newFunctions The new COSArray containing all functions.
+ */
+ public void setFunction(COSArray newFunctions)
+ {
+ functionArray = null;
+ function = null;
+ if (newFunctions == null)
+ {
+ getCOSDictionary().removeItem(COSName.FUNCTION);
+ }
+ else
+ {
+ getCOSDictionary().setItem(COSName.FUNCTION, newFunctions);
+ }
+ }
+
+ /**
+ * This will return the function used to convert the color values.
+ *
+ * @return The function
+ * @exception IOException If we are unable to create the PDFunction object.
+ */
+ public PDFunction getFunction() throws IOException
+ {
+ if (function == null)
+ {
+ COSBase dictionaryFunctionObject = getCOSDictionary().getDictionaryObject(COSName.FUNCTION);
+ if (dictionaryFunctionObject != null)
+ function = PDFunction.create(dictionaryFunctionObject);
+ }
+ return function;
+ }
+
+ /**
+ * Provide the function(s) of the shading dictionary as array.
+ *
+ * @return an array containing the function(s)
+ * @throws IOException throw if something went wrong
+ */
+ private PDFunction[] getFunctionsArray() throws IOException
+ {
+ if (functionArray == null)
+ {
+ COSBase functionObject = getCOSDictionary().getDictionaryObject(COSName.FUNCTION);
+ if (functionObject instanceof COSDictionary)
+ {
+ functionArray = new PDFunction[1];
+ functionArray[0] = PDFunction.create(functionObject);
+ }
+ else
+ {
+ COSArray functionCOSArray = (COSArray)functionObject;
+ int numberOfFunctions = functionCOSArray.size();
+ functionArray = new PDFunction[numberOfFunctions];
+ for (int i=0; i<numberOfFunctions; i++)
+ {
+ functionArray[i] = PDFunction.create(functionCOSArray.get(i));
+ }
+ }
+ }
+ return functionArray;
+ }
+
+ /**
+ * Convert the input value using the functions of the shading dictionary.
+ *
+ * @param inputValue the input value
+ * @return the output values
+ * @throws IOException thrown if something went wrong
+ */
+ public float[] evalFunction(float inputValue) throws IOException
+ {
+ return evalFunction(new float[] {inputValue});
+ }
+
+ /**
+ * Convert the input values using the functions of the shading dictionary.
+ *
+ * @param input the input values
+ * @return the output values
+ * @throws IOException thrown if something went wrong
+ */
+ public float[] evalFunction(float [] input) throws IOException
+ {
+ PDFunction[] functions = getFunctionsArray();
+ int numberOfFunctions = functions.length;
+ float[] returnValues = null;
+ if (numberOfFunctions == 1)
+ {
+ returnValues = functions[0].eval(input);
+ }
+ else
+ {
+ returnValues = new float[numberOfFunctions];
+ for (int i=0; i<numberOfFunctions;i++)
+ {
+ float[] newValue = functions[i].eval(input);
+ returnValues[i] = newValue[0];
+ }
+ }
+ return returnValues;
+ }
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java Fri Feb 14 21:01:38 2014
@@ -16,18 +16,13 @@
*/
package org.apache.pdfbox.pdmodel.graphics.shading;
-
-
import java.awt.geom.AffineTransform;
-import java.io.IOException;
import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSFloat;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSNumber;
-import org.apache.pdfbox.pdmodel.common.function.PDFunction;
import org.apache.pdfbox.util.Matrix;
/**
@@ -36,17 +31,15 @@ import org.apache.pdfbox.util.Matrix;
*/
public class PDShadingType1 extends PDShadingResources
{
-
+
private COSArray domain = null;
- private PDFunction function = null;
- private PDFunction[] functionArray = null;
-
+
/**
* Constructor using the given shading dictionary.
*
* @param shadingDictionary The dictionary for this shading.
*/
- public PDShadingType1( COSDictionary shadingDictionary )
+ public PDShadingType1(COSDictionary shadingDictionary)
{
super(shadingDictionary);
}
@@ -61,14 +54,14 @@ public class PDShadingType1 extends PDSh
/**
* This will get the optional Matrix of a function based shading.
- *
+ *
* @return the matrix
*/
public Matrix getMatrix()
{
Matrix retval = null;
- COSArray array = (COSArray)getCOSDictionary().getDictionaryObject( COSName.MATRIX );
- if( array != null )
+ COSArray array = (COSArray) getCOSDictionary().getDictionaryObject(COSName.MATRIX);
+ if (array != null)
{
retval = new Matrix();
retval.setValue(0, 0, ((COSNumber) array.get(0)).floatValue());
@@ -83,7 +76,7 @@ public class PDShadingType1 extends PDSh
/**
* Sets the optional Matrix entry for the function based shading.
- *
+ *
* @param transform the transformation matrix
*/
public void setMatrix(AffineTransform transform)
@@ -93,28 +86,28 @@ public class PDShadingType1 extends PDSh
transform.getMatrix(values);
for (double v : values)
{
- matrix.add(new COSFloat((float)v));
+ matrix.add(new COSFloat((float) v));
}
getCOSDictionary().setItem(COSName.MATRIX, matrix);
}
/**
* This will get the optional Domain values of a function based shading.
- *
+ *
* @return the domain values
*/
public COSArray getDomain()
{
if (domain == null)
{
- domain = (COSArray)getCOSDictionary().getDictionaryObject( COSName.DOMAIN );
+ domain = (COSArray) getCOSDictionary().getDictionaryObject(COSName.DOMAIN);
}
return domain;
}
/**
* Sets the optional Domain entry for the function based shading.
- *
+ *
* @param newDomain the domain array
*/
public void setDomain(COSArray newDomain)
@@ -122,88 +115,4 @@ public class PDShadingType1 extends PDSh
domain = newDomain;
getCOSDictionary().setItem(COSName.DOMAIN, newDomain);
}
-
- /**
- * This will set the function for the color conversion.
- *
- * @param newFunction The new function.
- */
- public void setFunction(PDFunction newFunction)
- {
- function = newFunction;
- getCOSDictionary().setItem(COSName.FUNCTION, newFunction);
- }
-
- /**
- * This will return the function used to convert the color values.
- *
- * @return The function
- * @exception IOException If we are unable to create the PDFunction object.
- */
- public PDFunction getFunction() throws IOException
- {
- if (function == null)
- {
- function = PDFunction.create(getCOSDictionary().getDictionaryObject(COSName.FUNCTION));
- }
- return function;
- }
-
- /**
- * Provide the function(s) of the shading dictionary as array.
- *
- * @return an array containing the function(s)
- * @throws IOException throw if something went wrong
- */
- private PDFunction[] getFunctionsArray() throws IOException
- {
- if (functionArray == null)
- {
- COSBase functionObject = getCOSDictionary().getDictionaryObject(COSName.FUNCTION);
- if (functionObject instanceof COSDictionary)
- {
- functionArray = new PDFunction[1];
- functionArray[0] = PDFunction.create(functionObject);
- }
- else
- {
- COSArray functionCOSArray = (COSArray)functionObject;
- int numberOfFunctions = functionCOSArray.size();
- functionArray = new PDFunction[numberOfFunctions];
- for (int i=0; i<numberOfFunctions; i++)
- {
- functionArray[i] = PDFunction.create(functionCOSArray.get(i));
- }
- }
- }
- return functionArray;
- }
-
- /**
- * Convert the input value using the functions of the shading dictionary.
- *
- * @param input the input values
- * @return the output values
- * @throws IOException thrown if something went wrong
- */
- public float[] evalFunction(float [] input) throws IOException
- {
- PDFunction[] functions = getFunctionsArray();
- int numberOfFunctions = functions.length;
- float[] returnValues = null;
- if (numberOfFunctions == 1)
- {
- returnValues = functions[0].eval(input);
- }
- else
- {
- returnValues = new float[numberOfFunctions];
- for (int i=0; i<numberOfFunctions;i++)
- {
- float[] newValue = functions[i].eval(input);
- returnValues[i] = newValue[0];
- }
- }
- return returnValues;
- }
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java Fri Feb 14 21:01:38 2014
@@ -16,15 +16,9 @@
*/
package org.apache.pdfbox.pdmodel.graphics.shading;
-
-
-import java.io.IOException;
-
import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.common.function.PDFunction;
/**
* This represents resources for an axial shading.
@@ -33,18 +27,16 @@ import org.apache.pdfbox.pdmodel.common.
*/
public class PDShadingType2 extends PDShadingResources
{
-
private COSArray coords = null;
private COSArray domain = null;
private COSArray extend = null;
- private PDFunction[] functionArray = null;
-
+
/**
* Constructor using the given shading dictionary.
*
* @param shadingDictionary The dictionary for this shading.
*/
- public PDShadingType2( COSDictionary shadingDictionary )
+ public PDShadingType2(COSDictionary shadingDictionary)
{
super(shadingDictionary);
}
@@ -59,21 +51,21 @@ public class PDShadingType2 extends PDSh
/**
* This will get the optional Extend values for this shading.
- *
+ *
* @return the extend values
*/
public COSArray getExtend()
{
if (extend == null)
{
- extend = (COSArray)getCOSDictionary().getDictionaryObject( COSName.EXTEND );
+ extend = (COSArray) getCOSDictionary().getDictionaryObject(COSName.EXTEND);
}
return extend;
}
/**
* Sets the optional Extend entry for this shading.
- *
+ *
* @param newExtend the extend array
*/
public void setExtend(COSArray newExtend)
@@ -91,21 +83,21 @@ public class PDShadingType2 extends PDSh
/**
* This will get the optional Domain values for this shading.
- *
+ *
* @return the domain values
*/
public COSArray getDomain()
{
if (domain == null)
{
- domain = (COSArray)getCOSDictionary().getDictionaryObject( COSName.DOMAIN );
+ domain = (COSArray) getCOSDictionary().getDictionaryObject(COSName.DOMAIN);
}
return domain;
}
/**
* Sets the optional Domain entry for this shading.
- *
+ *
* @param newDomain the domain array
*/
public void setDomain(COSArray newDomain)
@@ -115,7 +107,7 @@ public class PDShadingType2 extends PDSh
{
getCOSDictionary().removeItem(COSName.DOMAIN);
}
- else
+ else
{
getCOSDictionary().setItem(COSName.DOMAIN, newDomain);
}
@@ -123,21 +115,21 @@ public class PDShadingType2 extends PDSh
/**
* This will get the Coords values for this shading.
- *
+ *
* @return the coords values
*/
public COSArray getCoords()
{
if (coords == null)
{
- coords = (COSArray)getCOSDictionary().getDictionaryObject( COSName.COORDS );
+ coords = (COSArray) getCOSDictionary().getDictionaryObject(COSName.COORDS);
}
return coords;
}
/**
* Sets the Coords entry for this shading.
- *
+ *
* @param newCoords the coords array
*/
public void setCoords(COSArray newCoords)
@@ -152,116 +144,4 @@ public class PDShadingType2 extends PDSh
getCOSDictionary().setItem(COSName.COORDS, newCoords);
}
}
-
- /**
- * This will set the function for the color conversion.
- *
- * @param newFunction The new function.
- */
- public void setFunction(PDFunction newFunction)
- {
- functionArray = null;
- if (newFunction == null)
- {
- getCOSDictionary().removeItem(COSName.FUNCTION);
- }
- else
- {
- getCOSDictionary().setItem(COSName.FUNCTION, newFunction);
- }
- }
-
- /**
- * This will set the functions COSArray for the color conversion.
- *
- * @param newFunctions The new COSArray containing all functions.
- */
- public void setFunction(COSArray newFunctions)
- {
- functionArray = null;
- if (newFunctions == null)
- {
- getCOSDictionary().removeItem(COSName.FUNCTION);
- }
- else
- {
- getCOSDictionary().setItem(COSName.FUNCTION, newFunctions);
- }
- }
- /**
- * This will return the function used to convert the color values.
- *
- * @return The function
- *
- * @exception IOException If we are unable to create the PDFunction object.
- *
- * @deprecated
- *
- */
- public PDFunction getFunction() throws IOException
- {
- // TODO
- // change the return value to COSArray
- return null;
- }
-
- /**
- * Provide the function(s) of the shading dictionary as array.
- *
- * @return an array containing the function(s)
- * @throws IOException throw if something went wrong
- */
- private PDFunction[] getFunctionsArray() throws IOException
- {
- if (functionArray == null)
- {
- COSBase functionObject = getCOSDictionary().getDictionaryObject(COSName.FUNCTION);
- if (functionObject instanceof COSDictionary)
- {
- functionArray = new PDFunction[1];
- functionArray[0] = PDFunction.create(functionObject);
- }
- else
- {
- COSArray functionCOSArray = (COSArray)functionObject;
- int numberOfFunctions = functionCOSArray.size();
- functionArray = new PDFunction[numberOfFunctions];
- for (int i=0; i<numberOfFunctions; i++)
- {
- functionArray[i] = PDFunction.create(functionCOSArray.get(i));
- }
- }
- }
- return functionArray;
- }
-
- /**
- * Convert the input value using the functions of the shading dictionary.
- *
- * @param inputValue the input value
- * @return the output values
- * @throws IOException thrown if something went wrong
- */
- public float[] evalFunction(float inputValue) throws IOException
- {
- float[] input = new float[] {inputValue};
- PDFunction[] functions = getFunctionsArray();
- int numberOfFunctions = functions.length;
- float[] returnValues = null;
- if (numberOfFunctions == 1)
- {
- returnValues = functions[0].eval(input);
- }
- else
- {
- returnValues = new float[numberOfFunctions];
- for (int i=0; i<numberOfFunctions;i++)
- {
- float[] newValue = functions[i].eval(input);
- returnValues[i] = newValue[0];
- }
- }
- return returnValues;
- }
-
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java Fri Feb 14 21:01:38 2014
@@ -16,8 +16,6 @@
*/
package org.apache.pdfbox.pdmodel.graphics.shading;
-
-
import org.apache.pdfbox.cos.COSDictionary;
/**
@@ -27,13 +25,12 @@ import org.apache.pdfbox.cos.COSDictiona
*/
public class PDShadingType3 extends PDShadingType2
{
-
/**
* Constructor using the given shading dictionary.
*
* @param shadingDictionary The dictionary for this shading.
*/
- public PDShadingType3( COSDictionary shadingDictionary )
+ public PDShadingType3(COSDictionary shadingDictionary)
{
super(shadingDictionary);
}
@@ -45,5 +42,4 @@ public class PDShadingType3 extends PDSh
{
return PDShadingResources.SHADING_TYPE3;
}
-
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType4.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType4.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType4.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType4.java Fri Feb 14 21:01:38 2014
@@ -16,27 +16,23 @@
*/
package org.apache.pdfbox.pdmodel.graphics.shading;
-import java.io.IOException;
-
import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.common.PDRange;
-import org.apache.pdfbox.pdmodel.common.function.PDFunction;
/**
- * This represents resources for a shading type 4 (Free-Form Gouraud-Shaded Triangle Meshes).
+ * This represents resources for a shading type 4 (Free-Form Gouraud-Shaded
+ * Triangle Meshes).
*
*/
public class PDShadingType4 extends PDShadingResources
{
-
- private PDFunction function = null;
+
/**
- * An array of 2^n numbers specifying the linear mapping of sample values
- * into the range appropriate for the function's output values.
- * Default value: same as the value of Range
+ * An array of 2^n numbers specifying the linear mapping of sample values
+ * into the range appropriate for the function's output values. Default
+ * value: same as the value of Range
*/
private COSArray decode = null;
@@ -45,7 +41,7 @@ public class PDShadingType4 extends PDSh
*
* @param shadingDictionary The dictionary for this shading.
*/
- public PDShadingType4( COSDictionary shadingDictionary )
+ public PDShadingType4(COSDictionary shadingDictionary)
{
super(shadingDictionary);
}
@@ -59,42 +55,14 @@ public class PDShadingType4 extends PDSh
}
/**
- * This will set the function for the color conversion.
- *
- * @param newFunction The new function.
- */
- public void setFunction(PDFunction newFunction)
- {
- function = newFunction;
- getCOSDictionary().setItem(COSName.FUNCTION, newFunction);
- }
-
- /**
- * This will return the function used to convert the color values.
- *
- * @return The function
- * @exception IOException If we are unable to create the PDFunction object.
- */
- public PDFunction getFunction() throws IOException
- {
- if (function == null)
- {
- COSBase dictionaryFunctionObject = getCOSDictionary().getDictionaryObject(COSName.FUNCTION);
- if (dictionaryFunctionObject != null)
- function = PDFunction.create(dictionaryFunctionObject);
- }
- return function;
- }
-
- /**
- * The bits per component of this shading.
- * This will return -1 if one has not been set.
+ * The bits per component of this shading. This will return -1 if one has
+ * not been set.
*
* @return The number of bits per component.
*/
public int getBitsPerComponent()
{
- return getCOSDictionary().getInt( COSName.BITS_PER_COMPONENT, -1 );
+ return getCOSDictionary().getInt(COSName.BITS_PER_COMPONENT, -1);
}
/**
@@ -102,20 +70,20 @@ public class PDShadingType4 extends PDSh
*
* @param bpc The number of bits per component.
*/
- public void setBitsPerComponent( int bpc )
+ public void setBitsPerComponent(int bpc)
{
- getCOSDictionary().setInt( COSName.BITS_PER_COMPONENT, bpc );
+ getCOSDictionary().setInt(COSName.BITS_PER_COMPONENT, bpc);
}
/**
- * The bits per coordinate of this shading.
- * This will return -1 if one has not been set.
+ * The bits per coordinate of this shading. This will return -1 if one has
+ * not been set.
*
* @return The number of bits per coordinate.
*/
public int getBitsPerCoordinate()
{
- return getCOSDictionary().getInt( COSName.BITS_PER_COORDINATE, -1 );
+ return getCOSDictionary().getInt(COSName.BITS_PER_COORDINATE, -1);
}
/**
@@ -123,20 +91,20 @@ public class PDShadingType4 extends PDSh
*
* @param bpc The number of bits per coordinate.
*/
- public void setBitsPerCoordinate( int bpc )
+ public void setBitsPerCoordinate(int bpc)
{
- getCOSDictionary().setInt( COSName.BITS_PER_COORDINATE, bpc );
+ getCOSDictionary().setInt(COSName.BITS_PER_COORDINATE, bpc);
}
/**
- * The bits per flag of this shading.
- * This will return -1 if one has not been set.
+ * The bits per flag of this shading. This will return -1 if one has not
+ * been set.
*
* @return The number of bits per flag.
*/
public int getBitsPerFlag()
{
- return getCOSDictionary().getInt( COSName.BITS_PER_FLAG, -1 );
+ return getCOSDictionary().getInt(COSName.BITS_PER_FLAG, -1);
}
/**
@@ -144,21 +112,21 @@ public class PDShadingType4 extends PDSh
*
* @param bpf The number of bits per flag.
*/
- public void setBitsPerFlag( int bpf )
+ public void setBitsPerFlag(int bpf)
{
- getCOSDictionary().setInt( COSName.BITS_PER_FLAG, bpf );
+ getCOSDictionary().setInt(COSName.BITS_PER_FLAG, bpf);
}
/**
* Returns all decode values as COSArray.
- *
- * @return the decode array.
+ *
+ * @return the decode array.
*/
- private COSArray getDecodeValues()
+ private COSArray getDecodeValues()
{
if (decode == null)
{
- decode = (COSArray)getCOSDictionary().getDictionaryObject( COSName.DECODE );
+ decode = (COSArray) getCOSDictionary().getDictionaryObject(COSName.DECODE);
}
return decode;
}
@@ -181,13 +149,13 @@ public class PDShadingType4 extends PDSh
*
* @return The decode parameter range or null if none is set.
*/
- public PDRange getDecodeForParameter( int paramNum )
+ public PDRange getDecodeForParameter(int paramNum)
{
PDRange retval = null;
COSArray decodeValues = getDecodeValues();
- if( decodeValues != null && decodeValues.size() >= paramNum*2+1 )
+ if (decodeValues != null && decodeValues.size() >= paramNum * 2 + 1)
{
- retval = new PDRange(decodeValues, paramNum );
+ retval = new PDRange(decodeValues, paramNum);
}
return retval;
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType5.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType5.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType5.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType5.java Fri Feb 14 21:01:38 2014
@@ -1,197 +1,162 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.pdmodel.graphics.shading;
-
-
-
-import java.io.IOException;
-
-import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.common.PDRange;
-import org.apache.pdfbox.pdmodel.common.function.PDFunction;
-
-/**
- * This represents resources for a shading type 5 (Lattice-Form Gouraud-Shaded Triangle Meshes).
- *
- */
-public class PDShadingType5 extends PDShadingResources
-{
-
- private PDFunction function = null;
- /**
- * An array of 2^n numbers specifying the linear mapping of sample values
- * into the range appropriate for the function's output values.
- * Default value: same as the value of Range
- */
- private COSArray decode = null;
-
- /**
- * Constructor using the given shading dictionary.
- *
- * @param shadingDictionary The dictionary for this shading.
- */
- public PDShadingType5( COSDictionary shadingDictionary )
- {
- super(shadingDictionary);
- }
-
- /**
- * {@inheritDoc}
- */
- public int getShadingType()
- {
- return PDShadingResources.SHADING_TYPE5;
- }
-
- /**
- * This will set the function for the color conversion.
- *
- * @param newFunction The new function.
- */
- public void setFunction(PDFunction newFunction)
- {
- function = newFunction;
- getCOSDictionary().setItem(COSName.FUNCTION, newFunction);
- }
-
- /**
- * This will return the function used to convert the color values.
- *
- * @return The function
- * @exception IOException If we are unable to create the PDFunction object.
- */
- public PDFunction getFunction() throws IOException
- {
- if (function == null)
- {
- COSBase dictionaryFunctionObject = getCOSDictionary().getDictionaryObject(COSName.FUNCTION);
- if (dictionaryFunctionObject != null)
- function = PDFunction.create(dictionaryFunctionObject);
- }
- return function;
- }
-
- /**
- * The bits per component of this shading.
- * This will return -1 if one has not been set.
- *
- * @return The number of bits per component.
- */
- public int getBitsPerComponent()
- {
- return getCOSDictionary().getInt( COSName.BITS_PER_COMPONENT, -1 );
- }
-
- /**
- * Set the number of bits per component.
- *
- * @param bpc The number of bits per component.
- */
- public void setBitsPerComponent( int bpc )
- {
- getCOSDictionary().setInt( COSName.BITS_PER_COMPONENT, bpc );
- }
-
- /**
- * The bits per coordinate of this shading.
- * This will return -1 if one has not been set.
- *
- * @return The number of bits per coordinate.
- */
- public int getBitsPerCoordinate()
- {
- return getCOSDictionary().getInt( COSName.BITS_PER_COORDINATE, -1 );
- }
-
- /**
- * Set the number of bits per coordinate.
- *
- * @param bpc The number of bits per coordinate.
- */
- public void setBitsPerCoordinate( int bpc )
- {
- getCOSDictionary().setInt( COSName.BITS_PER_COORDINATE, bpc );
- }
-
- /**
- * The vertices per row of this shading.
- * This will return -1 if one has not been set.
- *
- * @return The number of vertices per row.
- */
- public int getVerticesPerRow()
- {
- return getCOSDictionary().getInt( COSName.VERTICES_PER_ROW, -1 );
- }
-
- /**
- * Set the number of vertices per row.
- *
- * @param vpr The number of vertices per row.
- */
- public void setVerticesPerRow( int vpr )
- {
- getCOSDictionary().setInt( COSName.VERTICES_PER_ROW, vpr );
- }
-
- /**
- * Returns all decode values as COSArray.
- *
- * @return the decode array.
- */
- private COSArray getDecodeValues()
- {
- if (decode == null)
- {
- decode = (COSArray)getCOSDictionary().getDictionaryObject( COSName.DECODE );
- }
- return decode;
- }
-
- /**
- * This will set the decode values.
- *
- * @param decodeValues The new decode values.
- */
- public void setDecodeValues(COSArray decodeValues)
- {
- decode = decodeValues;
- getCOSDictionary().setItem(COSName.DECODE, decodeValues);
- }
-
- /**
- * Get the decode for the input parameter.
- *
- * @param paramNum The function parameter number.
- *
- * @return The decode parameter range or null if none is set.
- */
- public PDRange getDecodeForParameter( int paramNum )
- {
- PDRange retval = null;
- COSArray decodeValues = getDecodeValues();
- if( decodeValues != null && decodeValues.size() >= paramNum*2+1 )
- {
- retval = new PDRange(decodeValues, paramNum );
- }
- return retval;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.PDRange;
+
+/**
+ * This represents resources for a shading type 5 (Lattice-Form Gouraud-Shaded
+ * Triangle Meshes).
+ *
+ */
+public class PDShadingType5 extends PDShadingResources
+{
+
+ /**
+ * An array of 2^n numbers specifying the linear mapping of sample values
+ * into the range appropriate for the function's output values. Default
+ * value: same as the value of Range
+ */
+ private COSArray decode = null;
+
+ /**
+ * Constructor using the given shading dictionary.
+ *
+ * @param shadingDictionary The dictionary for this shading.
+ */
+ public PDShadingType5(COSDictionary shadingDictionary)
+ {
+ super(shadingDictionary);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getShadingType()
+ {
+ return PDShadingResources.SHADING_TYPE5;
+ }
+
+ /**
+ * The bits per component of this shading. This will return -1 if one has
+ * not been set.
+ *
+ * @return The number of bits per component.
+ */
+ public int getBitsPerComponent()
+ {
+ return getCOSDictionary().getInt(COSName.BITS_PER_COMPONENT, -1);
+ }
+
+ /**
+ * Set the number of bits per component.
+ *
+ * @param bpc The number of bits per component.
+ */
+ public void setBitsPerComponent(int bpc)
+ {
+ getCOSDictionary().setInt(COSName.BITS_PER_COMPONENT, bpc);
+ }
+
+ /**
+ * The bits per coordinate of this shading. This will return -1 if one has
+ * not been set.
+ *
+ * @return The number of bits per coordinate.
+ */
+ public int getBitsPerCoordinate()
+ {
+ return getCOSDictionary().getInt(COSName.BITS_PER_COORDINATE, -1);
+ }
+
+ /**
+ * Set the number of bits per coordinate.
+ *
+ * @param bpc The number of bits per coordinate.
+ */
+ public void setBitsPerCoordinate(int bpc)
+ {
+ getCOSDictionary().setInt(COSName.BITS_PER_COORDINATE, bpc);
+ }
+
+ /**
+ * The vertices per row of this shading. This will return -1 if one has not
+ * been set.
+ *
+ * @return The number of vertices per row.
+ */
+ public int getVerticesPerRow()
+ {
+ return getCOSDictionary().getInt(COSName.VERTICES_PER_ROW, -1);
+ }
+
+ /**
+ * Set the number of vertices per row.
+ *
+ * @param vpr The number of vertices per row.
+ */
+ public void setVerticesPerRow(int vpr)
+ {
+ getCOSDictionary().setInt(COSName.VERTICES_PER_ROW, vpr);
+ }
+
+ /**
+ * Returns all decode values as COSArray.
+ *
+ * @return the decode array.
+ */
+ private COSArray getDecodeValues()
+ {
+ if (decode == null)
+ {
+ decode = (COSArray) getCOSDictionary().getDictionaryObject(COSName.DECODE);
+ }
+ return decode;
+ }
+
+ /**
+ * This will set the decode values.
+ *
+ * @param decodeValues The new decode values.
+ */
+ public void setDecodeValues(COSArray decodeValues)
+ {
+ decode = decodeValues;
+ getCOSDictionary().setItem(COSName.DECODE, decodeValues);
+ }
+
+ /**
+ * Get the decode for the input parameter.
+ *
+ * @param paramNum The function parameter number.
+ *
+ * @return The decode parameter range or null if none is set.
+ */
+ public PDRange getDecodeForParameter(int paramNum)
+ {
+ PDRange retval = null;
+ COSArray decodeValues = getDecodeValues();
+ if (decodeValues != null && decodeValues.size() >= paramNum * 2 + 1)
+ {
+ retval = new PDRange(decodeValues, paramNum);
+ }
+ return retval;
+ }
+}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType6.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType6.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType6.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType6.java Fri Feb 14 21:01:38 2014
@@ -16,7 +16,6 @@
*/
package org.apache.pdfbox.pdmodel.graphics.shading;
-
import org.apache.pdfbox.cos.COSDictionary;
/**
@@ -26,13 +25,12 @@ import org.apache.pdfbox.cos.COSDictiona
*/
public class PDShadingType6 extends PDShadingType4
{
-
/**
* Constructor using the given shading dictionary.
*
* @param shadingDictionary The dictionary for this shading.
*/
- public PDShadingType6( COSDictionary shadingDictionary )
+ public PDShadingType6(COSDictionary shadingDictionary)
{
super(shadingDictionary);
}
@@ -44,5 +42,4 @@ public class PDShadingType6 extends PDSh
{
return PDShadingResources.SHADING_TYPE6;
}
-
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType7.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType7.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType7.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType7.java Fri Feb 14 21:01:38 2014
@@ -16,7 +16,6 @@
*/
package org.apache.pdfbox.pdmodel.graphics.shading;
-
import org.apache.pdfbox.cos.COSDictionary;
/**
@@ -26,13 +25,12 @@ import org.apache.pdfbox.cos.COSDictiona
*/
public class PDShadingType7 extends PDShadingType4
{
-
/**
* Constructor using the given shading dictionary.
*
* @param shadingDictionary The dictionary for this shading.
*/
- public PDShadingType7( COSDictionary shadingDictionary )
+ public PDShadingType7(COSDictionary shadingDictionary)
{
super(shadingDictionary);
}
@@ -44,5 +42,4 @@ public class PDShadingType7 extends PDSh
{
return PDShadingResources.SHADING_TYPE6;
}
-
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java Fri Feb 14 21:01:38 2014
@@ -34,48 +34,46 @@ import org.apache.pdfbox.pdmodel.common.
import org.apache.pdfbox.util.Matrix;
/**
- * This represents the Paint of a type 4 (Gouraud triangle mesh) shading context.
- *
+ * This represents the Paint of a type 4 (Gouraud triangle mesh) shading
+ * context.
+ *
* @author Tilman Hausherr
*/
class Type4ShadingContext extends GouraudShadingContext
{
private static final Log LOG = LogFactory.getLog(Type4ShadingContext.class);
- private PDShadingType4 shadingType;
private int bitsPerFlag;
-
/**
* Constructor creates an instance to be used for fill operations.
- *
+ *
* @param shadingType4 the shading type to be used
* @param colorModelValue the color model to be used
* @param xform transformation for user to device space
* @param ctm current transformation matrix
* @param pageHeight height of the current page
- *
+ *
*/
public Type4ShadingContext(PDShadingType4 shadingType4, ColorModel colorModelValue,
AffineTransform xform, Matrix ctm, int pageHeight) throws IOException
{
super(shadingType4, colorModelValue, xform, ctm, pageHeight);
-
+
ArrayList<Vertex> vertexList = new ArrayList<Vertex>();
- shadingType = shadingType4;
LOG.debug("Type4ShadingContext");
- bitsPerColorComponent = shadingType.getBitsPerComponent();
+ bitsPerColorComponent = shadingType4.getBitsPerComponent();
LOG.debug("bitsPerColorComponent: " + bitsPerColorComponent);
- bitsPerCoordinate = shadingType.getBitsPerCoordinate();
+ bitsPerCoordinate = shadingType4.getBitsPerCoordinate();
LOG.debug(Math.pow(2, bitsPerCoordinate) - 1);
long maxSrcCoord = (int) Math.pow(2, bitsPerCoordinate) - 1;
long maxSrcColor = (int) Math.pow(2, bitsPerColorComponent) - 1;
LOG.debug("maxSrcCoord: " + maxSrcCoord);
LOG.debug("maxSrcColor: " + maxSrcColor);
- COSDictionary cosDictionary = shadingType.getCOSDictionary();
+ COSDictionary cosDictionary = shadingType4.getCOSDictionary();
COSStream cosStream = (COSStream) cosDictionary;
//The Decode key specifies how
@@ -94,28 +92,22 @@ class Type4ShadingContext extends Gourau
PDRange[] colRangeTab = new PDRange[numberOfColorComponents];
for (int i = 0; i < numberOfColorComponents; ++i)
{
- colRangeTab[i] = shadingType.getDecodeForParameter(2 + i);
+ colRangeTab[i] = shadingType4.getDecodeForParameter(2 + i);
}
LOG.debug("bitsPerCoordinate: " + bitsPerCoordinate);
- bitsPerFlag = shadingType.getBitsPerFlag();
- if (shadingType.getFunction() != null)
- {
- LOG.error("function based type 4 shading not implemented, please file issue with sample file");
- }
- LOG.debug("function: " + shadingType.getFunction()); //TODO implement function based shading
+ bitsPerFlag = shadingType4.getBitsPerFlag();
LOG.debug("bitsPerFlag: " + bitsPerFlag); //TODO handle cases where bitperflag isn't 8
LOG.debug("Stream size: " + cosStream.getInt(COSName.LENGTH));
-
+
// get background values if available
- COSArray bg = shadingType.getBackground();
+ COSArray bg = shadingType4.getBackground();
if (bg != null)
{
background = bg.toFloatArray();
}
-
+
//TODO missing: BBox, AntiAlias (p. 305 in 1.7 spec)
-
// p318:
// reading in sequence from higher-order to lower-order bit positions
ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.getFilteredStream());
@@ -129,9 +121,9 @@ class Type4ShadingContext extends Gourau
{
case 0:
Vertex v1 = readVertex(mciis, flag, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRangeTab);
- Vertex v2 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
+ Vertex v2 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
rangeX, rangeY, colRangeTab);
- Vertex v3 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
+ Vertex v3 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
rangeX, rangeY, colRangeTab);
// add them after they're read, so that they are never added if there is a premature EOF
@@ -190,12 +182,11 @@ class Type4ShadingContext extends Gourau
mciis.close();
transformVertices(vertexList, ctm, xform, pageHeight);
createTriangleList(vertexList);
- createArea();
}
/**
* Create GouraudTriangle list from vertices, see p.316 of pdf spec 1.7.
- *
+ *
* @param vertexList list of vertices
*/
private void createTriangleList(ArrayList<Vertex> vertexList)
@@ -259,6 +250,5 @@ class Type4ShadingContext extends Gourau
public void dispose()
{
super.dispose();
- shadingType = null;
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java?rev=1568519&r1=1568518&r2=1568519&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java Fri Feb 14 21:01:38 2014
@@ -43,8 +43,6 @@ public class Type5ShadingContext extends
{
private static final Log LOG = LogFactory.getLog(Type5ShadingContext.class);
- private PDShadingType5 shadingType;
-
/**
* Constructor creates an instance to be used for fill operations.
*
@@ -53,7 +51,7 @@ public class Type5ShadingContext extends
* @param xform transformation for user to device space
* @param ctm current transformation matrix
* @param pageHeight height of the current page
- *
+ *
* @throws IOException if something went wrong
*/
public Type5ShadingContext(PDShadingType5 shadingType5, ColorModel colorModelValue,
@@ -61,20 +59,18 @@ public class Type5ShadingContext extends
{
super(shadingType5, colorModelValue, xform, ctm, pageHeight);
- shadingType = shadingType5;
-
LOG.debug("Type5ShadingContext");
- bitsPerColorComponent = shadingType.getBitsPerComponent();
+ bitsPerColorComponent = shadingType5.getBitsPerComponent();
LOG.debug("bitsPerColorComponent: " + bitsPerColorComponent);
- bitsPerCoordinate = shadingType.getBitsPerCoordinate();
+ bitsPerCoordinate = shadingType5.getBitsPerCoordinate();
LOG.debug(Math.pow(2, bitsPerCoordinate) - 1);
long maxSrcCoord = (int) Math.pow(2, bitsPerCoordinate) - 1;
long maxSrcColor = (int) Math.pow(2, bitsPerColorComponent) - 1;
LOG.debug("maxSrcCoord: " + maxSrcCoord);
LOG.debug("maxSrcColor: " + maxSrcColor);
- COSDictionary cosDictionary = shadingType.getCOSDictionary();
+ COSDictionary cosDictionary = shadingType5.getCOSDictionary();
COSStream cosStream = (COSStream) cosDictionary;
//The Decode key specifies how
@@ -93,30 +89,25 @@ public class Type5ShadingContext extends
PDRange[] colRangeTab = new PDRange[numberOfColorComponents];
for (int i = 0; i < numberOfColorComponents; ++i)
{
- colRangeTab[i] = shadingType.getDecodeForParameter(2 + i);
+ colRangeTab[i] = shadingType5.getDecodeForParameter(2 + i);
}
LOG.debug("bitsPerCoordinate: " + bitsPerCoordinate);
- if (shadingType.getFunction() != null)
- {
- LOG.error("function based type 4 shading not implemented, please file issue with sample file");
- }
- LOG.debug("function: " + shadingType.getFunction()); //TODO implement function based shading
// get background values if available
- COSArray bg = shadingType.getBackground();
+ COSArray bg = shadingType5.getBackground();
if (bg != null)
{
background = bg.toFloatArray();
}
//TODO missing: BBox, AntiAlias (p. 305 in 1.7 spec)
-
+
// p318:
// reading in sequence from higher-order to lower-order bit positions
ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.getFilteredStream());
- int verticesPerRow = shadingType.getVerticesPerRow(); //TODO check >=2
+ int verticesPerRow = shadingType5.getVerticesPerRow(); //TODO check >=2
LOG.debug("verticesPerRow" + verticesPerRow);
try
@@ -157,8 +148,6 @@ public class Type5ShadingContext extends
}
mciis.close();
-
- createArea();
}
/**
@@ -168,7 +157,6 @@ public class Type5ShadingContext extends
public void dispose()
{
super.dispose();
- shadingType = null;
}
}