|
1 | 1 | // Copyright (c) Six Labors and contributors. |
2 | 2 | // Licensed under the Apache License, Version 2.0. |
3 | 3 |
|
4 | | -using System; |
5 | | - |
| 4 | +using System.Linq; |
6 | 5 | using SixLabors.ImageSharp.Processing; |
7 | 6 | using SixLabors.ImageSharp.Processing.Drawing.Brushes; |
8 | 7 |
|
@@ -81,6 +80,54 @@ public void HorizontalLinearGradientBrushReturnsUnicolorColumns() |
81 | 80 | } |
82 | 81 | } |
83 | 82 |
|
| 83 | + [Theory] |
| 84 | + [InlineData(new[] { 0.5f })] |
| 85 | + [InlineData(new[] { 0.2f, 0.4f, 0.6f, 0.8f })] |
| 86 | + [InlineData(new[] { 0.1f, 0.3f, 0.6f })] |
| 87 | + public void LinearGradientsWithDoubledStopsProduceDashedPatterns( |
| 88 | + float[] pattern) |
| 89 | + { |
| 90 | + int width = 20; |
| 91 | + int height = 10; |
| 92 | + |
| 93 | + // ensure the input data is valid |
| 94 | + Assert.True(pattern.Length > 0); |
| 95 | + |
| 96 | + // create the input pattern: 0, followed by each of the arguments twice, followed by 1.0 - toggling black and white. |
| 97 | + LinearGradientBrush<Rgba32>.ColorStop[] colorStops = |
| 98 | + Enumerable.Repeat(new LinearGradientBrush<Rgba32>.ColorStop(0, Rgba32.Black), 1) |
| 99 | + .Concat( |
| 100 | + pattern |
| 101 | + .SelectMany((f, index) => new[] |
| 102 | + { |
| 103 | + new LinearGradientBrush<Rgba32>.ColorStop(f, index % 2 == 0 ? Rgba32.Black : Rgba32.White), |
| 104 | + new LinearGradientBrush<Rgba32>.ColorStop(f, index % 2 == 0 ? Rgba32.White : Rgba32.Black) |
| 105 | + })) |
| 106 | + .Concat(Enumerable.Repeat(new LinearGradientBrush<Rgba32>.ColorStop(1, pattern.Length % 2 == 0 ? Rgba32.Black : Rgba32.White), 1)) |
| 107 | + .ToArray(); |
| 108 | + |
| 109 | + string path = TestEnvironment.CreateOutputDirectory("Fill", "LinearGradientBrush"); |
| 110 | + using (var image = new Image<Rgba32>(width, height)) |
| 111 | + { |
| 112 | + LinearGradientBrush<Rgba32> unicolorLinearGradientBrush = |
| 113 | + new LinearGradientBrush<Rgba32>( |
| 114 | + new SixLabors.Primitives.Point(0, 0), |
| 115 | + new SixLabors.Primitives.Point(width, 0), |
| 116 | + colorStops); |
| 117 | + |
| 118 | + image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); |
| 119 | + image.Save($"{path}/blackAndWhite{pattern[0]}.png"); |
| 120 | + |
| 121 | + using (PixelAccessor<Rgba32> sourcePixels = image.Lock()) |
| 122 | + { |
| 123 | + // the result must be a black and white pattern, no other color should occur: |
| 124 | + Assert.All( |
| 125 | + Enumerable.Range(0, width).Select(i => sourcePixels[i, 0]), |
| 126 | + color => Assert.True(color == Rgba32.Black || color == Rgba32.White)); |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + |
84 | 131 | [Fact] |
85 | 132 | public void VerticalLinearGradientBrushReturnsUnicolorColumns() |
86 | 133 | { |
@@ -131,7 +178,6 @@ public void DiagonalLinearGradientBrushReturnsUnicolorColumns( |
131 | 178 | int startX, int startY, int endX, int endY) |
132 | 179 | { |
133 | 180 | int size = 500; |
134 | | - int lastIndex = size - 1; |
135 | 181 |
|
136 | 182 | string path = TestEnvironment.CreateOutputDirectory("Fill", "LinearGradientBrush"); |
137 | 183 | using (var image = new Image<Rgba32>(size, size)) |
|
0 commit comments