forked from Sergio0694/ComputeSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (30 loc) · 1.35 KB
/
Program.cs
File metadata and controls
40 lines (30 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.IO;
using System.Reflection;
using ComputeSharp.BokehBlur.Processors;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
Configuration.Default.PreferContiguousImageBuffers = true;
Console.WriteLine(">> Loading image");
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "city.jpg");
using Image<ImageSharpRgba32> image = Image.Load<ImageSharpRgba32>(path);
// Apply a series of processors and save the results
foreach ((string Name, IImageProcessor Processor) effect in new (string Name, IImageProcessor Processor)[]
{
("bokeh", new HlslBokehBlurProcessor(80, 2)),
("gaussian", new HlslGaussianBlurProcessor(80))
})
{
Console.WriteLine($">> Applying {effect.Name}");
using Image copy = image.Clone(c => c.ApplyProcessor(effect.Processor));
Console.WriteLine($">> Saving {effect.Name} to disk");
string targetPath = Path.GetDirectoryName(path)!;
while (Path.GetFileName(targetPath) != "ComputeSharp.ImageProcessing")
{
targetPath = Path.GetDirectoryName(targetPath)!;
}
targetPath = Path.Combine(targetPath, $"{Path.GetFileNameWithoutExtension(path)}_{effect.Name}{Path.GetExtension(path)}");
copy.Save(targetPath);
}