From 35cd09d1e60f519b03185c5f3b5b968ea5841e04 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 20 Aug 2022 12:43:32 +0200 Subject: [PATCH] Fix TornEdges effect corner glitches --- ShareX.HelpersLib/Helpers/ImageHelpers.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index fe188ac5b..ecacdfa1b 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -1769,7 +1769,9 @@ public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorS if (sides.HasFlag(AnchorStyles.Top) && horizontalTornCount > 1) { - for (int x = 0; x < bmp.Width; x += tornRange) + int startX = (sides.HasFlag(AnchorStyles.Left) && verticalTornCount > 1) ? tornDepth : 0; + int endX = (sides.HasFlag(AnchorStyles.Right) && verticalTornCount > 1) ? bmp.Width - tornDepth : bmp.Width; + for (int x = startX; x < endX; x += tornRange) { int y = random ? RandomFast.Next(0, tornDepth) : ((x / tornRange) & 1) * tornDepth; points.Add(new Point(x, y)); @@ -1783,7 +1785,9 @@ public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorS if (sides.HasFlag(AnchorStyles.Right) && verticalTornCount > 1) { - for (int y = 0; y < bmp.Height; y += tornRange) + int startY = (sides.HasFlag(AnchorStyles.Top) && horizontalTornCount > 1) ? tornDepth : 0; + int endY = (sides.HasFlag(AnchorStyles.Bottom) && horizontalTornCount > 1) ? bmp.Height - tornDepth : bmp.Height; + for (int y = startY; y < endY; y += tornRange) { int x = random ? RandomFast.Next(0, tornDepth) : ((y / tornRange) & 1) * tornDepth; points.Add(new Point(bmp.Width - tornDepth + x, y)); @@ -1797,7 +1801,9 @@ public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorS if (sides.HasFlag(AnchorStyles.Bottom) && horizontalTornCount > 1) { - for (int x = bmp.Width; x >= 0; x = (x / tornRange - 1) * tornRange) + int startX = (sides.HasFlag(AnchorStyles.Right) && verticalTornCount > 1) ? bmp.Width - tornDepth : bmp.Width; + int endX = (sides.HasFlag(AnchorStyles.Left) && verticalTornCount > 1) ? tornDepth : 0; + for (int x = startX; x >= endX; x = (x / tornRange - 1) * tornRange) { int y = random ? RandomFast.Next(0, tornDepth) : ((x / tornRange) & 1) * tornDepth; points.Add(new Point(x, bmp.Height - tornDepth + y)); @@ -1811,7 +1817,9 @@ public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorS if (sides.HasFlag(AnchorStyles.Left) && verticalTornCount > 1) { - for (int y = bmp.Height; y >= 0; y = (y / tornRange - 1) * tornRange) + int startY = (sides.HasFlag(AnchorStyles.Bottom) && horizontalTornCount > 1) ? bmp.Height - tornDepth : bmp.Height; + int endY = (sides.HasFlag(AnchorStyles.Top) && horizontalTornCount > 1) ? tornDepth : 0; + for (int y = startY; y >= endY; y = (y / tornRange - 1) * tornRange) { int x = random ? RandomFast.Next(0, tornDepth) : ((y / tornRange) & 1) * tornDepth; points.Add(new Point(x, y));