Author: tilman
Date: Tue Aug 18 08:31:56 2026
New Revision: 1937199

Log:
PDFBOX-6077: assign alpha instead of combining, but only if not transparent; 
optimize; add comment

Modified:
   
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
        Tue Aug 18 08:30:56 2026        (r1937198)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
        Tue Aug 18 08:31:56 2026        (r1937199)
@@ -1256,6 +1256,8 @@ public class PageDrawer extends PDFGraph
                         if (rasterPixel[3] != 0)
                         {
                             alphaPixel = alpha.getPixel(x, y, alphaPixel);
+                            // assign alpha; it's also possible to combine but 
the visual
+                            // difference is currently minimal (see code of 
16.8.2026)
                             rasterPixel[3] = alphaPixel[0];
                             raster.setPixel(x, y, rasterPixel);
                         }
@@ -1396,34 +1398,37 @@ public class PageDrawer extends PDFGraph
                 int maskX = (int) Math.floor(point.getX() - origin.getX());
                 int maskY = (int) Math.floor(point.getY() - origin.getY());
 
-                int alphaScale;
-                if (maskX >= 0 && maskY >= 0 && maskX < maskRaster.getWidth() 
&& maskY < maskRaster.getHeight())
+                rasterPixel = raster.getPixel(x, y, rasterPixel);
+                if (rasterPixel[3] != 0)
                 {
-                    maskRaster.getPixel(maskX, maskY, gray);
-                    if (transferFunction != null)
+                    int alphaScale;
+                    if (maskX >= 0 && maskY >= 0 && maskX < 
maskRaster.getWidth() && maskY < maskRaster.getHeight())
                     {
-                        Float f = map[gray[0]];
-                        if (f == null)
+                        maskRaster.getPixel(maskX, maskY, gray);
+                        if (transferFunction != null)
+                        {
+                            Float f = map[gray[0]];
+                            if (f == null)
+                            {
+                                input[0] = gray[0] / 255f;
+                                f = transferFunction.eval(input)[0];
+                                map[gray[0]] = f;
+                            }
+                            alphaScale = Math.round(255 * f);
+                        }
+                        else
                         {
-                            input[0] = gray[0] / 255f;
-                            f = transferFunction.eval(input)[0];
-                            map[gray[0]] = f;
+                            alphaScale = gray[0];
                         }
-                        alphaScale = Math.round(255 * f);
                     }
                     else
                     {
-                        alphaScale = gray[0];
+                        alphaScale = backdropColorValue;
                     }
-                }
-                else
-                {
-                    alphaScale = backdropColorValue;
-                }
 
-                rasterPixel = raster.getPixel(x, y, rasterPixel);
-                rasterPixel[3] = rasterPixel[3] * alphaScale / 255;
-                raster.setPixel(x, y, rasterPixel);
+                    rasterPixel[3] = alphaScale;
+                    raster.setPixel(x, y, rasterPixel);
+                }
             }
         }
     }

Reply via email to