Browse Source

Fix Grayscale param order

af/merge-core
James Jackson-South 9 years ago
parent
commit
1ca02ea014
  1. 40
      src/ImageSharp/Processing/ColorMatrix/Grayscale.cs
  2. 2
      tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs

40
src/ImageSharp/Processing/ColorMatrix/Grayscale.cs

@ -5,8 +5,6 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
@ -17,6 +15,18 @@ namespace ImageSharp
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
return Grayscale(source, GrayscaleMode.Bt709);
}
/// <summary>
/// Applies Grayscale toning to the image.
/// </summary>
@ -24,23 +34,41 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, GrayscaleMode mode = GrayscaleMode.Bt709)
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, GrayscaleMode mode)
where TPixel : struct, IPixel<TPixel>
{
return Grayscale(source, source.Bounds, mode);
return Grayscale(source, mode, source.Bounds);
}
/// <summary>
/// Applies Grayscale toning to the image.
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</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>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
IImageProcessor<TPixel> processor = new GrayscaleBt709Processor<TPixel>();
source.ApplyProcessor(processor, rectangle);
return source;
}
/// <summary>
/// Applies Grayscale toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, GrayscaleMode mode, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
IImageProcessor<TPixel> processor = mode == GrayscaleMode.Bt709

2
tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs

@ -51,7 +51,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
using (var image = new Image<TPixel>(source))
{
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Grayscale(bounds, value)
image.Grayscale(value, bounds)
.DebugSave(provider, value.ToString());
// Draw identical shapes over the bounded and compare to ensure changes are constrained.

Loading…
Cancel
Save