Cupola/Tranquility/MainWindow.xaml.cs

107 lines
2.8 KiB
C#
Raw Normal View History

2023-02-12 23:23:10 +00:00
using System.Windows;
using Microsoft.WindowsAPICodePack.Dialogs;
using WinRT;
2023-02-13 09:58:11 +00:00
using Cupola;
using System.IO;
2023-02-13 10:01:31 +00:00
using System;
2023-02-13 10:10:38 +00:00
using ComputeSharp;
2023-02-12 23:23:10 +00:00
namespace Tranquility
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
2023-02-13 09:58:11 +00:00
string[]? files;
2023-02-13 10:10:38 +00:00
2023-02-12 23:23:10 +00:00
public MainWindow()
{
InitializeComponent();
}
private void LoadFilesClick(object sender, RoutedEventArgs e)
{
2023-02-13 09:58:11 +00:00
string file = OpenFolder();
files = Directory.GetFiles(file);
2023-02-13 10:01:31 +00:00
string iFilesT = "";
foreach (string iFile in files)
{
iFilesT += iFile + Environment.NewLine;
}
Input_Folder.Text = file;
Input_Files.Text = iFilesT;
2023-02-12 23:23:10 +00:00
}
private static string? OpenFolder()
{
CommonOpenFileDialog dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
CommonFileDialogResult result = dialog.ShowDialog();
if (result == CommonFileDialogResult.Ok)
return dialog.FileName;
return null;
}
2023-02-13 10:08:27 +00:00
2023-02-13 12:25:46 +00:00
private void RunOp(object sender, RoutedEventArgs e)
2023-02-13 10:08:27 +00:00
{
2023-02-13 10:10:38 +00:00
if (files == null)
throw new Exception("Please select files before running");
2023-02-13 17:16:32 +00:00
int opt; // 0 - Picture, 1 - Video
opt = Options.SelectedIndex;
2023-02-13 12:39:34 +00:00
Progress.Value = 10;
2023-02-13 10:10:38 +00:00
ReadWriteTexture2D<Bgra32, float4>[] images = Cupola.Cupola.Load(files);
2023-02-13 10:08:27 +00:00
2023-02-13 12:39:34 +00:00
Progress.Value = 30;
2023-02-13 17:16:32 +00:00
if (opt == 0)
{
ReadWriteTexture2D<Bgra32, float4> finalImage = Cupola.Cupola.RunSingle(images);
Progress.Value = 90;
CommonSaveFileDialog saveFileDialog = new CommonSaveFileDialog();
saveFileDialog.DefaultExtension = ".jpg";
saveFileDialog.EnsurePathExists = true;
CommonFileDialogResult result = saveFileDialog.ShowDialog();
if (result != CommonFileDialogResult.Ok)
throw new Exception("please set location valid OKAY");
2023-02-13 12:39:34 +00:00
2023-02-13 17:16:32 +00:00
finalImage.Save(saveFileDialog.FileName);
2023-02-13 12:39:34 +00:00
2023-02-13 17:16:32 +00:00
Progress.Value = 100;
}
else if (opt == 1)
{
ReadWriteTexture2D<Bgra32, float4>[] finalImages = Cupola.Cupola.RunMulti(images);
Progress.Value = 90;
2023-02-13 12:39:34 +00:00
2023-02-13 17:16:32 +00:00
string save = OpenFolder();
2023-02-13 12:39:34 +00:00
2023-02-13 17:16:32 +00:00
for (int i = 0; i < finalImages.Length; i++)
{
finalImages[i].Save(save + "\\" + i.ToString() + ".jpg");
}
}
else
{
throw new Exception("invalid option please die");
}
2023-02-13 12:39:34 +00:00
2023-02-13 17:16:32 +00:00
2023-02-13 10:08:27 +00:00
}
2023-02-12 23:23:10 +00:00
}
}