Author: tilman
Date: Tue Aug 18 08:32:03 2026
New Revision: 1937201
Log:
PDFBOX-6077: assign alpha instead of combining, but only if not transparent;
optimize; add comment
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
==============================================================================
---
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Tue Aug 18 08:32:00 2026 (r1937200)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Tue Aug 18 08:32:03 2026 (r1937201)
@@ -1254,6 +1254,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);
}
@@ -1394,34 +1396,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);
+ }
}
}
}