From 209c432cfbd417c7ea9170d3bac82f968b2cabdb Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 27 Nov 2026 14:34:46 +1000 Subject: [PATCH] Use the full-precision tint color in the CPU layer effects The CPU acrylic, drop shadow, backdrop drop shadow, glow and inner shadow effects converted the tint color to Rgba32 before they built the color matrix. That cut the tint to 8 bits for each channel, while the WebGPU effects use the full-precision color. The CPU effects now use Color.ToScaledVector4 with the same alpha representation as their WebGPU counterparts. --- src/ImageSharp.Drawing/Processing/BackdropLayerEffect.cs | 4 ++-- src/ImageSharp.Drawing/Processing/LayerEffect.cs | 6 +++--- ...terLayerEffects_MatchesDefaultOutput_acrylic_Default.png | 4 ++-- ...ts_MatchesDefaultOutput_acrylic_WebGPU_NativeSurface.png | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/BackdropLayerEffect.cs b/src/ImageSharp.Drawing/Processing/BackdropLayerEffect.cs index ae258ff9c..2563aad91 100644 --- a/src/ImageSharp.Drawing/Processing/BackdropLayerEffect.cs +++ b/src/ImageSharp.Drawing/Processing/BackdropLayerEffect.cs @@ -109,7 +109,7 @@ private static Action CreateOperation(float sigma, Colo // Blending a constant colour over the backdrop is linear, so it is expressed as a colour // matrix: the backdrop's channels scale by one minus the tint's alpha and the constant row // carries the pre-scaled tint. The backdrop's own alpha is preserved. - Vector4 vector = color.ToPixel().ToScaledVector4(); + Vector4 vector = color.ToScaledVector4(PixelAlphaRepresentation.Unassociated); float keep = 1F - vector.W; ColorMatrix tint = default; tint.M11 = keep; @@ -186,7 +186,7 @@ private static Action CreateOperation(float sigma, Colo // The tint replaces the backdrop's colour with the constant shadow colour and scales its // alpha; the DestOver write-back slots the blurred silhouette beneath the untouched // backdrop at the offset. - Vector4 vector = color.ToPixel().ToScaledVector4(); + Vector4 vector = color.ToScaledVector4(PixelAlphaRepresentation.Unassociated); ColorMatrix tint = default; tint.M44 = vector.W; tint.M51 = vector.X; diff --git a/src/ImageSharp.Drawing/Processing/LayerEffect.cs b/src/ImageSharp.Drawing/Processing/LayerEffect.cs index 2c54fd4e1..c1b90dca6 100644 --- a/src/ImageSharp.Drawing/Processing/LayerEffect.cs +++ b/src/ImageSharp.Drawing/Processing/LayerEffect.cs @@ -172,7 +172,7 @@ private static Action CreateOperation(float sigma, Colo // alpha. The colour filter operates on straight alpha, so with the RGB rows zeroed the // constant row sets the colour outright; because the colour is then constant across the // snapshot, the blur only spreads alpha and cannot bleed foreign colours into the shadow. - Vector4 vector = color.ToPixel().ToScaledVector4(); + Vector4 vector = color.ToScaledVector4(PixelAlphaRepresentation.Unassociated); ColorMatrix tint = default; tint.M44 = vector.W; tint.M51 = vector.X; @@ -244,7 +244,7 @@ private static Action CreateOperation(float sigma, Colo // alpha. The colour filter operates on straight alpha, so with the RGB rows zeroed the // constant row sets the colour outright; because the colour is then constant across the // snapshot, the blur only spreads alpha and cannot bleed foreign colours into the glow. - Vector4 vector = color.ToPixel().ToScaledVector4(); + Vector4 vector = color.ToScaledVector4(PixelAlphaRepresentation.Unassociated); ColorMatrix tint = default; tint.M44 = vector.W; tint.M51 = vector.X; @@ -326,7 +326,7 @@ private static Action CreateOperation(float sigma, Colo // with the constant RGB rows carrying the shadow colour, the blur feathers the boundary, // and the SrcAtop write-back clips the result onto the content so only the parts that // reach inside its edges remain. - Vector4 vector = color.ToPixel().ToScaledVector4(); + Vector4 vector = color.ToScaledVector4(PixelAlphaRepresentation.Unassociated); ColorMatrix invertedTint = default; invertedTint.M44 = -vector.W; invertedTint.M54 = vector.W; diff --git a/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_Default.png b/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_Default.png index d151a9b57..b9207cfc2 100644 --- a/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_Default.png +++ b/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_Default.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b500298b467004907a1ad28829754f07becdae12cd3efbf5329b78bebbc527a6 -size 66512 +oid sha256:baccc50c278877e04f0d84785d91cebf1ef14a5c60013d263aa2f86d658f0594 +size 80785 diff --git a/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_WebGPU_NativeSurface.png b/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_WebGPU_NativeSurface.png index 4d3bab323..df5c05c3d 100644 --- a/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_WebGPU_NativeSurface.png +++ b/tests/Images/ReferenceOutput/Drawing/WebGPUDrawingBackendTests/DrawText_WithBackdropFilterLayerEffects_MatchesDefaultOutput_acrylic_WebGPU_NativeSurface.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5d846917eb6c45c177dc13bc37f5744db329f3041941a37f0ba1e9a1141781ac -size 65215 +oid sha256:8ec10bd4e7cb6d7f51d5549eaf1c771d1dfd5195bfc3ff9beb11f3e93d61fd7c +size 79300