Skip to content

Commit 520cc5e

Browse files
Generics FTW!
1 parent ada16ab commit 520cc5e

File tree

6 files changed

+23
-30
lines changed

6 files changed

+23
-30
lines changed

src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProce
6161
/// <param name="source">The image this method extends.</param>
6262
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
6363
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
64-
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation)
64+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation)
6565
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
6666

6767
/// <summary>
@@ -71,7 +71,7 @@ public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProce
7171
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
7272
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
7373
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
74-
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, PixelConversionModifiers modifiers)
74+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, PixelConversionModifiers modifiers)
7575
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers));
7676

7777
/// <summary>
@@ -83,7 +83,7 @@ public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProce
8383
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
8484
/// </param>
8585
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
86-
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, Rectangle rectangle)
86+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle)
8787
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
8888

8989
/// <summary>
@@ -96,7 +96,7 @@ public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProce
9696
/// </param>
9797
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
9898
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
99-
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
99+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
100100
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
101101
}
102102
}

src/ImageSharp/Processing/PixelRowOperation.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ namespace SixLabors.ImageSharp.Processing
1212
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
1313
/// <remarks>The <see cref="Vector4.X"/>, <see cref="Vector4.Y"/>, <see cref="Vector4.Z"/>, and <see cref="Vector4.W"/> fields map the RGBA channels respectively.</remarks>
1414
public delegate void PixelRowOperation(Span<Vector4> span);
15+
16+
/// <summary>
17+
/// A <see langword="delegate"/> representing a user defined processing delegate to use to modify image rows.
18+
/// </summary>
19+
/// <typeparam name="T">
20+
/// The type of the parameter of the method that this delegate encapsulates.
21+
/// This type parameter is contravariant.That is, you can use either the type you specified or any type that is less derived.
22+
/// </typeparam>
23+
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
24+
/// <param name="value">The parameter of the method that this delegate encapsulates.</param>
25+
/// <remarks>The <see cref="Vector4.X"/>, <see cref="Vector4.Y"/>, <see cref="Vector4.Z"/>, and <see cref="Vector4.W"/> fields map the RGBA channels respectively.</remarks>
26+
public delegate void PixelRowOperation<in T>(Span<Vector4> span, T value);
1527
}

src/ImageSharp/Processing/PositionAwarePixelRowOperation.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
88
/// <summary>
99
/// Applies a user defined row processing delegate to the image.
1010
/// </summary>
11-
public sealed class PixelRowDelegateProcessor : IImageProcessor
11+
internal sealed class PixelRowDelegateProcessor : IImageProcessor
1212
{
1313
/// <summary>
1414
/// Initializes a new instance of the <see cref="PixelRowDelegateProcessor"/> class.

src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
88
/// <summary>
99
/// Applies a user defined, position aware, row processing delegate to the image.
1010
/// </summary>
11-
public sealed class PositionAwarePixelRowDelegateProcessor : IImageProcessor
11+
internal sealed class PositionAwarePixelRowDelegateProcessor : IImageProcessor
1212
{
1313
/// <summary>
1414
/// Initializes a new instance of the <see cref="PositionAwarePixelRowDelegateProcessor"/> class.
1515
/// </summary>
1616
/// <param name="pixelRowOperation">The user defined, position aware, row processing delegate.</param>
1717
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
18-
public PositionAwarePixelRowDelegateProcessor(PositionAwarePixelRowOperation pixelRowOperation, PixelConversionModifiers modifiers)
18+
public PositionAwarePixelRowDelegateProcessor(PixelRowOperation<Point> pixelRowOperation, PixelConversionModifiers modifiers)
1919
{
2020
this.PixelRowOperation = pixelRowOperation;
2121
this.Modifiers = modifiers;
@@ -24,7 +24,7 @@ public PositionAwarePixelRowDelegateProcessor(PositionAwarePixelRowOperation pix
2424
/// <summary>
2525
/// Gets the user defined, position aware, row processing delegate.
2626
/// </summary>
27-
public PositionAwarePixelRowOperation PixelRowOperation { get; }
27+
public PixelRowOperation<Point> PixelRowOperation { get; }
2828

2929
/// <summary>
3030
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.

src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
1515
internal sealed class PositionAwarePixelRowDelegateProcessor<TPixel> : PixelRowDelegateProcessorBase<TPixel>
1616
where TPixel : struct, IPixel<TPixel>
1717
{
18-
/// <summary>
19-
/// The user defined pixel shader.
20-
/// </summary>
21-
private readonly PositionAwarePixelRowOperation pixelShader;
18+
private readonly PixelRowOperation<Point> pixelRowOperation;
2219

2320
/// <summary>
2421
/// Initializes a new instance of the <see cref="PositionAwarePixelRowDelegateProcessor{TPixel}"/> class.
@@ -30,10 +27,10 @@ internal sealed class PositionAwarePixelRowDelegateProcessor<TPixel> : PixelRowD
3027
public PositionAwarePixelRowDelegateProcessor(Configuration configuration, PositionAwarePixelRowDelegateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
3128
: base(configuration, definition.Modifiers, source, sourceRectangle)
3229
{
33-
this.pixelShader = definition.PixelRowOperation;
30+
this.pixelRowOperation = definition.PixelRowOperation;
3431
}
3532

3633
/// <inheritdoc/>
37-
protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelShader(span, offset);
34+
protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelRowOperation(span, offset);
3835
}
3936
}

0 commit comments

Comments
 (0)