From ff9fa35989ee4cf00364f6adefdea6fcc80288a9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 20 Aug 2022 00:44:45 +0200 Subject: [PATCH] Enable proper D2D1 bokeh blur unit tests --- .../ComputeSharp.D2D1.Tests.csproj | 3 +++ .../ComputeSharp.D2D1.Tests/EndToEndTests.cs | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj index dbe90541..09b62fe1 100644 --- a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj @@ -50,6 +50,9 @@ PreserveNewest + + PreserveNewest + diff --git a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs index 619e57c0..b6bcd911 100644 --- a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs @@ -3,8 +3,11 @@ using System.Reflection; using ComputeSharp.BokehBlur.Processors; using ComputeSharp.D2D1.Tests.Effects; using ComputeSharp.D2D1.Tests.Helpers; +using ComputeSharp.Tests.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; namespace ComputeSharp.D2D1.Tests; @@ -53,15 +56,27 @@ public class EndToEndTests } [TestMethod] - public void BokehBlur() + [DataRow(8, 1, "Landscape")] + [DataRow(32, 3, "Landscape")] + [DataRow(80, 1, "City")] + [DataRow(80, 2, "City")] + public void BokehBlur(int radius, int numberOfComponents, string filename) { - BokehBlurEffect bokehBlurEffect = new(32, 3); - string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets"); string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp"); + string sourcePath = Path.Combine(assetsPath, Path.ChangeExtension(filename, "png")); + string destinationPathForCpu = Path.Combine(temporaryPath, Path.ChangeExtension($"{filename}_{radius}_{numberOfComponents}_cpu", "png")); + string destinationPathForGpu = Path.Combine(temporaryPath, Path.ChangeExtension($"{filename}_{radius}_{numberOfComponents}_gpu", "png")); - bokehBlurEffect.ApplyEffect( - Path.Combine(assetsPath, "Landscape.png"), - Path.Combine(temporaryPath, "Landscape_BokehBlur.png")); + _ = Directory.CreateDirectory(temporaryPath); + + using Image original = Image.Load(sourcePath); + using Image cpu = original.Clone(c => c.BokehBlur(radius, numberOfComponents, 3)); + + cpu.SaveAsPng(destinationPathForCpu); + + new BokehBlurEffect(radius, numberOfComponents).ApplyEffect(sourcePath, destinationPathForGpu); + + TolerantImageComparer.AssertEqual(destinationPathForCpu, destinationPathForGpu, 0.00002f); } } \ No newline at end of file