pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1656635 - in /pdfbox/branches/1.8/pdfbox/src/test: java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMapTest.java resources/org/apache/pdfbox/pdmodel/graphics/xobject/gif.gif
Date Tue, 03 Feb 2015 07:36:32 GMT
Author: tilman
Date: Tue Feb  3 07:36:31 2015
New Revision: 1656635

URL: http://svn.apache.org/r1656635
Log:
PDFBOX-2654: create test for transparent GIF images

Added:
    pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/xobject/gif.gif
  (with props)
Modified:
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMapTest.java

Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMapTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMapTest.java?rev=1656635&r1=1656634&r2=1656635&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMapTest.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMapTest.java
Tue Feb  3 07:36:31 2015
@@ -310,6 +310,46 @@ public class PDPixelMapTest extends Test
         assertNull(ximage.getSMaskImage());
         document.close();
     }
+    
+    /**
+     * Tests LosslessFactoryTest#createFromImage(PDDocument document,
+     * BufferedImage image) with transparent GIF
+     *
+     * @throws java.io.IOException
+     */
+    public void testCreateLosslessFromTransparentGIF() throws IOException, COSVisitorException
+    {
+        PDDocument document = new PDDocument();
+        BufferedImage imageFromTransparentColorGif = ImageIO.read(this.getClass().getResourceAsStream("gif.gif"));
+        
+        assertEquals(Transparency.BITMASK, imageFromTransparentColorGif.getColorModel().getTransparency());
+        
+        PDXObjectImage ximage = new PDPixelMap(document, imageFromTransparentColorGif);
+
+        checkIdent(imageFromTransparentColorGif, ximage.getRGBImage());
+        validate(ximage, 8, 343, 287, "png", PDDeviceRGB.NAME);
+
+        validate(ximage.getSMaskImage(), 1, imageFromTransparentColorGif.getWidth(), imageFromTransparentColorGif.getHeight(),
"png", PDDeviceGray.NAME);
+        assertEquals(2, colorCount(ximage.getSMaskImage().getRGBImage()));
+
+        // This part isn't really needed because this test doesn't break
+        // if the mask has the wrong colorspace (PDFBOX-2057), but it is still useful
+        // if something goes wrong in the future and we want to have a PDF to open.
+        PDPage page = new PDPage();
+        document.addPage(page);
+        PDPageContentStream contentStream = new PDPageContentStream(document, page, true,
false);
+        contentStream.drawXObject(ximage, 150, 300, ximage.getWidth(), ximage.getHeight());
+        contentStream.drawXObject(ximage, 200, 350, ximage.getWidth(), ximage.getHeight());
+
+        contentStream.close();
+        File pdfFile = new File(testResultsDir, "gif.pdf");
+        document.save(pdfFile);
+        document.close();
+        document = PDDocument.loadNonSeq(pdfFile, null);
+        List<PDPage> pdPages = document.getDocumentCatalog().getAllPages();
+        pdPages.get(0).convertToImage();
+        document.close();
+    }
 
     /**
      * Tests INT_ARGB LosslessFactoryTest#createFromImage(PDDocument document,

Added: pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/xobject/gif.gif
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/xobject/gif.gif?rev=1656635&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/xobject/gif.gif
------------------------------------------------------------------------------
    svn:mime-type = image/gif



Mime
View raw message