pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1868969 - /pdfbox/branches/issue45/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
Date Sat, 26 Oct 2019 02:12:06 GMT
Author: tilman
Date: Sat Oct 26 02:12:05 2019
New Revision: 1868969

URL: http://svn.apache.org/viewvc?rev=1868969&view=rev
Log:
PDFBOX-4674: make sure that USHORT_555_RGB images are properly handled if there are optimizations
in the future

Modified:
    pdfbox/branches/issue45/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java

Modified: pdfbox/branches/issue45/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java?rev=1868969&r1=1868968&r2=1868969&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
(original)
+++ pdfbox/branches/issue45/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java
Sat Oct 26 02:12:05 2019
@@ -236,6 +236,45 @@ public class LosslessFactoryTest extends
     }
 
     /**
+     * Tests USHORT_555_RGB LosslessFactoryTest#createFromImage(PDDocument document, BufferedImage
+     * image). This should create an 8-bit-image; prevent the problems from PDFBOX-4674 in
case
+     * image creation is modified in the future.
+     *
+     * @throws java.io.IOException
+     */
+    public void testCreateLosslessFromImageUSHORT_555_RGB() throws IOException
+    {
+        PDDocument document = new PDDocument();
+        BufferedImage image = ImageIO.read(this.getClass().getResourceAsStream("png.png"));
+
+        // create an USHORT_555_RGB image
+        int w = image.getWidth();
+        int h = image.getHeight();
+        BufferedImage rgbImage = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_555_RGB);
+        Graphics ag = rgbImage.getGraphics();
+        ag.drawImage(image, 0, 0, null);
+        ag.dispose();
+
+        for (int x = 0; x < rgbImage.getWidth(); ++x)
+        {
+            for (int y = 0; y < rgbImage.getHeight(); ++y)
+            {
+                rgbImage.setRGB(x, y, (rgbImage.getRGB(x, y) & 0xFFFFFF) | ((y / 10 *
10) << 24));
+            }
+        }
+
+        PDImageXObject ximage = LosslessFactory.createFromImage(document, rgbImage);
+
+        validate(ximage, 8, w, h, "png", PDDeviceRGB.INSTANCE.getName());
+        checkIdent(rgbImage, ximage.getImage());
+        checkIdentRGB(rgbImage, ximage.getOpaqueImage());
+
+        assertNull(ximage.getSoftMask());
+
+        doWritePDF(document, ximage, testResultsDir, "ushort555rgb.pdf");
+    }
+
+    /**
      * Tests LosslessFactoryTest#createFromImage(PDDocument document,
      * BufferedImage image) with transparent GIF
      *



Mime
View raw message