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;
///
/// Applies bokeh blur processing to the image.
///
public sealed partial class HlslBokehBlurProcessor : IImageProcessor
{
///
/// The default radius used by the parameterless constructor.
///
public const int DefaultRadius = 32;
///
/// The default component count used by the parameterless constructor.
///
public const int DefaultComponents = 2;
///
/// Initializes a new instance of the class.
///
public HlslBokehBlurProcessor()
: this(GraphicsDevice.GetDefault(), DefaultRadius, DefaultComponents)
{
}
///
/// Initializes a new instance of the class.
///
/// The size of the area to sample.
/// The number of components to use to approximate the original 2D bokeh blur convolution kernel.
public HlslBokehBlurProcessor(int radius, int components)
: this(GraphicsDevice.GetDefault(), radius, components)
{
}
///
/// Initializes a new instance of the class.
///
/// The associated with the current instance.
/// The size of the area to sample.
/// The number of components to use to approximate the original 2D bokeh blur convolution kernel.
public HlslBokehBlurProcessor(GraphicsDevice device, int radius, int components)
{
GraphicsDevice = device;
Radius = radius;
Components = components;
}
///
/// Gets the associated with the current instance.
///
public GraphicsDevice GraphicsDevice { get; }
///
/// Gets the radius.
///
public int Radius { get; }
///
/// Gets the number of components.
///
public int Components { 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);
}
}