pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1598912 - in /pdfbox/trunk/pdfbox/src/test: java/org/apache/pdfbox/pdmodel/graphics/image/ resources/org/apache/pdfbox/pdmodel/graphics/image/
Date Sat, 31 May 2014 20:02:16 GMT
Author: tilman
Date: Sat May 31 20:02:15 2014
New Revision: 1598912

URL: http://svn.apache.org/r1598912
Log:
PDFBOX-2105: added test for multipage tiffs

Added:
    pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg4multi.tif
  (with props)
Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java?rev=1598912&r1=1598911&r2=1598912&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Sat May 31 20:02:15 2014
@@ -15,14 +15,22 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.image;
 
+import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.stream.ImageInputStream;
 
 import junit.framework.TestCase;
 import org.apache.pdfbox.io.RandomAccess;
 import org.apache.pdfbox.io.RandomAccessFile;
 import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
+import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.checkIdent;
 import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.doWritePDF;
 import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.validate;
 
@@ -44,16 +52,69 @@ public class CCITTFactoryTest extends Te
 
     /**
      * Tests CCITTFactory#createFromRandomAccess(PDDocument document,
-     * RandomAccess reader)
+     * RandomAccess reader) with a single page TIFF
      */
-    public void testCreateFromRandomAccess() throws IOException
+    public void testCreateFromRandomAccessSingle() throws IOException
     {
         String tiffPath = "src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg4.tif";
+        
         PDDocument document = new PDDocument();
         RandomAccess reader = new RandomAccessFile(new File(tiffPath), "r");
         PDImageXObject ximage = CCITTFactory.createFromRandomAccess(document, reader);
         validate(ximage, 1, 344, 287, "tiff", PDDeviceGray.INSTANCE.getName());
         
-        doWritePDF(document, ximage, testResultsDir, "tiff.pdf");        
+        doWritePDF(document, ximage, testResultsDir, "singletiff.pdf");
+    }
+    
+    /**
+     * Tests CCITTFactory#createFromRandomAccess(PDDocument document,
+     * RandomAccess reader) with a multi page TIFF
+     */
+    public void testCreateFromRandomAccessMulti() throws IOException
+    {
+        String tiffPath = "src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg4multi.tif";
+        
+        ImageInputStream is = ImageIO.createImageInputStream(new File(tiffPath));
+        ImageReader imageReader = ImageIO.getImageReaders(is).next();
+        imageReader.setInput(is);
+        int countTiffImages = imageReader.getNumImages(true);
+        assertTrue(countTiffImages > 1);
+        
+        PDDocument document = new PDDocument();
+        RandomAccess reader = new RandomAccessFile(new File(tiffPath), "r");
+        
+        int pdfPageNum = 0;
+        while (true)
+        {
+            PDImageXObject ximage = CCITTFactory.createFromRandomAccess(document, reader,
pdfPageNum);
+            if (ximage == null)
+            {
+                break;
+            }
+            BufferedImage bim = imageReader.read(pdfPageNum);
+            validate(ximage, 1, bim.getWidth(), bim.getHeight(), "tiff", PDDeviceGray.INSTANCE.getName());
+            checkIdent(bim, ximage.getOpaqueImage());
+            PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
+            float fX = ximage.getWidth() / page.getMediaBox().getWidth();
+            float fY = ximage.getHeight() / page.getMediaBox().getHeight();
+            float factor = Math.max(fX, fY);
+            document.addPage(page);
+            PDPageContentStream contentStream = new PDPageContentStream(document, page, true,
false);
+            contentStream.drawXObject(ximage, 0, 0, ximage.getWidth() / factor, ximage.getHeight()
/ factor);
+            contentStream.close();
+            ++pdfPageNum;
+        }
+        
+        assertEquals(countTiffImages, pdfPageNum);
+
+        document.save(testResultsDir + "/multitiff.pdf");
+        document.close();
+        
+        document = PDDocument.loadNonSeq(new File(testResultsDir, "multitiff.pdf"), null);
+        List pages = document.getDocumentCatalog().getAllPages();
+        assertEquals(countTiffImages, pages.size());
+        
+        document.close();  
+        imageReader.dispose();
     }
 }

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java?rev=1598912&r1=1598911&r2=1598912&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
Sat May 31 20:02:15 2014
@@ -26,13 +26,12 @@ import java.io.IOException;
 import java.util.Random;
 import javax.imageio.ImageIO;
 import junit.framework.TestCase;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
+import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.checkIdent;
 import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.colorCount;
 import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.doWritePDF;
 import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.validate;
@@ -209,33 +208,6 @@ public class LosslessFactoryTest extends
     }
 
     /**
-     * Check whether the images are identical.
-     *
-     * @param expectedImage
-     * @param actualImage
-     */
-    private void checkIdent(BufferedImage expectedImage, BufferedImage actualImage)
-    {
-        String errMsg = "";
-
-        int w = expectedImage.getWidth();
-        int h = expectedImage.getHeight();
-        assertEquals(w, actualImage.getWidth());
-        assertEquals(h, actualImage.getHeight());
-        for (int y = 0; y < h; ++y)
-        {
-            for (int x = 0; x < w; ++x)
-            {
-                if (expectedImage.getRGB(x, y) != actualImage.getRGB(x, y))
-                {
-                    errMsg = String.format("(%d,%d) %08X != %08X", x, y, expectedImage.getRGB(x,
y), actualImage.getRGB(x, y));
-                }
-                assertEquals(errMsg, expectedImage.getRGB(x, y), actualImage.getRGB(x, y));
-            }
-        }
-    }
-
-    /**
      * Check whether the RGB part of images are identical.
      *
      * @param expectedImage

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java?rev=1598912&r1=1598911&r2=1598912&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java
Sat May 31 20:02:15 2014
@@ -107,5 +107,34 @@ public class ValidateXImage
         new PDFRenderer(document).renderImage(0);
         document.close();
     }
+    
+    /**
+     * Check whether the images are identical.
+     *
+     * @param expectedImage
+     * @param actualImage
+     */
+    static void checkIdent(BufferedImage expectedImage, BufferedImage actualImage)
+    {
+        String errMsg = "";
+
+        int w = expectedImage.getWidth();
+        int h = expectedImage.getHeight();
+        assertEquals(w, actualImage.getWidth());
+        assertEquals(h, actualImage.getHeight());
+        for (int y = 0; y < h; ++y)
+        {
+            for (int x = 0; x < w; ++x)
+            {
+                if (expectedImage.getRGB(x, y) != actualImage.getRGB(x, y))
+                {
+                    errMsg = String.format("(%d,%d) %08X != %08X", x, y, expectedImage.getRGB(x,
y), actualImage.getRGB(x, y));
+                }
+                assertEquals(errMsg, expectedImage.getRGB(x, y), actualImage.getRGB(x, y));
+            }
+        }
+    }
+
+    
 
 }

Added: pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg4multi.tif
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg4multi.tif?rev=1598912&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg4multi.tif
------------------------------------------------------------------------------
    svn:mime-type = image/tiff



Mime
View raw message