Author: tilman
Date: Fri Aug 21 11:50:22 2026
New Revision: 1937283

Log:
PDFBOX-6077: Add regression tests for stencil-mask pattern fills, by Valery 
Bokov; closes #492

Added:
   
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
      - copied, changed from r1937280, 
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
Modified:
   pdfbox/branches/2.0/pdfbox/pom.xml
   
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java

Modified: pdfbox/branches/2.0/pdfbox/pom.xml
==============================================================================
--- pdfbox/branches/2.0/pdfbox/pom.xml  Fri Aug 21 08:30:32 2026        
(r1937282)
+++ pdfbox/branches/2.0/pdfbox/pom.xml  Fri Aug 21 11:50:22 2026        
(r1937283)
@@ -930,6 +930,45 @@
                             
<sha512>2ee83beb6658792c6b963010462515ff1187aafe64930c1a7465dc26e86ab5236dc98cb006986e5fcd60876bedef7f00e4e1cb86bbf590bba000a00187af0ee3</sha512>
                         </configuration>
                     </execution>
+                    <execution>
+                        <id>PDFBOX-6077-1</id>
+                        <phase>generate-test-resources</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            
<url>https://issues.apache.org/jira/secure/attachment/13078553/example.pdf</url>
+                            
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
+                            
<outputFileName>PDFBOX-6077-example.pdf</outputFileName>
+                            
<sha512>f4faaa68062073ffdfd48119563f1e1a6eff6d9a063188dc2ec59ccc747277fcaa6139936cebf2f3f7b1b99b80ca13934fb4568658a169e0bf25bf4e748de101</sha512>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>PDFBOX-6077-2</id>
+                        <phase>generate-test-resources</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            
<url>https://issues.apache.org/jira/secure/attachment/13078557/PDFBOX-5842-reduced.pdf</url>
+                            
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
+                            
<outputFileName>PDFBOX-5842-reduced.pdf</outputFileName>
+                            
<sha512>c66b13230d343d6b0a2de81680f5d1ae7f8d92713acbc453ff36fe085831fa89127e0428d297e7494b87fc932ca8a721744db1fe79a41cc5c3cf7d631fc209fc</sha512>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>PDFBOX-5403</id>
+                        <phase>generate-test-resources</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            
<url>https://issues.apache.org/jira/secure/attachment/13041734/bad+rendering.pdf</url>
+                            
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
+                            
<outputFileName>PDFBOX-5403-bad-rendering.pdf</outputFileName>
+                            
<sha512>0d7160a4af04bf2f785bf4155f69876da4b7ff7a196e7eda1eb904c02c35aa03c31041d9339fda90322cb58bde16b87bae8460c617bfe5b8dc0670ddab102f62</sha512>
+                        </configuration>
+                    </execution>
                 </executions>
             </plugin>
         </plugins>

Modified: 
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java
==============================================================================
--- 
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java
       Fri Aug 21 08:30:32 2026        (r1937282)
+++ 
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java
       Fri Aug 21 11:50:22 2026        (r1937283)
@@ -110,7 +110,7 @@ public class ValidateXImage
         }
     }
 
-    static int colorCount(BufferedImage bim)
+    static public int colorCount(BufferedImage bim)
     {
         Set<Integer> colors = new HashSet<Integer>();
         int w = bim.getWidth();

Copied and modified: 
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
 (from r1937280, 
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java)
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
       Fri Aug 21 05:00:25 2026        (r1937280, copy source)
+++ 
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestQuality.java
       Fri Aug 21 11:50:22 2026        (r1937283)
@@ -19,45 +19,20 @@ package org.apache.pdfbox.rendering;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
-import org.apache.pdfbox.Loader;
-import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
-import org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
 
 /**
  *
- * @author Tilman Hausherr
  */
-class TestQuality
+public class TestQuality
 {
     private static final File TARGET_PDF_DIR = new File("target/pdfs");
 
     /**
-     * PDFBOX-4831: PDF with a 300 dpi bitonal scan must be bitonal when 
rendered at 300 dpi
-     * and identical to the scan in the PDF.
-     *
-     * @throws IOException
-     */
-    @Test
-    void testPDFBox4831() throws IOException
-    {
-        File file = new File(TARGET_PDF_DIR, "PDFBOX-4831.pdf");
-        try (PDDocument doc = Loader.loadPDF(file))
-        {
-            PDFRenderer renderer = new PDFRenderer(doc);
-            BufferedImage renderedImage = renderer.renderImageWithDPI(0, 300);
-            Assertions.assertEquals(2, 
ValidateXImage.colorCount(renderedImage));
-            PDImageXObject xObjectImage =
-                    (PDImageXObject) 
doc.getPage(0).getResources().getXObject(COSName.getPDFName("I0"));
-            BufferedImage extractedImage = xObjectImage.getImage();
-            ValidateXImage.checkIdent(extractedImage, renderedImage);
-        }
-    }
-
-    /**
      * PDFBOX-6077: a stencil mask filled with a pattern must not paint the 
gaps between the
      * pattern's own tiles as opaque black. Before the fix, the stencil mask's 
alpha overwrote
      * the pattern paint's own alpha instead of being combined with it, so any 
pixel the pattern
@@ -66,17 +41,16 @@ class TestQuality
      * @throws IOException
      */
     @Test
-    void testPDFBox6077() throws IOException
+    public void testPDFBox6077() throws IOException
     {
         File file = new File(TARGET_PDF_DIR, "PDFBOX-6077-example.pdf");
-        try (PDDocument doc = Loader.loadPDF(file))
-        {
-            PDFRenderer renderer = new PDFRenderer(doc);
-            BufferedImage renderedImage = renderer.renderImageWithDPI(0, 100);
-            // a gap between the tiling pattern's own painted tiles, which 
must stay transparent
-            // (i.e. show the white page background) instead of turning opaque 
black
-            Assertions.assertEquals(0xFFFFFFFF, renderedImage.getRGB(280, 23));
-        }
+        PDDocument doc = PDDocument.load(file);
+        PDFRenderer renderer = new PDFRenderer(doc);
+        BufferedImage renderedImage = renderer.renderImageWithDPI(0, 100);
+        // a gap between the tiling pattern's own painted tiles, which must 
stay transparent
+        // (i.e. show the white page background) instead of turning opaque 
black
+        assertEquals(0xFFFFFFFF, renderedImage.getRGB(280, 23));
+        doc.close();
     }
 
     /**
@@ -88,17 +62,16 @@ class TestQuality
      * @throws IOException
      */
     @Test
-    void testPDFBox5842() throws IOException
+    public void testPDFBox5842() throws IOException
     {
         File file = new File(TARGET_PDF_DIR, "PDFBOX-5842-reduced.pdf");
-        try (PDDocument doc = Loader.loadPDF(file))
-        {
-            PDFRenderer renderer = new PDFRenderer(doc);
-            BufferedImage renderedImage = renderer.renderImageWithDPI(0, 100);
-            // a pixel within the soft-masked pattern's map marker icon; if 
the soft mask's alpha
-            // lookup is broken, this whole region renders as blank white 
instead
-            Assertions.assertNotEquals(0xFFFFFFFF, renderedImage.getRGB(267, 
1329));
-        }
+        PDDocument doc = PDDocument.load(file);
+        PDFRenderer renderer = new PDFRenderer(doc);
+        BufferedImage renderedImage = renderer.renderImageWithDPI(0, 100);
+        // a pixel within the soft-masked pattern's map marker icon; if the 
soft mask's alpha
+        // lookup is broken, this whole region renders as blank white instead
+        assertNotEquals(0xFFFFFFFF, renderedImage.getRGB(267, 1329));
+        doc.close();
     }
 
     /**
@@ -111,19 +84,17 @@ class TestQuality
      * @throws IOException
      */
     @Test
-    void testPDFBox5403() throws IOException
+    public void testPDFBox5403() throws IOException
     {
         File file = new File(TARGET_PDF_DIR, "PDFBOX-5403-bad-rendering.pdf");
-        try (PDDocument doc = Loader.loadPDF(file))
-        {
-            PDFRenderer renderer = new PDFRenderer(doc);
-            BufferedImage renderedImage = renderer.renderImageWithDPI(2, 100);
-            // a pixel within a line of text rendered via a pattern-filled 
stencil mask; a
-            // hairline tile-boundary seam previously showed through as a 
washed-out gray streak
-            int rgb = renderedImage.getRGB(159, 115);
-            int red = (rgb >> 16) & 0xFF;
-            Assertions.assertTrue(red < 100,
-                    "expected a dark text pixel but was too light: " + 
Integer.toHexString(rgb));
-        }
+        PDDocument doc = PDDocument.load(file);
+        PDFRenderer renderer = new PDFRenderer(doc);
+        BufferedImage renderedImage = renderer.renderImageWithDPI(2, 100);
+        // a pixel within a line of text rendered via a pattern-filled stencil 
mask; a
+        // hairline tile-boundary seam previously showed through as a 
washed-out gray streak
+        int rgb = renderedImage.getRGB(159, 115);
+        int red = (rgb >> 16) & 0xFF;
+        assertTrue("expected a dark text pixel but was too light: " + 
Integer.toHexString(rgb), red < 100);
+        doc.close();
     }
 }

Reply via email to