From 8a94842bf568ca3230e9e9eb7817eb890ce9ddaf Mon Sep 17 00:00:00 2001
From: graveljp
Date: Tue, 8 Oct 2024 21:51:20 -0400
Subject: [PATCH] Apply globalAlpha on the canvas filter source
The previous specification for canvas filters applies the globalAlpha on the filter result. The drawing model essentially says:
1. Render the shape, creating image A.
2. When the current filter is set, use it on image A to create image B.
3. Multiply the alpha component of every pixel in B by global alpha.
This leads to a unexpected behavior. When drawing a transparent shape with a drop-shadow filter, the shadow should be visible through the transparent foreground. This should be true whether the drawing is made transparent via fillStyle or via globalAlpha. This is how Chromium and Gecko behave. Following the specification to the letter however, the shadow wouldn't be visible through the foreground.
Align the standard with Chromium's and Gecko's behavior:
1. Render the shape, creating image A.
2. Multiply the alpha component of every pixel in A by global alpha, creating image B.
3. When the current filter is set, use it on image B to create image C.
---
source | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/source b/source
index 17970179bb7..8989fa93533 100644
--- a/source
+++ b/source
@@ -70026,6 +70026,9 @@ console.log(pixels.data[2]);
and line styles must be honored, and the stroke must itself also be subjected to the current
transformation matrix.
+ Multiply the alpha component of every pixel in A by global alpha
.
+
When the current filter is set to a
value other than "none
" and all the externally-defined filters it
@@ -70041,16 +70044,10 @@ console.log(pixels.data[2]);
When shadows are drawn, render the shadow from image B,
using the current shadow styles, creating image C.
- When shadows are drawn, multiply the alpha component of every pixel in
- C by global alpha
.
-
When shadows are drawn, composite C within the
clipping region over the current output bitmap using the current
compositing and blending operator.
- Multiply the alpha component of every pixel in B by global alpha
.
-
Composite B within the clipping region over the current
output bitmap using the current compositing and blending
operator.