Skip to content

Commit 4f8ea7f

Browse files
Tweak bounds clamping
1 parent 4b852e6 commit 4f8ea7f

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/ImageSharp/Formats/AnimationUtilities.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,12 @@ public static (bool Difference, Rectangle Bounds) DeDuplicatePixels<TPixel>(
148148
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, result, resultFrame.DangerousGetPixelRowMemory(y).Span, PixelConversionModifiers.Scale);
149149
}
150150

151-
Rectangle bounds = Rectangle.FromLTRB(
152-
left = Numerics.Clamp(left, 0, resultFrame.Width - 1),
153-
top = Numerics.Clamp(top, 0, resultFrame.Height - 1),
154-
Numerics.Clamp(right, left + 1, resultFrame.Width),
155-
Numerics.Clamp(bottom, top + 1, resultFrame.Height));
151+
left = Math.Max(0, Math.Min(left, resultFrame.Width - 1));
152+
top = Math.Max(0, Math.Min(top, resultFrame.Height - 1));
153+
right = Math.Max(left + 1, Math.Min(right, resultFrame.Width));
154+
bottom = Math.Max(top + 1, Math.Min(bottom, resultFrame.Height));
155+
156+
Rectangle bounds = Rectangle.FromLTRB(left, top, right, bottom);
156157

157158
// Webp requires even bounds
158159
if (clampingMode == ClampingMode.Even)

0 commit comments

Comments
 (0)