Browse Source

Cleanup TransformKernel and handle negative transform dimensions

pull/775/head
James Jackson-South 8 years ago
parent
commit
2afd0d5729
  1. 6
      src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
  2. 15
      src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs

6
src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs

@ -38,6 +38,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// We want to resize the canvas here taking into account any translations. // We want to resize the canvas here taking into account any translations.
this.TargetDimensions = new Size(this.transformedRectangle.Right, this.transformedRectangle.Bottom); this.TargetDimensions = new Size(this.transformedRectangle.Right, this.transformedRectangle.Bottom);
// Handle a negative translation that exceeds the original with of the image.
if (this.TargetDimensions.Width <= 0 || this.TargetDimensions.Height <= 0)
{
this.TargetDimensions = sourceSize;
}
} }
/// <summary> /// <summary>

15
src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs

@ -21,8 +21,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{ {
private readonly Buffer2D<float> yBuffer; private readonly Buffer2D<float> yBuffer;
private readonly Buffer2D<float> xBuffer; private readonly Buffer2D<float> xBuffer;
private readonly float yScale;
private readonly float xScale;
private readonly int yLength; private readonly int yLength;
private readonly int xLength; private readonly int xLength;
private readonly Vector2 extents; private readonly Vector2 extents;
@ -39,12 +37,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public TransformKernelMap(Configuration configuration, Size source, Size destination, IResampler sampler) public TransformKernelMap(Configuration configuration, Size source, Size destination, IResampler sampler)
{ {
this.sampler = sampler; this.sampler = sampler;
(float radius, float scale) yRadiusScale = this.GetSamplingRadius(source.Height, destination.Height); float yRadius = this.GetSamplingRadius(source.Height, destination.Height);
(float radius, float scale) xRadiusScale = this.GetSamplingRadius(source.Width, destination.Width); float xRadius = this.GetSamplingRadius(source.Width, destination.Width);
this.yScale = yRadiusScale.scale; this.extents = new Vector2(xRadius, yRadius);
this.xScale = xRadiusScale.scale;
this.extents = new Vector2(xRadiusScale.radius, yRadiusScale.radius);
this.xLength = (int)MathF.Ceiling((this.extents.X * 2) + 2); this.xLength = (int)MathF.Ceiling((this.extents.X * 2) + 2);
this.yLength = (int)MathF.Ceiling((this.extents.Y * 2) + 2); this.yLength = (int)MathF.Ceiling((this.extents.Y * 2) + 2);
@ -167,7 +163,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// } // }
} }
private (float radius, float scale) GetSamplingRadius(int sourceSize, int destinationSize) [MethodImpl(InliningOptions.ShortMethod)]
private float GetSamplingRadius(int sourceSize, int destinationSize)
{ {
float scale = (float)sourceSize / destinationSize; float scale = (float)sourceSize / destinationSize;
@ -176,7 +173,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
scale = 1F; scale = 1F;
} }
return (MathF.Ceiling(scale * this.sampler.Radius), scale); return MathF.Ceiling(scale * this.sampler.Radius);
} }
public void Dispose() public void Dispose()

Loading…
Cancel
Save