Skip to content

Commit

Permalink
Merge pull request #2609 from SixLabors/issue/2608
Browse files Browse the repository at this point in the history
Correctly calculate foreground Rectangle when negative background location is set (3.1 fix)
  • Loading branch information
JimBobSquarePants committed Dec 9, 2023
2 parents cb07e36 + 9906ee5 commit df21451
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ protected override void OnFrameApply(ImageFrame<TPixelBg> source)
if (this.BackgroundLocation.X < 0)
{
foregroundRectangle.Width += this.BackgroundLocation.X;
foregroundRectangle.X -= this.BackgroundLocation.X;
left = 0;
}

if (this.BackgroundLocation.Y < 0)
{
foregroundRectangle.Height += this.BackgroundLocation.Y;
foregroundRectangle.Y -= this.BackgroundLocation.Y;
top = 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 @@ -251,4 +251,25 @@ public void Issue2447_C<TPixel>(TestImageProvider<TPixel> provider)
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}

[Theory]
[WithFile(TestImages.Png.Issue2447, PixelTypes.Rgba32)]
public void Issue2608_NegOffset<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(-10, -10), new Rectangle(32, 32, 32, 32), 1F));

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

background.CompareToReferenceOutput(
provider,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}
}
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 df21451

Please sign in to comment.