From f9068b40981259daf2ce1409064bd7fc8c156034 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 19 Aug 2019 01:08:40 +0200 Subject: [PATCH] Added mirrored convolution --- samples/ComputeSharp.BokehBlur/Program.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/samples/ComputeSharp.BokehBlur/Program.cs b/samples/ComputeSharp.BokehBlur/Program.cs index 1fde59e2..05ae8c0b 100644 --- a/samples/ComputeSharp.BokehBlur/Program.cs +++ b/samples/ComputeSharp.BokehBlur/Program.cs @@ -25,7 +25,7 @@ namespace ComputeSharp.BokehBlur { // Load the input image Console.WriteLine(">> Loading image"); - using Image image = Image.Load(ImagePath); + using Image image = Image.Load(ImagePath); var (height, width) = (image.Height, image.Width); // Get the vector buffer @@ -35,7 +35,7 @@ namespace ComputeSharp.BokehBlur // Populate the buffer Parallel.For(0, height, i => { - ref Rgb24 rPixel = ref image.GetPixelRowSpan(i).GetPinnableReference(); + ref Rgba32 rPixel = ref image.GetPixelRowSpan(i).GetPinnableReference(); ref Vector4 r4 = ref vectorArray[i * width]; for (int j = 0; j < width; j++) @@ -84,8 +84,10 @@ namespace ComputeSharp.BokehBlur int iy = i + y; int jx = j + x; - if (iy < 0 || iy > height) continue; - if (jx < 0 || jx > width) continue; + if (iy < 0) iy = -iy; + else if (iy > height) iy -= height; + if (jx < 0) jx = -jx; + else if (jx > width) jx -= width; int ki = Radius - y; int kj = Radius - x; @@ -101,7 +103,7 @@ namespace ComputeSharp.BokehBlur Console.WriteLine(">> Storing pixel data"); Parallel.For(0, height, i => { - ref Rgb24 rPixel = ref image.GetPixelRowSpan(i).GetPinnableReference(); + ref Rgba32 rPixel = ref image.GetPixelRowSpan(i).GetPinnableReference(); ref Vector4 r4 = ref resultArray[i * width]; for (int j = 0; j < width; j++)