diff --git a/src/ImageProcessorCore/Filters/Kodachrome.cs b/src/ImageProcessorCore/Filters/Kodachrome.cs index 4ab33e8f7..0f4bf2ae8 100644 --- a/src/ImageProcessorCore/Filters/Kodachrome.cs +++ b/src/ImageProcessorCore/Filters/Kodachrome.cs @@ -8,7 +8,7 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { diff --git a/src/ImageProcessorCore/Filters/Saturation.cs b/src/ImageProcessorCore/Filters/Saturation.cs new file mode 100644 index 000000000..3c39d4e5c --- /dev/null +++ b/src/ImageProcessorCore/Filters/Saturation.cs @@ -0,0 +1,60 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// ------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessorCore +{ + using Processors; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Alters the saturation component of the image. + /// + /// The pixel format. + /// The packed format. long, float. + /// The image this method extends. + /// The new saturation of the image. Must be between -100 and 100. + /// A delegate which is called as progress is made processing the image. + /// The . + public static Image Saturation(this Image source, int amount, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + return Saturation(source, amount, source.Bounds, progressHandler); + } + + /// + /// Alters the saturation component of the image. + /// + /// The pixel format. + /// The packed format. long, float. + /// The image this method extends. + /// The new saturation of the image. Must be between -100 and 100. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// A delegate which is called as progress is made processing the image. + /// The . + public static Image Saturation(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + SaturationProcessor processor = new SaturationProcessor(amount); + processor.OnProgress += progressHandler; + + try + { + return source.Process(rectangle, processor); + } + finally + { + processor.OnProgress -= progressHandler; + } + } + } +} diff --git a/src/ImageProcessorCore/Filters/Sepia.cs b/src/ImageProcessorCore/Filters/Sepia.cs new file mode 100644 index 000000000..6a007d3b3 --- /dev/null +++ b/src/ImageProcessorCore/Filters/Sepia.cs @@ -0,0 +1,58 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore +{ + using Processors; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Applies sepia toning to the image. + /// + /// The pixel format. + /// The packed format. long, float. + /// The image this method extends. + /// A delegate which is called as progress is made processing the image. + /// The . + public static Image Sepia(this Image source, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + return Sepia(source, source.Bounds, progressHandler); + } + + /// + /// Applies sepia toning to the image. + /// + /// The pixel format. + /// The packed format. long, float. + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// A delegate which is called as progress is made processing the image. + /// The . + public static Image Sepia(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + SepiaProcessor processor = new SepiaProcessor(); + processor.OnProgress += progressHandler; + + try + { + return source.Process(rectangle, processor); + } + finally + { + processor.OnProgress -= progressHandler; + } + } + } +} diff --git a/tests/ImageProcessorCore.Tests/Processors/Filters/SaturationTest.cs b/tests/ImageProcessorCore.Tests/Processors/Filters/SaturationTest.cs new file mode 100644 index 000000000..2dbfadb68 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Filters/SaturationTest.cs @@ -0,0 +1,47 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class SaturationTest : FileTestBase + { + public static readonly TheoryData SaturationValues + = new TheoryData + { + 50 , + -50 , + }; + + [Theory] + [MemberData("SaturationValues")] + public void ImageShouldApplySaturationFilter(int value) + { + const string path = "TestOutput/Saturation"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileNameWithoutExtension(file) + "-" + value + Path.GetExtension(file); + + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.Saturation(value) + .Save(output); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Filters/SepiaTest.cs b/tests/ImageProcessorCore.Tests/Processors/Filters/SepiaTest.cs new file mode 100644 index 000000000..f8017d4b4 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Filters/SepiaTest.cs @@ -0,0 +1,38 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class SepiaTest : FileTestBase + { + [Fact] + public void ImageShouldApplySepiaFilter() + { + const string path = "TestOutput/Sepia"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileName(file); + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.Sepia() + .Save(output); + } + } + } + } + } +} \ No newline at end of file