|
12 | 12 |
|
13 | 13 | namespace SixLabors.ImageSharp.Tests.Drawing |
14 | 14 | { |
| 15 | + [GroupOutput("Drawing/GradientBrushes")] |
15 | 16 | public class FillEllipticGradientBrushTests : FileTestBase |
16 | 17 | { |
17 | | - [Fact] |
18 | | - public void EllipticGradientBrushWithEqualColorsAndReturnsUnicolorImage() |
| 18 | + [Theory] |
| 19 | + [WithBlankImages(10, 10, PixelTypes.Rgba32)] |
| 20 | + public void EllipticGradientBrushWithEqualColorsAndReturnsUnicolorImage<TPixel>( |
| 21 | + TestImageProvider<TPixel> provider) |
| 22 | + where TPixel : struct, IPixel<TPixel> |
19 | 23 | { |
20 | | - string path = TestEnvironment.CreateOutputDirectory("Fill", "EllipticGradientBrush"); |
21 | | - using (var image = new Image<Rgba32>(10, 10)) |
| 24 | + TPixel red = NamedColors<TPixel>.Red; |
| 25 | + |
| 26 | + using (Image<TPixel> image = provider.GetImage()) |
22 | 27 | { |
23 | | - EllipticGradientBrush<Rgba32> unicolorLinearGradientBrush = |
24 | | - new EllipticGradientBrush<Rgba32>( |
| 28 | + EllipticGradientBrush<TPixel> unicolorLinearGradientBrush = |
| 29 | + new EllipticGradientBrush<TPixel>( |
25 | 30 | new SixLabors.Primitives.Point(0, 0), |
26 | 31 | new SixLabors.Primitives.Point(10, 0), |
27 | 32 | 1.0f, |
28 | 33 | GradientRepetitionMode.None, |
29 | | - new ColorStop<Rgba32>(0, Rgba32.Red), |
30 | | - new ColorStop<Rgba32>(1, Rgba32.Red)); |
| 34 | + new ColorStop<TPixel>(0, red), |
| 35 | + new ColorStop<TPixel>(1, red)); |
31 | 36 |
|
32 | 37 | image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); |
33 | | - image.Save($"{path}/UnicolorCircleGradient.png"); |
| 38 | + image.DebugSave(provider); |
34 | 39 |
|
35 | | - using (PixelAccessor<Rgba32> sourcePixels = image.Lock()) |
| 40 | + using (PixelAccessor<TPixel> sourcePixels = image.Lock()) |
36 | 41 | { |
37 | | - Assert.Equal(Rgba32.Red, sourcePixels[0, 0]); |
38 | | - Assert.Equal(Rgba32.Red, sourcePixels[9, 9]); |
39 | | - Assert.Equal(Rgba32.Red, sourcePixels[5, 5]); |
40 | | - Assert.Equal(Rgba32.Red, sourcePixels[3, 8]); |
| 42 | + Assert.Equal(red, sourcePixels[0, 0]); |
| 43 | + Assert.Equal(red, sourcePixels[9, 9]); |
| 44 | + Assert.Equal(red, sourcePixels[5, 5]); |
| 45 | + Assert.Equal(red, sourcePixels[3, 8]); |
41 | 46 | } |
| 47 | + |
| 48 | + image.CompareToReferenceOutput(provider); |
42 | 49 | } |
43 | 50 | } |
44 | 51 |
|
45 | 52 | [Theory] |
46 | | - [InlineData(0.1)] |
47 | | - [InlineData(0.4)] |
48 | | - [InlineData(0.8)] |
49 | | - [InlineData(1.0)] |
50 | | - [InlineData(1.2)] |
51 | | - [InlineData(1.6)] |
52 | | - [InlineData(2.0)] |
53 | | - public void EllipticGradientBrushProducesAxisParallelEllipsesWithDifferentRatio( |
| 53 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.1)] |
| 54 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.4)] |
| 55 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.8)] |
| 56 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 1.0)] |
| 57 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 1.2)] |
| 58 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 1.6)] |
| 59 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 2.0)] |
| 60 | + public void EllipticGradientBrushProducesAxisParallelEllipsesWithDifferentRatio<TPixel>( |
| 61 | + TestImageProvider<TPixel> provider, |
54 | 62 | float ratio) |
| 63 | + where TPixel : struct, IPixel<TPixel> |
55 | 64 | { |
56 | | - string path = TestEnvironment.CreateOutputDirectory("Fill", "EllipticGradientBrush"); |
57 | | - using (var image = new Image<Rgba32>(1000, 1000)) |
| 65 | + TPixel yellow = NamedColors<TPixel>.Yellow; |
| 66 | + TPixel red = NamedColors<TPixel>.Red; |
| 67 | + TPixel black = NamedColors<TPixel>.Black; |
| 68 | + |
| 69 | + using (var image = provider.GetImage()) |
58 | 70 | { |
59 | | - EllipticGradientBrush<Rgba32> unicolorLinearGradientBrush = |
60 | | - new EllipticGradientBrush<Rgba32>( |
61 | | - new SixLabors.Primitives.Point(500, 500), |
62 | | - new SixLabors.Primitives.Point(500, 750), |
| 71 | + EllipticGradientBrush<TPixel> unicolorLinearGradientBrush = |
| 72 | + new EllipticGradientBrush<TPixel>( |
| 73 | + new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2), |
| 74 | + new SixLabors.Primitives.Point(image.Width / 2, (image.Width * 3) / 2), |
63 | 75 | ratio, |
64 | 76 | GradientRepetitionMode.None, |
65 | | - new ColorStop<Rgba32>(0, Rgba32.Yellow), |
66 | | - new ColorStop<Rgba32>(1, Rgba32.Red), |
67 | | - new ColorStop<Rgba32>(1, Rgba32.Black)); |
| 77 | + new ColorStop<TPixel>(0, yellow), |
| 78 | + new ColorStop<TPixel>(1, red), |
| 79 | + new ColorStop<TPixel>(1, black)); |
68 | 80 |
|
69 | 81 | image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); |
70 | | - image.Save($"{path}/Ellipsis{ratio}.png"); |
| 82 | + image.DebugSave(provider, ratio); |
| 83 | + image.CompareToReferenceOutput(provider, ratio); |
71 | 84 | } |
72 | 85 | } |
73 | 86 |
|
74 | 87 | [Theory] |
75 | | - [InlineData(0.1, 0)] |
76 | | - [InlineData(0.4, 0)] |
77 | | - [InlineData(0.8, 0)] |
78 | | - [InlineData(1.0, 0)] |
79 | | - |
80 | | - [InlineData(0.1, 45)] |
81 | | - [InlineData(0.4, 45)] |
82 | | - [InlineData(0.8, 45)] |
83 | | - [InlineData(1.0, 45)] |
84 | | - |
85 | | - [InlineData(0.1, 90)] |
86 | | - [InlineData(0.4, 90)] |
87 | | - [InlineData(0.8, 90)] |
88 | | - [InlineData(1.0, 90)] |
89 | | - |
90 | | - [InlineData(0.1, 30)] |
91 | | - [InlineData(0.4, 30)] |
92 | | - [InlineData(0.8, 30)] |
93 | | - [InlineData(1.0, 30)] |
94 | | - public void EllipticGradientBrushProducesRotatedEllipsesWithDifferentRatio( |
| 88 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.1, 0)] |
| 89 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.4, 0)] |
| 90 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.8, 0)] |
| 91 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 1.0, 0)] |
| 92 | + |
| 93 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.1, 45)] |
| 94 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.4, 45)] |
| 95 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.8, 45)] |
| 96 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 1.0, 45)] |
| 97 | + |
| 98 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.1, 90)] |
| 99 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.4, 90)] |
| 100 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.8, 90)] |
| 101 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 1.0, 90)] |
| 102 | + |
| 103 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.1, 30)] |
| 104 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.4, 30)] |
| 105 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 0.8, 30)] |
| 106 | + [WithBlankImages(1000, 1000, PixelTypes.Rgba32, 1.0, 30)] |
| 107 | + public void EllipticGradientBrushProducesRotatedEllipsesWithDifferentRatio<TPixel>( |
| 108 | + TestImageProvider<TPixel> provider, |
95 | 109 | float ratio, |
96 | 110 | float rotationInDegree) |
| 111 | + where TPixel: struct, IPixel<TPixel> |
97 | 112 | { |
98 | | - var center = new SixLabors.Primitives.Point(500, 500); |
| 113 | + string variant = $"{ratio}at{rotationInDegree}°"; |
| 114 | + |
| 115 | + using (var image = provider.GetImage()) |
| 116 | + { |
| 117 | + TPixel yellow = NamedColors<TPixel>.Yellow; |
| 118 | + TPixel red = NamedColors<TPixel>.Red; |
| 119 | + TPixel black = NamedColors<TPixel>.Black; |
99 | 120 |
|
100 | | - var rotation = (Math.PI * rotationInDegree) / 180.0; |
101 | | - var cos = Math.Cos(rotation); |
102 | | - var sin = Math.Sin(rotation); |
| 121 | + var center = new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2); |
103 | 122 |
|
104 | | - int axisX = (int)((center.X * cos) - (center.Y * sin)); |
105 | | - int axisY = (int)((center.X * sin) + (center.Y * cos)); |
| 123 | + var rotation = (Math.PI * rotationInDegree) / 180.0; |
| 124 | + var cos = Math.Cos(rotation); |
| 125 | + var sin = Math.Sin(rotation); |
106 | 126 |
|
107 | | - string path = TestEnvironment.CreateOutputDirectory("Fill", "EllipticGradientBrush"); |
108 | | - using (var image = new Image<Rgba32>(1000, 1000)) |
109 | | - { |
110 | | - EllipticGradientBrush<Rgba32> unicolorLinearGradientBrush = |
111 | | - new EllipticGradientBrush<Rgba32>( |
| 127 | + int axisX = (int)((center.X * cos) - (center.Y * sin)); |
| 128 | + int axisY = (int)((center.X * sin) + (center.Y * cos)); |
| 129 | + |
| 130 | + |
| 131 | + EllipticGradientBrush<TPixel> unicolorLinearGradientBrush = |
| 132 | + new EllipticGradientBrush<TPixel>( |
112 | 133 | center, |
113 | 134 | new SixLabors.Primitives.Point(axisX, axisY), |
114 | 135 | ratio, |
115 | 136 | GradientRepetitionMode.None, |
116 | | - new ColorStop<Rgba32>(0, Rgba32.Yellow), |
117 | | - new ColorStop<Rgba32>(1, Rgba32.Red), |
118 | | - new ColorStop<Rgba32>(1, Rgba32.Black)); |
| 137 | + new ColorStop<TPixel>(0, yellow), |
| 138 | + new ColorStop<TPixel>(1, red), |
| 139 | + new ColorStop<TPixel>(1, black)); |
119 | 140 |
|
120 | 141 | image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); |
121 | | - image.Save($"{path}/Ellipsis{ratio}_rot{rotationInDegree}°.png"); |
| 142 | + image.DebugSave(provider, variant); |
| 143 | + image.CompareToReferenceOutput(provider, variant); |
122 | 144 | } |
123 | 145 | } |
124 | 146 | } |
|
0 commit comments