pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1432578 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java
Date Sun, 13 Jan 2013 10:29:33 GMT
Author: lehmi
Date: Sun Jan 13 10:29:32 2013
New Revision: 1432578

URL: http://svn.apache.org/viewvc?rev=1432578&view=rev
Log:
PDFBOX-1491: avoid NPE if an image mask uses colour key masking

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java?rev=1432578&r1=1432577&r2=1432578&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java
Sun Jan 13 10:29:32 2013
@@ -175,20 +175,30 @@ public abstract class PDXObjectImage ext
     public BufferedImage mask(BufferedImage baseImage) 
     	throws IOException
     {
-    	PDXObjectImage maskImageRef = (PDXObjectImage)PDXObject.createXObject(getMask());
-    	BufferedImage maskImage = maskImageRef.getRGBImage();
-   	 	if(maskImage == null)
-   	 	{
-	   		 LOG.warn("masking getRGBImage returned NULL");
-	   		 return baseImage;
-   	 	}
-   	 
-	   	 BufferedImage newImage = new BufferedImage( maskImage.getWidth(), maskImage.getHeight(),
BufferedImage.TYPE_INT_ARGB);
-	   	 Graphics2D graphics = (Graphics2D)newImage.getGraphics();
-	   	 graphics.drawImage(baseImage, 0, 0, maskImage.getWidth(), maskImage.getHeight(), 0,
0, baseImage.getWidth(), baseImage.getHeight(), null);   
-	   	 graphics.setComposite(AlphaComposite.DstIn);
-	   	 graphics.drawImage(maskImage, null, 0, 0);
-	   	 return newImage;
+        COSBase mask = getMask();
+        if (mask instanceof COSStream)
+        {
+        	PDXObjectImage maskImageRef = (PDXObjectImage)PDXObject.createXObject((COSStream)mask);
+        	BufferedImage maskImage = maskImageRef.getRGBImage();
+       	 	if(maskImage == null)
+       	 	{
+    	   		 LOG.warn("masking getRGBImage returned NULL");
+    	   		 return baseImage;
+       	 	}
+       	 
+    	   	 BufferedImage newImage = new BufferedImage( maskImage.getWidth(), maskImage.getHeight(),
BufferedImage.TYPE_INT_ARGB);
+    	   	 Graphics2D graphics = (Graphics2D)newImage.getGraphics();
+    	   	 graphics.drawImage(baseImage, 0, 0, maskImage.getWidth(), maskImage.getHeight(),
0, 0, baseImage.getWidth(), baseImage.getHeight(), null);   
+    	   	 graphics.setComposite(AlphaComposite.DstIn);
+    	   	 graphics.drawImage(maskImage, null, 0, 0);
+    	   	 return newImage;
+        }
+        else
+        {
+            // TODO Colour key masking
+            LOG.warn("Colour key masking isn't supported");
+            return baseImage;
+        }
     }
 
     /**



Mime
View raw message