Skip to content

Commit b25e102

Browse files
Update based on feedback.
1 parent 585b7be commit b25e102

25 files changed

+296
-396
lines changed

src/ImageSharp/Processing/Processors/Transforms/Automorphic/AffineTransformProcessor{TPixel}.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/ImageSharp/Processing/Processors/Transforms/Automorphic/ProjectiveTransformProcessor{TPixel}.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/ImageSharp/Processing/Processors/Transforms/IResampler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface IResampler
2929
/// </summary>
3030
/// <typeparam name="TPixel">The pixel format.</typeparam>
3131
/// <param name="processor">The transforming image processor.</param>
32-
void ApplyTransform<TPixel>(IResamplingImageProcessor<TPixel> processor)
32+
void ApplyTransform<TPixel>(IResamplingTransformImageProcessor<TPixel> processor)
3333
where TPixel : struct, IPixel<TPixel>;
3434
}
3535
}

src/ImageSharp/Processing/Processors/Transforms/IResamplingImageProcessor{TPixel}.cs renamed to src/ImageSharp/Processing/Processors/Transforms/IResamplingTransformImageProcessor{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
77
{
88
/// <summary>
9-
/// Implements an algorithm to alter the pixels of an image via a resampling transforms.
9+
/// Implements an algorithm to alter the pixels of an image via resampling transforms.
1010
/// </summary>
1111
/// <typeparam name="TPixel">The pixel format.</typeparam>
12-
public interface IResamplingImageProcessor<TPixel> : IImageProcessor<TPixel>
12+
public interface IResamplingTransformImageProcessor<TPixel> : IImageProcessor<TPixel>
1313
where TPixel : struct, IPixel<TPixel>
1414
{
1515
/// <summary>
Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,53 @@
1111

1212
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
1313
{
14-
/// <content>
15-
/// Contains the application code for performing an affine transform.
16-
/// </content>
17-
internal partial class AffineTransformProcessor<TPixel>
14+
/// <summary>
15+
/// Provides the base methods to perform affine transforms on an image.
16+
/// </summary>
17+
/// <typeparam name="TPixel">The pixel format.</typeparam>
18+
internal class AffineTransformProcessor<TPixel> : TransformProcessor<TPixel>, IResamplingTransformImageProcessor<TPixel>
19+
where TPixel : struct, IPixel<TPixel>
1820
{
21+
private readonly Size destinationSize;
22+
private readonly Matrix3x2 transformMatrix;
23+
private readonly IResampler resampler;
24+
private ImageFrame<TPixel> source;
25+
private ImageFrame<TPixel> destination;
26+
1927
/// <summary>
20-
/// Applies an affine transformation upon an image.
28+
/// Initializes a new instance of the <see cref="AffineTransformProcessor{TPixel}"/> class.
2129
/// </summary>
22-
/// <typeparam name="TResampler">The type of sampler.</typeparam>
23-
/// <param name="configuration">The configuration.</param>
24-
/// <param name="sampler">The pixel sampler.</param>
25-
/// <param name="source">The source image frame.</param>
26-
/// <param name="destination">The destination image frame.</param>
27-
/// <param name="matrix">The transform matrix.</param>
28-
public static void ApplyAffineTransform<TResampler>(
29-
Configuration configuration,
30-
in TResampler sampler,
31-
ImageFrame<TPixel> source,
32-
ImageFrame<TPixel> destination,
33-
Matrix3x2 matrix)
30+
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
31+
/// <param name="definition">The <see cref="AffineTransformProcessor"/> defining the processor parameters.</param>
32+
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
33+
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
34+
public AffineTransformProcessor(Configuration configuration, AffineTransformProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
35+
: base(configuration, source, sourceRectangle)
36+
{
37+
this.destinationSize = definition.DestinationSize;
38+
this.transformMatrix = definition.TransformMatrix;
39+
this.resampler = definition.Sampler;
40+
}
41+
42+
protected override Size GetDestinationSize() => this.destinationSize;
43+
44+
/// <inheritdoc/>
45+
protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixel> destination)
46+
{
47+
this.source = source;
48+
this.destination = destination;
49+
this.resampler.ApplyTransform(this);
50+
}
51+
52+
/// <inheritdoc/>
53+
public void ApplyTransform<TResampler>(in TResampler sampler)
3454
where TResampler : struct, IResampler
3555
{
56+
Configuration configuration = this.Configuration;
57+
ImageFrame<TPixel> source = this.source;
58+
ImageFrame<TPixel> destination = this.destination;
59+
Matrix3x2 matrix = this.transformMatrix;
60+
3661
// Handle transforms that result in output identical to the original.
3762
if (matrix.Equals(default) || matrix.Equals(Matrix3x2.Identity))
3863
{
@@ -55,8 +80,8 @@ public static void ApplyAffineTransform<TResampler>(
5580
return;
5681
}
5782

58-
int yRadius = AutomorphicTransformUtilities.GetSamplingRadius(in sampler, source.Height, destination.Height);
59-
int xRadius = AutomorphicTransformUtilities.GetSamplingRadius(in sampler, source.Width, destination.Width);
83+
int yRadius = LinearTransformUtilities.GetSamplingRadius(in sampler, source.Height, destination.Height);
84+
int xRadius = LinearTransformUtilities.GetSamplingRadius(in sampler, source.Width, destination.Width);
6085
var radialExtents = new Vector2(xRadius, yRadius);
6186
int yLength = (yRadius * 2) + 1;
6287
int xLength = (xRadius * 2) + 1;
@@ -186,7 +211,7 @@ public void Invoke(in RowInterval rows, Span<Vector4> span)
186211
// Use the single precision position to calculate correct bounding pixels
187212
// otherwise we get rogue pixels outside of the bounds.
188213
var point = Vector2.Transform(new Vector2(x, y), this.matrix);
189-
AutomorphicTransformUtilities.Convolve(
214+
LinearTransformUtilities.Convolve(
190215
in this.sampler,
191216
point,
192217
sourceBuffer,

0 commit comments

Comments
 (0)