Skip to content

Commit 2b1de78

Browse files
author
N00MKRAD
committed
Added separate buttons to upscale entire preview or just the cutout
1 parent febcb8c commit 2b1de78

File tree

12 files changed

+34
-11
lines changed

12 files changed

+34
-11
lines changed

Code/Cupscale/ConfigData.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

Code/Cupscale/Logger.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public static void Log(string s, bool replaceLastLine = false)
1717
s = s.Replace("\n", Environment.NewLine);
1818
if (textbox != null)
1919
{
20-
Console.WriteLine("appending to logTbox: " + s);
2120
textbox.AppendText(Environment.NewLine + s);
2221
}
2322
else
File renamed without changes.

Code/Cupscale/IOUtils.cs renamed to Code/IO/IOUtils.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7+
using System.Windows.Forms;
78

89
namespace Cupscale
910
{
@@ -154,5 +155,19 @@ public static void ReplaceInFilename(string path, string textToFind, string text
154155
}
155156
File.Move(path, targetPath);
156157
}
158+
159+
public static bool TryCopy (string source, string dest, bool overwrite) // Copy with error handling. Returns false if failed
160+
{
161+
try
162+
{
163+
File.Copy(source, dest, overwrite);
164+
}
165+
catch (Exception e)
166+
{
167+
MessageBox.Show("Copy from \"" + source + "\" to \"" + dest + " (Overwrite: " + overwrite + " failed: \n\n" + e.Message);
168+
return false;
169+
}
170+
return true;
171+
}
157172
}
158173
}
File renamed without changes.
File renamed without changes.

Code/Cupscale.OS/ESRGAN.cs renamed to Code/OS/ESRGAN.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static async Task UpscaleBasic(string inpath, string outpath, string mode
1616
string modelArg = "\"" + formattedModelPath + "/" + model + ".pth\"";
1717
Program.mainForm.SetPreviewProgress(5f, "Starting ESRGAN...");
1818
await Run(inpath, outpath, modelArg, tilesize, alpha);
19+
File.Delete(Paths.progressLogfile);
1920
if (isPreview)
2021
{
2122
Program.mainForm.SetPreviewProgress(100f, "Merging into preview...");
File renamed without changes.
File renamed without changes.

Code/Cupscale.UI/PreviewTabHelper.cs renamed to Code/UI/PreviewTabHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static async void UpscalePreview(bool fullImage = false)
149149
Program.mainForm.SetPreviewProgress(3f, "Preparing...");
150150
if (fullImage)
151151
{
152-
previewImg.Image.Save(Path.Combine(Paths.previewPath, "preview.png"));
152+
if(!IOUtils.TryCopy(Program.lastFilename, Path.Combine(Paths.previewPath, "preview.png"), true)) return;
153153
}
154154
else
155155
{
@@ -159,6 +159,7 @@ public static async void UpscalePreview(bool fullImage = false)
159159
{
160160
string mdl = GetMdl();
161161
if (string.IsNullOrWhiteSpace(mdl)) return;
162+
Logger.Log(Paths.previewPath + " - " + Paths.previewOutPath + " - " + mdl + " - " + Config.Get("tilesize") + " - " + bool.Parse(Config.Get("alpha")));
162163
await ESRGAN.UpscaleBasic(Paths.previewPath, Paths.previewOutPath, mdl, Config.Get("tilesize"), bool.Parse(Config.Get("alpha")), isPreview: true);
163164
}
164165
}
@@ -185,7 +186,7 @@ public static void SaveCurrentCutout()
185186
GetCurrentRegion().Save(path);
186187
}
187188

188-
public static Bitmap GetCurrentRegion()
189+
public static Bitmap GetCurrentRegion() // thx ieu
189190
{
190191
RectangleF sourceImageRegion = previewImg.GetSourceImageRegion();
191192
int num = (int)Math.Round(sourceImageRegion.Width);

0 commit comments

Comments
 (0)