|
|
@ -1,8 +1,11 @@ |
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
|
|
|
|
using System.Numerics; |
|
|
|
|
|
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
using SixLabors.ImageSharp.Processing.Processors.Transforms; |
|
|
using SixLabors.ImageSharp.Processing.Processors.Transforms; |
|
|
|
|
|
using SixLabors.Primitives; |
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Processing |
|
|
namespace SixLabors.ImageSharp.Processing |
|
|
{ |
|
|
{ |
|
|
@ -11,6 +14,29 @@ namespace SixLabors.ImageSharp.Processing |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static class TransformExtensions |
|
|
public static class TransformExtensions |
|
|
{ |
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Performs an affine transform of an image using the specified sampling algorithm.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
|
|
|
|
/// <param name="ctx">The <see cref="IImageProcessingContext{TPixel}"/>.</param>
|
|
|
|
|
|
/// <param name="sourceRectangle">The source rectangle</param>
|
|
|
|
|
|
/// <param name="transform">The transformation matrix.</param>
|
|
|
|
|
|
/// <param name="targetDimensions">The size of the result image.</param>
|
|
|
|
|
|
/// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
|
|
|
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
|
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>( |
|
|
|
|
|
this IImageProcessingContext<TPixel> ctx, |
|
|
|
|
|
Rectangle sourceRectangle, |
|
|
|
|
|
Matrix3x2 transform, |
|
|
|
|
|
Size targetDimensions, |
|
|
|
|
|
IResampler sampler) |
|
|
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
|
|
{ |
|
|
|
|
|
return ctx.ApplyProcessor( |
|
|
|
|
|
new AffineTransformProcessor<TPixel>(transform, sampler, targetDimensions), |
|
|
|
|
|
sourceRectangle); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Performs an affine transform of an image.
|
|
|
/// Performs an affine transform of an image.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -18,7 +44,9 @@ namespace SixLabors.ImageSharp.Processing |
|
|
/// <param name="source">The image to transform.</param>
|
|
|
/// <param name="source">The image to transform.</param>
|
|
|
/// <param name="builder">The affine transform builder.</param>
|
|
|
/// <param name="builder">The affine transform builder.</param>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, AffineTransformBuilder builder) |
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>( |
|
|
|
|
|
this IImageProcessingContext<TPixel> source, |
|
|
|
|
|
AffineTransformBuilder builder) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
=> Transform(source, builder, KnownResamplers.Bicubic); |
|
|
=> Transform(source, builder, KnownResamplers.Bicubic); |
|
|
|
|
|
|
|
|
@ -26,13 +54,39 @@ namespace SixLabors.ImageSharp.Processing |
|
|
/// Performs an affine transform of an image using the specified sampling algorithm.
|
|
|
/// Performs an affine transform of an image using the specified sampling algorithm.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
|
/// <param name="source">The image to transform.</param>
|
|
|
/// <param name="ctx">The <see cref="IImageProcessingContext{TPixel}"/>.</param>
|
|
|
|
|
|
/// <param name="sourceRectangle">The source rectangle</param>
|
|
|
|
|
|
/// <param name="builder">The affine transform builder.</param>
|
|
|
|
|
|
/// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
|
|
|
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
|
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>( |
|
|
|
|
|
this IImageProcessingContext<TPixel> ctx, |
|
|
|
|
|
Rectangle sourceRectangle, |
|
|
|
|
|
AffineTransformBuilder builder, |
|
|
|
|
|
IResampler sampler) |
|
|
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
|
|
{ |
|
|
|
|
|
Matrix3x2 transform = builder.BuildMatrix(sourceRectangle); |
|
|
|
|
|
Size targetDimensions = TransformUtils.GetTransformedSize(sourceRectangle.Size, transform); |
|
|
|
|
|
return ctx.Transform(sourceRectangle, transform, targetDimensions, sampler); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Performs an affine transform of an image using the specified sampling algorithm.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
|
|
|
|
/// <param name="ctx">The <see cref="IImageProcessingContext{TPixel}"/>.</param>
|
|
|
/// <param name="builder">The affine transform builder.</param>
|
|
|
/// <param name="builder">The affine transform builder.</param>
|
|
|
/// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
|
|
|
/// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, AffineTransformBuilder builder, IResampler sampler) |
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>( |
|
|
|
|
|
this IImageProcessingContext<TPixel> ctx, |
|
|
|
|
|
AffineTransformBuilder builder, |
|
|
|
|
|
IResampler sampler) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
=> source.ApplyProcessor(new AffineTransformProcessor<TPixel>(builder.BuildMatrix(), sampler, builder.Size)); |
|
|
{ |
|
|
|
|
|
return ctx.Transform(new Rectangle(Point.Empty, ctx.GetCurrentSize()), builder, sampler); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Performs a projective transform of an image.
|
|
|
/// Performs a projective transform of an image.
|
|
|
@ -41,7 +95,9 @@ namespace SixLabors.ImageSharp.Processing |
|
|
/// <param name="source">The image to transform.</param>
|
|
|
/// <param name="source">The image to transform.</param>
|
|
|
/// <param name="builder">The affine transform builder.</param>
|
|
|
/// <param name="builder">The affine transform builder.</param>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, ProjectiveTransformBuilder builder) |
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>( |
|
|
|
|
|
this IImageProcessingContext<TPixel> source, |
|
|
|
|
|
ProjectiveTransformBuilder builder) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
=> Transform(source, builder, KnownResamplers.Bicubic); |
|
|
=> Transform(source, builder, KnownResamplers.Bicubic); |
|
|
|
|
|
|
|
|
@ -53,7 +109,10 @@ namespace SixLabors.ImageSharp.Processing |
|
|
/// <param name="builder">The projective transform builder.</param>
|
|
|
/// <param name="builder">The projective transform builder.</param>
|
|
|
/// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
|
|
|
/// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
/// <returns>The <see cref="Image{TPixel}"/></returns>
|
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>(this IImageProcessingContext<TPixel> source, ProjectiveTransformBuilder builder, IResampler sampler) |
|
|
public static IImageProcessingContext<TPixel> Transform<TPixel>( |
|
|
|
|
|
this IImageProcessingContext<TPixel> source, |
|
|
|
|
|
ProjectiveTransformBuilder builder, |
|
|
|
|
|
IResampler sampler) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
=> source.ApplyProcessor(new ProjectiveTransformProcessor<TPixel>(builder.BuildMatrix(), sampler, builder.Size)); |
|
|
=> source.ApplyProcessor(new ProjectiveTransformProcessor<TPixel>(builder.BuildMatrix(), sampler, builder.Size)); |
|
|
} |
|
|
} |
|
|
|