Browse Source
Merge pull request #2609 from SixLabors/issue/2608
Correctly calculate foreground Rectangle when negative background location is set (3.1 fix)
pull/2614/head
James Jackson-South
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
26 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/Issue2608_NegOffset.png
|
|
|
@ -87,12 +87,14 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg> |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -251,4 +251,25 @@ public class DrawImageTests |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,3 @@ |
|
|
|
version https://git-lfs.github.com/spec/v1 |
|
|
|
oid sha256:edfd0e17aa304f5b16ad42a761c044c3d617aaee9b9e1e74674567bbcd74d532 |
|
|
|
size 590 |