diff --git a/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs b/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs index 7cf7775ce6..5801e7276e 100644 --- a/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs +++ b/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (Image image = provider.GetImage()) { - EllipticGradientBrush unicolorLinearGradientBrush = + var unicolorLinearGradientBrush = new EllipticGradientBrush( new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(10, 0), @@ -35,17 +35,11 @@ namespace SixLabors.ImageSharp.Tests.Drawing new ColorStop(1, red)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); - image.DebugSave(provider); - using (PixelAccessor sourcePixels = image.Lock()) - { - Assert.Equal(red, sourcePixels[0, 0]); - Assert.Equal(red, sourcePixels[9, 9]); - Assert.Equal(red, sourcePixels[5, 5]); - Assert.Equal(red, sourcePixels[3, 8]); - } + image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); - image.CompareToReferenceOutput(provider); + // no need for reference image in this test: + image.ComparePixelBufferTo(red); } } @@ -66,22 +60,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing TPixel red = NamedColors.Red; TPixel black = NamedColors.Black; - using (var image = provider.GetImage()) - { - EllipticGradientBrush unicolorLinearGradientBrush = - new EllipticGradientBrush( - new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2), - new SixLabors.Primitives.Point(image.Width / 2, (image.Width * 2) / 3), - ratio, - GradientRepetitionMode.None, - new ColorStop(0, yellow), - new ColorStop(1, red), - new ColorStop(1, black)); - - image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); - image.DebugSave(provider, ratio.ToString("F1")); - image.CompareToReferenceOutput(provider, ratio); - } + provider.VerifyOperation( + image => + { + var unicolorLinearGradientBrush = new EllipticGradientBrush( + new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2), + new SixLabors.Primitives.Point(image.Width / 2, (image.Width * 2) / 3), + ratio, + GradientRepetitionMode.None, + new ColorStop(0, yellow), + new ColorStop(1, red), + new ColorStop(1, black)); + + image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); + }, + $"{ratio:F2}", + false, + false); } [Theory] @@ -110,38 +105,39 @@ namespace SixLabors.ImageSharp.Tests.Drawing float rotationInDegree) where TPixel: struct, IPixel { - string variant = $"{ratio:F2}at{rotationInDegree:00}°"; - - using (var image = provider.GetImage()) - { - TPixel yellow = NamedColors.Yellow; - TPixel red = NamedColors.Red; - TPixel black = NamedColors.Black; - - var center = new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2); - - var rotation = (Math.PI * rotationInDegree) / 180.0; - var cos = Math.Cos(rotation); - var sin = Math.Sin(rotation); - - int offsetY = image.Height / 6; - int axisX = center.X + (int)-(offsetY * sin); - int axisY = center.Y + (int)(offsetY * cos); - - EllipticGradientBrush unicolorLinearGradientBrush = - new EllipticGradientBrush( - center, - new SixLabors.Primitives.Point(axisX, axisY), - ratio, - GradientRepetitionMode.None, - new ColorStop(0, yellow), - new ColorStop(1, red), - new ColorStop(1, black)); - - image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); - image.DebugSave(provider, variant); - image.CompareToReferenceOutput(provider, variant); - } + FormattableString variant = $"{ratio:F2}_AT_{rotationInDegree:00}deg"; + + provider.VerifyOperation( + image => + { + TPixel yellow = NamedColors.Yellow; + TPixel red = NamedColors.Red; + TPixel black = NamedColors.Black; + + var center = new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2); + + double rotation = (Math.PI * rotationInDegree) / 180.0; + double cos = Math.Cos(rotation); + double sin = Math.Sin(rotation); + + int offsetY = image.Height / 6; + int axisX = center.X + (int)-(offsetY * sin); + int axisY = center.Y + (int)(offsetY * cos); + + var unicolorLinearGradientBrush = new EllipticGradientBrush( + center, + new SixLabors.Primitives.Point(axisX, axisY), + ratio, + GradientRepetitionMode.None, + new ColorStop(0, yellow), + new ColorStop(1, red), + new ColorStop(1, black)); + + image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); + }, + variant, + false, + false); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs index 955209f9c8..a9f08eb44f 100644 --- a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs @@ -26,21 +26,24 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void WithEqualColorsReturnsUnicolorImage(TestImageProvider provider) where TPixel : struct, IPixel { - provider.VerifyOperation( - image => - { - TPixel red = NamedColors.Red; - var unicolorLinearGradientBrush = new LinearGradientBrush( - new SixLabors.Primitives.Point(0, 0), - new SixLabors.Primitives.Point(10, 0), - GradientRepetitionMode.None, - new ColorStop(0, red), - new ColorStop(1, red)); + using (Image image = provider.GetImage()) + { + TPixel red = NamedColors.Red; - image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); - }, - false, - false); + var unicolorLinearGradientBrush = new LinearGradientBrush( + new SixLabors.Primitives.Point(0, 0), + new SixLabors.Primitives.Point(10, 0), + GradientRepetitionMode.None, + new ColorStop(0, red), + new ColorStop(1, red)); + + image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); + + image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); + + // no need for reference image in this test: + image.ComparePixelBufferTo(red); + } } [Theory] diff --git a/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs index b365156e09..98004326ed 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs @@ -18,23 +18,25 @@ namespace SixLabors.ImageSharp.Tests.Drawing TestImageProvider provider) where TPixel : struct, IPixel { - provider.VerifyOperation( - image => - { - TPixel red = NamedColors.Red; + using (Image image = provider.GetImage()) + { + TPixel red = NamedColors.Red; - var unicolorRadialGradientBrush = - new RadialGradientBrush( - new SixLabors.Primitives.Point(0, 0), - 100, - GradientRepetitionMode.None, - new ColorStop(0, red), - new ColorStop(1, red)); + var unicolorRadialGradientBrush = + new RadialGradientBrush( + new SixLabors.Primitives.Point(0, 0), + 100, + GradientRepetitionMode.None, + new ColorStop(0, red), + new ColorStop(1, red)); - image.Mutate(x => x.Fill(unicolorRadialGradientBrush)); - }, - false, - false); + image.Mutate(x => x.Fill(unicolorRadialGradientBrush)); + + image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); + + // no need for reference image in this test: + image.ComparePixelBufferTo(red); + } } [Theory] diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index c811b02418..f4c7869e25 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -450,6 +450,9 @@ namespace SixLabors.ImageSharp.Tests return image; } + /// + /// All pixels in all frames should be exactly equal to 'expectedPixel'. + /// public static Image ComparePixelBufferTo(this Image image, TPixel expectedPixel) where TPixel : struct, IPixel { @@ -461,6 +464,9 @@ namespace SixLabors.ImageSharp.Tests return image; } + /// + /// All pixels in the frame should be exactly equal to 'expectedPixel'. + /// public static ImageFrame ComparePixelBufferTo(this ImageFrame imageFrame, TPixel expectedPixel) where TPixel : struct, IPixel { @@ -473,7 +479,7 @@ namespace SixLabors.ImageSharp.Tests return imageFrame; } - + public static ImageFrame ComparePixelBufferTo( this ImageFrame image, Span expectedPixels)