Browse Source
Merge pull request #2610 from SixLabors/issue/2603
Handle case when Foreground image overhangs bottom of background image during DrawImage Call (3.1 target)
pull/2614/head
Scott Williams
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
28 additions and
0 deletions
-
src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
-
tests/ImageSharp.Tests/Drawing/DrawImageTests.cs
-
tests/Images/External/ReferenceOutput/Drawing/DrawImageTests/Issue2603.png
|
|
|
@ -98,6 +98,10 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg> |
|
|
|
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) |
|
|
|
|
|
|
|
@ -272,4 +272,25 @@ public class DrawImageTests |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,3 @@ |
|
|
|
version https://git-lfs.github.com/spec/v1 |
|
|
|
oid sha256:307ef8cea7999e615420740bb0a403a64b24f1fff5356c2ac45c1952f84c5e4c |
|
|
|
size 508 |