|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Tests.Processing.Transforms |
|
|
|
{ |
|
|
|
@ -14,50 +15,69 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms |
|
|
|
|
|
|
|
public class TransformTests : FileTestBase |
|
|
|
{ |
|
|
|
public static readonly TheoryData<float, float, float> TransformValues |
|
|
|
= new TheoryData<float, float, float> |
|
|
|
public static readonly TheoryData<float, float, float, float, float> TransformValues |
|
|
|
= new TheoryData<float, float, float, float, float> |
|
|
|
{ |
|
|
|
{ 20, 10, 45 }, |
|
|
|
{ -20, -10, 45 } |
|
|
|
{ 45, 1, 1, 20, 10 }, |
|
|
|
{ 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 |
|
|
|
= new List<string> |
|
|
|
public static readonly TheoryData<string> ResamplerNames = |
|
|
|
new TheoryData<string> |
|
|
|
{ |
|
|
|
nameof(KnownResamplers.Bicubic), |
|
|
|
//nameof(KnownResamplers.Box),
|
|
|
|
//nameof(KnownResamplers.CatmullRom),
|
|
|
|
//nameof(KnownResamplers.Hermite),
|
|
|
|
//nameof(KnownResamplers.Lanczos2),
|
|
|
|
//nameof(KnownResamplers.Lanczos3),
|
|
|
|
//nameof(KnownResamplers.Lanczos5),
|
|
|
|
//nameof(KnownResamplers.Lanczos8),
|
|
|
|
//nameof(KnownResamplers.MitchellNetravali),
|
|
|
|
//nameof(KnownResamplers.NearestNeighbor),
|
|
|
|
//nameof(KnownResamplers.Robidoux),
|
|
|
|
//nameof(KnownResamplers.RobidouxSharp),
|
|
|
|
//nameof(KnownResamplers.Spline),
|
|
|
|
//nameof(KnownResamplers.Triangle),
|
|
|
|
//nameof(KnownResamplers.Welch),
|
|
|
|
nameof(KnownResamplers.Box), |
|
|
|
nameof(KnownResamplers.CatmullRom), |
|
|
|
nameof(KnownResamplers.Hermite), |
|
|
|
nameof(KnownResamplers.Lanczos2), |
|
|
|
nameof(KnownResamplers.Lanczos3), |
|
|
|
nameof(KnownResamplers.Lanczos5), |
|
|
|
nameof(KnownResamplers.Lanczos8), |
|
|
|
nameof(KnownResamplers.MitchellNetravali), |
|
|
|
nameof(KnownResamplers.NearestNeighbor), |
|
|
|
nameof(KnownResamplers.Robidoux), |
|
|
|
nameof(KnownResamplers.RobidouxSharp), |
|
|
|
nameof(KnownResamplers.Spline), |
|
|
|
nameof(KnownResamplers.Triangle), |
|
|
|
nameof(KnownResamplers.Welch), |
|
|
|
}; |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFileCollection(nameof(DefaultFiles), nameof(TransformValues), DefaultPixelType)] |
|
|
|
public void ImageShouldTransformWithSampler<TPixel>(TestImageProvider<TPixel> provider, float x, float y, float z) |
|
|
|
[WithTestPatternImages(nameof(TransformValues), 100, 50, DefaultPixelType)] |
|
|
|
public void Transform_RotateScaleTranslate<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); |
|
|
|
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); |
|
|
|
using (Image<TPixel> image = provider.GetImage()) |
|
|
|
{ |
|
|
|
Matrix3x2 rotate = Matrix3x2Extensions.CreateRotationDegrees(z); |
|
|
|
Matrix3x2 scale = Matrix3x2Extensions.CreateScale(new SizeF(.5F, .5F)); |
|
|
|
Matrix3x2 rotate = Matrix3x2Extensions.CreateRotationDegrees(45); |
|
|
|
Matrix3x2 scale = Matrix3x2Extensions.CreateScale(new SizeF(.5F, .5F)); |
|
|
|
|
|
|
|
image.Mutate(i => i.Transform(rotate * scale, sampler)); |
|
|
|
image.DebugSave(provider, string.Join("_", x, y, resamplerName)); |
|
|
|
} |
|
|
|
image.Mutate(i => i.Transform(rotate * scale, sampler)); |
|
|
|
image.DebugSave(provider, resamplerName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|