diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs index 89bc2a947..daddf106c 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/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 /// public static partial class ImageExtensions { + /// + /// Applies Grayscale toning to the image. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static Image Grayscale(this Image source) + where TPixel : struct, IPixel + { + return Grayscale(source, GrayscaleMode.Bt709); + } + /// /// Applies Grayscale toning to the image. /// @@ -24,23 +34,41 @@ namespace ImageSharp /// The image this method extends. /// The formula to apply to perform the operation. /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709) + public static Image Grayscale(this Image source, GrayscaleMode mode) where TPixel : struct, IPixel { - return Grayscale(source, source.Bounds, mode); + return Grayscale(source, mode, source.Bounds); } /// - /// Applies Grayscale toning to the image. + /// Applies Grayscale toning to the image. /// /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// + /// The . + public static Image Grayscale(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel + { + IImageProcessor processor = new GrayscaleBt709Processor(); + + source.ApplyProcessor(processor, rectangle); + return source; + } + + /// + /// Applies Grayscale toning to the image. + /// + /// The pixel format. + /// The image this method extends. /// The formula to apply to perform the operation. + /// + /// The structure that specifies the portion of the image object to alter. + /// /// The . - public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) + public static Image Grayscale(this Image source, GrayscaleMode mode, Rectangle rectangle) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs index be0983df8..c68b7c5c3 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs @@ -51,7 +51,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix using (var image = new Image(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.