From 7c2aa00c418c4938c34bbb3728c2aa0bd71f1af0 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 18 Aug 2019 23:27:10 +0200 Subject: [PATCH] Added empty processing block and comments --- samples/ComputeSharp.BokehBlur/Program.cs | 24 ++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/samples/ComputeSharp.BokehBlur/Program.cs b/samples/ComputeSharp.BokehBlur/Program.cs index f939f185..f5b3e2e0 100644 --- a/samples/ComputeSharp.BokehBlur/Program.cs +++ b/samples/ComputeSharp.BokehBlur/Program.cs @@ -1,10 +1,11 @@ -using System.IO; -using System.Numerics; +using System; +using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; +using Vector4 = System.Numerics.Vector4; namespace ComputeSharp.BokehBlur { @@ -18,10 +19,12 @@ namespace ComputeSharp.BokehBlur static void Main() { // Load the input image + Console.WriteLine(">> Loading image"); using Image image = Image.Load(ImagePath); var (height, width) = (image.Height, image.Width); // Get the vector buffer + Console.WriteLine(">> Getting pixel data"); Vector4[] vectorArray = new Vector4[height * width]; // Populate the buffer @@ -36,11 +39,25 @@ namespace ComputeSharp.BokehBlur } }); + // Apply the effect + Console.WriteLine(">> Applying effect"); + Vector4[] resultArray = new Vector4[height * width]; + Parallel.For(0, height * width, ij => + { + int i = ij / width; + int j = ij % width; + ref Vector4 rin = ref vectorArray[0]; + ref Vector4 rout = ref resultArray[0]; + + Unsafe.Add(ref rout, i * width + j) = Unsafe.Add(ref rin, i * width + j); + }); + // Copy the modified image back + Console.WriteLine(">> Storing pixel data"); Parallel.For(0, height, i => { ref Rgb24 rPixel = ref image.GetPixelRowSpan(i).GetPinnableReference(); - ref Vector4 r4 = ref vectorArray[i * width]; + ref Vector4 r4 = ref resultArray[i * width]; for (int j = 0; j < width; j++) { @@ -49,6 +66,7 @@ namespace ComputeSharp.BokehBlur }); // Save the resulting image + Console.WriteLine(">> Saving to disk"); string targetPath = Path.Combine( Path.GetDirectoryName(ImagePath), $"{Path.GetFileNameWithoutExtension(ImagePath)}_bokeh{Path.GetExtension(ImagePath)}");