SixLabors / ImageSharp.Drawing

:pen: Extensions to ImageSharp containing a cross-platform 2D polygon manipulation API and drawing operations.
https://sixlabors.com/products/imagesharp-drawing/
Other
285 stars 38 forks source link

ImageBrush incorrectly offset when target region (Path or Rectangle) has a negative offset. #308

Closed tocsoft closed 11 months ago

tocsoft commented 11 months ago

Prerequisites

Description

When applying a ImageBrush to a region that overlaps a negative postion the texture start drawing at the backound image edge rather than being offset.

[Theory]
[WithTestPatternImage(400, 400, PixelTypes.Rgba32)]
public void CanOffsetImage<TPixel>(TestImageProvider<TPixel> provider)
    where TPixel : unmanaged, IPixel<TPixel>
{
    byte[] data = TestFile.Create(TestImages.Png.Ducky).Bytes;
    using Image<TPixel> background = provider.GetImage();
    using Image overlay = Image.Load<Rgba32>(data);

    var brush = new ImageBrush(overlay);
    background.Mutate(c => c.Fill(brush, new RectangularPolygon(0, 0, 400, 200)));
    background.Mutate(c => c.Fill(brush, new RectangularPolygon(-100, 200, 500, 200)));

    background.DebugSave(provider, appendSourceFileOrDescription: false);
    background.CompareToReferenceOutput(provider, appendSourceFileOrDescription: false);
}

Currently produces

CanOffsetImage_Rgba32

Should produce

CanOffsetImage_Rgba32

this only effects negative offsets as postive ones work correctly

var brush = new ImageBrush(overlay);
background.Mutate(c => c.Fill(brush, new RectangularPolygon(0, 0, 400, 200)));
background.Mutate(c => c.Fill(brush, new RectangularPolygon(150, 200, 500, 200)));

CanOffsetImage_Rgba32