Skip to content

Commit 3b1266c

Browse files
Merge pull request #1096 from SixLabors/js/rename-pixel-shaders
Rename Pixel Shader Extensions and Delegates
2 parents 71547c4 + 520cc5e commit 3b1266c

13 files changed

+237
-285
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (c) Six Labors and contributors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using SixLabors.ImageSharp.PixelFormats;
5+
using SixLabors.ImageSharp.Processing.Processors.Effects;
6+
7+
namespace SixLabors.ImageSharp.Processing
8+
{
9+
/// <summary>
10+
/// Defines extension methods that allow the application of user defined processing delegate to an <see cref="Image"/>.
11+
/// </summary>
12+
public static class PixelRowDelegateExtensions
13+
{
14+
/// <summary>
15+
/// Applies a user defined processing delegate to the image.
16+
/// </summary>
17+
/// <param name="source">The image this method extends.</param>
18+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
19+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
20+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation)
21+
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
22+
23+
/// <summary>
24+
/// Applies a user defined processing delegate to the image.
25+
/// </summary>
26+
/// <param name="source">The image this method extends.</param>
27+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
28+
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
29+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
30+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, PixelConversionModifiers modifiers)
31+
=> source.ApplyProcessor(new PixelRowDelegateProcessor(rowOperation, modifiers));
32+
33+
/// <summary>
34+
/// Applies a user defined processing delegate to the image.
35+
/// </summary>
36+
/// <param name="source">The image this method extends.</param>
37+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
38+
/// <param name="rectangle">
39+
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
40+
/// </param>
41+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
42+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, Rectangle rectangle)
43+
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
44+
45+
/// <summary>
46+
/// Applies a user defined processing delegate to the image.
47+
/// </summary>
48+
/// <param name="source">The image this method extends.</param>
49+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
50+
/// <param name="rectangle">
51+
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
52+
/// </param>
53+
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
54+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
55+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
56+
=> source.ApplyProcessor(new PixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
57+
58+
/// <summary>
59+
/// Applies a user defined processing delegate to the image.
60+
/// </summary>
61+
/// <param name="source">The image this method extends.</param>
62+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
63+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
64+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation)
65+
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
66+
67+
/// <summary>
68+
/// Applies a user defined processing delegate to the image.
69+
/// </summary>
70+
/// <param name="source">The image this method extends.</param>
71+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
72+
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
73+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
74+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, PixelConversionModifiers modifiers)
75+
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers));
76+
77+
/// <summary>
78+
/// Applies a user defined processing delegate to the image.
79+
/// </summary>
80+
/// <param name="source">The image this method extends.</param>
81+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
82+
/// <param name="rectangle">
83+
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
84+
/// </param>
85+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
86+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle)
87+
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
88+
89+
/// <summary>
90+
/// Applies a user defined processing delegate to the image.
91+
/// </summary>
92+
/// <param name="source">The image this method extends.</param>
93+
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
94+
/// <param name="rectangle">
95+
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
96+
/// </param>
97+
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
98+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
99+
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
100+
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
101+
}
102+
}

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

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Six Labors and contributors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
using System.Numerics;
6+
7+
namespace SixLabors.ImageSharp.Processing
8+
{
9+
/// <summary>
10+
/// A <see langword="delegate"/> representing a user defined processing delegate to use to modify image rows.
11+
/// </summary>
12+
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
13+
/// <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>
14+
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);
27+
}

src/ImageSharp/Processing/PixelShader.cs

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

src/ImageSharp/Processing/PositionAwarePixelShader.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Six Labors and contributors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using SixLabors.ImageSharp.PixelFormats;
5+
6+
namespace SixLabors.ImageSharp.Processing.Processors.Effects
7+
{
8+
/// <summary>
9+
/// Applies a user defined row processing delegate to the image.
10+
/// </summary>
11+
internal sealed class PixelRowDelegateProcessor : IImageProcessor
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="PixelRowDelegateProcessor"/> class.
15+
/// </summary>
16+
/// <param name="pixelRowOperation">The user defined, row processing delegate.</param>
17+
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
18+
public PixelRowDelegateProcessor(PixelRowOperation pixelRowOperation, PixelConversionModifiers modifiers)
19+
{
20+
this.PixelRowOperation = pixelRowOperation;
21+
this.Modifiers = modifiers;
22+
}
23+
24+
/// <summary>
25+
/// Gets the user defined row processing delegate to the image.
26+
/// </summary>
27+
public PixelRowOperation PixelRowOperation { get; }
28+
29+
/// <summary>
30+
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
31+
/// </summary>
32+
public PixelConversionModifiers Modifiers { get; }
33+
34+
/// <inheritdoc />
35+
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
36+
where TPixel : struct, IPixel<TPixel>
37+
=> new PixelRowDelegateProcessor<TPixel>(configuration, this, source, sourceRectangle);
38+
}
39+
}

0 commit comments

Comments
 (0)