From 7e4bf3dd45e233b060e5ad4e6a12860ca2dc93cb Mon Sep 17 00:00:00 2001 From: Cameron White Date: Sat, 21 Dec 2024 18:22:37 -0500 Subject: [PATCH] Fix transparency issues for a few effects Premultiplied alpha should be used since the colors are from a Cairo surface Fixes: #1184 --- CHANGELOG.md | 1 + Pinta.Effects/Effects/InkSketchEffect.cs | 15 ++++++++------ Pinta.Effects/Effects/RadialBlurEffect.cs | 24 +++++++++++------------ Pinta.Effects/Effects/ZoomBlurEffect.cs | 18 ++++++++--------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7dfbeed39..03c6916afc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Thanks to the following contributors who worked on this release: - Fixed various artifacts in the shape tools, particularly with larger brush widths (#733, #955) - Fixed an issue where the text tool did not immediately redraw after changes to the font or color of unfinalized text (#952, #975) - Fixed a bug where cut / paste operations did not behave as expected with complex selections (#951, #978) +- Fixed transparency behavior for several effects (#1184) ## [2.1.2](https://github.com/PintaProject/Pinta/releases/tag/2.1.2) - 2024/04/20 diff --git a/Pinta.Effects/Effects/InkSketchEffect.cs b/Pinta.Effects/Effects/InkSketchEffect.cs index 2fc864ae6b..b596521e5e 100644 --- a/Pinta.Effects/Effects/InkSketchEffect.cs +++ b/Pinta.Effects/Effects/InkSketchEffect.cs @@ -93,7 +93,7 @@ public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan src_data, int width, int x, int y, RectangleI adjustedBounds) + private static ColorBgra CreateBaseRGBA (ReadOnlySpan src_data, int width, int x, int y, RectangleI adjustedBounds) { int r = 0; int g = 0; int b = 0; + int a = 0; for (int v = adjustedBounds.Top; v < adjustedBounds.Bottom; v++) { @@ -124,13 +125,15 @@ private static ColorBgra CreateBaseRGB (ReadOnlySpan src_data, int wi r += src_pixel.R * w; g += src_pixel.G * w; b += src_pixel.B * w; + a += src_pixel.A * w; } } - return ColorBgra.FromBgr ( + return ColorBgra.FromBgra ( b: Utility.ClampToByte (b), g: Utility.ClampToByte (g), - r: Utility.ClampToByte (r) + r: Utility.ClampToByte (r), + a: Utility.ClampToByte (a) ); } @@ -141,8 +144,8 @@ private ColorBgra CreateTopLayer (ColorBgra baseRGB) // Adjust Brightness and Contrast return - (topLayer.R > (Data.InkOutline * 255 / 100)) - ? ColorBgra.FromBgra (255, 255, 255, topLayer.A) + (topLayer.ToStraightAlpha ().R > (Data.InkOutline * 255 / 100)) + ? ColorBgra.FromBgra (topLayer.A, topLayer.A, topLayer.A, topLayer.A) : ColorBgra.FromBgra (0, 0, 0, topLayer.A); } #endregion diff --git a/Pinta.Effects/Effects/RadialBlurEffect.cs b/Pinta.Effects/Effects/RadialBlurEffect.cs index 1df748f123..bf926a4d6a 100644 --- a/Pinta.Effects/Effects/RadialBlurEffect.cs +++ b/Pinta.Effects/Effects/RadialBlurEffect.cs @@ -104,9 +104,9 @@ private static ColorBgra GetFinalPixelColor ( X: (pixel.coordinates.X << 16) - settings.fcx, Y: (pixel.coordinates.Y << 16) - settings.fcy); - int sr = sourcePixel.R * sourcePixel.A; - int sg = sourcePixel.G * sourcePixel.A; - int sb = sourcePixel.B * sourcePixel.A; + int sr = sourcePixel.R; + int sg = sourcePixel.G; + int sb = sourcePixel.B; int sa = sourcePixel.A; int sc = 1; @@ -126,9 +126,9 @@ private static ColorBgra GetFinalPixelColor ( ColorBgra sample = sourceData[p1.Y * settings.canvasSize.Width + p1.X]; - sr += sample.R * sample.A; - sg += sample.G * sample.A; - sb += sample.B * sample.A; + sr += sample.R; + sg += sample.G; + sb += sample.B; sa += sample.A; ++sc; @@ -142,9 +142,9 @@ private static ColorBgra GetFinalPixelColor ( ColorBgra sample = sourceData[p2.Y * settings.canvasSize.Width + p2.X]; - sr += sample.R * sample.A; - sg += sample.G * sample.A; - sb += sample.B * sample.A; + sr += sample.R; + sg += sample.G; + sb += sample.B; sa += sample.A; ++sc; @@ -154,9 +154,9 @@ private static ColorBgra GetFinalPixelColor ( return (sa > 0) ? ColorBgra.FromBgra ( - b: Utility.ClampToByte (sb / sa), - g: Utility.ClampToByte (sg / sa), - r: Utility.ClampToByte (sr / sa), + b: Utility.ClampToByte (sb / sc), + g: Utility.ClampToByte (sg / sc), + r: Utility.ClampToByte (sr / sc), a: Utility.ClampToByte (sa / sc)) : ColorBgra.FromUInt32 (0); } diff --git a/Pinta.Effects/Effects/ZoomBlurEffect.cs b/Pinta.Effects/Effects/ZoomBlurEffect.cs index 7719ce5675..224f197196 100644 --- a/Pinta.Effects/Effects/ZoomBlurEffect.cs +++ b/Pinta.Effects/Effects/ZoomBlurEffect.cs @@ -102,9 +102,9 @@ private static ColorBgra GetFinalPixelColor ( int sc = 0; ColorBgra src_pixel = sourceData[pixel.memoryOffset]; - sr += src_pixel.R * src_pixel.A; - sg += src_pixel.G * src_pixel.A; - sb += src_pixel.B * src_pixel.A; + sr += src_pixel.R; + sg += src_pixel.G; + sb += src_pixel.B; sa += src_pixel.A; ++sc; @@ -124,9 +124,9 @@ private static ColorBgra GetFinalPixelColor ( settings.size.Width, transformed); - sr += src_pixel_2.R * src_pixel_2.A; - sg += src_pixel_2.G * src_pixel_2.A; - sb += src_pixel_2.B * src_pixel_2.A; + sr += src_pixel_2.R; + sg += src_pixel_2.G; + sb += src_pixel_2.B; sa += src_pixel_2.A; ++sc; } @@ -135,9 +135,9 @@ private static ColorBgra GetFinalPixelColor ( return (sa != 0) ? ColorBgra.FromBgra ( - b: Utility.ClampToByte (sb / sa), - g: Utility.ClampToByte (sg / sa), - r: Utility.ClampToByte (sr / sa), + b: Utility.ClampToByte (sb / sc), + g: Utility.ClampToByte (sg / sc), + r: Utility.ClampToByte (sr / sc), a: Utility.ClampToByte (sa / sc)) : ColorBgra.FromUInt32 (0); }