pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1780443 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Date Thu, 26 Jan 2017 19:40:21 GMT
Author: tilman
Date: Thu Jan 26 19:40:21 2017
New Revision: 1780443

URL: http://svn.apache.org/viewvc?rev=1780443&view=rev
Log:
PDFBOX-3000: detect gray ICC colorspaces

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1780443&r1=1780442&r2=1780443&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Thu Jan
26 19:40:21 2017
@@ -61,6 +61,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
+import org.apache.pdfbox.pdmodel.graphics.color.PDICCBased;
 import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
 import org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
@@ -1383,7 +1384,7 @@ public class PageDrawer extends PDFGraph
             height = maxY - minY;
 
             // FIXME - color space
-            if (form.getGroup().getColorSpace() instanceof PDDeviceGray)
+            if (isGray(form.getGroup().getColorSpace()))
             {
                 image = create2ByteGrayAlphaImage(width, height);
             }
@@ -1396,7 +1397,7 @@ public class PageDrawer extends PDFGraph
             {
                 // "If the subtype is Luminosity, the transparency group XObject G shall
be 
                 // composited with a fully opaque backdrop whose colour is everywhere defined

-                // by the soft-mask dictionary’s BC entry."
+                // by the soft-mask dictionary's BC entry."
                 g.setBackground(new Color(backdropColor.toRGB()));
                 g.clearRect(0, 0, width, height);
             }
@@ -1484,7 +1485,27 @@ public class PageDrawer extends PDFGraph
             // Create a custom BufferedImage with the raster and a suitable color model
             return new BufferedImage(CM_GRAY_ALPHA, raster, false, null);
         }
-        
+
+        private boolean isGray(PDColorSpace colorSpace)
+        {
+            if (colorSpace instanceof PDDeviceGray)
+            {
+                return true;
+            }
+            if (colorSpace instanceof PDICCBased)
+            {
+                try
+                {
+                    return ((PDICCBased) colorSpace).getAlternateColorSpace() instanceof
PDDeviceGray;
+                }
+                catch (IOException ex)
+                {
+                    return false;
+                }
+            }
+            return false;
+        }
+
         public BufferedImage getImage()
         {
             return image;



Mime
View raw message