pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1616942 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/
Date Sat, 09 Aug 2014 13:07:41 GMT
Author: tilman
Date: Sat Aug  9 13:07:40 2014
New Revision: 1616942

URL: http://svn.apache.org/r1616942
Log:
PDFBOX-1915: created abstract shading resource type for common stuff to 4,5,6,7; more refactoring

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDTriangleBasedShadingType.java
  (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
    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/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/PatchMeshesShadingContext.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/ShadingContext.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TriangleBasedShadingContext.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.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
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -28,7 +28,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBoolean;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.function.PDFunction;
 import org.apache.pdfbox.util.Matrix;
 
@@ -46,16 +45,16 @@ public class AxialShadingContext extends
 {
     private static final Log LOG = LogFactory.getLog(AxialShadingContext.class);
 
-    private PDShadingType2 shading;
+    private PDShadingType2 axialShadingType;
 
-    private float[] coords;
-    private float[] domain;
+    private final float[] coords;
+    private final float[] domain;
     private float[] background;
     private int rgbBackground;
-    private boolean[] extend;
-    private double x1x0;
-    private double y1y0;
-    private float d1d0;
+    private final boolean[] extend;
+    private final double x1x0;
+    private final double y1y0;
+    private final float d1d0;
     private double denom;
     
     private final double axialLength;
@@ -74,7 +73,7 @@ public class AxialShadingContext extends
                                Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
         super(shading, colorModel, xform, ctm, pageHeight, dBounds);
-        this.shading = shading;
+        this.axialShadingType = shading;
         coords = shading.getCoords().toFloatArray();
 
         if (ctm != null)
@@ -137,7 +136,7 @@ public class AxialShadingContext extends
         {
             try
             {
-                float[] values = shading.evalFunction(domain[0]);
+                float[] values = axialShadingType.evalFunction(domain[0]);
                 map[0] = convertToRGB(values);
             }
             catch (IOException exception)
@@ -152,7 +151,7 @@ public class AxialShadingContext extends
                 float t = domain[0] + d1d0 * i / (float)axialLength;
                 try
                 {
-                    float[] values = shading.evalFunction(t);
+                    float[] values = axialShadingType.evalFunction(t);
                     map[i] = convertToRGB(values);
                 }
                 catch (IOException exception)
@@ -188,7 +187,7 @@ public class AxialShadingContext extends
     {
         outputColorModel = null;
         shadingColorSpace = null;
-        shading = null;
+        axialShadingType = null;
     }
 
     @Override
@@ -343,6 +342,6 @@ public class AxialShadingContext extends
      */
     public PDFunction getFunction() throws IOException
     {
-        return shading.getFunction();
+        return axialShadingType.getFunction();
     }
 }

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=1616942&r1=1616941&r2=1616942&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
Sat Aug  9 13:07:40 2014
@@ -20,13 +20,9 @@ package org.apache.pdfbox.pdmodel.graphi
 import java.awt.PaintContext;
 import java.awt.Point;
 import java.awt.Rectangle;
-import java.awt.Transparency;
-import java.awt.color.ColorSpace;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
 import java.io.IOException;
@@ -55,18 +51,10 @@ abstract class GouraudShadingContext ext
     /** triangle list. */
     protected ArrayList<CoonsTriangle> triangleList;
 
-    /** bits per coordinate. */
-    protected int bitsPerCoordinate;
-
-    /** bits per color component. */
-    protected int bitsPerColorComponent;
-
     /** background values.*/
     protected float[] background;
     protected int rgbBackground;
 
-    protected final PDShading gouraudShadingType;
-    
     protected HashMap<Point, Integer> pixelTable;
 
     /**
@@ -82,7 +70,6 @@ abstract class GouraudShadingContext ext
                                     Matrix ctm, int pageHeight, Rectangle dBounds) throws
IOException
     {
         super(shading, colorModel, xform, ctm, pageHeight, dBounds);
-        gouraudShadingType = shading;
         triangleList = new ArrayList<CoonsTriangle>();
         numberOfColorComponents = hasFunction ? 1 : shadingColorSpace.getNumberOfComponents();
         LOG.debug("Background: " + shading.getBackground());

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=1616942&r1=1616941&r2=1616942&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
Sat Aug  9 13:07:40 2014
@@ -16,10 +16,8 @@
  */
 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;
 import org.apache.pdfbox.util.Matrix;
 
 import java.awt.Paint;
@@ -27,13 +25,8 @@ import java.awt.Paint;
 /**
  * Resources for a shading type 4 (Free-Form Gouraud-Shaded Triangle Mesh).
  */
-public class PDShadingType4 extends PDShading
+public class PDShadingType4 extends PDTriangleBasedShadingType
 {
-    // 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
@@ -50,42 +43,6 @@ public class PDShadingType4 extends PDSh
     }
 
     /**
-     * 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 bitsPerComponent the number of bits per component
-     */
-    public void setBitsPerComponent(int bitsPerComponent)
-    {
-        getCOSDictionary().setInt(COSName.BITS_PER_COMPONENT, bitsPerComponent);
-    }
-
-    /**
-     * 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 bitsPerComponent the number of bits per coordinate
-     */
-    public void setBitsPerCoordinate(int bitsPerComponent)
-    {
-        getCOSDictionary().setInt(COSName.BITS_PER_COORDINATE, bitsPerComponent);
-    }
-
-    /**
      * The bits per flag of this shading. This will return -1 if one has not been set.
      * @return The number of bits per flag.
      */
@@ -103,45 +60,6 @@ public class PDShadingType4 extends PDSh
         getCOSDictionary().setInt(COSName.BITS_PER_FLAG, bitsPerFlag);
     }
 
-    /**
-     * 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;
-    }
-
     @Override
     public Paint toPaint(Matrix matrix, int pageHeight)
     {

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=1616942&r1=1616941&r2=1616942&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
Sat Aug  9 13:07:40 2014
@@ -16,10 +16,8 @@
  */
 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;
 import org.apache.pdfbox.util.Matrix;
 
 import java.awt.Paint;
@@ -27,13 +25,8 @@ import java.awt.Paint;
 /**
  * Resources for a shading type 5 (Lattice-Form Gouraud-Shade Triangle Mesh).
  */
-public class PDShadingType5 extends PDShading
+public class PDShadingType5 extends PDTriangleBasedShadingType
 {
-    // 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
@@ -50,42 +43,6 @@ public class PDShadingType5 extends PDSh
     }
 
     /**
-     * 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 bitsPerComponent the number of bits per component
-     */
-    public void setBitsPerComponent(int bitsPerComponent)
-    {
-        getCOSDictionary().setInt(COSName.BITS_PER_COMPONENT, bitsPerComponent);
-    }
-
-    /**
-     * 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 bitsPerComponent the number of bits per coordinate
-     */
-    public void setBitsPerCoordinate(int bitsPerComponent)
-    {
-        getCOSDictionary().setInt(COSName.BITS_PER_COORDINATE, bitsPerComponent);
-    }
-
-    /**
      * The vertices per row of this shading. This will return -1 if one has not been set.
      * @return the number of vertices per row
      */
@@ -103,45 +60,6 @@ public class PDShadingType5 extends PDSh
         getCOSDictionary().setInt(COSName.VERTICES_PER_ROW, verticesPerRow);
     }
 
-    /**
-     * 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;
-    }
-
     @Override
     public Paint toPaint(Matrix matrix, int pageHeight)
     {

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=1616942&r1=1616941&r2=1616942&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
Sat Aug  9 13:07:40 2014
@@ -16,8 +16,6 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.util.Matrix;
 
@@ -28,10 +26,10 @@ import java.awt.Paint;
  */
 public class PDShadingType6 extends PDShadingType4
 {
-    private static final Log LOG = LogFactory.getLog(PDShadingType6.class);
 
     /**
      * Constructor using the given shading dictionary.
+     *
      * @param shadingDictionary the dictionary for this shading
      */
     public PDShadingType6(COSDictionary shadingDictionary)

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=1616942&r1=1616941&r2=1616942&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
Sat Aug  9 13:07:40 2014
@@ -16,8 +16,6 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.util.Matrix;
 
@@ -26,12 +24,12 @@ import java.awt.Paint;
 /**
  * Resources for a shading type 7 (Tensor-Product Patch Mesh).
  */
-public class PDShadingType7 extends PDShadingType4
+public class PDShadingType7 extends PDShadingType6
 {
-    private static final Log LOG = LogFactory.getLog(PDShadingType7.class);
 
     /**
      * Constructor using the given shading dictionary.
+     *
      * @param shadingDictionary the dictionary for this shading
      */
     public PDShadingType7(COSDictionary shadingDictionary)

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDTriangleBasedShadingType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDTriangleBasedShadingType.java?rev=1616942&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDTriangleBasedShadingType.java
(added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDTriangleBasedShadingType.java
Sat Aug  9 13:07:40 2014
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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.COSName;
+import org.apache.pdfbox.pdmodel.common.PDRange;
+import org.apache.pdfbox.cos.COSDictionary;
+
+/**
+ * Common resources for shading types 4,5,6 and 7
+ */
+abstract class PDTriangleBasedShadingType extends PDShading
+{
+    // 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;
+
+    PDTriangleBasedShadingType(COSDictionary shadingDictionary)
+    {
+        super(shadingDictionary);
+    }
+
+    /**
+     * 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 bitsPerComponent the number of bits per component
+     */
+    public void setBitsPerComponent(int bitsPerComponent)
+    {
+        getCOSDictionary().setInt(COSName.BITS_PER_COMPONENT, bitsPerComponent);
+    }
+
+    /**
+     * 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 bitsPerComponent the number of bits per coordinate
+     */
+    public void setBitsPerCoordinate(int bitsPerComponent)
+    {
+        getCOSDictionary().setInt(COSName.BITS_PER_COORDINATE, bitsPerComponent);
+    }
+
+    /**
+     * 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;
+    }
+
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDTriangleBasedShadingType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PatchMeshesShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PatchMeshesShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PatchMeshesShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PatchMeshesShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -54,8 +54,6 @@ abstract class PatchMeshesShadingContext
     
     // the following fields are not intialized in this abstract class
     protected ArrayList<Patch> patchList; // patch list
-    protected int bitsPerCoordinate; // bits per coordinate
-    protected int bitsPerColorComponent; // bits per color component
     protected int bitsPerFlag; // bits per flag
     protected HashMap<Point, Integer> pixelTable;
     
@@ -74,6 +72,7 @@ abstract class PatchMeshesShadingContext
     {
         super(shading, colorModel, xform, ctm, pageHeight, dBounds);
         patchMeshesShadingType = shading;
+        bitsPerFlag = ((PDShadingType6) shading).getBitsPerFlag();
         patchList = new ArrayList<Patch>();
         numberOfColorComponents = hasFunction ? 1 : shadingColorSpace.getNumberOfComponents();
         

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -28,7 +28,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBoolean;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.function.PDFunction;
 import org.apache.pdfbox.util.Matrix;
 
@@ -45,25 +44,24 @@ public class RadialShadingContext extend
 {
     private static final Log LOG = LogFactory.getLog(RadialShadingContext.class);
 
-    private PDShadingType3 shading;
+    private PDShadingType3 radialShadingType;
 
-    private float[] coords;
-    private float[] domain;
+    private final float[] coords;
+    private final float[] domain;
     private float[] background;
     private int rgbBackground;
-    private boolean[] extend;
-    private double x1x0; 
-    private double y1y0;
-    private double r1r0;
-    private double x1x0pow2;
-    private double y1y0pow2;
-    private double r0pow2;
-
-    private float d1d0;
-    private double denom;
+    private final boolean[] extend;
+    private final double x1x0; 
+    private final double y1y0;
+    private final double r1r0;
+    private final double x1x0pow2;
+    private final double y1y0pow2;
+    private final double r0pow2;
+    private final float d1d0;
+    private final double denom;
 
     private final double longestDistance;
-    private int[] colorTable;
+    private final int[] colorTable;
 
     /**
      * Constructor creates an instance to be used for fill operations.
@@ -78,7 +76,7 @@ public class RadialShadingContext extend
                                 Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
         super(shading, colorModel, xform, ctm, pageHeight, dBounds);
-        this.shading = shading;
+        this.radialShadingType = shading;
         coords = shading.getCoords().toFloatArray();
 
         if (ctm != null)
@@ -98,7 +96,7 @@ public class RadialShadingContext extend
         coords[5] *= xform.getScaleX();
 
         // domain values
-        if (this.shading.getDomain() != null)
+        if (this.radialShadingType.getDomain() != null)
         {
             domain = shading.getDomain().toFloatArray();
         }
@@ -178,7 +176,7 @@ public class RadialShadingContext extend
         {
             try
             {
-                float[] values = shading.evalFunction(domain[0]);
+                float[] values = radialShadingType.evalFunction(domain[0]);
                 map[0] = convertToRGB(values);
             }
             catch (IOException exception)
@@ -193,7 +191,7 @@ public class RadialShadingContext extend
                 float t = domain[0] + d1d0 * i / (float)longestDistance;
                 try
                 {
-                    float[] values = shading.evalFunction(t);
+                    float[] values = radialShadingType.evalFunction(t);
                     map[i] = convertToRGB(values);
                 }
                 catch (IOException exception)
@@ -228,7 +226,7 @@ public class RadialShadingContext extend
     public void dispose() 
     {
         outputColorModel = null;
-        shading = null;
+        radialShadingType = null;
         shadingColorSpace = null;
     }
 
@@ -461,6 +459,6 @@ public class RadialShadingContext extend
      */
     public PDFunction getFunction() throws IOException
     {
-        return shading.getFunction();
+        return radialShadingType.getFunction();
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/ShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/ShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/ShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -39,6 +39,7 @@ public abstract class ShadingContext
 {
     private static final Log LOG = LogFactory.getLog(ShadingContext.class);
 
+    protected final PDShading shading;
     protected final Rectangle deviceBounds;
     protected PDColorSpace shadingColorSpace;
     protected PDRectangle bboxRect;
@@ -48,6 +49,7 @@ public abstract class ShadingContext
     public ShadingContext(PDShading shading, ColorModel cm, AffineTransform xform,
             Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
+        this.shading = shading;
         deviceBounds = dBounds;
         shadingColorSpace = shading.getColorSpace();
         

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TriangleBasedShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TriangleBasedShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TriangleBasedShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TriangleBasedShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -40,15 +40,24 @@ abstract class TriangleBasedShadingConte
     private static final Log LOG = LogFactory.getLog(TriangleBasedShadingContext.class);
     
     protected final boolean hasFunction;
-    protected final PDShading shading;
+
+    /** bits per coordinate. */
+    protected int bitsPerCoordinate;
+    
+    /** bits per color component */
+    protected int bitsPerColorComponent; 
 
     public TriangleBasedShadingContext(PDShading shading, ColorModel cm, 
             AffineTransform xform, Matrix ctm, int pageHeight, Rectangle dBounds) 
             throws IOException
     {
         super(shading, cm, xform, ctm, pageHeight, dBounds);
+        PDTriangleBasedShadingType triangleBasedShadingType = (PDTriangleBasedShadingType)
shading;
         hasFunction = shading.getFunction() != null;
-        this.shading = shading;
+        bitsPerCoordinate = triangleBasedShadingType.getBitsPerCoordinate();
+        LOG.debug("bitsPerCoordinate: " + (Math.pow(2, bitsPerCoordinate) - 1));
+        bitsPerColorComponent = triangleBasedShadingType.getBitsPerComponent();
+        LOG.debug("bitsPerColorComponent: " + bitsPerColorComponent);
     }
 
     // convert color to RGB color value, using function if required, 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -37,9 +37,9 @@ class Type1ShadingContext extends Shadin
 {
     private static final Log LOG = LogFactory.getLog(Type1ShadingContext.class);
 
-    private PDShadingType1 shading;
+    private PDShadingType1 type1ShadingType;
     private AffineTransform rat;
-    private float[] domain;
+    private final float[] domain;
     private Matrix matrix;
     private float[] background;
 
@@ -56,15 +56,15 @@ class Type1ShadingContext extends Shadin
                                Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
         super(shading, colorModel, xform, ctm, pageHeight, dBounds);
-        this.shading = shading;
+        this.type1ShadingType = shading;
         
         // spec p.308
         // (Optional) An array of four numbers [ xmin xmax ymin ymax ] 
         // specifying the rectangular domain of coordinates over which the 
         // color function(s) are defined. Default value: [ 0.0 1.0 0.0 1.0 ].
-        if (this.shading.getDomain() != null)
+        if (shading.getDomain() != null)
         {
-            domain = this.shading.getDomain().toFloatArray();
+            domain = shading.getDomain().toFloatArray();
         }
         else
         {
@@ -74,7 +74,7 @@ class Type1ShadingContext extends Shadin
             };
         }
 
-        matrix = this.shading.getMatrix();
+        matrix = shading.getMatrix();
         if (matrix == null)
         {
             matrix = new Matrix();
@@ -107,7 +107,7 @@ class Type1ShadingContext extends Shadin
     {
         outputColorModel = null;
         shadingColorSpace = null;
-        shading = null;
+        type1ShadingType = null;
     }
 
     @Override
@@ -168,7 +168,7 @@ class Type1ShadingContext extends Shadin
                 {
                     try
                     {
-                        values = shading.evalFunction(values);
+                        values = type1ShadingType.evalFunction(values);
                     }
                     catch (IOException exception)
                     {

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=1616942&r1=1616941&r2=1616942&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
Sat Aug  9 13:07:40 2014
@@ -56,10 +56,6 @@ class Type4ShadingContext extends Gourau
         super(shading, cm, xform, ctm, pageHeight, dBounds);
         LOG.debug("Type4ShadingContext");
 
-        bitsPerColorComponent = shading.getBitsPerComponent();
-        LOG.debug("bitsPerColorComponent: " + bitsPerColorComponent);
-        bitsPerCoordinate = shading.getBitsPerCoordinate();
-        LOG.debug(Math.pow(2, bitsPerCoordinate) - 1);
         bitsPerFlag = shading.getBitsPerFlag();
         LOG.debug("bitsPerFlag: " + bitsPerFlag); //TODO handle cases where bitperflag isn't
8
         triangleList = getTriangleList(xform,ctm);
@@ -68,14 +64,14 @@ class Type4ShadingContext extends Gourau
     
     private ArrayList<CoonsTriangle> getTriangleList(AffineTransform xform,Matrix ctm)
throws IOException
     {
-        PDShadingType4 FreeTriangleShadingType = (PDShadingType4) gouraudShadingType;
-        COSDictionary cosDictionary = FreeTriangleShadingType.getCOSDictionary();
-        PDRange rangeX = FreeTriangleShadingType.getDecodeForParameter(0);
-        PDRange rangeY = FreeTriangleShadingType.getDecodeForParameter(1);
+        PDShadingType4 freeTriangleShadingType = (PDShadingType4) shading;
+        COSDictionary cosDictionary = freeTriangleShadingType.getCOSDictionary();
+        PDRange rangeX = freeTriangleShadingType.getDecodeForParameter(0);
+        PDRange rangeY = freeTriangleShadingType.getDecodeForParameter(1);
         PDRange[] colRange = new PDRange[numberOfColorComponents];
         for (int i = 0; i < numberOfColorComponents; ++i)
         {
-            colRange[i] = FreeTriangleShadingType.getDecodeForParameter(2 + i);
+            colRange[i] = freeTriangleShadingType.getDecodeForParameter(2 + i);
         }
         ArrayList<CoonsTriangle> list = new ArrayList<CoonsTriangle>();
         long maxSrcCoord = (long) Math.pow(2, bitsPerCoordinate) - 1;

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=1616942&r1=1616941&r2=1616942&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
Sat Aug  9 13:07:40 2014
@@ -57,10 +57,6 @@ class Type5ShadingContext extends Gourau
 
         LOG.debug("Type5ShadingContext");
 
-        bitsPerColorComponent = shading.getBitsPerComponent();
-        LOG.debug("bitsPerColorComponent: " + bitsPerColorComponent);
-        bitsPerCoordinate = shading.getBitsPerCoordinate();
-        LOG.debug(Math.pow(2, bitsPerCoordinate) - 1);
         triangleList = getTriangleList(xform,ctm);
         pixelTable = calcPixelTable();
     }
@@ -68,15 +64,15 @@ class Type5ShadingContext extends Gourau
     private ArrayList<CoonsTriangle> getTriangleList(AffineTransform xform, Matrix
ctm) throws IOException
     {
         ArrayList<CoonsTriangle> list = new ArrayList<CoonsTriangle>();
-        PDShadingType5 LatticeTriangleShadingType = (PDShadingType5) gouraudShadingType;
-        COSDictionary cosDictionary = LatticeTriangleShadingType.getCOSDictionary();
-        PDRange rangeX = LatticeTriangleShadingType.getDecodeForParameter(0);
-        PDRange rangeY = LatticeTriangleShadingType.getDecodeForParameter(1);
-        int numPerRow = LatticeTriangleShadingType.getVerticesPerRow();
+        PDShadingType5 latticeTriangleShadingType = (PDShadingType5) shading;
+        COSDictionary cosDictionary = latticeTriangleShadingType.getCOSDictionary();
+        PDRange rangeX = latticeTriangleShadingType.getDecodeForParameter(0);
+        PDRange rangeY = latticeTriangleShadingType.getDecodeForParameter(1);
+        int numPerRow = latticeTriangleShadingType.getVerticesPerRow();
         PDRange[] colRange = new PDRange[numberOfColorComponents];
         for (int i = 0; i < numberOfColorComponents; ++i)
         {
-            colRange[i] = LatticeTriangleShadingType.getDecodeForParameter(2 + i);
+            colRange[i] = latticeTriangleShadingType.getDecodeForParameter(2 + i);
         }
         ArrayList<Vertex> vlist = new ArrayList<Vertex>(); 
         long maxSrcCoord = (long) Math.pow(2, bitsPerCoordinate) - 1;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -22,8 +22,6 @@ import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
 import java.io.IOException;
 import java.util.ArrayList;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.pdmodel.common.PDRange;
 import org.apache.pdfbox.util.Matrix;
@@ -35,7 +33,6 @@ import org.apache.pdfbox.util.Matrix;
  */
 class Type6ShadingContext extends PatchMeshesShadingContext
 {
-    private static final Log LOG = LogFactory.getLog(Type6ShadingContext.class);
     
      /**
      * Constructor creates an instance to be used for fill operations.
@@ -51,9 +48,6 @@ class Type6ShadingContext extends PatchM
                                 Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
         super(shading, colorModel, xform, ctm, pageHeight, dBounds);
-        bitsPerColorComponent = shading.getBitsPerComponent();
-        bitsPerCoordinate = shading.getBitsPerCoordinate();
-        bitsPerFlag = shading.getBitsPerFlag();
         patchList = getCoonsPatchList(xform, ctm);
         pixelTable = calcPixelTable();
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java?rev=1616942&r1=1616941&r2=1616942&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java
Sat Aug  9 13:07:40 2014
@@ -22,8 +22,6 @@ import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
 import java.io.IOException;
 import java.util.ArrayList;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.pdmodel.common.PDRange;
 import org.apache.pdfbox.util.Matrix;
@@ -35,7 +33,6 @@ import org.apache.pdfbox.util.Matrix;
  */
 class Type7ShadingContext extends PatchMeshesShadingContext
 {
-    private static final Log LOG = LogFactory.getLog(Type7ShadingContext.class);
     
     /**
      * Constructor creates an instance to be used for fill operations.
@@ -51,9 +48,6 @@ class Type7ShadingContext extends PatchM
                                 Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
         super(shading, colorModel, xform, ctm, pageHeight, dBounds);
-        bitsPerColorComponent = shading.getBitsPerComponent();
-        bitsPerCoordinate = shading.getBitsPerCoordinate();
-        bitsPerFlag = shading.getBitsPerFlag();
         patchList = getTensorPatchList(xform, ctm);
         pixelTable = calcPixelTable();
     }



Mime
View raw message