Browse Source

better TransformTests

pull/386/head
Anton Firszov 9 years ago
parent
commit
2890969a2d
  1. 82
      tests/ImageSharp.Tests/Processing/Transforms/TransformTests.cs

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

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
@ -14,50 +15,69 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
public class TransformTests : FileTestBase public class TransformTests : FileTestBase
{ {
public static readonly TheoryData<float, float, float> TransformValues public static readonly TheoryData<float, float, float, float, float> TransformValues
= new TheoryData<float, float, float> = new TheoryData<float, float, float, float, float>
{ {
{ 20, 10, 45 }, { 45, 1, 1, 20, 10 },
{ -20, -10, 45 } { 45, 1, 1, -20, -10 },
{ 45, 1.5f, 1.5f, 0, 0 },
{ 0, 2f, 1f, 0, 0 },
{ 0, 1f, 2f, 0, 0 },
}; };
public static readonly List<string> ResamplerNames public static readonly TheoryData<string> ResamplerNames =
= new List<string> new TheoryData<string>
{ {
nameof(KnownResamplers.Bicubic), nameof(KnownResamplers.Bicubic),
//nameof(KnownResamplers.Box), nameof(KnownResamplers.Box),
//nameof(KnownResamplers.CatmullRom), nameof(KnownResamplers.CatmullRom),
//nameof(KnownResamplers.Hermite), nameof(KnownResamplers.Hermite),
//nameof(KnownResamplers.Lanczos2), nameof(KnownResamplers.Lanczos2),
//nameof(KnownResamplers.Lanczos3), nameof(KnownResamplers.Lanczos3),
//nameof(KnownResamplers.Lanczos5), nameof(KnownResamplers.Lanczos5),
//nameof(KnownResamplers.Lanczos8), nameof(KnownResamplers.Lanczos8),
//nameof(KnownResamplers.MitchellNetravali), nameof(KnownResamplers.MitchellNetravali),
//nameof(KnownResamplers.NearestNeighbor), nameof(KnownResamplers.NearestNeighbor),
//nameof(KnownResamplers.Robidoux), nameof(KnownResamplers.Robidoux),
//nameof(KnownResamplers.RobidouxSharp), nameof(KnownResamplers.RobidouxSharp),
//nameof(KnownResamplers.Spline), nameof(KnownResamplers.Spline),
//nameof(KnownResamplers.Triangle), nameof(KnownResamplers.Triangle),
//nameof(KnownResamplers.Welch), nameof(KnownResamplers.Welch),
}; };
[Theory] [Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(TransformValues), DefaultPixelType)] [WithTestPatternImages(nameof(TransformValues), 100, 50, DefaultPixelType)]
public void ImageShouldTransformWithSampler<TPixel>(TestImageProvider<TPixel> provider, float x, float y, float z) public void Transform_RotateScaleTranslate<TPixel>(
TestImageProvider<TPixel> provider,
float angleDeg,
float sx, float sy,
float tx, float ty)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage())
{
Matrix3x2 rotate = Matrix3x2Extensions.CreateRotationDegrees(angleDeg);
Matrix3x2 translate = Matrix3x2Extensions.CreateTranslation(new PointF(tx, ty));
Matrix3x2 scale = Matrix3x2Extensions.CreateScale(new SizeF(sx, sy));
image.Mutate(i => i.Transform(rotate * scale * translate));
image.DebugSave(provider, $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})");
}
}
foreach (string resamplerName in ResamplerNames) [Theory]
[WithTestPatternImages(nameof(ResamplerNames), 100, 200, DefaultPixelType)]
public void Transform_WithSampler<TPixel>(TestImageProvider<TPixel> provider, string resamplerName)
where TPixel : struct, IPixel<TPixel>
{
IResampler sampler = GetResampler(resamplerName);
using (Image<TPixel> image = provider.GetImage())
{ {
IResampler sampler = GetResampler(resamplerName); Matrix3x2 rotate = Matrix3x2Extensions.CreateRotationDegrees(45);
using (Image<TPixel> image = provider.GetImage()) Matrix3x2 scale = Matrix3x2Extensions.CreateScale(new SizeF(.5F, .5F));
{
Matrix3x2 rotate = Matrix3x2Extensions.CreateRotationDegrees(z);
Matrix3x2 scale = Matrix3x2Extensions.CreateScale(new SizeF(.5F, .5F));
image.Mutate(i => i.Transform(rotate * scale, sampler)); image.Mutate(i => i.Transform(rotate * scale, sampler));
image.DebugSave(provider, string.Join("_", x, y, resamplerName)); image.DebugSave(provider, resamplerName);
}
} }
} }

Loading…
Cancel
Save