From 7cae3c1d1902f80fbca7a08a183267e52d04ab9d Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 21 Apr 2018 16:01:33 +0200 Subject: [PATCH] #542: add tests for multi-color gradients somehow these don't look correct yet, containing hard edges sometimes. --- .../Drawing/FillLinearGradientBrushTests.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs index 52979d792..9ba7f7e62 100644 --- a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs @@ -158,5 +158,60 @@ namespace SixLabors.ImageSharp.Tests.Drawing } } } + + [Theory] + [InlineData("a", 0, 0, 499, 499, new[] { 0f, .2f, .5f, .9f }, new[] { 0, 0, 1, 1 })] + [InlineData("b", 0, 499, 499, 0, new[] { 0f, 0.2f, 0.5f, 0.9f }, new[] { 0, 1, 2, 3 })] + [InlineData("c", 499, 499, 0, 0, new[] { 0f, 0.7f, 0.8f, 0.9f}, new[] { 0, 1, 2, 0 })] + [InlineData("d", 0, 0, 499, 499, new[] { 0f, .5f, 1f}, new[]{0, 1, 3})] + public void ArbitraryLinearGradientsProduceImages_VisualCheckOnly( + string filenameSuffix, + int startX, int startY, + int endX, int endY, + float[] stopPositions, + int[] stopColorCodes) + { + var colors = new Rgba32[] + { + Rgba32.Navy, + Rgba32.LightGreen, + Rgba32.Yellow, + Rgba32.Red + }; + + var colorStops = new LinearGradientBrush.ColorStop[stopPositions.Length]; + for (int i = 0; i < stopPositions.Length; i++) + { + colorStops[i] = new LinearGradientBrush.ColorStop( + stopPositions[i], + colors[stopColorCodes[i]]); + } + + + int size = 500; + int lastIndex = size - 1; + + + string path = TestEnvironment.CreateOutputDirectory("Fill", "LinearGradientBrush"); + using (var image = new Image(size, size)) + { + LinearGradientBrush unicolorLinearGradientBrush = + new LinearGradientBrush( + new SixLabors.Primitives.Point(startX, startY), + new SixLabors.Primitives.Point(endX, endY), + colorStops); + + image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); + image.Save($"{path}/arbitraryGradient_{filenameSuffix}.png"); + + using (PixelAccessor sourcePixels = image.Lock()) + { + for (int i = 0; i < size; i++) + { + // it's diagonal, so for any (a, a) on the gradient line, for all (a-x, b+x) - +/- depending on the diagonal direction - must be the same color) + } + } + } + } } } \ No newline at end of file