diff --git a/samples/ComputeSharp.BokehBlur/ComputeSharp.BokehBlur.csproj b/samples/ComputeSharp.BokehBlur/ComputeSharp.BokehBlur.csproj new file mode 100644 index 00000000..4d935707 --- /dev/null +++ b/samples/ComputeSharp.BokehBlur/ComputeSharp.BokehBlur.csproj @@ -0,0 +1,16 @@ + + + + Exe + netcoreapp3.0 + + + + + + + + + + + diff --git a/samples/ComputeSharp.BokehBlur/Program.cs b/samples/ComputeSharp.BokehBlur/Program.cs new file mode 100644 index 00000000..f939f185 --- /dev/null +++ b/samples/ComputeSharp.BokehBlur/Program.cs @@ -0,0 +1,58 @@ +using System.IO; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; + +namespace ComputeSharp.BokehBlur +{ + class Program + { + /// + /// The path of the image to process (the modified version will be saved as a copy) + /// + private const string ImagePath = @""; + + static void Main() + { + // Load the input image + using Image image = Image.Load(ImagePath); + var (height, width) = (image.Height, image.Width); + + // Get the vector buffer + Vector4[] vectorArray = new Vector4[height * width]; + + // Populate the buffer + Parallel.For(0, height, i => + { + ref Rgb24 rPixel = ref image.GetPixelRowSpan(i).GetPinnableReference(); + ref Vector4 r4 = ref vectorArray[i * width]; + + for (int j = 0; j < width; j++) + { + Unsafe.Add(ref r4, j) = Unsafe.Add(ref rPixel, i).ToVector4(); + } + }); + + // Copy the modified image back + Parallel.For(0, height, i => + { + ref Rgb24 rPixel = ref image.GetPixelRowSpan(i).GetPinnableReference(); + ref Vector4 r4 = ref vectorArray[i * width]; + + for (int j = 0; j < width; j++) + { + Unsafe.Add(ref rPixel, i).FromVector4(Unsafe.Add(ref r4, i)); + } + }); + + // Save the resulting image + string targetPath = Path.Combine( + Path.GetDirectoryName(ImagePath), + $"{Path.GetFileNameWithoutExtension(ImagePath)}_bokeh{Path.GetExtension(ImagePath)}"); + image.Save(targetPath); + } + } +} diff --git a/src/ComputeSharp.sln b/src/ComputeSharp.sln index 3cedb543..99223faf 100644 --- a/src/ComputeSharp.sln +++ b/src/ComputeSharp.sln @@ -24,7 +24,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests", "..\te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.Internals", "..\tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj", "{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.Benchmark", "..\samples\ComputeSharp.Benchmark\ComputeSharp.Benchmark.csproj", "{34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Benchmark", "..\samples\ComputeSharp.Benchmark\ComputeSharp.Benchmark.csproj", "{34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.BokehBlur", "..\samples\ComputeSharp.BokehBlur\ComputeSharp.BokehBlur.csproj", "{524CC5DD-1DEE-4A30-9515-AB90965E5207}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -90,6 +92,14 @@ Global {34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Release|Any CPU.Build.0 = Release|Any CPU {34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Release|x64.ActiveCfg = Release|Any CPU {34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Release|x64.Build.0 = Release|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Debug|Any CPU.Build.0 = Debug|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Debug|x64.ActiveCfg = Debug|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Debug|x64.Build.0 = Debug|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Release|Any CPU.ActiveCfg = Release|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Release|Any CPU.Build.0 = Release|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Release|x64.ActiveCfg = Release|Any CPU + {524CC5DD-1DEE-4A30-9515-AB90965E5207}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -99,6 +109,7 @@ Global {E91F4D24-922A-4921-A8D7-9C45A143C45D} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7} {E889E6D6-A814-4950-AAC1-68F1ECFC5BD6} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7} {34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} + {524CC5DD-1DEE-4A30-9515-AB90965E5207} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}