diff --git a/src/ImageProcessorCore/ImageExtensions.cs b/src/ImageProcessorCore/ImageExtensions.cs index 09cd06f63..50665b747 100644 --- a/src/ImageProcessorCore/ImageExtensions.cs +++ b/src/ImageProcessorCore/ImageExtensions.cs @@ -10,6 +10,8 @@ namespace ImageProcessorCore using Formats; + using ImageProcessorCore.Samplers; + /// /// Exstension methods for the type. /// @@ -89,7 +91,7 @@ namespace ImageProcessorCore /// The target image height. /// Any processors to apply to the image. /// The . - public static Image Process(this Image source, int width, int height, params IImageProcessor[] processors) + public static Image Process(this Image source, int width, int height, params IImageSampler[] processors) { return Process(source, width, height, source.Bounds, default(Rectangle), processors); } @@ -113,12 +115,12 @@ namespace ImageProcessorCore /// /// Any processors to apply to the image. /// The . - public static Image Process(this Image source, int width, int height, Rectangle sourceRectangle, Rectangle targetRectangle, params IImageProcessor[] processors) + public static Image Process(this Image source, int width, int height, Rectangle sourceRectangle, Rectangle targetRectangle, params IImageSampler[] processors) { // ReSharper disable once LoopCanBeConvertedToQuery - foreach (IImageProcessor filter in processors) + foreach (IImageSampler sampler in processors) { - source = PerformAction(source, false, (sourceImage, targetImage) => filter.Apply(targetImage, sourceImage, width, height, targetRectangle, sourceRectangle)); + source = PerformAction(source, false, (sourceImage, targetImage) => sampler.Apply(targetImage, sourceImage, width, height, targetRectangle, sourceRectangle)); } return source; diff --git a/src/ImageProcessorCore/Samplers/Crop.cs b/src/ImageProcessorCore/Samplers/Crop.cs index 5b61aa94e..0d17e2f54 100644 --- a/src/ImageProcessorCore/Samplers/Crop.cs +++ b/src/ImageProcessorCore/Samplers/Crop.cs @@ -10,7 +10,7 @@ namespace ImageProcessorCore.Samplers /// /// Provides methods to allow the cropping of an image. /// - public class Crop : ParallelImageProcessor + public class Crop : ImageSampler { /// protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) diff --git a/src/ImageProcessorCore/Samplers/EntropyCrop.cs b/src/ImageProcessorCore/Samplers/EntropyCrop.cs index f1dca16b9..b6fd26915 100644 --- a/src/ImageProcessorCore/Samplers/EntropyCrop.cs +++ b/src/ImageProcessorCore/Samplers/EntropyCrop.cs @@ -14,7 +14,7 @@ namespace ImageProcessorCore.Samplers /// Provides methods to allow the cropping of an image to preserve areas of highest /// entropy. /// - public class EntropyCrop : ParallelImageProcessor + public class EntropyCrop : ImageSampler { /// /// The rectangle for cropping diff --git a/src/ImageProcessorCore/Samplers/IImageSampler.cs b/src/ImageProcessorCore/Samplers/IImageSampler.cs new file mode 100644 index 000000000..4cd1912cd --- /dev/null +++ b/src/ImageProcessorCore/Samplers/IImageSampler.cs @@ -0,0 +1,14 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Samplers +{ + /// + /// Acts as a marker for generic parameters that require an image sampler. + /// + public interface IImageSampler : IImageProcessor + { + } +} diff --git a/src/ImageProcessorCore/Samplers/ImageSampler.cs b/src/ImageProcessorCore/Samplers/ImageSampler.cs new file mode 100644 index 000000000..a78105ec3 --- /dev/null +++ b/src/ImageProcessorCore/Samplers/ImageSampler.cs @@ -0,0 +1,15 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Samplers +{ + /// + /// Applies sampling methods to an image. + /// All processors requiring resampling or resizing should inherit from this. + /// + public abstract class ImageSampler : ParallelImageProcessor, IImageSampler + { + } +} diff --git a/src/ImageProcessorCore/Samplers/ImageSampleExtensions.cs b/src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs similarity index 98% rename from src/ImageProcessorCore/Samplers/ImageSampleExtensions.cs rename to src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs index 6cff4bd2a..97cba15e2 100644 --- a/src/ImageProcessorCore/Samplers/ImageSampleExtensions.cs +++ b/src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -8,7 +8,7 @@ namespace ImageProcessorCore.Samplers /// /// Extensions methods for to apply samplers to the image. /// - public static class ImageSampleExtensions + public static class ImageSamplerExtensions { /// /// Crops an image to the given width and height. diff --git a/src/ImageProcessorCore/Samplers/Resampler.cs b/src/ImageProcessorCore/Samplers/Resampler.cs index e60f8c648..4b7239af4 100644 --- a/src/ImageProcessorCore/Samplers/Resampler.cs +++ b/src/ImageProcessorCore/Samplers/Resampler.cs @@ -12,7 +12,7 @@ namespace ImageProcessorCore.Samplers /// /// Provides methods that allow the resampling of images using various algorithms. /// - public abstract class Resampler : ParallelImageProcessor + public abstract class Resampler : ImageSampler { /// /// Initializes a new instance of the class. diff --git a/tests/ImageProcessorCore.Tests/Processors/Filters/FilterTests.cs b/tests/ImageProcessorCore.Tests/Processors/Filters/FilterTests.cs index 9214afdaa..bd1b17cb6 100644 --- a/tests/ImageProcessorCore.Tests/Processors/Filters/FilterTests.cs +++ b/tests/ImageProcessorCore.Tests/Processors/Filters/FilterTests.cs @@ -74,10 +74,5 @@ namespace ImageProcessorCore.Tests } } } - - private void ProgressUpdate(object sender, ProgressEventArgs e) - { - Assert.InRange(e.RowsProcessed, 1, e.TotalRows); - } } } diff --git a/tests/ImageProcessorCore.Tests/Processors/ProcessorTestBase.cs b/tests/ImageProcessorCore.Tests/Processors/ProcessorTestBase.cs index e6a45be88..e653702b0 100644 --- a/tests/ImageProcessorCore.Tests/Processors/ProcessorTestBase.cs +++ b/tests/ImageProcessorCore.Tests/Processors/ProcessorTestBase.cs @@ -9,6 +9,8 @@ namespace ImageProcessorCore.Tests { using System.Collections.Generic; + using Xunit; + /// /// The processor test base. /// @@ -29,5 +31,10 @@ namespace ImageProcessorCore.Tests "TestImages/Formats/Gif/rings.gif", //"TestImages/Formats/Gif/giphy.gif" // Perf: Enable for local testing only }; + + protected void ProgressUpdate(object sender, ProgressEventArgs e) + { + Assert.InRange(e.RowsProcessed, 1, e.TotalRows); + } } } diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs index 52600f1cc..93f6a36a6 100644 --- a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs @@ -30,7 +30,7 @@ //{ "Welch", new WelchResampler() } }; - public static readonly TheoryData Samplers = new TheoryData + public static readonly TheoryData Samplers = new TheoryData { { "Resize", new Resize(new BicubicResampler()) }, { "Crop", new Crop() } @@ -47,7 +47,7 @@ [Theory] [MemberData("Samplers")] - public void SampleImage(string name, IImageProcessor processor) + public void SampleImage(string name, IImageSampler processor) { if (!Directory.Exists("TestOutput/Sample")) { @@ -64,7 +64,8 @@ using (FileStream output = File.OpenWrite($"TestOutput/Sample/{ Path.GetFileName(filename) }")) { processor.OnProgress += this.ProgressUpdate; - image.Process(image.Width / 2, image.Height / 2, processor).Save(output); + image = image.Process(image.Width / 2, image.Height / 2, processor); + image.Save(output); processor.OnProgress -= this.ProgressUpdate; } @@ -269,10 +270,5 @@ Assert.Equal(result, expected); } - - private void ProgressUpdate(object sender, ProgressEventArgs e) - { - Assert.InRange(e.RowsProcessed, 1, e.TotalRows); - } } }