Add ComplexVector4 type to bokeh blur tests

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-02 17:02:41 +02:00
1 親 bddd2a395c
コミット 2b992ac3c2
6ファイル変更
+48 -46

検索条件に一致するファイルはありません

+1
ファイルの表示
@@ -7,6 +7,7 @@
<ItemGroup>
<Compile Include="..\ComputeSharp.ImageProcessing\Primitives\Complex64.cs" Link="Imaging\Primitives\Complex64.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Primitives\ComplexVector4.cs" Link="Imaging\Primitives\ComplexVector4.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor.cs" Link="Imaging\Processors\HlslBokehBlurProcessor.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslBokehBlurProcessor{TPixel}.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor.cs" />
+32
ファイルの表示
@@ -0,0 +1,32 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp;
/// <summary>
/// A vector with 4 values of type <see cref="Complex64"/>.
/// </summary>
internal struct ComplexVector4
{
/// <summary>
/// The real part of the complex vector
/// </summary>
public Vector4 Real;
/// <summary>
/// The imaginary part of the complex number
/// </summary>
public Vector4 Imaginary;
/// <summary>
/// Performs a weighted sum on the current instance according to the given parameters
/// </summary>
/// <param name="a">The 'a' parameter, for the real component</param>
/// <param name="b">The 'b' parameter, for the imaginary component</param>
/// <returns>The resulting <see cref="Vector4"/> value</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4 WeightedSum(float a, float b) => (this.Real * a) + (this.Imaginary * b);
}
+4 -5
ファイルの表示
@@ -363,13 +363,12 @@ public sealed partial class HlslBokehBlurProcessor
/// <inheritdoc/>
public void Execute()
{
float4 real = float4.Zero;
float4 imaginary = float4.Zero;
int maxY = target.Height;
int maxX = target.Width;
int kernelLength = kernel.Length;
int radiusX = kernelLength >> 1;
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
ComplexVector4 result = default;
for (int i = 0; i < kernelLength; i++)
{
@@ -378,11 +377,11 @@ public sealed partial class HlslBokehBlurProcessor
float4 sourceImaginary = imaginaries[offsetX, offsetY];
Complex64 factors = kernel[i];
real += factors.Real * sourceReal - factors.Imaginary * sourceImaginary;
imaginary += factors.Real * sourceImaginary + factors.Imaginary * sourceReal;
result.Real += (Vector4)(factors.Real * sourceReal - factors.Imaginary * sourceImaginary);
result.Imaginary += (Vector4)(factors.Real * sourceImaginary + factors.Imaginary * sourceReal);
}
target[ThreadIds.XY] += real * z + imaginary * w;
target[ThreadIds.XY] += (float4)result.WeightedSum(z, w);
}
}
+5
ファイルの表示
@@ -25,6 +25,11 @@
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Primitives\Complex64.cs" Link="Imaging\Primitives\Complex64.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Primitives\ComplexVector4.cs" Link="Imaging\Primitives\ComplexVector4.cs" />
</ItemGroup>
<ItemGroup>
<None Update="Assets\Landscape.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+5 -41
ファイルの表示
@@ -9,6 +9,7 @@ using ComputeSharp.D2D1;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Extensions;
using ComputeSharp.D2D1.Tests.Helpers;
using SixLabors.ImageSharp;
using Win32;
using Win32.Graphics.Direct2D;
@@ -568,10 +569,9 @@ public sealed partial class BokehBlurEffect
/// <inheritdoc/>
public float4 Execute()
{
float4 real = float4.Zero;
float4 imaginary = float4.Zero;
int length = this.kernelLength;
int radiusX = length >> 1;
ComplexVector4 result = default;
for (int i = 0; i < length; i++)
{
@@ -580,11 +580,11 @@ public sealed partial class BokehBlurEffect
float realFactor = kernelReals[i];
float imaginaryFactor = kernelImaginaries[i];
real += realFactor * sourceReal - imaginaryFactor * sourceImaginary;
imaginary += realFactor * sourceImaginary + imaginaryFactor * sourceReal;
result.Real += (Vector4)(realFactor * sourceReal - imaginaryFactor * sourceImaginary);
result.Imaginary += (Vector4)(realFactor * sourceImaginary + imaginaryFactor * sourceReal);
}
return real * z + imaginary * w;
return result.WeightedSum(z, w);
}
}
}
@@ -633,40 +633,4 @@ public sealed partial class BokehBlurEffect
return pixel;
}
}
/// <summary>
/// Represents a complex number, where the real and imaginary parts are stored as <see cref="float"/> values.
/// </summary>
private readonly struct Complex64
{
/// <summary>
/// The real part of the complex number.
/// </summary>
public readonly float Real;
/// <summary>
/// The imaginary part of the complex number.
/// </summary>
public readonly float Imaginary;
/// <summary>
/// Initializes a new instance of the <see cref="Complex64"/> struct.
/// </summary>
/// <param name="real">The real part in the complex number.</param>
/// <param name="imaginary">The imaginary part in the complex number.</param>
public Complex64(float real, float imaginary)
{
this.Real = real;
this.Imaginary = imaginary;
}
/// <summary>
/// Performs the multiplication operation between a <see cref="Complex64"/> instance and a <see cref="float"/> scalar.
/// </summary>
/// <param name="value">The <see cref="Complex64"/> value to multiply.</param>
/// <param name="scalar">The <see cref="float"/> scalar to use to multiply the <see cref="Complex64"/> value.</param>
/// <returns>The <see cref="Complex64"/> result.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Complex64 operator *(Complex64 value, float scalar) => new(value.Real * scalar, value.Imaginary * scalar);
}
}
+1
ファイルの表示
@@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Primitives\Complex64.cs" Link="Imaging\Primitives\Complex64.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Primitives\ComplexVector4.cs" Link="Imaging\Primitives\ComplexVector4.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor.cs" Link="Imaging\Processors\HlslBokehBlurProcessor.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslBokehBlurProcessor{TPixel}.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor.cs" />