From 3db5c31aabec90212a9c9aea7616bf8c48c9ce52 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 2 Sep 2019 02:19:56 +0200 Subject: [PATCH] Added gaussian blur to processing samples --- .gitignore | 1 + samples/ComputeSharp.BokehBlur/Program.cs | 26 ++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 109cd325..23c39fe0 100644 --- a/.gitignore +++ b/.gitignore @@ -331,3 +331,4 @@ ASALocalRun/ # Sample bokeh blur image **/*_bokeh.jpg +**/*_gaussian.jpg diff --git a/samples/ComputeSharp.BokehBlur/Program.cs b/samples/ComputeSharp.BokehBlur/Program.cs index 4c970cb4..d31184db 100644 --- a/samples/ComputeSharp.BokehBlur/Program.cs +++ b/samples/ComputeSharp.BokehBlur/Program.cs @@ -5,6 +5,7 @@ using ComputeSharp.BokehBlur.Processor; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; namespace ComputeSharp.BokehBlur { @@ -14,16 +15,25 @@ namespace ComputeSharp.BokehBlur { Console.WriteLine(">> Loading image"); string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "city.jpg"); - using Image image = Image.Load(path); + using Image image = Image.Load(path); - Console.WriteLine(">> Applying blur"); - image.Mutate(c => c.ApplyProcessor(new HlslBokehBlurProcessor(80, 2, 3))); + // Apply a series of processors and save the results + foreach (var effect in new (string Name, IImageProcessor Processor)[] + { + ("bokeh", new HlslBokehBlurProcessor(80, 2, 3)), + ("gaussian", new HlslGaussianBlurProcessor(80)) + }) + { + Console.WriteLine($">> Applying {effect.Name}"); + using Image copy = image.Clone(); + copy.Mutate(c => c.ApplyProcessor(effect.Processor)); - Console.WriteLine(">> Saving to disk"); - string targetPath = Path.Combine( - Path.GetRelativePath(Path.GetDirectoryName(path), @"..\..\..\"), - $"{Path.GetFileNameWithoutExtension(path)}_bokeh{Path.GetExtension(path)}"); - image.Save(targetPath); + Console.WriteLine($">> Saving {effect.Name} to disk"); + string targetPath = Path.Combine( + Path.GetRelativePath(Path.GetDirectoryName(path), @"..\..\..\"), + $"{Path.GetFileNameWithoutExtension(path)}_{effect.Name}{Path.GetExtension(path)}"); + copy.Save(targetPath); + } } } }