Browse Source

Simplify Resamplers

af/octree-no-pixelmap
James Jackson-South 6 years ago
parent
commit
6bac83838b
  1. 34
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  2. 22
      src/ImageSharp/Processing/KnownResamplers.cs
  3. 77
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/CatmullRomResampler.cs
  4. 153
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/CubicResampler.cs
  5. 76
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/HermiteResampler.cs
  6. 83
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/Lanczos2Resampler.cs
  7. 83
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/Lanczos3Resampler.cs
  8. 83
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/Lanczos8Resampler.cs
  9. 38
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/LanczosResampler.cs
  10. 74
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/MitchellNetravaliResampler.cs
  11. 75
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/RobidouxResampler.cs
  12. 75
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/RobidouxSharpResampler.cs
  13. 75
      src/ImageSharp/Processing/Processors/Transforms/Resamplers/SplineResampler.cs

34
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -242,40 +242,6 @@ namespace SixLabors.ImageSharp
return 1F;
}
/// <summary>
/// Returns the result of a B-C filter against the given value.
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
/// </summary>
/// <param name="x">The value to process.</param>
/// <param name="b">The B-Spline curve variable.</param>
/// <param name="c">The Cardinal curve variable.</param>
/// <returns>
/// The <see cref="float"/>.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static float GetBcValue(float x, float b, float c)
{
if (x < 0F)
{
x = -x;
}
float temp = x * x;
if (x < 1F)
{
x = ((12 - (9 * b) - (6 * c)) * (x * temp)) + ((-18 + (12 * b) + (6 * c)) * temp) + (6 - (2 * b));
return x / 6F;
}
if (x < 2F)
{
x = ((-b - (6 * c)) * (x * temp)) + (((6 * b) + (30 * c)) * temp) + (((-12 * b) - (48 * c)) * x) + ((8 * b) + (24 * c));
return x / 6F;
}
return 0F;
}
/// <summary>
/// Gets the bounding <see cref="Rectangle"/> from the given points.
/// </summary>

22
src/ImageSharp/Processing/KnownResamplers.cs

@ -24,43 +24,43 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// Gets the Catmull-Rom sampler, a well known standard Cubic Filter often used as a interpolation function
/// </summary>
public static IResampler CatmullRom { get; } = default(CatmullRomResampler);
public static IResampler CatmullRom { get; } = CubicResampler.CatmullRom;
/// <summary>
/// Gets the Hermite sampler. A type of smoothed triangular interpolation filter that rounds off strong edges while
/// preserving flat 'color levels' in the original image.
/// </summary>
public static IResampler Hermite { get; } = default(HermiteResampler);
public static IResampler Hermite { get; } = CubicResampler.Hermite;
/// <summary>
/// Gets the Lanczos kernel sampler that implements smooth interpolation with a radius of 2 pixels.
/// This algorithm provides sharpened results when compared to others when downsampling.
/// </summary>
public static IResampler Lanczos2 { get; } = default(Lanczos2Resampler);
public static IResampler Lanczos2 { get; } = LanczosResampler.Lanczos2;
/// <summary>
/// Gets the Lanczos kernel sampler that implements smooth interpolation with a radius of 3 pixels
/// This algorithm provides sharpened results when compared to others when downsampling.
/// </summary>
public static IResampler Lanczos3 { get; } = default(Lanczos3Resampler);
public static IResampler Lanczos3 { get; } = LanczosResampler.Lanczos3;
/// <summary>
/// Gets the Lanczos kernel sampler that implements smooth interpolation with a radius of 5 pixels
/// This algorithm provides sharpened results when compared to others when downsampling.
/// </summary>
public static IResampler Lanczos5 { get; } = default(Lanczos5Resampler);
public static IResampler Lanczos5 { get; } = LanczosResampler.Lanczos5;
/// <summary>
/// Gets the Lanczos kernel sampler that implements smooth interpolation with a radius of 8 pixels
/// This algorithm provides sharpened results when compared to others when downsampling.
/// </summary>
public static IResampler Lanczos8 { get; } = default(Lanczos8Resampler);
public static IResampler Lanczos8 { get; } = LanczosResampler.Lanczos8;
/// <summary>
/// Gets the Mitchell-Netravali sampler. This seperable cubic algorithm yields a very good equilibrium between
/// detail preservation (sharpness) and smoothness.
/// </summary>
public static IResampler MitchellNetravali { get; } = default(MitchellNetravaliResampler);
public static IResampler MitchellNetravali { get; } = CubicResampler.MitchellNetravali;
/// <summary>
/// Gets the Nearest-Neighbour sampler that implements the nearest neighbor algorithm. This uses a very fast, unscaled filter
@ -72,17 +72,17 @@ namespace SixLabors.ImageSharp.Processing
/// Gets the Robidoux sampler. This algorithm developed by Nicolas Robidoux providing a very good equilibrium between
/// detail preservation (sharpness) and smoothness comparable to <see cref="MitchellNetravali"/>.
/// </summary>
public static IResampler Robidoux { get; } = default(RobidouxResampler);
public static IResampler Robidoux { get; } = CubicResampler.Robidoux;
/// <summary>
/// Gets the Robidoux Sharp sampler. A sharpened form of the <see cref="Robidoux"/> sampler
/// </summary>
public static IResampler RobidouxSharp { get; } = default(RobidouxSharpResampler);
public static IResampler RobidouxSharp { get; } = CubicResampler.RobidouxSharp;
/// <summary>
/// Gets the Spline sampler. A seperable cubic algorithm similar to <see cref="MitchellNetravali"/> but yielding smoother results.
/// Gets the Spline sampler. A separable cubic algorithm similar to <see cref="MitchellNetravali"/> but yielding smoother results.
/// </summary>
public static IResampler Spline { get; } = default(SplineResampler);
public static IResampler Spline { get; } = CubicResampler.Spline;
/// <summary>
/// Gets the Triangle sampler, otherwise known as Bilinear. This interpolation algorithm can be used where perfect image transformation

77
src/ImageSharp/Processing/Processors/Transforms/Resamplers/CatmullRomResampler.cs

@ -1,77 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The Catmull-Rom filter is a well known standard Cubic Filter often used as a interpolation function.
/// This filter produces a reasonably sharp edge, but without a the pronounced gradient change on large
/// scale image enlargements that a 'Lagrange' filter can produce.
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
/// </summary>
public readonly struct CatmullRomResampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
const float B = 0;
const float C = 0.5F;
return ImageMaths.GetBcValue(x, B, C);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

153
src/ImageSharp/Processing/Processors/Transforms/Resamplers/CubicResampler.cs

@ -0,0 +1,153 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// Cubic filters contain a collection of different filters of varying B-Spline and
/// Cardinal values. With these two values you can generate any smoothly fitting
/// (continuious first derivative) piece-wise cubic filter.
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
/// <see href="https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf"/>
/// </summary>
public readonly struct CubicResampler : IResampler
{
private readonly float bspline;
private readonly float cardinal;
/// <summary>
/// The Catmull-Rom filter is a well known standard Cubic Filter often used as a interpolation function.
/// This filter produces a reasonably sharp edge, but without a the pronounced gradient change on large
/// scale image enlargements that a 'Lagrange' filter can produce.
/// </summary>
public static CubicResampler CatmullRom = new CubicResampler(2, 0, .5F);
/// <summary>
/// The Hermite filter is type of smoothed triangular interpolation Filter,
/// This filter rounds off strong edges while preserving flat 'color levels' in the original image.
/// </summary>
public static CubicResampler Hermite = new CubicResampler(2, 0, 0);
/// <summary>
/// The function implements the Mitchell-Netravali algorithm as described on
/// <see href="https://de.wikipedia.org/wiki/Mitchell-Netravali-Filter">Wikipedia</see>
/// </summary>
public static CubicResampler MitchellNetravali = new CubicResampler(2, .3333333F, .3333333F);
/// <summary>
/// The function implements the Robidoux algorithm.
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
/// </summary>
public static CubicResampler Robidoux = new CubicResampler(2, .37821575509399867F, .31089212245300067F);
/// <summary>
/// The function implements the Robidoux Sharp algorithm.
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
/// </summary>
public static CubicResampler RobidouxSharp = new CubicResampler(2, .2620145123990142F, .3689927438004929F);
/// <summary>
/// The function implements the spline algorithm.
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
/// </summary>
/// <summary>
/// The function implements the Robidoux Sharp algorithm.
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
/// </summary>
public static CubicResampler Spline = new CubicResampler(2, 1, 0);
/// <summary>
/// Initializes a new instance of the <see cref="CubicResampler"/> struct.
/// </summary>
/// <param name="radius">The sampling radius.</param>
/// <param name="bspline">The B-Spline value.</param>
/// <param name="cardinal">The Cardinal cubic value.</param>
public CubicResampler(float radius, float bspline, float cardinal)
{
this.Radius = radius;
this.bspline = bspline;
this.cardinal = cardinal;
}
/// <inheritdoc/>
public float Radius { get; }
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
float b = this.bspline;
float c = this.cardinal;
if (x < 0F)
{
x = -x;
}
float temp = x * x;
if (x < 1F)
{
x = ((12 - (9 * b) - (6 * c)) * (x * temp)) + ((-18 + (12 * b) + (6 * c)) * temp) + (6 - (2 * b));
return x / 6F;
}
if (x < 2F)
{
x = ((-b - (6 * c)) * (x * temp)) + (((6 * b) + (30 * c)) * temp) + (((-12 * b) - (48 * c)) * x) + ((8 * b) + (24 * c));
return x / 6F;
}
return 0F;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

76
src/ImageSharp/Processing/Processors/Transforms/Resamplers/HermiteResampler.cs

@ -1,76 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The Hermite filter is type of smoothed triangular interpolation Filter,
/// This filter rounds off strong edges while preserving flat 'color levels' in the original image.
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
/// </summary>
public readonly struct HermiteResampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
const float B = 0F;
const float C = 0F;
return ImageMaths.GetBcValue(x, B, C);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

83
src/ImageSharp/Processing/Processors/Transforms/Resamplers/Lanczos2Resampler.cs

@ -1,83 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the Lanczos kernel algorithm as described on
/// <see href="https://en.wikipedia.org/wiki/Lanczos_resampling#Algorithm">Wikipedia</see>
/// with a radius of 2 pixels.
/// </summary>
public readonly struct Lanczos2Resampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
if (x < 0F)
{
x = -x;
}
if (x < 2F)
{
return ImageMaths.SinC(x) * ImageMaths.SinC(x / 2F);
}
return 0F;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

83
src/ImageSharp/Processing/Processors/Transforms/Resamplers/Lanczos3Resampler.cs

@ -1,83 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the Lanczos kernel algorithm as described on
/// <see href="https://en.wikipedia.org/wiki/Lanczos_resampling#Algorithm">Wikipedia</see>
/// with a radius of 3 pixels.
/// </summary>
public readonly struct Lanczos3Resampler : IResampler
{
/// <inheritdoc/>
public float Radius => 3;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
if (x < 0F)
{
x = -x;
}
if (x < 3F)
{
return ImageMaths.SinC(x) * ImageMaths.SinC(x / 3F);
}
return 0F;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

83
src/ImageSharp/Processing/Processors/Transforms/Resamplers/Lanczos8Resampler.cs

@ -1,83 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the Lanczos kernel algorithm as described on
/// <see href="https://en.wikipedia.org/wiki/Lanczos_resampling#Algorithm">Wikipedia</see>
/// with a radius of 8 pixels.
/// </summary>
public readonly struct Lanczos8Resampler : IResampler
{
/// <inheritdoc/>
public float Radius => 8;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
if (x < 0F)
{
x = -x;
}
if (x < 8F)
{
return ImageMaths.SinC(x) * ImageMaths.SinC(x / 8F);
}
return 0F;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

38
src/ImageSharp/Processing/Processors/Transforms/Resamplers/Lanczos5Resampler.cs → src/ImageSharp/Processing/Processors/Transforms/Resamplers/LanczosResampler.cs

@ -9,13 +9,38 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the Lanczos kernel algorithm as described on
/// <see href="https://en.wikipedia.org/wiki/Lanczos_resampling#Algorithm">Wikipedia</see>
/// with a radius of 5 pixels.
/// <see href="https://en.wikipedia.org/wiki/Lanczos_resampling#Algorithm">Wikipedia</see>.
/// </summary>
public readonly struct Lanczos5Resampler : IResampler
public readonly struct LanczosResampler : IResampler
{
/// <summary>
/// Implements the Lanczos kernel algorithm with a radius of 2.
/// </summary>
public static LanczosResampler Lanczos2 = new LanczosResampler(2);
/// <summary>
/// Implements the Lanczos kernel algorithm with a radius of 3.
/// </summary>
public static LanczosResampler Lanczos3 = new LanczosResampler(3);
/// <summary>
/// Implements the Lanczos kernel algorithm with a radius of 5.
/// </summary>
public static LanczosResampler Lanczos5 = new LanczosResampler(5);
/// <summary>
/// Implements the Lanczos kernel algorithm with a radius of 8.
/// </summary>
public static LanczosResampler Lanczos8 = new LanczosResampler(8);
/// <summary>
/// Initializes a new instance of the <see cref="LanczosResampler"/> struct.
/// </summary>
/// <param name="radius">The sampling radius.</param>
public LanczosResampler(float radius) => this.Radius = radius;
/// <inheritdoc/>
public float Radius => 5;
public float Radius { get; }
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -26,9 +51,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
x = -x;
}
if (x < 5F)
float radius = this.Radius;
if (x < radius)
{
return ImageMaths.SinC(x) * ImageMaths.SinC(x / 5F);
return ImageMaths.SinC(x) * ImageMaths.SinC(x / radius);
}
return 0F;

74
src/ImageSharp/Processing/Processors/Transforms/Resamplers/MitchellNetravaliResampler.cs

@ -1,74 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the mitchell algorithm as described on
/// <see href="https://de.wikipedia.org/wiki/Mitchell-Netravali-Filter">Wikipedia</see>
/// </summary>
public readonly struct MitchellNetravaliResampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
public float GetValue(float x)
{
const float B = 0.3333333F;
const float C = 0.3333333F;
return ImageMaths.GetBcValue(x, B, C);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

75
src/ImageSharp/Processing/Processors/Transforms/Resamplers/RobidouxResampler.cs

@ -1,75 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the Robidoux algorithm.
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
/// </summary>
public readonly struct RobidouxResampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
const float B = 0.37821575509399867F;
const float C = 0.31089212245300067F;
return ImageMaths.GetBcValue(x, B, C);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

75
src/ImageSharp/Processing/Processors/Transforms/Resamplers/RobidouxSharpResampler.cs

@ -1,75 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the Robidoux Sharp algorithm.
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
/// </summary>
public readonly struct RobidouxSharpResampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
const float B = 0.2620145123990142F;
const float C = 0.3689927438004929F;
return ImageMaths.GetBcValue(x, B, C);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}

75
src/ImageSharp/Processing/Processors/Transforms/Resamplers/SplineResampler.cs

@ -1,75 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// The function implements the spline algorithm.
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
/// </summary>
public readonly struct SplineResampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public float GetValue(float x)
{
const float B = 1F;
const float C = 0F;
return ImageMaths.GetBcValue(x, B, C);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyResizeTransform<TPixel>(
Configuration configuration,
Image<TPixel> source,
Image<TPixel> destination,
Rectangle sourceRectangle,
Rectangle destinationRectangle,
bool compand)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyResizeTransform(
configuration,
in this,
source,
destination,
sourceRectangle,
destinationRectangle,
compand);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyAffineTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix3x2 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyAffineTransform(
configuration,
in this,
source,
destination,
matrix);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void ApplyProjectiveTransform<TPixel>(
Configuration configuration,
ImageFrame<TPixel> source,
ImageFrame<TPixel> destination,
Matrix4x4 matrix)
where TPixel : struct, IPixel<TPixel> => ResamplerExtensions.ApplyProjectiveTransform(
configuration,
in this,
source,
destination,
matrix);
}
}
Loading…
Cancel
Save