diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index 94dd903b43..53986e6d51 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -9,6 +9,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { + using System; + public class DrawImageTest : FileTestBase { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32; @@ -42,5 +44,45 @@ namespace SixLabors.ImageSharp.Tests image.DebugSave(provider, new { mode }); } } + + [Theory] + [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, TestImages.Png.Splash)] + public void ImageShouldHandleNegativeLocation(TestImageProvider provider, string backgroundPath) + { + using (Image background = TestFile.Create(backgroundPath).CreateImage()) + using (Image overlay = provider.GetImage()) + { + int xy = -25; + Rgba32 backgroundPixel = background[0, 0]; + Rgba32 overlayPixel = overlay[Math.Abs(xy) + 1, Math.Abs(xy) + 1]; + + background.Mutate(x => x.DrawImage(overlay, PixelBlenderMode.Normal, 1F, new Size(overlay.Width, overlay.Height), new Point(xy, xy))); + + Assert.Equal(default(Rgba32), backgroundPixel); + Assert.Equal(overlayPixel, background[0, 0]); + + background.DebugSave(provider, new[] { "Negative" }); + } + } + + [Theory] + [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, TestImages.Png.Splash)] + public void ImageShouldHandlePositiveLocation(TestImageProvider provider, string backgroundPath) + { + using (Image background = TestFile.Create(backgroundPath).CreateImage()) + using (Image overlay = provider.GetImage()) + { + int xy = 25; + Rgba32 backgroundPixel = background[xy - 1, xy - 1]; + Rgba32 overlayPixel = overlay[0, 0]; + + background.Mutate(x => x.DrawImage(overlay, PixelBlenderMode.Normal, 1F, new Size(overlay.Width, overlay.Height), new Point(xy, xy))); + + Assert.Equal(default(Rgba32), backgroundPixel); + Assert.Equal(overlayPixel, background[xy, xy]); + + background.DebugSave(provider, new[] { "Positive" }); + } + } } }