diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs
index 45ed5f053..96f78ef98 100644
--- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs
+++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs
@@ -13,6 +13,8 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
+ using SixLabors.Primitives;
+
///
/// Represents a single frame in a animation.
///
@@ -53,6 +55,16 @@ namespace SixLabors.ImageSharp
this.MetaData = metaData;
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The of the frame.
+ /// The meta data.
+ internal ImageFrame(Size size, ImageFrameMetaData metaData)
+ : this(size.Width, size.Height, metaData)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
diff --git a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
index fb07eb023..07c247d73 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
@@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
internal class AffineTransformProcessor : InterpolatedTransformProcessorBase
where TPixel : struct, IPixel
{
- private Size? targetDimensions;
+ private Size targetDimensions;
///
/// Initializes a new instance of the class.
@@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// The transform matrix
/// The sampler to perform the transform operation.
public AffineTransformProcessor(Matrix3x2 matrix, IResampler sampler)
- : this(matrix, sampler, Rectangle.Empty)
+ : this(matrix, sampler, Size.Empty)
{
}
@@ -47,14 +47,14 @@ namespace SixLabors.ImageSharp.Processing.Processors
///
/// The transform matrix
/// The sampler to perform the transform operation.
- /// The rectangle to constrain the transformed image to.
- public AffineTransformProcessor(Matrix3x2 matrix, IResampler sampler, Rectangle rectangle)
+ /// The target dimensions to constrain the transformed image to.
+ public AffineTransformProcessor(Matrix3x2 matrix, IResampler sampler, Size targetDimensions)
: base(sampler)
{
// Tansforms are inverted else the output is the opposite of the expected.
Matrix3x2.Invert(matrix, out matrix);
this.TransformMatrix = matrix;
- this.targetDimensions = rectangle == Rectangle.Empty ?(Size?)null : rectangle.Size;
+ this.targetDimensions = targetDimensions;
}
///
@@ -65,17 +65,15 @@ namespace SixLabors.ImageSharp.Processing.Processors
///
protected override Image CreateDestination(Image source, Rectangle sourceRectangle)
{
- if (!this.targetDimensions.HasValue)
+ if (this.targetDimensions == Size.Empty)
{
// TODO: CreateDestination() should not modify the processors state! (kinda CQRS)
this.targetDimensions = this.GetTransformedDimensions(sourceRectangle.Size, this.TransformMatrix);
}
- Size targetDims = this.targetDimensions.Value;
-
// We will always be creating the clone even for mutate because we may need to resize the canvas
IEnumerable> frames =
- source.Frames.Select(x => new ImageFrame(targetDims.Width, targetDims.Height, x.MetaData.Clone()));
+ source.Frames.Select(x => new ImageFrame(this.targetDimensions, x.MetaData.Clone()));
// Use the overload to prevent an extra frame being added
return new Image(source.GetConfiguration(), source.MetaData.Clone(), frames);
@@ -88,14 +86,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
Rectangle sourceRectangle,
Configuration configuration)
{
- int height = this.targetDimensions.Value.Height;
- int width = this.targetDimensions.Value.Width;
+ int height = this.targetDimensions.Height;
+ int width = this.targetDimensions.Width;
Rectangle sourceBounds = source.Bounds();
var targetBounds = new Rectangle(0, 0, width, height);
// Since could potentially be resizing the canvas we might need to re-calculate the matrix
-
Matrix3x2 matrix = this.GetProcessingMatrix(sourceBounds, targetBounds);
if (this.Sampler is NearestNeighborResampler)
diff --git a/src/ImageSharp/Processing/Transforms/Transform.cs b/src/ImageSharp/Processing/Transforms/Transform.cs
index cbfe6da18..87c7306b8 100644
--- a/src/ImageSharp/Processing/Transforms/Transform.cs
+++ b/src/ImageSharp/Processing/Transforms/Transform.cs
@@ -46,9 +46,35 @@ namespace SixLabors.ImageSharp
/// The to perform the resampling.
/// The rectangle to constrain the transformed image to.
/// The
- public static IImageProcessingContext Transform(this IImageProcessingContext source, Matrix3x2 matrix, IResampler sampler, Rectangle rectangle)
+ public static IImageProcessingContext Transform(
+ this IImageProcessingContext source,
+ Matrix3x2 matrix,
+ IResampler sampler,
+ Rectangle rectangle)
where TPixel : struct, IPixel
- => source.ApplyProcessor(new AffineTransformProcessor(matrix, sampler, rectangle));
+ {
+ // TODO: Fixme!
+ return source.ApplyProcessor(new AffineTransformProcessor(matrix, sampler, rectangle.Size));
+ }
+
+ ///
+ /// Transforms an image by the given matrix using the specified sampling algorithm.
+ ///
+ /// The pixel format.
+ /// The image to transform.
+ /// The transformation matrix.
+ /// The to perform the resampling.
+ /// The dimensions to constrain the transformed image to.
+ /// The
+ public static IImageProcessingContext Transform(
+ this IImageProcessingContext source,
+ Matrix3x2 matrix,
+ IResampler sampler,
+ Size destinationSize)
+ where TPixel : struct, IPixel
+ {
+ return source.ApplyProcessor(new AffineTransformProcessor(matrix, sampler, destinationSize));
+ }
///
/// Transforms an image by the given matrix.