Browse Source

BlackWhite

Former-commit-id: 08361487c9988e874329dee40c21725ae6cc3a90
Former-commit-id: da89003e33f7ab41ee727e787c39d898af0b1e8d
Former-commit-id: 7e90879b76b3a162d664e2c5bb0cd782e6dd6e77
af/merge-core
James Jackson-South 10 years ago
parent
commit
4540b42652
  1. 58
      src/ImageProcessorCore/Filters/BlackWhite.cs
  2. 38
      tests/ImageProcessorCore.Tests/Processors/Filters/BlackWhiteTest.cs

58
src/ImageProcessorCore/Filters/BlackWhite.cs

@ -0,0 +1,58 @@
// <copyright file="BlackWhite.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 black and white 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{T,TP}"/>.</returns>
public static Image<T, TP> BlackWhite<T, TP>(this Image<T, TP> source, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
return BlackWhite(source, source.Bounds, progressHandler);
}
/// <summary>
/// Applies black and white 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{T,TP}"/>.</returns>
public static Image<T, TP> BlackWhite<T, TP>(this Image<T, TP> source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
BlackWhiteProcessor<T, TP> processor = new BlackWhiteProcessor<T, TP>();
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

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

@ -0,0 +1,38 @@
// <copyright file="BlackWhiteTest.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 BlackWhiteTest : FileTestBase
{
[Fact]
public void ImageShouldApplyBlackWhiteFilter()
{
const string path = "TestOutput/BlackWhite";
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.BlackWhite()
.Save(output);
}
}
}
}
}
}
Loading…
Cancel
Save