using System.Runtime.CompilerServices; using Microsoft.Toolkit.Diagnostics; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32; 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(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) { Radius = radius; Components = components; } /// /// 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)) { ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format"); } var processor = new Implementation(this, configuration, Unsafe.As>(source), sourceRectangle); return Unsafe.As>(processor); } } }