Browse Source

Merge pull request #1096 from SixLabors/js/rename-pixel-shaders

Rename Pixel Shader Extensions and Delegates
af/octree-no-pixelmap
James Jackson-South 6 years ago
committed by GitHub
parent
commit
f3652b7f68
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 102
      src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs
  2. 102
      src/ImageSharp/Processing/Extensions/Effects/PixelShaderExtensions.cs
  3. 27
      src/ImageSharp/Processing/PixelRowOperation.cs
  4. 15
      src/ImageSharp/Processing/PixelShader.cs
  5. 16
      src/ImageSharp/Processing/PositionAwarePixelShader.cs
  6. 39
      src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs
  7. 21
      src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs
  8. 18
      src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel}.cs
  9. 58
      src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor.cs
  10. 39
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs
  11. 19
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs
  12. 58
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor.cs
  13. 8
      tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs

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

@ -0,0 +1,102 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Effects;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Defines extension methods that allow the application of user defined processing delegate to an <see cref="Image"/>.
/// </summary>
public static class PixelRowDelegateExtensions
{
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <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, PixelRowOperation rowOperation)
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <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, PixelRowOperation rowOperation, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelRowDelegateProcessor(rowOperation, modifiers));
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// 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, PixelRowOperation rowOperation, Rectangle rectangle)
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </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, PixelRowOperation rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <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, PixelRowOperation<Point> rowOperation)
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <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, PixelRowOperation<Point> rowOperation, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers));
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// 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, PixelRowOperation<Point> rowOperation, Rectangle rectangle)
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </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, PixelRowOperation<Point> rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
}
}

102
src/ImageSharp/Processing/Extensions/Effects/PixelShaderExtensions.cs

@ -1,102 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Effects;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Defines extension methods that allow the application of user defined pixel shaders to an <see cref="Image"/>.
/// </summary>
public static class PixelShaderExtensions
{
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</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 ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader, modifiers));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// 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 ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader, Rectangle rectangle)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader), rectangle);
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </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 ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader, modifiers), rectangle);
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</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 ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader, modifiers));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// 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 ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader, Rectangle rectangle)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader), rectangle);
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </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 ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader, modifiers), rectangle);
}
}

27
src/ImageSharp/Processing/PixelRowOperation.cs

@ -0,0 +1,27 @@
// 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 processing delegate to use to modify image rows.
/// </summary>
/// <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);
}

15
src/ImageSharp/Processing/PixelShader.cs

@ -1,15 +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 pixel shader.
/// </summary>
/// <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 PixelShader(Span<Vector4> span);
}

16
src/ImageSharp/Processing/PositionAwarePixelShader.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 pixel shader.
/// </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 PositionAwarePixelShader(Span<Vector4> span, Point offset);
}

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

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined row processing delegate to the image.
/// </summary>
internal sealed class PixelRowDelegateProcessor : IImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelRowDelegateProcessor"/> class.
/// </summary>
/// <param name="pixelRowOperation">The user defined, row processing delegate.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PixelRowDelegateProcessor(PixelRowOperation pixelRowOperation, PixelConversionModifiers modifiers)
{
this.PixelRowOperation = pixelRowOperation;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined row processing delegate to the image.
/// </summary>
public PixelRowOperation PixelRowOperation { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PixelRowDelegateProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

21
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs → src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs

@ -3,7 +3,6 @@
using System;
using System.Numerics;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Advanced.ParallelUtils;
using SixLabors.ImageSharp.PixelFormats;
@ -11,10 +10,10 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined pixel shader effect through a given delegate.
/// The base class for all processors that accept a user defined row processing delegate.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class PixelShaderProcessorBase<TPixel> : ImageProcessor<TPixel>
internal abstract class PixelRowDelegateProcessorBase<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
@ -23,17 +22,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
private readonly PixelConversionModifiers modifiers;
/// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessorBase{TPixel}"/> class.
/// Initializes a new instance of the <see cref="PixelRowDelegateProcessorBase{TPixel}"/> class.
/// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
protected PixelShaderProcessorBase(Configuration configuration, PixelConversionModifiers modifiers, Image<TPixel> source, Rectangle sourceRectangle)
protected PixelRowDelegateProcessorBase(Configuration configuration, PixelConversionModifiers modifiers, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
this.modifiers = modifiers;
}
=> this.modifiers = modifiers;
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source)
@ -55,8 +52,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
Span<TPixel> rowSpan = source.GetPixelRowSpan(y).Slice(startX, length);
PixelOperations<TPixel>.Instance.ToVector4(configuration, rowSpan, vectorSpan, modifiers);
// Run the user defined pixel shader on the current row of pixels
this.ApplyPixelShader(vectorSpan, new Point(startX, y));
// Run the user defined pixel shader to the current row of pixels
this.ApplyPixelRowDelegate(vectorSpan, new Point(startX, y));
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, rowSpan, modifiers);
}
@ -64,10 +61,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
}
/// <summary>
/// Applies the current pixel shader effect on a target row of preprocessed pixels.
/// Applies the current pixel row delegate to a target row of preprocessed pixels.
/// </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>
protected abstract void ApplyPixelShader(Span<Vector4> span, Point offset);
protected abstract void ApplyPixelRowDelegate(Span<Vector4> span, Point offset);
}
}

18
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs → src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel}.cs

@ -9,31 +9,31 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined pixel shader effect through a given delegate.
/// Applies a user defined row processing delegate to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal sealed class PixelShaderProcessor<TPixel> : PixelShaderProcessorBase<TPixel>
internal sealed class PixelRowDelegateProcessor<TPixel> : PixelRowDelegateProcessorBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// The user defined pixel shader.
/// The user defined pixel row processing delegate.
/// </summary>
private readonly PixelShader pixelShader;
private readonly PixelRowOperation pixelRowOperation;
/// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="PixelRowDelegateProcessor{TPixel}"/> class.
/// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PixelShaderProcessor"/> defining the processor parameters.</param>
/// <param name="definition">The <see cref="PixelRowDelegateProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PixelShaderProcessor(Configuration configuration, PixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
public PixelRowDelegateProcessor(Configuration configuration, PixelRowDelegateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, definition.Modifiers, source, sourceRectangle)
{
this.pixelShader = definition.PixelShader;
this.pixelRowOperation = definition.PixelRowOperation;
}
/// <inheritdoc/>
protected override void ApplyPixelShader(Span<Vector4> span, Point offset) => this.pixelShader(span);
protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelRowOperation(span);
}
}

58
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor.cs

@ -1,58 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined pixel shader effect through a given delegate.
/// </summary>
public sealed class PixelShaderProcessor : IImageProcessor
{
/// <summary>
/// The default <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public const PixelConversionModifiers DefaultModifiers = PixelConversionModifiers.None;
/// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
public PixelShaderProcessor(PixelShader pixelShader)
{
this.PixelShader = pixelShader;
this.Modifiers = DefaultModifiers;
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PixelShaderProcessor(PixelShader pixelShader, PixelConversionModifiers modifiers)
{
this.PixelShader = pixelShader;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined pixel shader.
/// </summary>
public PixelShader PixelShader { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PixelShaderProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

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

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined, position aware, row processing delegate to the image.
/// </summary>
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(PixelRowOperation<Point> pixelRowOperation, PixelConversionModifiers modifiers)
{
this.PixelRowOperation = pixelRowOperation;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined, position aware, row processing delegate.
/// </summary>
public PixelRowOperation<Point> PixelRowOperation { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PositionAwarePixelRowDelegateProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

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

@ -9,31 +9,28 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined pixel shader effect through a given delegate.
/// Applies a user defined, position aware, row processing delegate to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal sealed class PositionAwarePixelShaderProcessor<TPixel> : PixelShaderProcessorBase<TPixel>
internal sealed class PositionAwarePixelRowDelegateProcessor<TPixel> : PixelRowDelegateProcessorBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// The user defined pixel shader.
/// </summary>
private readonly PositionAwarePixelShader pixelShader;
private readonly PixelRowOperation<Point> pixelRowOperation;
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor{TPixel}"/> class.
/// Initializes a new instance of the <see cref="PositionAwarePixelRowDelegateProcessor{TPixel}"/> class.
/// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PositionAwarePixelShaderProcessor"/> defining the processor parameters.</param>
/// <param name="definition">The <see cref="PositionAwarePixelRowDelegateProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PositionAwarePixelShaderProcessor(Configuration configuration, PositionAwarePixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
public PositionAwarePixelRowDelegateProcessor(Configuration configuration, PositionAwarePixelRowDelegateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, definition.Modifiers, source, sourceRectangle)
{
this.pixelShader = definition.PixelShader;
this.pixelRowOperation = definition.PixelRowOperation;
}
/// <inheritdoc/>
protected override void ApplyPixelShader(Span<Vector4> span, Point offset) => this.pixelShader(span, offset);
protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelRowOperation(span, offset);
}
}

58
src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor.cs

@ -1,58 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined pixel shader effect through a given delegate.
/// </summary>
public sealed class PositionAwarePixelShaderProcessor : IImageProcessor
{
/// <summary>
/// The default <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public const PixelConversionModifiers DefaultModifiers = PixelConversionModifiers.None;
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
public PositionAwarePixelShaderProcessor(PositionAwarePixelShader pixelShader)
{
this.PixelShader = pixelShader;
this.Modifiers = DefaultModifiers;
}
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PositionAwarePixelShaderProcessor(PositionAwarePixelShader pixelShader, PixelConversionModifiers modifiers)
{
this.PixelShader = pixelShader;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined pixel shader.
/// </summary>
public PositionAwarePixelShader PixelShader { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PositionAwarePixelShaderProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

8
tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel>
{
provider.RunValidatingProcessorTest(
x => x.ApplyPixelShaderProcessor(
x => x.ProcessPixelRowsAsVector4(
span =>
{
for (int i = 0; i < span.Length; i++)
@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel>
{
provider.RunRectangleConstrainedValidatingProcessorTest(
(x, rect) => x.ApplyPixelShaderProcessor(
(x, rect) => x.ProcessPixelRowsAsVector4(
span =>
{
for (int i = 0; i < span.Length; i++)
@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel>
{
provider.RunValidatingProcessorTest(
c => c.ApplyPixelShaderProcessor(
c => c.ProcessPixelRowsAsVector4(
(span, offset) =>
{
int y = offset.Y;
@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel>
{
provider.RunRectangleConstrainedValidatingProcessorTest(
(c, rect) => c.ApplyPixelShaderProcessor(
(c, rect) => c.ProcessPixelRowsAsVector4(
(span, offset) =>
{
int y = offset.Y;

Loading…
Cancel
Save