diff --git a/src/ImageSharp/Processing/Extensions/PixelShaderExtensions.cs b/src/ImageSharp/Processing/Extensions/Effects/PixelShaderExtensions.cs
similarity index 100%
rename from src/ImageSharp/Processing/Extensions/PixelShaderExtensions.cs
rename to src/ImageSharp/Processing/Extensions/Effects/PixelShaderExtensions.cs
diff --git a/src/ImageSharp/Processing/PositionAwarePixelShader.cs b/src/ImageSharp/Processing/PositionAwarePixelShader.cs
index 63e9246b41..1ae3ba295a 100644
--- a/src/ImageSharp/Processing/PositionAwarePixelShader.cs
+++ b/src/ImageSharp/Processing/PositionAwarePixelShader.cs
@@ -3,6 +3,7 @@
using System;
using System.Numerics;
+using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
@@ -10,8 +11,7 @@ namespace SixLabors.ImageSharp.Processing
/// A representing a user defined pixel shader.
///
/// The target row of pixels to process.
- /// The initial vertical offset for the input pixels to process.
- /// The initial horizontal offset for the input 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 PositionAwarePixelShader(Span span, int offsetY, int offsetX);
+ public delegate void PositionAwarePixelShader(Span span, Point offset);
}
diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs b/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs
index d75d23a51f..d46a4cf320 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs
@@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
PixelOperations.Instance.ToVector4(configuration, rowSpan, vectorSpan, modifiers);
// Run the user defined pixel shader on the current row of pixels
- this.ApplyPixelShader(vectorSpan, y, startX);
+ this.ApplyPixelShader(vectorSpan, new Point(startX, y));
PixelOperations.Instance.FromVector4Destructive(configuration, vectorSpan, rowSpan, modifiers);
}
@@ -67,8 +67,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// Applies the current pixel shader effect on a target row of preprocessed pixels.
///
/// The target row of pixels to process.
- /// The initial vertical offset for the input pixels to process.
- /// The initial horizontal offset for the input pixels to process.
- protected abstract void ApplyPixelShader(Span span, int offsetY, int offsetX);
+ /// The initial horizontal and vertical offset for the input pixels to process.
+ protected abstract void ApplyPixelShader(Span span, Point offset);
}
}
diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs
index 4abd698386..ce7b858a3e 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// Applies a user defined pixel shader effect through a given delegate.
///
/// The pixel format.
- internal class PixelShaderProcessor : PixelShaderProcessorBase
+ internal sealed class PixelShaderProcessor : PixelShaderProcessorBase
where TPixel : struct, IPixel
{
///
@@ -34,6 +34,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
}
///
- protected override void ApplyPixelShader(Span span, int offsetY, int offsetX) => this.pixelShader(span);
+ protected override void ApplyPixelShader(Span span, Point offset) => this.pixelShader(span);
}
}
diff --git a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor{TPixel}.cs
index 3b9f37b485..549dedac15 100644
--- a/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor{TPixel}.cs
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
/// Applies a user defined pixel shader effect through a given delegate.
///
/// The pixel format.
- internal class PositionAwarePixelShaderProcessor : PixelShaderProcessorBase
+ internal sealed class PositionAwarePixelShaderProcessor : PixelShaderProcessorBase
where TPixel : struct, IPixel
{
///
@@ -34,6 +34,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
}
///
- protected override void ApplyPixelShader(Span span, int offsetY, int offsetX) => this.pixelShader(span, offsetY, offsetX);
+ protected override void ApplyPixelShader(Span span, Point offset) => this.pixelShader(span, offset);
}
}
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs
index d9af215b97..c18f043852 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs
@@ -58,8 +58,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
provider.RunValidatingProcessorTest(
c => c.ApplyPixelShaderProcessor(
- (span, y, x) =>
+ (span, offset) =>
{
+ int y = offset.Y;
+ int x = offset.X;
for (int i = 0; i < span.Length; i++)
{
float
@@ -67,8 +69,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
cosine = MathF.Cos(x + i),
sum = sine + cosine,
abs = MathF.Abs(sum),
- a = 0.5f + abs / 2; // Max value for sin(y) + cos(x) is 2
-
+ a = 0.5f + (abs / 2); // Max value for sin(y) + cos(x) is 2
+
Vector4 v4 = span[i];
float avg = (v4.X + v4.Y + v4.Z) / 3f;
var gray = new Vector4(avg, avg, avg, a);
@@ -86,8 +88,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
provider.RunRectangleConstrainedValidatingProcessorTest(
(c, rect) => c.ApplyPixelShaderProcessor(
- (span, y, x) =>
+ (span, offset) =>
{
+ int y = offset.Y;
+ int x = offset.X;
for (int i = 0; i < span.Length; i++)
{
float
@@ -95,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
cosine = MathF.Cos(x + i),
sum = sine + cosine,
abs = MathF.Abs(sum),
- a = 0.5f + abs / 2;
+ a = 0.5f + (abs / 2);
Vector4 v4 = span[i];
float avg = (v4.X + v4.Y + v4.Z) / 3f;