pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1429514 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading: AxialShadingContext.java RadialShadingContext.java
Date Sun, 06 Jan 2013 13:15:27 GMT
Author: lehmi
Date: Sun Jan  6 13:15:27 2013
New Revision: 1429514

URL: http://svn.apache.org/viewvc?rev=1429514&view=rev
Log:
PDFBOX-1482: take tint transformation into account when creating a shading color context

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/RadialShadingContext.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=1429514&r1=1429513&r2=1429514&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
Sun Jan  6 13:15:27 2013
@@ -30,7 +30,9 @@ import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBoolean;
 import org.apache.pdfbox.pdmodel.common.function.PDFunction;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
+import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
 import org.apache.pdfbox.util.Matrix;
 
 /**
@@ -46,6 +48,7 @@ public class AxialShadingContext impleme
     private ColorModel colorModel;
     private PDFunction function;
     private ColorSpace shadingColorSpace;
+    private PDFunction shadingTinttransform;
 
     private float[] coords;
     private float[] domain;
@@ -103,6 +106,14 @@ public class AxialShadingContext impleme
             {
                 // we have to create an instance of the shading colorspace if it isn't RGB
                 shadingColorSpace = cs.getJavaColorSpace();
+                if (cs instanceof PDDeviceN)
+                {
+                    shadingTinttransform = ((PDDeviceN)cs).getTintTransform();
+                }
+                else if (cs instanceof PDSeparation)
+                {
+                    shadingTinttransform = ((PDSeparation)cs).getTintTransform();
+                }
             }
         } 
         catch (IOException exception) 
@@ -173,6 +184,8 @@ public class AxialShadingContext impleme
     {
         colorModel = null;
         function = null;
+        shadingColorSpace = null;
+        shadingTinttransform = null;
     }
 
     /**
@@ -227,20 +240,24 @@ public class AxialShadingContext impleme
                 }
                 input[0] = (float)(domain[0] + (d1d0*inputValue));
                 float[] values = null;
+                int index = (j * w + i) * 3;
                 try 
                 {
                     values = function.eval(input);
+                    // convert color values from shading colorspace to RGB 
+                    if (shadingColorSpace != null)
+                    {
+                        if (shadingTinttransform != null)
+                        {
+                            values = shadingTinttransform.eval(values);
+                        }
+                        values = shadingColorSpace.toRGB(values);
+                    }
                 } 
                 catch (IOException exception) 
                 {
                     LOG.error("error while processing a function", exception);
                 }
-                int index = (j * w + i) * 3;
-                // convert color values from shading colorspace to RGB 
-                if (shadingColorSpace != null)
-                {
-                    values = shadingColorSpace.toRGB(values);
-                }
                 data[index] = (int)(values[0]*255);
                 data[index+1] = (int)(values[1]*255);
                 data[index+2] = (int)(values[2]*255);

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=1429514&r1=1429513&r2=1429514&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
Sun Jan  6 13:15:27 2013
@@ -30,7 +30,9 @@ import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBoolean;
 import org.apache.pdfbox.pdmodel.common.function.PDFunction;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
+import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
 import org.apache.pdfbox.util.Matrix;
 
 /**
@@ -46,6 +48,7 @@ public class RadialShadingContext implem
     private ColorModel colorModel;
     private PDFunction function;
     private ColorSpace shadingColorSpace;
+    private PDFunction shadingTinttransform;
 
     private float[] coords;
     private float[] domain;
@@ -63,7 +66,7 @@ public class RadialShadingContext implem
     /**
      * Log instance.
      */
-    private static final Log LOG = LogFactory.getLog(AxialShadingContext.class);
+    private static final Log LOG = LogFactory.getLog(RadialShadingContext.class);
 
     /**
      * Constructor creates an instance to be used for fill operations.
@@ -110,6 +113,14 @@ public class RadialShadingContext implem
             {
                 // we have to create an instance of the shading colorspace if it isn't RGB
                 shadingColorSpace = cs.getJavaColorSpace();
+                if (cs instanceof PDDeviceN)
+                {
+                    shadingTinttransform = ((PDDeviceN)cs).getTintTransform();
+                }
+                else if (cs instanceof PDSeparation)
+                {
+                    shadingTinttransform = ((PDSeparation)cs).getTintTransform();
+                }
             }
         } 
         catch (IOException exception) 
@@ -184,6 +195,8 @@ public class RadialShadingContext implem
     {
         colorModel = null;
         function = null;
+        shadingColorSpace = null;
+        shadingTinttransform = null;
     }
 
     /**
@@ -265,20 +278,24 @@ public class RadialShadingContext implem
                 }
                 input[0] = (float)(domain[0] + (d1d0*inputValue));
                 float[] values = null;
+                int index = (j * w + i) * 3;
                 try 
                 {
                     values = function.eval(input);
-                } 
+                    // convert color values from shading colorspace to RGB 
+                    if (shadingColorSpace != null)
+                    {
+                        if (shadingTinttransform != null)
+                        {
+                            values = shadingTinttransform.eval(values);
+                        }
+                        values = shadingColorSpace.toRGB(values);
+                    }
+                }
                 catch (IOException exception) 
                 {
                     LOG.error("error while processing a function", exception);
                 }
-                int index = (j * w + i) * 3;
-                // convert color values from shading colorspace to RGB 
-                if (shadingColorSpace != null)
-                {
-                    values = shadingColorSpace.toRGB(values);
-                }
                 data[index] = (int)(values[0]*255);
                 data[index+1] = (int)(values[1]*255);
                 data[index+2] = (int)(values[2]*255);



Mime
View raw message