//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp
{
using System;
using Processing;
using Processing.Processors;
///
/// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Applies Grayscale toning to the image.
///
/// The pixel format.
/// 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)
where TColor : struct, IPixel
{
return Grayscale(source, source.Bounds, mode);
}
///
/// 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 formula to apply to perform the operation.
/// The .
public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPixel
{
IImageProcessor processor = mode == GrayscaleMode.Bt709
? (IImageProcessor)new GrayscaleBt709Processor()
: new GrayscaleBt601Processor();
source.ApplyProcessor(processor, rectangle);
return source;
}
}
}