Skip to content

Commit

Permalink
Added CPU support
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Sep 20, 2020
1 parent 4841a7e commit 7d8c030
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 73 deletions.
152 changes: 88 additions & 64 deletions Code/Forms/SettingsForm.Designer.cs

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

6 changes: 3 additions & 3 deletions Code/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ private void SettingsForm_Load(object sender, EventArgs e)
{
Program.mainForm.Enabled = false;
Logger.textbox = logTbox;
ConfigTabHelper.LoadEsrganSettings(confTilesize, confAlpha, modelPathBox, alphaColorTbox, jpegExtBox);
ConfigTabHelper.LoadSettings(tilesize, alpha, modelPath, alphaColor, jpegExt, useCpu);
}

private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
{
ConfigTabHelper.SaveSettings(confTilesize, confAlpha, modelPathBox, alphaColorTbox, jpegExtBox);
ConfigTabHelper.SaveSettings(tilesize, alpha, modelPath, alphaColor, jpegExt, useCpu);
Program.mainForm.Enabled = true;
}

private void confAlphaBgColorBtn_Click(object sender, EventArgs e)
{
alphaBgColorDialog.ShowDialog();
string colorStr = ColorTranslator.ToHtml(Color.FromArgb(alphaBgColorDialog.Color.ToArgb())).Replace("#", "") + "FF";
alphaColorTbox.Text = colorStr;
alphaColor.Text = colorStr;
Config.Set("alphaBgColor", colorStr);
}

Expand Down
1 change: 1 addition & 0 deletions Code/IO/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private static string WriteDefaultValIfExists(string key)
"alpha" => WriteDefault("alpha", "False"),
"alphaBgColor" => WriteDefault("alphaBgColor", "000000FF"),
"jpegExtension" => WriteDefault("jpegExtension", "jpg"),
"useCpu" => WriteDefault("useCpu", "False"),
_ => null,
};
}
Expand Down
8 changes: 4 additions & 4 deletions Code/OS/ESRGAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static string GetModelArg (ModelData mdl)
string mdl1 = mdl.model1Path;
string mdl2 = mdl.model2Path;
ModelData.ModelMode mdlMode = mdl.mode;
string mdlPath = Config.Get("modelPath").Replace("/", "\\").TrimEnd('\\');
if(mdlMode == ModelData.ModelMode.Single)
{
Program.lastModelName = mdl.model1Name;
Expand All @@ -86,11 +85,12 @@ public static async Task Run(string inpath, string outpath, string modelArg, str
outpath = "\"" + outpath + "\"";
string alphaStr = " --noalpha";
if (alpha)
{
alphaStr = "";
}
string deviceStr = " --device cuda";
if(Config.GetBool("useCpu"))
deviceStr = " --device cpu";
string cmd2 = "/C cd /D \"" + Config.Get("esrganPath") + "\" & ";
cmd2 = cmd2 + "python esrlmain.py " + inpath + " " + outpath + " --tilesize " + tilesize + alphaStr + modelArg;
cmd2 = cmd2 + "python esrlmain.py " + inpath + " " + outpath + deviceStr + " --tilesize " + tilesize + alphaStr + modelArg;
Logger.Log("CMD: " + cmd2);
Process esrganProcess = new Process();
esrganProcess.StartInfo.UseShellExecute = false;
Expand Down
6 changes: 4 additions & 2 deletions Code/UI/ConfigTabHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ namespace Cupscale.UI
{
internal class ConfigTabHelper
{
public static void LoadEsrganSettings(ComboBox tilesize, CheckBox alpha, TextBox modelPath, TextBox alphaColor, TextBox jpegExt)
public static void LoadSettings(ComboBox tilesize, CheckBox alpha, TextBox modelPath, TextBox alphaColor, TextBox jpegExt, CheckBox useCpu)
{
tilesize.Text = Config.Get("tilesize");
alpha.Checked = bool.Parse(Config.Get("alpha"));
modelPath.Text = Config.Get("modelPath");
alphaColor.Text = Config.Get("alphaBgColor");
jpegExt.Text = Config.Get("jpegExtension");
useCpu.Checked = bool.Parse(Config.Get("useCpu"));
}

public static void SaveSettings(ComboBox tilesize, CheckBox alpha, TextBox modelPath, TextBox alphaColor, TextBox jpegExt)
public static void SaveSettings(ComboBox tilesize, CheckBox alpha, TextBox modelPath, TextBox alphaColor, TextBox jpegExt, CheckBox useCpu)
{
Config.Set("tilesize", tilesize.Text.TrimNumbers());
Config.Set("alpha", alpha.Checked.ToString());
Config.Set("modelPath", modelPath.Text.Trim());
Config.Set("alphaBgColor", alphaColor.Text.Trim());
Config.Set("jpegExtension", jpegExt.Text.Trim());
Config.Set("useCpu", useCpu.Checked.ToString());
//MessageBox.Show("Saved settings to config file.", "Notice");
EsrganData.CheckModelDir();
}
Expand Down

0 comments on commit 7d8c030

Please sign in to comment.