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()) using (Image<TPixel> image = provider.GetImage())
{ {
EllipticGradientBrush<TPixel> unicolorLinearGradientBrush = var unicolorLinearGradientBrush =
new EllipticGradientBrush<TPixel>( new EllipticGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(10, 0), new SixLabors.Primitives.Point(10, 0),
@ -35,17 +35,11 @@ namespace SixLabors.ImageSharp.Tests.Drawing
new ColorStop<TPixel>(1, red)); new ColorStop<TPixel>(1, red));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider);
using (PixelAccessor<TPixel> sourcePixels = image.Lock()) image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
{
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.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 red = NamedColors<TPixel>.Red;
TPixel black = NamedColors<TPixel>.Black; TPixel black = NamedColors<TPixel>.Black;
using (var image = provider.GetImage()) provider.VerifyOperation(
{ image =>
EllipticGradientBrush<TPixel> unicolorLinearGradientBrush = {
new EllipticGradientBrush<TPixel>( var unicolorLinearGradientBrush = new EllipticGradientBrush<TPixel>(
new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2), new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2),
new SixLabors.Primitives.Point(image.Width / 2, (image.Width * 2) / 3), new SixLabors.Primitives.Point(image.Width / 2, (image.Width * 2) / 3),
ratio, ratio,
GradientRepetitionMode.None, GradientRepetitionMode.None,
new ColorStop<TPixel>(0, yellow), new ColorStop<TPixel>(0, yellow),
new ColorStop<TPixel>(1, red), new ColorStop<TPixel>(1, red),
new ColorStop<TPixel>(1, black)); new ColorStop<TPixel>(1, black));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider, ratio.ToString("F1")); },
image.CompareToReferenceOutput(provider, ratio); $"{ratio:F2}",
} false,
false);
} }
[Theory] [Theory]
@ -110,38 +105,39 @@ namespace SixLabors.ImageSharp.Tests.Drawing
float rotationInDegree) float rotationInDegree)
where TPixel: struct, IPixel<TPixel> where TPixel: struct, IPixel<TPixel>
{ {
string variant = $"{ratio:F2}at{rotationInDegree:00}°"; FormattableString variant = $"{ratio:F2}_AT_{rotationInDegree:00}deg";
using (var image = provider.GetImage()) provider.VerifyOperation(
{ image =>
TPixel yellow = NamedColors<TPixel>.Yellow; {
TPixel red = NamedColors<TPixel>.Red; TPixel yellow = NamedColors<TPixel>.Yellow;
TPixel black = NamedColors<TPixel>.Black; TPixel red = NamedColors<TPixel>.Red;
TPixel black = NamedColors<TPixel>.Black;
var center = new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2);
var center = new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2);
var rotation = (Math.PI * rotationInDegree) / 180.0;
var cos = Math.Cos(rotation); double rotation = (Math.PI * rotationInDegree) / 180.0;
var sin = Math.Sin(rotation); double cos = Math.Cos(rotation);
double sin = Math.Sin(rotation);
int offsetY = image.Height / 6;
int axisX = center.X + (int)-(offsetY * sin); int offsetY = image.Height / 6;
int axisY = center.Y + (int)(offsetY * cos); int axisX = center.X + (int)-(offsetY * sin);
int axisY = center.Y + (int)(offsetY * cos);
EllipticGradientBrush<TPixel> unicolorLinearGradientBrush =
new EllipticGradientBrush<TPixel>( var unicolorLinearGradientBrush = new EllipticGradientBrush<TPixel>(
center, center,
new SixLabors.Primitives.Point(axisX, axisY), new SixLabors.Primitives.Point(axisX, axisY),
ratio, ratio,
GradientRepetitionMode.None, GradientRepetitionMode.None,
new ColorStop<TPixel>(0, yellow), new ColorStop<TPixel>(0, yellow),
new ColorStop<TPixel>(1, red), new ColorStop<TPixel>(1, red),
new ColorStop<TPixel>(1, black)); new ColorStop<TPixel>(1, black));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider, variant); },
image.CompareToReferenceOutput(provider, variant); 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) public void WithEqualColorsReturnsUnicolorImage<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.VerifyOperation( using (Image<TPixel> image = provider.GetImage())
image => {
{ TPixel red = NamedColors<TPixel>.Red;
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));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
}, new SixLabors.Primitives.Point(0, 0),
false, new SixLabors.Primitives.Point(10, 0),
false); 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] [Theory]

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

@ -18,23 +18,25 @@ namespace SixLabors.ImageSharp.Tests.Drawing
TestImageProvider<TPixel> provider) TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.VerifyOperation( using (Image<TPixel> image = provider.GetImage())
image => {
{ TPixel red = NamedColors<TPixel>.Red;
TPixel red = NamedColors<TPixel>.Red;
var unicolorRadialGradientBrush = var unicolorRadialGradientBrush =
new RadialGradientBrush<TPixel>( new RadialGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(0, 0),
100, 100,
GradientRepetitionMode.None, GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red), new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, red)); new ColorStop<TPixel>(1, red));
image.Mutate(x => x.Fill(unicolorRadialGradientBrush)); image.Mutate(x => x.Fill(unicolorRadialGradientBrush));
},
false, image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
false);
// no need for reference image in this test:
image.ComparePixelBufferTo(red);
}
} }
[Theory] [Theory]

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

@ -450,6 +450,9 @@ namespace SixLabors.ImageSharp.Tests
return image; 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) public static Image<TPixel> ComparePixelBufferTo<TPixel>(this Image<TPixel> image, TPixel expectedPixel)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
@ -461,6 +464,9 @@ namespace SixLabors.ImageSharp.Tests
return image; 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) public static ImageFrame<TPixel> ComparePixelBufferTo<TPixel>(this ImageFrame<TPixel> imageFrame, TPixel expectedPixel)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
@ -473,7 +479,7 @@ namespace SixLabors.ImageSharp.Tests
return imageFrame; return imageFrame;
} }
public static ImageFrame<TPixel> ComparePixelBufferTo<TPixel>( public static ImageFrame<TPixel> ComparePixelBufferTo<TPixel>(
this ImageFrame<TPixel> image, this ImageFrame<TPixel> image,
Span<TPixel> expectedPixels) Span<TPixel> expectedPixels)

Loading…
Cancel
Save