Browse Source

Generics FTW!

pull/1096/head
James Jackson-South 6 years ago
parent
commit
520cc5e19c
  1. 8
      src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs
  2. 12
      src/ImageSharp/Processing/PixelRowOperation.cs
  3. 16
      src/ImageSharp/Processing/PositionAwarePixelRowOperation.cs
  4. 2
      src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs
  5. 6
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs
  6. 9
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs

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

@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation)
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation)
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
/// <summary>
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, PixelConversionModifiers modifiers)
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers));
/// <summary>
@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, Rectangle rectangle)
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle)
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
/// <summary>
@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PositionAwarePixelRowOperation rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
}
}

12
src/ImageSharp/Processing/PixelRowOperation.cs

@ -12,4 +12,16 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <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>
public delegate void PixelRowOperation(Span<Vector4> span);
/// <summary>
/// A <see langword="delegate"/> representing a user defined processing delegate to use to modify image rows.
/// </summary>
/// <typeparam name="T">
/// 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.
/// </typeparam>
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <param name="value">The parameter of the method that this delegate encapsulates.</param>
/// <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>
public delegate void PixelRowOperation<in T>(Span<Vector4> span, T value);
}

16
src/ImageSharp/Processing/PositionAwarePixelRowOperation.cs

@ -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
{
/// <summary>
/// A <see langword="delegate"/> representing a user defined, position aware, processing delegate to use to modify image rows.
/// </summary>
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <param name="offset">The initial horizontal and vertical offset for the input pixels to process.</param>
/// <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>
public delegate void PositionAwarePixelRowOperation(Span<Vector4> span, Point offset);
}

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

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary>
/// Applies a user defined row processing delegate to the image.
/// </summary>
public sealed class PixelRowDelegateProcessor : IImageProcessor
internal sealed class PixelRowDelegateProcessor : IImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelRowDelegateProcessor"/> class.

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

@ -8,14 +8,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary>
/// Applies a user defined, position aware, row processing delegate to the image.
/// </summary>
public sealed class PositionAwarePixelRowDelegateProcessor : IImageProcessor
internal sealed class PositionAwarePixelRowDelegateProcessor : IImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelRowDelegateProcessor"/> class.
/// </summary>
/// <param name="pixelRowOperation">The user defined, position aware, row processing delegate.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PositionAwarePixelRowDelegateProcessor(PositionAwarePixelRowOperation pixelRowOperation, PixelConversionModifiers modifiers)
public PositionAwarePixelRowDelegateProcessor(PixelRowOperation<Point> pixelRowOperation, PixelConversionModifiers modifiers)
{
this.PixelRowOperation = pixelRowOperation;
this.Modifiers = modifiers;
@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// <summary>
/// Gets the user defined, position aware, row processing delegate.
/// </summary>
public PositionAwarePixelRowOperation PixelRowOperation { get; }
public PixelRowOperation<Point> PixelRowOperation { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.

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

@ -15,10 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
internal sealed class PositionAwarePixelRowDelegateProcessor<TPixel> : PixelRowDelegateProcessorBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// The user defined pixel shader.
/// </summary>
private readonly PositionAwarePixelRowOperation pixelShader;
private readonly PixelRowOperation<Point> pixelRowOperation;
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelRowDelegateProcessor{TPixel}"/> class.
@ -30,10 +27,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
public PositionAwarePixelRowDelegateProcessor(Configuration configuration, PositionAwarePixelRowDelegateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, definition.Modifiers, source, sourceRectangle)
{
this.pixelShader = definition.PixelRowOperation;
this.pixelRowOperation = definition.PixelRowOperation;
}
/// <inheritdoc/>
protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelShader(span, offset);
protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelRowOperation(span, offset);
}
}

Loading…
Cancel
Save