From 8f8a6a72d16621263bccfe5d51c26595115e6471 Mon Sep 17 00:00:00 2001 From: Jason Heard Date: Sat, 10 Aug 2019 12:15:34 -0600 Subject: [PATCH 1/3] Add test illustrating issue --- .../Drawing/FillRegionProcessorTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index c23ec98745..5320a58a69 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -12,6 +12,7 @@ using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; using Xunit; using SixLabors.ImageSharp.Processing.Processors.Drawing; +using SixLabors.Shapes; namespace SixLabors.ImageSharp.Tests.Drawing { @@ -68,6 +69,24 @@ namespace SixLabors.ImageSharp.Tests.Drawing } } + [Fact] + public void DoesNotThrowFillingTriangle() + { + using(var image = new Image(28, 28)) + { + var path = new Polygon( + new LinearLineSegment(new PointF(17.11f, 13.99659f), new PointF(14.01433f, 27.06201f)), + new LinearLineSegment(new PointF(14.01433f, 27.06201f), new PointF(13.79267f, 14.00023f)), + new LinearLineSegment(new PointF(13.79267f, 14.00023f), new PointF(17.11f, 13.99659f)) + ); + + image.Mutate(ctx => + { + ctx.Fill(Rgba32.White, path); + }); + } + } + // Mocking the region throws an error in netcore2.0 private class MockRegion1 : Region { From 4f65fd1d1e5f3e0105b9054733f76f2af5c39b68 Mon Sep 17 00:00:00 2001 From: Jason Heard Date: Sat, 10 Aug 2019 12:15:58 -0600 Subject: [PATCH 2/3] Add test from issue #928 --- .../Drawing/FillRegionProcessorTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 5320a58a69..972f5cf4a1 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -69,6 +69,32 @@ namespace SixLabors.ImageSharp.Tests.Drawing } } + [Fact] + public void DoesNotThrowForIssue928() + { + var rectText = new RectangleF(0, 0, 2000, 2000); + using (Image img = new Image((int)rectText.Width, (int)rectText.Height)) + { + img.Mutate(x => x.Fill(Rgba32.Transparent)); + + img.Mutate(ctx => { + ctx.DrawLines( + Rgba32.Red, + 0.984252f, + new PointF(104.762581f, 1074.99365f), + new PointF(104.758667f, 1075.01721f), + new PointF(104.757675f, 1075.04114f), + new PointF(104.759628f, 1075.065f), + new PointF(104.764488f, 1075.08838f), + new PointF(104.772186f, 1075.111f), + new PointF(104.782608f, 1075.13245f), + new PointF(104.782608f, 1075.13245f) + ); + } + ); + } + } + [Fact] public void DoesNotThrowFillingTriangle() { From ba07fc22bafb3909a4387300b3f44e88b129f0d7 Mon Sep 17 00:00:00 2001 From: Jason Heard Date: Sat, 10 Aug 2019 12:16:12 -0600 Subject: [PATCH 3/3] Add possible fix --- .../Processors/Drawing/FillRegionProcessor{TPixel}.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs index d5778c865f..f3196a8e89 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing QuickSort.Sort(buffer.Slice(0, pointsFound)); - for (int point = 0; point < pointsFound; point += 2) + for (int point = 0; point < pointsFound && point < buffer.Length - 1; point += 2) { // points will be paired up float scanStart = buffer[point] - minX;