Skip to content

Commit

Permalink
b8
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Sep 20, 2020
1 parent 4f9cbcb commit 4841a7e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 21 deletions.
22 changes: 18 additions & 4 deletions Code/ClipboardPreview.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using ImageMagick;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
Expand All @@ -16,7 +18,7 @@ class ClipboardPreview
public static Bitmap originalPreview;
public static Bitmap resultPreview;

public static void CopyToClipboardSideBySide(bool fullImage = false)
public static async void CopyToClipboardSideBySide(bool saveToFile, bool fullImage = false)
{
//if (resultPreview == null)
//return;
Expand Down Expand Up @@ -101,10 +103,22 @@ public static void CopyToClipboardSideBySide(bool fullImage = false)
}
try
{
Clipboard.SetDataObject(outputImage);
if (saveToFile)
{
string comparisonSavePath = Path.ChangeExtension(Program.lastFilename, null) + "-comparison.png";
outputImage.Save(comparisonSavePath);
await ImageProcessing.ConvertImage(comparisonSavePath, ImageProcessing.Format.PngFast, false, false);
MessageBox.Show("Saved current comparison to:\n\n" + comparisonSavePath, "Message");
}
else
{
Clipboard.SetDataObject(outputImage);
}
}
catch
{ }
{
MessageBox.Show("Failed to save comparison.", "Error");
}
}

public static void CopyToClipboardSlider(bool fullImage = false)
Expand Down
1 change: 1 addition & 0 deletions Code/Cupscale.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</PackageReference>
<PackageReference Include="HTAlt.WinForms" Version="0.1.5.1" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.21.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.1" />
<PackageReference Include="TabControl" Version="2.1.2" />
</ItemGroup>
<ItemGroup>
Expand Down
23 changes: 21 additions & 2 deletions Code/Cupscale/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Code/Cupscale/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async Task DragNDrop (string [] array)
File.Copy(path, Paths.tempImgPath, true);
//await Upscale.Preprocessing(Paths.tempImgPath.GetParentDir());
bool fillAlpha = !bool.Parse(Config.Get("alpha"));
await UpscaleProcessing.ConvertImageTo(path, Paths.tempImgPath, UpscaleProcessing.Format.PngFast, fillAlpha, false, false);
await ImageProcessing.ConvertImageTo(path, Paths.tempImgPath, ImageProcessing.Format.PngFast, fillAlpha, false, false);
Logger.Log("Done Preprocessing");
previewImg.Image = IOUtils.GetImage(Paths.tempImgPath);
Program.lastFilename = path;
Expand Down Expand Up @@ -248,8 +248,8 @@ private void refreshPreviewCutoutBtn_Click(object sender, EventArgs e)

private void copyCompToClipboardBtn_Click(object sender, EventArgs e)
{
if (prevClipboardTypeCombox.SelectedIndex == 0) ClipboardPreview.CopyToClipboardSideBySide();
if (prevClipboardTypeCombox.SelectedIndex == 1) ClipboardPreview.CopyToClipboardSlider();
if (prevClipboardTypeCombox.SelectedIndex == 0) ClipboardPreview.CopyToClipboardSideBySide(false);
if (prevClipboardTypeCombox.SelectedIndex == 1) ClipboardPreview.CopyToClipboardSlider(false);
}

private void model1TreeBtn_Click(object sender, EventArgs e)
Expand All @@ -261,5 +261,11 @@ private void model2TreeBtn_Click(object sender, EventArgs e)
{
ModelSelectForm treeForm = new ModelSelectForm(model2TreeBtn, 2);
}

private void savePreviewToFileBtn_Click(object sender, EventArgs e)
{
if (prevClipboardTypeCombox.SelectedIndex == 0) ClipboardPreview.CopyToClipboardSideBySide(true);
if (prevClipboardTypeCombox.SelectedIndex == 1) ClipboardPreview.CopyToClipboardSlider(true);
}
}
}
14 changes: 7 additions & 7 deletions Code/Cupscale/Upscale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static async Task Preprocessing (string path, bool appendExt = false)
{
Logger.Log("Preprocessing: " + path);
bool fillAlpha = !bool.Parse(Config.Get("alpha"));
await UpscaleProcessing.ConvertImages(path, UpscaleProcessing.Format.PngFast, fillAlpha);
await ImageProcessing.ConvertImages(path, ImageProcessing.Format.PngFast, fillAlpha);
}

public static async Task Postprocessing()
Expand All @@ -82,17 +82,17 @@ public static async Task Postprocessing()
await Program.PutTaskDelay();
Logger.Log("Postprocessing - outputFormat.SelectedIndex = " + outputFormat.SelectedIndex);
if (outputFormat.SelectedIndex == 0)
UpscaleProcessing.ChangeOutputExtensions("png");
ImageProcessing.ChangeOutputExtensions("png");
if (outputFormat.SelectedIndex == 1)
await UpscaleProcessing.ConvertImagesToOriginalFormat();
await ImageProcessing.ConvertImagesToOriginalFormat();
if (outputFormat.SelectedIndex == 2)
await UpscaleProcessing.ConvertImages(Paths.imgOutPath, UpscaleProcessing.Format.JpegHigh);
await ImageProcessing.ConvertImages(Paths.imgOutPath, ImageProcessing.Format.JpegHigh);
if (outputFormat.SelectedIndex == 3)
await UpscaleProcessing.ConvertImages(Paths.imgOutPath, UpscaleProcessing.Format.JpegMed);
await ImageProcessing.ConvertImages(Paths.imgOutPath, ImageProcessing.Format.JpegMed);
if (outputFormat.SelectedIndex == 4)
await UpscaleProcessing.ConvertImages(Paths.imgOutPath, UpscaleProcessing.Format.WeppyHigh);
await ImageProcessing.ConvertImages(Paths.imgOutPath, ImageProcessing.Format.WeppyHigh);
if (outputFormat.SelectedIndex == 5)
await UpscaleProcessing.ConvertImages(Paths.imgOutPath, UpscaleProcessing.Format.WeppyLow);
await ImageProcessing.ConvertImages(Paths.imgOutPath, ImageProcessing.Format.WeppyLow);
}

public static async Task FilenamePostprocessing ()
Expand Down
5 changes: 3 additions & 2 deletions Code/Forms/ModelSelectForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion Code/Forms/ModelSelectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,34 @@ public ModelSelectForm(Button modelButton, int modelNumber)
CenterToScreen();
modelBtn = modelButton;
modelNo = modelNumber;
SelectLastUsed();
}

private void ModelSelectForm_Load(object sender, EventArgs e)
{
DirectoryInfo modelsDir = new DirectoryInfo(Config.Get("modelPath"));
BuildTree(modelsDir, modelTree.Nodes);
modelTree.ExpandAll();
modelTree.SelectedNode = modelTree.Nodes[0];
}

private void SelectLastUsed()
{
if(string.IsNullOrWhiteSpace(Program.currentModel1))
modelTree.SelectedNode = modelTree.Nodes[0];
else
CheckNodesRecursive(modelTree.Nodes[0]);
}

private void CheckNodesRecursive(TreeNode parentNode)
{
Logger.Log("Checking if " + parentNode.Text.Trim() + " == " + modelBtn.Text.Trim());
if (parentNode.Text.Trim() == modelBtn.Text.Trim())
modelTree.SelectedNode = parentNode;

foreach (TreeNode oSubNode in parentNode.Nodes)
{
CheckNodesRecursive(oSubNode);
}
}

private void BuildTree(DirectoryInfo directoryInfo, TreeNodeCollection addInMe)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cupscale.IO;
using ImageMagick;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using Paths = Cupscale.IO.Paths;

namespace Cupscale
{
internal class UpscaleProcessing
internal class ImageProcessing
{
public enum Format
{
Expand Down
2 changes: 1 addition & 1 deletion Code/UI/MainUIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static async void UpscaleImage()
Cancel("I/O Error");
return;
}
await UpscaleProcessing.ConvertImages(Paths.imgInPath, UpscaleProcessing.Format.PngFast, !Config.GetBool("alpha"), true, true);
await ImageProcessing.ConvertImages(Paths.imgInPath, ImageProcessing.Format.PngFast, !Config.GetBool("alpha"), true, true);
ModelData mdl = Upscale.GetModelData();
await ESRGAN.UpscaleBasic(Paths.imgInPath, Paths.imgOutPath, mdl, Config.Get("tilesize"), bool.Parse(Config.Get("alpha")), ESRGAN.PreviewMode.None);
await Upscale.Postprocessing();
Expand Down

0 comments on commit 4841a7e

Please sign in to comment.