Browse Source

Add another test and make some methods public

af/merge-core
James Jackson-South 8 years ago
parent
commit
a803e49fb0
  1. 7
      src/ImageSharp/Processing/Transforms/TransformExtensions.cs
  2. 21
      tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs

7
src/ImageSharp/Processing/Transforms/TransformExtensions.cs

@ -86,26 +86,25 @@ namespace SixLabors.ImageSharp.Processing.Transforms
/// <param name="source">The image to transform.</param>
/// <param name="matrix">The transformation matrix.</param>
/// <returns>The <see cref="Image{TPixel}"/></returns>
internal static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix)
public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel>
=> Transform(source, matrix, KnownResamplers.Bicubic);
/// <summary>
/// Applies a projective transform to the image by the given matrix using the specified sampling algorithm.
/// TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to transform.</param>
/// <param name="matrix">The transformation matrix.</param>
/// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
/// <returns>The <see cref="Image{TPixel}"/></returns>
internal static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix, IResampler sampler)
public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, Matrix4x4 matrix, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new ProjectiveTransformProcessor<TPixel>(matrix, sampler, source.GetCurrentSize()));
/// <summary>
/// Applies a projective transform to the image by the given matrix using the specified sampling algorithm.
/// TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior
/// TODO: Should we be offsetting the matrix here?
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to transform.</param>

21
tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs

@ -61,6 +61,27 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
}
}
[Theory]
[WithSolidFilledImages(100, 100, 0, 0, 255, PixelTypes.Rgba32)]
public void RawTransformMatchesDocumentedExample<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
// This test matches the output described in the example at
// https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/transforms/non-affine
using (Image<TPixel> image = provider.GetImage())
{
Matrix4x4 m = Matrix4x4.Identity;
m.M13 = 0.01F;
image.Mutate(i => { i.Transform(m); });
image.DebugSave(provider);
// TODO: Enable and add more tests.
// image.CompareToReferenceOutput(ValidatorComparer, provider, resamplerName);
}
}
private static IResampler GetResampler(string name)
{
PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name);

Loading…
Cancel
Save