move to dll
This commit is contained in:
parent
13596d0998
commit
07fce3609b
@ -1,16 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComputeSharp" Version="2.0.3" />
|
||||
<PackageReference Include="ComputeSharp.Dynamic" Version="2.0.3" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>net7.0-windows10.0.17763.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComputeSharp" Version="2.0.3" />
|
||||
<PackageReference Include="ComputeSharp.Dynamic" Version="2.0.3" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,25 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32901.215
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cupola", "Cupola.csproj", "{83EBE364-D0B0-4262-8AFC-539506D72116}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {AD483A57-321A-4AD6-A68F-038CC1DB8066}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32901.215
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cupola", "Cupola.csproj", "{83EBE364-D0B0-4262-8AFC-539506D72116}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{83EBE364-D0B0-4262-8AFC-539506D72116}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {AD483A57-321A-4AD6-A68F-038CC1DB8066}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
182
Cupola/Program.cs
Normal file
182
Cupola/Program.cs
Normal file
@ -0,0 +1,182 @@
|
||||
using ComputeSharp;
|
||||
using System.Xml.Linq;
|
||||
using Windows.Devices.Geolocation;
|
||||
using static Cupola.Program;
|
||||
|
||||
namespace Cupola
|
||||
{
|
||||
internal partial class Program
|
||||
{
|
||||
public static void RunSingle(string imgDir, string outDir)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, float4>[] images = Load(imgDir);
|
||||
|
||||
ReadWriteTexture2D<Bgra32, float4> finalImage = RunSingle(images);
|
||||
|
||||
finalImage.Save(outDir + ".jpg");
|
||||
}
|
||||
|
||||
public static ReadWriteTexture2D<Bgra32, float4> RunSingle(ReadWriteTexture2D<Bgra32, float4>[] images)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, Float4> brightest = images[0];
|
||||
ReadWriteTexture2D<Bgra32, Float4> output = images[0];
|
||||
|
||||
for (int i = 1; i < images.Length; i++)
|
||||
{
|
||||
Console.WriteLine(i.ToString());
|
||||
|
||||
ReadWriteTexture2D<Bgra32, Float4> temp = images[i];
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Brightest(brightest, temp)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, output, 0.5f)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, brightest, 0.6f)
|
||||
);
|
||||
|
||||
output = temp;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static void RunMulti(string imgDir, string outDir)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, float4>[] images = Load(imgDir);
|
||||
|
||||
ReadWriteTexture2D<Bgra32, float4>[] imagesOut = RunMulti(images);
|
||||
|
||||
for (int i = 0; i < imagesOut.Length; i++)
|
||||
{
|
||||
imagesOut[i].Save(outDir + "-" + i.ToString() + ".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
public static ReadWriteTexture2D<Bgra32, float4>[] RunMulti(ReadWriteTexture2D<Bgra32, float4>[] images)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, float4>[] outputImages = new ReadWriteTexture2D<Bgra32, Float4>[images.Length];
|
||||
|
||||
ReadWriteTexture2D<Bgra32, Float4> brightest = images[0];
|
||||
ReadWriteTexture2D<Bgra32, Float4> output = images[0];
|
||||
|
||||
outputImages[0] = output;
|
||||
|
||||
for (int i = 1; i < images.Length; i++)
|
||||
{
|
||||
Console.WriteLine(i.ToString());
|
||||
|
||||
ReadWriteTexture2D<Bgra32, Float4> temp = images[i];
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Brightest(brightest, temp)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, output, 0.5f)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, brightest, 0.6f)
|
||||
);
|
||||
|
||||
output = temp;
|
||||
|
||||
outputImages[i] = output;
|
||||
}
|
||||
|
||||
return outputImages;
|
||||
}
|
||||
|
||||
private static ReadWriteTexture2D<Bgra32, float4>[] Load(string dir)
|
||||
{
|
||||
string[] files = Directory.GetFiles(dir);
|
||||
|
||||
ReadWriteTexture2D<Bgra32, float4>[] images = new ReadWriteTexture2D<Bgra32, Float4>[files.Length];
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
Console.WriteLine(files[i]);
|
||||
images[i] = GraphicsDevice.GetDefault().LoadReadWriteTexture2D<Bgra32, float4>(files[i]);
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
public readonly partial struct Brightest : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input1;
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input2;
|
||||
|
||||
// Other captured resources or values here...
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
float3 i1 = input1[ThreadIds.XY].RGB;
|
||||
float3 i2 = input2[ThreadIds.XY].RGB;
|
||||
|
||||
float i1Intensity = (i1.X * i1.X) + (i1.Y * i1.Y) + (i1.Z * i1.Z);
|
||||
float i2Intensity = (i2.X * i2.X) + (i2.Y * i2.Y) + (i2.Z * i2.Z);
|
||||
|
||||
if (i1Intensity > i2Intensity)
|
||||
{
|
||||
input1[ThreadIds.XY].RGB = i1;
|
||||
}
|
||||
else
|
||||
{
|
||||
input1[ThreadIds.XY].RGB = i2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
public readonly partial struct Average : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input1;
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input2;
|
||||
public readonly float weight;
|
||||
|
||||
// Other captured resources or values here...
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
float w1 = weight;
|
||||
float w2 = 1 - weight;
|
||||
|
||||
float3 i1 = input1[ThreadIds.XY].RGB;
|
||||
float3 i2 = input2[ThreadIds.XY].RGB;
|
||||
|
||||
float3 o1 = 0;
|
||||
|
||||
o1.X = (i1.X * w1) + (i2.X * w2);
|
||||
o1.Y = (i1.Y * w1) + (i2.Y * w2);
|
||||
o1.Z = (i1.Z * w1) + (i2.Z * w2);
|
||||
|
||||
input1[ThreadIds.XY].RGB = o1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
169
Program.cs
169
Program.cs
@ -1,169 +0,0 @@
|
||||
using ComputeSharp;
|
||||
using static Cupola.Program;
|
||||
|
||||
namespace Cupola
|
||||
{
|
||||
internal partial class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Image Dir?");
|
||||
string? fileLoc = Console.ReadLine();
|
||||
|
||||
if (fileLoc == null)
|
||||
throw new ArgumentException("input should not be NULL");
|
||||
|
||||
string[] files = Directory.GetFiles(fileLoc);
|
||||
|
||||
ReadWriteTexture2D<Bgra32, float4>[] images = new ReadWriteTexture2D<Bgra32, Float4>[files.Length];
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
Console.WriteLine(files[i]);
|
||||
images[i] = GraphicsDevice.GetDefault().LoadReadWriteTexture2D<Bgra32, float4>(files[i]);
|
||||
}
|
||||
|
||||
Console.WriteLine("Output: ");
|
||||
|
||||
string? name = Console.ReadLine();
|
||||
|
||||
if (name == null)
|
||||
throw new Exception("UwU");
|
||||
|
||||
Console.WriteLine("mode?");
|
||||
Console.WriteLine();
|
||||
ConsoleKey key = Console.ReadKey().Key;
|
||||
|
||||
if (key == ConsoleKey.P)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, Float4> brightest = images[0];
|
||||
ReadWriteTexture2D<Bgra32, Float4> output = images[0];
|
||||
|
||||
for (int i = 1; i < images.Length; i++)
|
||||
{
|
||||
Console.WriteLine(i.ToString());
|
||||
|
||||
ReadWriteTexture2D<Bgra32, Float4> temp = images[i];
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Brightest(brightest, temp)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, output, 0.5f)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, brightest, 0.6f)
|
||||
);
|
||||
|
||||
output = temp;
|
||||
}
|
||||
|
||||
output.Save(name + ".jpg");
|
||||
}
|
||||
else if (key == ConsoleKey.V)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, Float4> brightest = images[0];
|
||||
ReadWriteTexture2D<Bgra32, Float4> output = images[0];
|
||||
|
||||
output.Save(name + "-" + 0.ToString() + ".jpg");
|
||||
|
||||
for (int i = 1; i < images.Length; i++)
|
||||
{
|
||||
Console.WriteLine(i.ToString());
|
||||
|
||||
ReadWriteTexture2D<Bgra32, Float4> temp = images[i];
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Brightest(brightest, temp)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, output, 0.5f)
|
||||
);
|
||||
|
||||
GraphicsDevice.GetDefault().For
|
||||
(
|
||||
temp.Width,
|
||||
temp.Height,
|
||||
new Average(temp, brightest, 0.6f)
|
||||
);
|
||||
|
||||
output = temp;
|
||||
|
||||
output.Save(name + "-" + i.ToString() + ".jpg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
public readonly partial struct Brightest : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input1;
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input2;
|
||||
|
||||
// Other captured resources or values here...
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
float3 i1 = input1[ThreadIds.XY].RGB;
|
||||
float3 i2 = input2[ThreadIds.XY].RGB;
|
||||
|
||||
float i1Intensity = (i1.X * i1.X) + (i1.Y * i1.Y) + (i1.Z * i1.Z);
|
||||
float i2Intensity = (i2.X * i2.X) + (i2.Y * i2.Y) + (i2.Z * i2.Z);
|
||||
|
||||
if (i1Intensity > i2Intensity)
|
||||
{
|
||||
input1[ThreadIds.XY].RGB = i1;
|
||||
}
|
||||
else
|
||||
{
|
||||
input1[ThreadIds.XY].RGB = i2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
public readonly partial struct Average : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input1;
|
||||
public readonly IReadWriteNormalizedTexture2D<float4> input2;
|
||||
public readonly float weight;
|
||||
|
||||
// Other captured resources or values here...
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
float w1 = weight;
|
||||
float w2 = 1 - weight;
|
||||
|
||||
float3 i1 = input1[ThreadIds.XY].RGB;
|
||||
float3 i2 = input2[ThreadIds.XY].RGB;
|
||||
|
||||
float3 o1 = 0;
|
||||
|
||||
o1.X = (i1.X * w1) + (i2.X * w2);
|
||||
o1.Y = (i1.Y * w1) + (i2.Y * w2);
|
||||
o1.Z = (i1.Z * w1) + (i2.Z * w2);
|
||||
|
||||
input1[ThreadIds.XY].RGB = o1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user