Skip to content

Commit 6f9bc03

Browse files
Merge branch 'main' into sn/promote-pixeltype
2 parents c7f18c8 + d885702 commit 6f9bc03

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,21 @@ 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

101+
// clamp the height/width to the availible space left to prevent overflowing
102+
foregroundRectangle.Width = Math.Min(source.Width - left, foregroundRectangle.Width);
103+
foregroundRectangle.Height = Math.Min(source.Height - top, foregroundRectangle.Height);
104+
99105
int width = foregroundRectangle.Width;
100106
int height = foregroundRectangle.Height;
101107
if (width <= 0 || height <= 0)

tests/ImageSharp.Tests/Drawing/DrawImageTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,46 @@ 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+
}
275+
276+
[Theory]
277+
[WithFile(TestImages.Png.Issue2447, PixelTypes.Rgba32)]
278+
public void Issue2603<TPixel>(TestImageProvider<TPixel> provider)
279+
where TPixel : unmanaged, IPixel<TPixel>
280+
{
281+
using Image<TPixel> foreground = provider.GetImage();
282+
using Image<Rgba32> background = new(100, 100, new Rgba32(0, 255, 255));
283+
284+
background.Mutate(c => c.DrawImage(foreground, new Point(80, 80), new Rectangle(32, 32, 32, 32), 1F));
285+
286+
background.DebugSave(
287+
provider,
288+
appendPixelTypeToFileName: false,
289+
appendSourceFileOrDescription: false);
290+
291+
background.CompareToReferenceOutput(
292+
provider,
293+
appendPixelTypeToFileName: false,
294+
appendSourceFileOrDescription: false);
295+
}
254296
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)