From 04cfafac8b505dc2662f3b484646b8ff32097db6 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 22 Oct 2015 21:39:51 +1100 Subject: [PATCH] Add Lanczos5 Former-commit-id: 6055bc865b95eeb9d89c3d6d5e7859ba7707f2e5 Former-commit-id: 552ea8768e0b173fd5fe103645da6c8f16cf143e Former-commit-id: 5594f396a9ffbb48272a27d1cd7d49e40021c399 --- .../Samplers/Resamplers/Lanczos5Resampler.cs | 33 +++++++++++++++++++ .../Processors/Samplers/SamplerTests.cs | 1 + 2 files changed, 34 insertions(+) create mode 100644 src/ImageProcessor/Samplers/Resamplers/Lanczos5Resampler.cs diff --git a/src/ImageProcessor/Samplers/Resamplers/Lanczos5Resampler.cs b/src/ImageProcessor/Samplers/Resamplers/Lanczos5Resampler.cs new file mode 100644 index 000000000..ef219874b --- /dev/null +++ b/src/ImageProcessor/Samplers/Resamplers/Lanczos5Resampler.cs @@ -0,0 +1,33 @@ +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessor.Samplers +{ + /// + /// The function implements the Lanczos kernel algorithm as described on + /// Wikipedia + /// + public class Lanczos5Resampler : IResampler + { + /// + public double Radius => 5; + + /// + public double GetValue(double x) + { + if (x < 0) + { + x = -x; + } + + if (x < 5) + { + return ImageMaths.SinC(x) * ImageMaths.SinC(x / 5f); + } + + return 0; + } + } +} diff --git a/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs index 9f5c9cccc..ffa4c5d54 100644 --- a/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs +++ b/tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs @@ -17,6 +17,7 @@ namespace ImageProcessor.Tests { "Triangle", new TriangleResampler() }, { "Box", new BoxResampler() }, { "Lanczos3", new Lanczos3Resampler() }, + { "Lanczos5", new Lanczos5Resampler() }, { "Lanczos8", new Lanczos8Resampler() }, { "MitchellNetravali", new MitchellNetravaliResampler() }, { "Hermite", new HermiteResampler() },