Browse Source

more/better TransformTests

af/merge-core
Anton Firszov 8 years ago
parent
commit
201e4f43bd
  1. 43
      tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs

43
tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs

@ -10,6 +10,8 @@ using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Helpers;
public class TransformTests public class TransformTests
{ {
private readonly ITestOutputHelper Output; private readonly ITestOutputHelper Output;
@ -17,7 +19,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
public static readonly TheoryData<float, float, float, float, float> TransformValues public static readonly TheoryData<float, float, float, float, float> TransformValues
= new TheoryData<float, float, float, float, float> = new TheoryData<float, float, float, float, float>
{ {
{ 0, 1, 1, 0, 0 },
{ 50, 1, 1, 0, 0 },
{ 0, 1, 1, 20, 10 },
{ 50, 1, 1, 20, 10 }, { 50, 1, 1, 20, 10 },
{ 0, 1, 1, -20, -10 },
{ 50, 1, 1, -20, -10 }, { 50, 1, 1, -20, -10 },
{ 50, 1.5f, 1.5f, 0, 0 }, { 50, 1.5f, 1.5f, 0, 0 },
{ 0, 2f, 1f, 0, 0 }, { 0, 2f, 1f, 0, 0 },
@ -75,7 +81,30 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
[Theory] [Theory]
[WithTestPatternImages(nameof(TransformValues), 100, 50, PixelTypes.Rgba32)] [WithTestPatternImages(nameof(TransformValues), 100, 50, PixelTypes.Rgba32)]
public void Transform_RotateScaleTranslate<TPixel>( public void Transform_RotateScaleTranslate_AutoDestRectangle<TPixel>(
TestImageProvider<TPixel> provider,
float angleDeg,
float sx, float sy,
float tx, float ty)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
Matrix3x2 rotate = Matrix3x2Extensions.CreateRotationDegrees(angleDeg);
var translate = Matrix3x2.CreateTranslation(tx, ty);
var scale = Matrix3x2.CreateScale(sx, sy);
Matrix3x2 m = rotate * scale * translate;
this.PrintMatrix(m);
image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic));
image.DebugSave(provider, $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})");
}
}
[Theory]
[WithTestPatternImages(nameof(TransformValues), 100, 50, PixelTypes.Rgba32)]
public void Transform_RotateScaleTranslate_SameDestRectangle<TPixel>(
TestImageProvider<TPixel> provider, TestImageProvider<TPixel> provider,
float angleDeg, float angleDeg,
float sx, float sy, float sx, float sy,
@ -89,13 +118,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
var scale = Matrix3x2.CreateScale(sx, sy); var scale = Matrix3x2.CreateScale(sx, sy);
Matrix3x2 m = rotate * scale * translate; Matrix3x2 m = rotate * scale * translate;
this.Output.WriteLine(m.ToString()); this.PrintMatrix(m);
image.Mutate(i => i.Transform(m)); Rectangle destBounds = image.Bounds();
image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic, destBounds));
image.DebugSave(provider, $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})"); image.DebugSave(provider, $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})");
} }
} }
[Theory] [Theory]
[WithTestPatternImages(nameof(ResamplerNames), 100, 200, PixelTypes.Rgba32)] [WithTestPatternImages(nameof(ResamplerNames), 100, 200, PixelTypes.Rgba32)]
public void Transform_WithSampler<TPixel>(TestImageProvider<TPixel> provider, string resamplerName) public void Transform_WithSampler<TPixel>(TestImageProvider<TPixel> provider, string resamplerName)
@ -141,5 +172,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
Assert.Equal(white, rgba.Rgb); Assert.Equal(white, rgba.Rgb);
} }
} }
private void PrintMatrix(Matrix3x2 a)
{
string s = $"{a.M11:F10},{a.M12:F10},{a.M21:F10},{a.M22:F10},{a.M31:F10},{a.M32:F10}";
this.Output.WriteLine(s);
}
} }
} }
Loading…
Cancel
Save