using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
#pragma warning disable IDE0290
namespace ComputeSharp.BokehBlur.Processors;
///
/// Defines Gaussian blur by a (Sigma, Radius) pair.
///
public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
{
///
/// The default value for .
///
public const float DefaultSigma = 3f;
///
/// Initializes a new instance of the class.
///
public HlslGaussianBlurProcessor()
: this(GraphicsDevice.GetDefault(), DefaultSigma, 9)
{
}
///
/// Initializes a new instance of the class.
///
/// The radius value representing the size of the area to sample.
public HlslGaussianBlurProcessor(int radius)
: this(GraphicsDevice.GetDefault(), radius / 3F, radius)
{
}
///
/// Initializes a new instance of the class.
///
/// The associated with the current instance.
/// The radius value representing the size of the area to sample.
public HlslGaussianBlurProcessor(GraphicsDevice device, int radius)
: this(device, radius / 3F, radius)
{
}
///
/// Initializes a new instance of the class.
///
/// The associated with the current instance.
/// The sigma value representing the weight of the blur.
/// The radius value representing the size of the area to sample (this should be at least twice the sigma value)
public HlslGaussianBlurProcessor(GraphicsDevice device, float sigma, int radius)
{
this.graphicsDevice = device;
Sigma = sigma;
Radius = radius;
}
///
/// The instance in use.
///
private readonly GraphicsDevice graphicsDevice;
///
/// Gets the sigma value representing the weight of the blur.
///
public float Sigma { get; }
///
/// Gets the radius defining the size of the area to sample.
///
public int Radius { get; }
///
public IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle)
where TPixel : unmanaged, IPixel
{
if (typeof(TPixel) != typeof(ImageSharpRgba32))
{
throw new NotSupportedException("This processor only supports the RGBA32 pixel format.");
}
Implementation processor = new(this, configuration, Unsafe.As>(source), sourceRectangle);
return Unsafe.As>(processor);
}
}