From d54d4c1e48566a013c0f50febc06b60eb776c6cc Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 28 Jul 2016 11:07:17 +1000 Subject: [PATCH] Add Kodachrome Former-commit-id: 395bbf802c958615ed5e497675200a9868bd816d Former-commit-id: ccc6ea01f5e2cf203991f4425e88faab7c56ac4c Former-commit-id: 3ff1d2812e905ee76bdbf50c4ccd4c6e0ad62a82 --- src/ImageProcessorCore/Filters/Kodachrome.cs | 58 +++++++++++++++++++ .../Processors/Filters/KodachromeTest.cs | 38 ++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/ImageProcessorCore/Filters/Kodachrome.cs create mode 100644 tests/ImageProcessorCore.Tests/Processors/Filters/KodachromeTest.cs diff --git a/src/ImageProcessorCore/Filters/Kodachrome.cs b/src/ImageProcessorCore/Filters/Kodachrome.cs new file mode 100644 index 000000000..4ab33e8f7 --- /dev/null +++ b/src/ImageProcessorCore/Filters/Kodachrome.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 + { + /// + /// Alters the colors of the image recreating an old Kodachrome camera effect. + /// + /// 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 Kodachrome(this Image source, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + return Kodachrome(source, source.Bounds, progressHandler); + } + + /// + /// Alters the colors of the image recreating an old Kodachrome camera effect. + /// + /// 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 Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + KodachromeProcessor processor = new KodachromeProcessor(); + processor.OnProgress += progressHandler; + + try + { + return source.Process(rectangle, processor); + } + finally + { + processor.OnProgress -= progressHandler; + } + } + } +} diff --git a/tests/ImageProcessorCore.Tests/Processors/Filters/KodachromeTest.cs b/tests/ImageProcessorCore.Tests/Processors/Filters/KodachromeTest.cs new file mode 100644 index 000000000..fa53bf5f3 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Filters/KodachromeTest.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 KodachromeTest : FileTestBase + { + [Fact] + public void ImageShouldApplyKodachromeFilter() + { + const string path = "TestOutput/Kodachrome"; + 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.Kodachrome() + .Save(output); + } + } + } + } + } +} \ No newline at end of file