Skip to content

Commit df21451

Browse files
Merge pull request #2609 from SixLabors/issue/2608
Correctly calculate foreground Rectangle when negative background location is set (3.1 fix)
2 parents cb07e36 + 9906ee5 commit df21451

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ protected override void OnFrameApply(ImageFrame<TPixelBg> source)
8787
if (this.BackgroundLocation.X < 0)
8888
{
8989
foregroundRectangle.Width += this.BackgroundLocation.X;
90+
foregroundRectangle.X -= this.BackgroundLocation.X;
9091
left = 0;
9192
}
9293

9394
if (this.BackgroundLocation.Y < 0)
9495
{
9596
foregroundRectangle.Height += this.BackgroundLocation.Y;
97+
foregroundRectangle.Y -= this.BackgroundLocation.Y;
9698
top = 0;
9799
}
98100

tests/ImageSharp.Tests/Drawing/DrawImageTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,25 @@ public void Issue2447_C<TPixel>(TestImageProvider<TPixel> provider)
251251
appendPixelTypeToFileName: false,
252252
appendSourceFileOrDescription: false);
253253
}
254+
255+
[Theory]
256+
[WithFile(TestImages.Png.Issue2447, PixelTypes.Rgba32)]
257+
public void Issue2608_NegOffset<TPixel>(TestImageProvider<TPixel> provider)
258+
where TPixel : unmanaged, IPixel<TPixel>
259+
{
260+
using Image<TPixel> foreground = provider.GetImage();
261+
using Image<Rgba32> background = new(100, 100, new Rgba32(0, 255, 255));
262+
263+
background.Mutate(c => c.DrawImage(foreground, new Point(-10, -10), new Rectangle(32, 32, 32, 32), 1F));
264+
265+
background.DebugSave(
266+
provider,
267+
appendPixelTypeToFileName: false,
268+
appendSourceFileOrDescription: false);
269+
270+
background.CompareToReferenceOutput(
271+
provider,
272+
appendPixelTypeToFileName: false,
273+
appendSourceFileOrDescription: false);
274+
}
254275
}
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)