pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1616843 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/
Date Fri, 08 Aug 2014 18:11:06 GMT
Author: tilman
Date: Fri Aug  8 18:11:05 2014
New Revision: 1616843

URL: http://svn.apache.org/r1616843
Log:
PDFBOX-1915: some minor reformat / rename / refactor

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsPatch.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsTriangle.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoordinateColorPair.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/Line.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/TensorPatch.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsPatch.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsPatch.java?rev=1616843&r1=1616842&r2=1616843&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsPatch.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsPatch.java
Fri Aug  8 18:11:05 2014
@@ -35,7 +35,7 @@ class CoonsPatch extends Patch
     {
         super(points, color);
         controlPoints = reshapeControlPoints(points);
-        level = calLevel();
+        level = calcLevel();
         listOfCoonsTriangle = getCoonsTriangle();
     }
     
@@ -63,7 +63,7 @@ class CoonsPatch extends Patch
     }
     
     // calculate the dividing level from control points
-    private int[] calLevel()
+    private int[] calcLevel()
     {
         int[] l = {4, 4};
         // if two opposite edges are both lines, there is a possibility to reduce the dividing
level

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsTriangle.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsTriangle.java?rev=1616843&r1=1616842&r2=1616843&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsTriangle.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoonsTriangle.java
Fri Aug  8 18:11:05 2014
@@ -21,25 +21,27 @@ import java.awt.geom.Point2D;
 import java.util.HashSet;
 
 /**
- * This is an assistant class for accomplishing type 6 and 7 shading.
- * It describes a triangle actually, which is used to compose a patch. It contains 
- * the degenerated cases, a triangle degenerates to a line or to a point.
- * This was done as part of GSoC2014, Tilman Hausherr is the mentor.
+ * This is an assistant class for accomplishing type 4, 5, 6 and 7 shading. It
+ * describes a triangle actually, which is used to compose a patch. It contains
+ * the degenerated cases, a triangle degenerates to a line or to a point. This
+ * was done as part of GSoC2014, Tilman Hausherr is the mentor.
+ *
  * @author Shaola Ren
  */
 class CoonsTriangle
 {
-    protected final Point2D[] corner; // vertexes coordinates of a triangle
+    protected final Point2D[] corner; // vertices coordinates of a triangle
     protected final float[][] color;
     private final double area; // area of the triangle
     
     /*
-    degree = 3 describes a normal triangle, degree = 2 when a triangle degenerates to a line,
+    degree = 3 describes a normal triangle, 
+    degree = 2 when a triangle degenerates to a line,
     degree = 1 when a triangle degenerates to a point
     */
     private final int degree;
     
-    // describes a rasterized line when a trianlge degerates to a line, otherwise this parameter
is null
+    // describes a rasterized line when a triangle degerates to a line, otherwise null
     private final Line line;
     
     // corner's edge (the opposite edge of a corner) equation value
@@ -49,7 +51,7 @@ class CoonsTriangle
     
     /**
      * Constructor of CoonsTriangle.
-     * @param p an array of the 3 vertexes of a triangle
+     * @param p an array of the 3 vertices of a triangle
      * @param c an array of color corresponding the vertex array p
      */
     public CoonsTriangle(Point2D[] p, float[][] c)
@@ -63,14 +65,18 @@ class CoonsTriangle
         {
             if (overlaps(corner[1], corner[2]) && !overlaps(corner[0], corner[2]))
             {
-                Point p0 = new Point((int)Math.round(corner[0].getX()), (int)Math.round(corner[0].getY()));
-                Point p1 = new Point((int)Math.round(corner[2].getX()), (int)Math.round(corner[2].getY()));
+                Point p0 = new Point((int)Math.round(corner[0].getX()), 
+                                     (int)Math.round(corner[0].getY()));
+                Point p1 = new Point((int)Math.round(corner[2].getX()), 
+                                     (int)Math.round(corner[2].getY()));
                 line = new Line(p0, p1, color[0], color[2]);
             }
             else
             {
-                Point p0 = new Point((int)Math.round(corner[1].getX()), (int)Math.round(corner[1].getY()));
-                Point p1 = new Point((int)Math.round(corner[2].getX()), (int)Math.round(corner[2].getY()));
+                Point p0 = new Point((int)Math.round(corner[1].getX()), 
+                                     (int)Math.round(corner[1].getY()));
+                Point p1 = new Point((int)Math.round(corner[2].getX()), 
+                                     (int)Math.round(corner[2].getY()));
                 line = new Line(p0, p1, color[1], color[2]);
             }
         }
@@ -85,9 +91,9 @@ class CoonsTriangle
     }
     
     /**
-     * Get the degree value of a triangle.
-     * @param p 3 vertexes coordinates
-     * @return number of unique points in the 3 vertexes of a triangle, 3, 2 or 1
+     * Calculate the degree value of a triangle.
+     * @param p 3 vertices coordinates
+     * @return number of unique points in the 3 vertices of a triangle, 3, 2 or 1
      */
     private int calcDeg(Point2D[] p)
     {
@@ -112,17 +118,26 @@ class CoonsTriangle
     public int[] getBoundary()
     {
         int[] boundary = new int[4];
-        int x0 = (int) Math.round(corner[0].getX()), x1 = (int) Math.round(corner[1].getX()),

-                                x2 = (int) Math.round(corner[2].getX());
-        int y0 = (int) Math.round(corner[0].getY()), y1 = (int) Math.round(corner[1].getY()),

-                                y2 = (int) Math.round(corner[2].getY());
+        int x0 = (int) Math.round(corner[0].getX());
+        int x1 = (int) Math.round(corner[1].getX());
+        int x2 = (int) Math.round(corner[2].getX());
+        int y0 = (int) Math.round(corner[0].getY());
+        int y1 = (int) Math.round(corner[1].getY());
+        int y2 = (int) Math.round(corner[2].getY());
+        
         boundary[0] = Math.min(Math.min(x0, x1), x2);
         boundary[1] = Math.max(Math.max(x0, x1), x2);
         boundary[2] = Math.min(Math.min(y0, y1), y2);
         boundary[3] = Math.max(Math.max(y0, y1), y2);
+        
         return boundary;
     }
     
+    /**
+     * Get the line of a triangle.
+     *
+     * @return points of the line, or null if this triangle isn't a line
+     */
     public Line getLine()
     {
         return line;
@@ -146,7 +161,7 @@ class CoonsTriangle
         }
         
         /*
-        the following code judges whether a point is contained in a normal trianlge, 
+        the following code judges whether a point is contained in a normal triangle, 
         taking the on edge case as contained
         */
         double pv0 = edgeEquationValue(p, corner[1], corner[2]);
@@ -177,35 +192,38 @@ class CoonsTriangle
     }
     
     /*
-    whether two points overlaps each other, as points' coordinates are double type, 
-    the coordinates' accuracy used here is 0.001
-    */
+     check whether two points overlaps each other, as points' coordinates are 
+     of type double, the coordinates' accuracy used here is 0.001
+     */
     private boolean overlaps(Point2D p0, Point2D p1)
     {
         return Math.abs(p0.getX() - p1.getX()) < 0.001 && Math.abs(p0.getY() -
p1.getY()) < 0.001;
     }
-    
+
     /*
-    two points can define a line equation, adjust the form of the equation to let the rhs
equals 0, 
-    calculate the lhs value by plugging the coordinate of p in the lhs expression
-    */
+     two points can define a line equation, adjust the form of the equation to 
+     let the rhs equals 0, calculate the lhs value by plugging the coordinate 
+     of p in the lhs expression
+     */
     private double edgeEquationValue(Point2D p, Point2D p1, Point2D p2)
     {
-        return (p2.getY() - p1.getY()) * (p.getX() - p1.getX()) - (p2.getX() - p1.getX())
* (p.getY() - p1.getY());
+        return (p2.getY() - p1.getY()) * (p.getX() - p1.getX()) - 
+               (p2.getX() - p1.getX()) * (p.getY() - p1.getY());
     }
-    
+
     // calcuate the area of a triangle
     private double getArea(Point2D a, Point2D b, Point2D c)
     {
-        return Math.abs((c.getX() - b.getX()) * (c.getY() - a.getY()) - (c.getX() - a.getX())
* (c.getY() - b.getY())) / 2.0;
+        return Math.abs((c.getX() - b.getX()) * (c.getY() - a.getY()) - 
+                        (c.getX() - a.getX()) * (c.getY() - b.getY())) / 2.0;
     }
-    
+
     /**
      * Calculate color of a point.
      * @param p the target point
      * @return an array denotes the point's color
      */
-    public float[] getColor(Point2D p)
+    public float[] calcColor(Point2D p)
     {
         int numberOfColorComponents = color[0].length;
         float[] pCol = new float[numberOfColorComponents];
@@ -214,13 +232,15 @@ class CoonsTriangle
         {
             for (int i = 0; i < numberOfColorComponents; i++)
             {
-                pCol[i] = (color[0][i] + color[1][i] + color[2][i]) / 3.0f; // average
+                // average
+                pCol[i] = (color[0][i] + color[1][i] + color[2][i]) / 3.0f; 
             }
         }
         else if (degree == 2)
         {
-            Point tp = new Point((int)Math.round(p.getX()), (int)Math.round(p.getY())); //
linear interpolation
-            return line.getColor(tp);
+            // linear interpolation
+            Point tp = new Point((int)Math.round(p.getX()), (int)Math.round(p.getY())); 
+            return line.calcColor(tp);
         }
         else
         {
@@ -229,7 +249,8 @@ class CoonsTriangle
             float cw = (float) (getArea(p, corner[0], corner[1]) / area);
             for (int i = 0; i < numberOfColorComponents; i++)
             {
-                pCol[i] = color[0][i] * aw + color[1][i] * bw + color[2][i] * cw; // barycentric
interpolation
+                // barycentric interpolation
+                pCol[i] = color[0][i] * aw + color[1][i] * bw + color[2][i] * cw;
             }
         }
         return pCol;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoordinateColorPair.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoordinateColorPair.java?rev=1616843&r1=1616842&r2=1616843&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoordinateColorPair.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/CoordinateColorPair.java
Fri Aug  8 18:11:05 2014
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
 import java.awt.geom.Point2D;
@@ -21,6 +20,7 @@ import java.awt.geom.Point2D;
 /**
  * This class is used to store a point's coordinate and its corresponding color.
  * This was done as part of GSoC2014, Tilman Hausherr is the mentor.
+ *
  * @author Shaola Ren
  */
 class CoordinateColorPair
@@ -30,6 +30,7 @@ class CoordinateColorPair
 
     /**
      * Constructor.
+     *
      * @param p point
      * @param c color
      */

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=1616843&r1=1616842&r2=1616843&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 Aug  8 18:11:05 2014
@@ -206,8 +206,7 @@ abstract class GouraudShadingContext imp
                 HashSet<Point> linePoints = line.linePoints;
                 for (Point p : linePoints)
                 {
-                    float[] values = line.getColor(p);
-                    map.put(p, convertToRGB(values));
+                    map.put(p, convertToRGB(line.calcColor(p)));
                 }
             }
             else
@@ -224,8 +223,7 @@ abstract class GouraudShadingContext imp
                         Point p = new Point(x, y);
                         if (tri.contains(p))
                         {
-                            float[] values = tri.getColor(p);
-                            map.put(p, convertToRGB(values));
+                            map.put(p, convertToRGB(tri.calcColor(p)));
                         }
                     }
                 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Line.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Line.java?rev=1616843&r1=1616842&r2=1616843&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Line.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Line.java
Fri Aug  8 18:11:05 2014
@@ -46,25 +46,21 @@ class Line
         point1 = p1;
         color0 = c0.clone();
         color1 = c1.clone();
-        linePoints = getLine();
-    }
-    
-    private HashSet<Point> getLine()
-    {
-        return getLine(point0.x, point0.y, point1.x, point1.y);
+        linePoints = calcLine(point0.x, point0.y, point1.x, point1.y);
     }
     
     /**
-     * Bresenham's line algorithm, http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
+     * Calculate the points of a line with Bresenham's line algorithm
+     * <a href="http://en.wikipedia.org/wiki/Bresenham's_line_algorithm">Bresenham's
line algorithm</a>
      * @param x0 coordinate
      * @param y0 coordinate
      * @param x1 coordinate
      * @param y1 coordinate
      * @return all the points on the rasterized line from (x0, y0) to (x1, y1)
      */
-    private HashSet<Point> getLine(int x0, int y0, int x1, int y1) 
+    private HashSet<Point> calcLine(int x0, int y0, int x1, int y1) 
     {
-        HashSet<Point> points = new HashSet<Point>();
+        HashSet<Point> points = new HashSet<Point>(3);
         int dx = (int) Math.round(Math.abs(x1 - x0));
         int dy = (int) Math.round(Math.abs(y1 - y0));
         int sx = x0 < x1 ? 1 : -1;
@@ -97,7 +93,7 @@ class Line
      * @param p target point, p should always be contained in linePoints
      * @return color
      */
-    protected float[] getColor(Point p)
+    protected float[] calcColor(Point p)
     {
         int numberOfColorComponents = color0.length;
         float[] pc = new float[numberOfColorComponents];
@@ -110,7 +106,8 @@ class Line
             float l = point1.y - point0.y;
             for (int i = 0; i < numberOfColorComponents; i++)
             {
-                pc[i] = (float) (color0[i] * (point1.y - p.y) / l + color1[i] * (p.y - point0.y)
/ l);
+                pc[i] = (float) (color0[i] * (point1.y - p.y) / l + 
+                                 color1[i] * (p.y - point0.y) / l);
             }
         }
         else
@@ -118,7 +115,8 @@ class Line
             float l = point1.x - point0.x;
             for (int i = 0; i < numberOfColorComponents; i++)
             {
-                pc[i] = (float) (color0[i] * (point1.x - p.x) / l + color1[i] * (p.x - point0.x)
/ l);
+                pc[i] = (float) (color0[i] * (point1.x - p.x) / l + 
+                                 color1[i] * (p.x - point0.x) / l);
             }
         }
         return pc;

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=1616843&r1=1616842&r2=1616843&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
Fri Aug  8 18:11:05 2014
@@ -127,13 +127,12 @@ abstract class PatchMeshesShadingContext
         }
     }
     
-    // this method is used to arrange the array to denote the left upper corner and right
lower corner of the BBox
+    // this helper method is used to arrange the array 
+    // to denote the left upper corner and right lower corner of the BBox
+    // i is always < j
     private void reOrder(float[] array, int i, int j)
     {
-        if (i < j && array[i] <= array[j])
-        {
-        }
-        else
+        if (array[i] > array[j])
         {
             float tmp = array[i];
             array[i] = array[j];
@@ -338,7 +337,7 @@ abstract class PatchMeshesShadingContext
                     HashSet<Point> linePoints = line.linePoints;
                     for (Point p : linePoints)
                     {
-                        float[] values = line.getColor(p);
+                        float[] values = line.calcColor(p);
                         map.put(p, convertToRGB(values));
                     }
                 }
@@ -356,7 +355,7 @@ abstract class PatchMeshesShadingContext
                             Point p = new Point(x, y);
                             if (tri.contains(p))
                             {
-                                float[] values = tri.getColor(p);
+                                float[] values = tri.calcColor(p);
                                 map.put(p, convertToRGB(values));
                             }
                         }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TensorPatch.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TensorPatch.java?rev=1616843&r1=1616842&r2=1616843&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TensorPatch.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/TensorPatch.java
Fri Aug  8 18:11:05 2014
@@ -35,7 +35,7 @@ class TensorPatch extends Patch
     {
         super(tcp, color);
         controlPoints = reshapeControlPoints(tcp);
-        level = calLevel();
+        level = calcLevel();
         listOfCoonsTriangle = getCoonsTriangle();
     }
     
@@ -63,7 +63,7 @@ class TensorPatch extends Patch
     }
     
     // calculate the dividing level from the control points
-    private int[] calLevel()
+    private int[] calcLevel()
     {
         int[] l = {4, 4};
         
@@ -78,12 +78,14 @@ class TensorPatch extends Patch
         if (isEdgeALine(ctlC1) & isEdgeALine(ctlC2))
         {
             /*
-            if any of the 4 inner control points is out of the patch formed by the 4 edges,
keep the high dividing level, 
+            if any of the 4 inner control points is out of the patch formed by the 4 edges,

+            keep the high dividing level, 
             otherwise, determine the dividing level by the lengths of edges
             */
             if (isOnSameSideCC(controlPoints[1][1]) | isOnSameSideCC(controlPoints[1][2])
|
                                 isOnSameSideCC(controlPoints[2][1]) | isOnSameSideCC(controlPoints[2][2]))
             {
+                // keep the high dividing level
             }
             else
             {
@@ -113,6 +115,7 @@ class TensorPatch extends Patch
             if (isOnSameSideDD(controlPoints[1][1]) | isOnSameSideDD(controlPoints[1][2])
|
                                 isOnSameSideDD(controlPoints[2][1]) | isOnSameSideDD(controlPoints[2][2]))
             {
+                // keep the high dividing level
             }
             else
             {

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=1616843&r1=1616842&r2=1616843&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
Fri Aug  8 18:11:05 2014
@@ -136,13 +136,12 @@ class Type1ShadingContext implements Pai
         }
     }
     
-    // this method is used to arrange the array to denote the left upper corner and right
lower corner of the BBox
+    // this helper method is used to arrange the array 
+    // to denote the left upper corner and right lower corner of the BBox
+    // i is always < j
     private void reOrder(float[] array, int i, int j)
     {
-        if (i < j && array[i] <= array[j])
-        {
-        }
-        else
+        if (array[i] > array[j])
         {
             float tmp = array[i];
             array[i] = array[j];



Mime
View raw message