Browse Source

Add Kodachrome

Former-commit-id: 395bbf802c958615ed5e497675200a9868bd816d
Former-commit-id: ccc6ea01f5e2cf203991f4425e88faab7c56ac4c
Former-commit-id: 3ff1d2812e905ee76bdbf50c4ccd4c6e0ad62a82
af/merge-core
James Jackson-South 10 years ago
parent
commit
d54d4c1e48
  1. 58
      src/ImageProcessorCore/Filters/Kodachrome.cs
  2. 38
      tests/ImageProcessorCore.Tests/Processors/Filters/KodachromeTest.cs

58
src/ImageProcessorCore/Filters/Kodachrome.cs

@ -0,0 +1,58 @@
// <copyright file="Kodachrome.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image{T,TP}"/>.</returns>
public static Image<T, TP> Kodachrome<T, TP>(this Image<T, TP> source, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
return Kodachrome(source, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary>
/// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image{T,TP}"/>.</returns>
public static Image<T, TP> Kodachrome<T, TP>(this Image<T, TP> source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
KodachromeProcessor<T, TP> processor = new KodachromeProcessor<T, TP>();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

38
tests/ImageProcessorCore.Tests/Processors/Filters/KodachromeTest.cs

@ -0,0 +1,38 @@
// <copyright file="KodachromeTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
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);
}
}
}
}
}
}
Loading…
Cancel
Save