Skip to content

Commit

Permalink
Merge pull request #2610 from SixLabors/issue/2603
Browse files Browse the repository at this point in the history
Handle case when Foreground image overhangs bottom of background image during DrawImage Call (3.1 target)
  • Loading branch information
tocsoft authored Dec 10, 2023
2 parents df21451 + a4ce7ca commit 6863127
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ protected override void OnFrameApply(ImageFrame<TPixelBg> source)
top = 0;
}

// clamp the height/width to the availible space left to prevent overflowing
foregroundRectangle.Width = Math.Min(source.Width - left, foregroundRectangle.Width);
foregroundRectangle.Height = Math.Min(source.Height - top, foregroundRectangle.Height);

int width = foregroundRectangle.Width;
int height = foregroundRectangle.Height;
if (width <= 0 || height <= 0)
Expand Down
21 changes: 21 additions & 0 deletions tests/ImageSharp.Tests/Drawing/DrawImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,25 @@ public void Issue2608_NegOffset<TPixel>(TestImageProvider<TPixel> provider)
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}

[Theory]
[WithFile(TestImages.Png.Issue2447, PixelTypes.Rgba32)]
public void Issue2603<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> foreground = provider.GetImage();
using Image<Rgba32> background = new(100, 100, new Rgba32(0, 255, 255));

background.Mutate(c => c.DrawImage(foreground, new Point(80, 80), new Rectangle(32, 32, 32, 32), 1F));

background.DebugSave(
provider,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);

background.CompareToReferenceOutput(
provider,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6863127

Please sign in to comment.