Browse Source

Saturation, Sepia

Former-commit-id: f0b02bfd300840689af44740b52a9bd5f7e2e49d
Former-commit-id: 0883c72b9b8aed6625672c6a495613d4a2fbd9e1
Former-commit-id: 6a570bbd38d20705a3e1c025b083ab0b47b481b8
af/merge-core
James Jackson-South 10 years ago
parent
commit
142f334608
  1. 2
      src/ImageProcessorCore/Filters/Kodachrome.cs
  2. 60
      src/ImageProcessorCore/Filters/Saturation.cs
  3. 58
      src/ImageProcessorCore/Filters/Sepia.cs
  4. 47
      tests/ImageProcessorCore.Tests/Processors/Filters/SaturationTest.cs
  5. 38
      tests/ImageProcessorCore.Tests/Processors/Filters/SepiaTest.cs

2
src/ImageProcessorCore/Filters/Kodachrome.cs

@ -8,7 +8,7 @@ namespace ImageProcessorCore
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// Extension methods for the <see cref="Image{T,TP}"/> type.
/// </summary>
public static partial class ImageExtensions
{

60
src/ImageProcessorCore/Filters/Saturation.cs

@ -0,0 +1,60 @@
// <copyright file="Saturation.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{T,TP}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the saturation component of the image.
/// </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="amount">The new saturation of the image. Must be between -100 and 100.</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> Saturation<T, TP>(this Image<T, TP> source, int amount, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
return Saturation(source, amount, source.Bounds, progressHandler);
}
/// <summary>
/// Alters the saturation component of the image.
/// </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="amount">The new saturation of the image. Must be between -100 and 100.</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> Saturation<T, TP>(this Image<T, TP> source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
SaturationProcessor<T, TP> processor = new SaturationProcessor<T, TP>(amount);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

58
src/ImageProcessorCore/Filters/Sepia.cs

@ -0,0 +1,58 @@
// <copyright file="Sepia.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{T,TP}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies sepia toning to the image.
/// </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"/>.</returns>
public static Image<T, TP> Sepia<T, TP>(this Image<T, TP> source, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
return Sepia(source, source.Bounds, progressHandler);
}
/// <summary>
/// Applies sepia toning to the image.
/// </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"/>.</returns>
public static Image<T, TP> Sepia<T, TP>(this Image<T, TP> source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
SepiaProcessor<T, TP> processor = new SepiaProcessor<T, TP>();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

47
tests/ImageProcessorCore.Tests/Processors/Filters/SaturationTest.cs

@ -0,0 +1,47 @@
// <copyright file="SaturationTest.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 SaturationTest : FileTestBase
{
public static readonly TheoryData<int> SaturationValues
= new TheoryData<int>
{
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);
}
}
}
}
}
}

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

@ -0,0 +1,38 @@
// <copyright file="SepiaTest.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 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);
}
}
}
}
}
}
Loading…
Cancel
Save