|
|
|
@ -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<Rgba32>.ColorStop[stopPositions.Length]; |
|
|
|
for (int i = 0; i < stopPositions.Length; i++) |
|
|
|
{ |
|
|
|
colorStops[i] = new LinearGradientBrush<Rgba32>.ColorStop( |
|
|
|
stopPositions[i], |
|
|
|
colors[stopColorCodes[i]]); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int size = 500; |
|
|
|
int lastIndex = size - 1; |
|
|
|
|
|
|
|
|
|
|
|
string path = TestEnvironment.CreateOutputDirectory("Fill", "LinearGradientBrush"); |
|
|
|
using (var image = new Image<Rgba32>(size, size)) |
|
|
|
{ |
|
|
|
LinearGradientBrush<Rgba32> unicolorLinearGradientBrush = |
|
|
|
new LinearGradientBrush<Rgba32>( |
|
|
|
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<Rgba32> 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)
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |