Browse Source

FillEllipticGradientBrushTests

af/merge-core
Anton Firszov 8 years ago
parent
commit
d939cfa78a
  1. 112
      tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs
  2. 31
      tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs
  3. 32
      tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs
  4. 8
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

112
tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
using (Image<TPixel> image = provider.GetImage())
{
EllipticGradientBrush<TPixel> unicolorLinearGradientBrush =
var unicolorLinearGradientBrush =
new EllipticGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(10, 0),
@ -35,17 +35,11 @@ namespace SixLabors.ImageSharp.Tests.Drawing
new ColorStop<TPixel>(1, red));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider);
using (PixelAccessor<TPixel> 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<TPixel>.Red;
TPixel black = NamedColors<TPixel>.Black;
using (var image = provider.GetImage())
{
EllipticGradientBrush<TPixel> unicolorLinearGradientBrush =
new EllipticGradientBrush<TPixel>(
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<TPixel>(0, yellow),
new ColorStop<TPixel>(1, red),
new ColorStop<TPixel>(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<TPixel>(
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<TPixel>(0, yellow),
new ColorStop<TPixel>(1, red),
new ColorStop<TPixel>(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<TPixel>
{
string variant = $"{ratio:F2}at{rotationInDegree:00}°";
using (var image = provider.GetImage())
{
TPixel yellow = NamedColors<TPixel>.Yellow;
TPixel red = NamedColors<TPixel>.Red;
TPixel black = NamedColors<TPixel>.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<TPixel> unicolorLinearGradientBrush =
new EllipticGradientBrush<TPixel>(
center,
new SixLabors.Primitives.Point(axisX, axisY),
ratio,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, yellow),
new ColorStop<TPixel>(1, red),
new ColorStop<TPixel>(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<TPixel>.Yellow;
TPixel red = NamedColors<TPixel>.Red;
TPixel black = NamedColors<TPixel>.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<TPixel>(
center,
new SixLabors.Primitives.Point(axisX, axisY),
ratio,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, yellow),
new ColorStop<TPixel>(1, red),
new ColorStop<TPixel>(1, black));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
},
variant,
false,
false);
}
}
}

31
tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs

@ -26,21 +26,24 @@ namespace SixLabors.ImageSharp.Tests.Drawing
public void WithEqualColorsReturnsUnicolorImage<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.VerifyOperation(
image =>
{
TPixel red = NamedColors<TPixel>.Red;
var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(10, 0),
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, red));
using (Image<TPixel> image = provider.GetImage())
{
TPixel red = NamedColors<TPixel>.Red;
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
},
false,
false);
var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(10, 0),
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(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]

32
tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs

@ -18,23 +18,25 @@ namespace SixLabors.ImageSharp.Tests.Drawing
TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.VerifyOperation(
image =>
{
TPixel red = NamedColors<TPixel>.Red;
using (Image<TPixel> image = provider.GetImage())
{
TPixel red = NamedColors<TPixel>.Red;
var unicolorRadialGradientBrush =
new RadialGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
100,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, red));
var unicolorRadialGradientBrush =
new RadialGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
100,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(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]

8
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -450,6 +450,9 @@ namespace SixLabors.ImageSharp.Tests
return image;
}
/// <summary>
/// All pixels in all frames should be exactly equal to 'expectedPixel'.
/// </summary>
public static Image<TPixel> ComparePixelBufferTo<TPixel>(this Image<TPixel> image, TPixel expectedPixel)
where TPixel : struct, IPixel<TPixel>
{
@ -461,6 +464,9 @@ namespace SixLabors.ImageSharp.Tests
return image;
}
/// <summary>
/// All pixels in the frame should be exactly equal to 'expectedPixel'.
/// </summary>
public static ImageFrame<TPixel> ComparePixelBufferTo<TPixel>(this ImageFrame<TPixel> imageFrame, TPixel expectedPixel)
where TPixel : struct, IPixel<TPixel>
{
@ -473,7 +479,7 @@ namespace SixLabors.ImageSharp.Tests
return imageFrame;
}
public static ImageFrame<TPixel> ComparePixelBufferTo<TPixel>(
this ImageFrame<TPixel> image,
Span<TPixel> expectedPixels)

Loading…
Cancel
Save