diff --git a/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs b/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs index ca4f9598ea..b622141b73 100644 --- a/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing /// The image this method extends. /// The user defined processing delegate to use to modify image rows. /// The to allow chaining of operations. - public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation) + public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation) => ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None); /// @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing /// The user defined processing delegate to use to modify image rows. /// The to apply during the pixel conversions. /// The to allow chaining of operations. - public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, PixelConversionModifiers modifiers) + public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, PixelConversionModifiers modifiers) => source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers)); /// @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing /// The structure that specifies the portion of the image object to alter. /// /// The to allow chaining of operations. - public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, Rectangle rectangle) + public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, Rectangle rectangle) => ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None); /// @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing /// /// The to apply during the pixel conversions. /// The to allow chaining of operations. - public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers) + public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers) => source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers), rectangle); } } diff --git a/src/ImageSharp/Processing/PixelRowOperation.cs b/src/ImageSharp/Processing/PixelRowOperation.cs index 6ef5b8bc3a..6857b24f19 100644 --- a/src/ImageSharp/Processing/PixelRowOperation.cs +++ b/src/ImageSharp/Processing/PixelRowOperation.cs @@ -12,4 +12,16 @@ namespace SixLabors.ImageSharp.Processing /// The target row of pixels to process. /// The , , , and fields map the RGBA channels respectively. public delegate void PixelRowOperation(Span span); + + /// + /// A representing a user defined processing delegate to use to modify image rows. + /// + /// + /// The type of the parameter of the method that this delegate encapsulates. + /// This type parameter is contravariant.That is, you can use either the type you specified or any type that is less derived. + /// + /// The target row of pixels to process. + /// The parameter of the method that this delegate encapsulates. + /// The , , , and fields map the RGBA channels respectively. + public delegate void PixelRowOperation(Span span, T value); } diff --git a/src/ImageSharp/Processing/PositionAwarePixelRowOperation.cs b/src/ImageSharp/Processing/PositionAwarePixelRowOperation.cs deleted file mode 100644 index c9fb1f96eb..0000000000 --- a/src/ImageSharp/Processing/PositionAwarePixelRowOperation.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Numerics; - -namespace SixLabors.ImageSharp.Processing -{ - /// - /// A representing a user defined, position aware, processing delegate to use to modify image rows. - /// - /// The target row of pixels to process. - /// The initial horizontal and vertical offset for the input pixels to process. - /// The , , , and fields map the RGBA channels respectively. - public delegate void PositionAwarePixelRowOperation(Span span, Point offset); -} diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs index 84305bea3a..5bdc0bc80b 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects /// /// Applies a user defined row processing delegate to the image. /// - public sealed class PixelRowDelegateProcessor : IImageProcessor + internal sealed class PixelRowDelegateProcessor : IImageProcessor { /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs index f4a6c7ac07..bf21f5b9b1 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs @@ -8,14 +8,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects /// /// Applies a user defined, position aware, row processing delegate to the image. /// - public sealed class PositionAwarePixelRowDelegateProcessor : IImageProcessor + internal sealed class PositionAwarePixelRowDelegateProcessor : IImageProcessor { /// /// Initializes a new instance of the class. /// /// The user defined, position aware, row processing delegate. /// The to apply during the pixel conversions. - public PositionAwarePixelRowDelegateProcessor(PositionAwarePixelRowOperation pixelRowOperation, PixelConversionModifiers modifiers) + public PositionAwarePixelRowDelegateProcessor(PixelRowOperation pixelRowOperation, PixelConversionModifiers modifiers) { this.PixelRowOperation = pixelRowOperation; this.Modifiers = modifiers; @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects /// /// Gets the user defined, position aware, row processing delegate. /// - public PositionAwarePixelRowOperation PixelRowOperation { get; } + public PixelRowOperation PixelRowOperation { get; } /// /// Gets the to apply during the pixel conversions. diff --git a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs index 7242d8dcb4..901a3a9856 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs @@ -15,10 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects internal sealed class PositionAwarePixelRowDelegateProcessor : PixelRowDelegateProcessorBase where TPixel : struct, IPixel { - /// - /// The user defined pixel shader. - /// - private readonly PositionAwarePixelRowOperation pixelShader; + private readonly PixelRowOperation pixelRowOperation; /// /// Initializes a new instance of the class. @@ -30,10 +27,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects public PositionAwarePixelRowDelegateProcessor(Configuration configuration, PositionAwarePixelRowDelegateProcessor definition, Image source, Rectangle sourceRectangle) : base(configuration, definition.Modifiers, source, sourceRectangle) { - this.pixelShader = definition.PixelRowOperation; + this.pixelRowOperation = definition.PixelRowOperation; } /// - protected override void ApplyPixelRowDelegate(Span span, Point offset) => this.pixelShader(span, offset); + protected override void ApplyPixelRowDelegate(Span span, Point offset) => this.pixelRowOperation(span, offset); } }