mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 81377f2d574fe5778b5a24c968c53bd967e8f08d Former-commit-id: 0dbdf15a7d41f51a7ca109a1b6fc39954c6cfa69 Former-commit-id: 48d223ff221f92f49f12685d44c09839bb76b2e4pull/17/head
18 changed files with 361 additions and 13 deletions
@ -0,0 +1,32 @@ |
|||
// <copyright file="BoxResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the box (nearest neighbour) algorithm.
|
|||
/// </summary>
|
|||
public class BoxResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 0.5; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
if (x < 0) |
|||
{ |
|||
x = -x; |
|||
} |
|||
|
|||
if (x <= 0.5) |
|||
{ |
|||
return 1; |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <copyright file="CatmullRomResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the Catmull-Rom algorithm.
|
|||
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
|
|||
/// </summary>
|
|||
public class CatmullRomResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 2; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
const double B = 0; |
|||
const double C = 1 / 2d; |
|||
|
|||
return ImageMaths.GetBcValue(x, B, C); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <copyright file="HermiteResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the hermite algorithm.
|
|||
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
|
|||
/// </summary>
|
|||
public class HermiteResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 2; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
const double B = 0; |
|||
const double C = 0; |
|||
|
|||
return ImageMaths.GetBcValue(x, B, C); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <copyright file="MitchellResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the mitchell algorithm as described on
|
|||
/// <see href="https://de.wikipedia.org/wiki/Mitchell-Netravali-Filter">Wikipedia</see>
|
|||
/// </summary>
|
|||
public class MitchellNetravaliResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 2; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
const double B = 1 / 3d; |
|||
const double C = 1 / 3d; |
|||
|
|||
return ImageMaths.GetBcValue(x, B, C); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <copyright file="RobidouxResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the Robidoux algorithm.
|
|||
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
|
|||
/// </summary>
|
|||
public class RobidouxResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 2; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
const double B = 0.3782; |
|||
const double C = 0.3109; |
|||
|
|||
return ImageMaths.GetBcValue(x, B, C); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <copyright file="RobidouxSharpResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the Robidoux Sharp algorithm.
|
|||
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
|
|||
/// </summary>
|
|||
public class RobidouxSharpResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 2; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
const double B = 0.2620; |
|||
const double C = 0.3690; |
|||
|
|||
return ImageMaths.GetBcValue(x, B, C); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <copyright file="RobidouxSoftResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the Robidoux Soft algorithm.
|
|||
/// <see href="http://www.imagemagick.org/Usage/filter/#robidoux"/>
|
|||
/// </summary>
|
|||
public class RobidouxSoftResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 2; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
const double B = 0.6796; |
|||
const double C = 0.1602; |
|||
|
|||
return ImageMaths.GetBcValue(x, B, C); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <copyright file="SplineResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the spline algorithm.
|
|||
/// <see href="http://www.imagemagick.org/Usage/filter/#cubic_bc"/>
|
|||
/// </summary>
|
|||
public class SplineResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 2; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
const double B = 1; |
|||
const double C = 0; |
|||
|
|||
return ImageMaths.GetBcValue(x, B, C); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
// <copyright file="TriangleResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the triangle (bilinear) algorithm.
|
|||
/// </summary>
|
|||
public class TriangleResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 1; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
if (x < 0) |
|||
{ |
|||
x = -x; |
|||
} |
|||
|
|||
if (x < 1) |
|||
{ |
|||
return 1 - x; |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
// <copyright file="WelchResampler.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Samplers |
|||
{ |
|||
/// <summary>
|
|||
/// The function implements the welch algorithm.
|
|||
/// <see href="http://www.imagemagick.org/Usage/filter/"/>
|
|||
/// </summary>
|
|||
public class WelchResampler : IResampler |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public double Radius => 3; |
|||
|
|||
/// <inheritdoc/>
|
|||
public double GetValue(double x) |
|||
{ |
|||
if (x < 0) |
|||
{ |
|||
x = -x; |
|||
} |
|||
|
|||
if (x < 3) |
|||
{ |
|||
return ImageMaths.SinC(x) * (1.0 - (x * x / 9.0)); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue