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