mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 173de39596036ccb0970ae195d47874cb5610db6 Former-commit-id: 156b60bd82d6e2d49c0733aa5954206417d63501 Former-commit-id: 6639ef8d33a006707c408193122d001189eec15daf/merge-core
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