diff --git a/Code/Forms/ModelComparisonForm.cs b/Code/Forms/ModelComparisonForm.cs index 49f6286..12a06dc 100644 --- a/Code/Forms/ModelComparisonForm.cs +++ b/Code/Forms/ModelComparisonForm.cs @@ -147,7 +147,7 @@ async Task DoUpscale (int index, ModelData mdl, bool fullImage) if (useNcnn) backend = ESRGAN.Backend.NCNN; string inpath = Paths.previewPath; if (fullImage) inpath = Paths.tempImgPath.GetParentDir(); - await ESRGAN.DoUpscale(inpath, Paths.compositionOut, mdl, Config.Get("tilesize"), Config.GetBool("alpha"), ESRGAN.PreviewMode.None, backend); + await ESRGAN.DoUpscale(inpath, Paths.compositionOut, mdl, false, Config.GetBool("alpha"), ESRGAN.PreviewMode.None, backend); if (backend == ESRGAN.Backend.NCNN) outImg = Directory.GetFiles(Paths.compositionOut, "*.png*", SearchOption.AllDirectories)[0]; else diff --git a/Code/Forms/ModelSelectForm.cs b/Code/Forms/ModelSelectForm.cs index 0752bf3..29093b6 100644 --- a/Code/Forms/ModelSelectForm.cs +++ b/Code/Forms/ModelSelectForm.cs @@ -39,7 +39,10 @@ private void ModelSelectForm_Load(object sender, EventArgs e) } DirectoryInfo modelsDir = new DirectoryInfo(modelDir); BuildTree(modelsDir, modelTree.Nodes); - modelTree.ExpandAll(); + if (Config.GetBool("modelSelectAutoExpand", true)) + modelTree.ExpandAll(); + else + modelTree.Nodes[0].Expand(); } private async void SelectLastUsed() diff --git a/Code/Forms/SettingsForm.Designer.cs b/Code/Forms/SettingsForm.Designer.cs index e4cde5d..3564944 100644 --- a/Code/Forms/SettingsForm.Designer.cs +++ b/Code/Forms/SettingsForm.Designer.cs @@ -34,6 +34,14 @@ private void InitializeComponent() this.settingsPage = new Cyotek.Windows.Forms.TabListPage(); this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); this.panel7 = new System.Windows.Forms.Panel(); + this.pictureBox14 = new System.Windows.Forms.PictureBox(); + this.gpuId = new System.Windows.Forms.TextBox(); + this.label16 = new System.Windows.Forms.Label(); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.pictureBox10 = new System.Windows.Forms.PictureBox(); + this.alphaDepth = new System.Windows.Forms.ComboBox(); + this.label6 = new System.Windows.Forms.Label(); + this.alphaMode = new System.Windows.Forms.ComboBox(); this.pythonRuntime = new System.Windows.Forms.ComboBox(); this.label24 = new System.Windows.Forms.Label(); this.seamlessMode = new System.Windows.Forms.ComboBox(); @@ -133,18 +141,15 @@ private void InitializeComponent() this.logTbox = new System.Windows.Forms.TextBox(); this.alphaBgColorDialog = new System.Windows.Forms.ColorDialog(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); - this.alphaMode = new System.Windows.Forms.ComboBox(); - this.label6 = new System.Windows.Forms.Label(); - this.alphaDepth = new System.Windows.Forms.ComboBox(); - this.pictureBox10 = new System.Windows.Forms.PictureBox(); - this.pictureBox2 = new System.Windows.Forms.PictureBox(); - this.label16 = new System.Windows.Forms.Label(); - this.gpuId = new System.Windows.Forms.TextBox(); - this.pictureBox14 = new System.Windows.Forms.PictureBox(); + this.modelSelectAutoExpand = new System.Windows.Forms.CheckBox(); + this.label35 = new System.Windows.Forms.Label(); this.tabList1.SuspendLayout(); this.settingsPage.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout(); this.panel7.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox14)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox10)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.panel6.SuspendLayout(); @@ -173,9 +178,6 @@ private void InitializeComponent() this.panel4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox9)).BeginInit(); this.logPage.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox10)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox14)).BeginInit(); this.SuspendLayout(); // // tabList1 @@ -244,6 +246,107 @@ private void InitializeComponent() this.panel7.Size = new System.Drawing.Size(455, 463); this.panel7.TabIndex = 4; // + // pictureBox14 + // + this.pictureBox14.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.pictureBox14.Image = global::Cupscale.Properties.Resources.questmark; + this.pictureBox14.Location = new System.Drawing.Point(95, 196); + this.pictureBox14.Name = "pictureBox14"; + this.pictureBox14.Size = new System.Drawing.Size(22, 22); + this.pictureBox14.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox14.TabIndex = 30; + this.pictureBox14.TabStop = false; + this.toolTip.SetToolTip(this.pictureBox14, "Set which GPU will be used for upscaling.\r\n0 is the first device, 1 the second, a" + + "nd so on."); + // + // gpuId + // + this.gpuId.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.gpuId.ForeColor = System.Drawing.Color.White; + this.gpuId.Location = new System.Drawing.Point(220, 197); + this.gpuId.Name = "gpuId"; + this.gpuId.Size = new System.Drawing.Size(225, 20); + this.gpuId.TabIndex = 29; + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(6, 200); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(83, 13); + this.label16.TabIndex = 28; + this.label16.Text = "GPU ID (CUDA)"; + // + // pictureBox2 + // + this.pictureBox2.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.pictureBox2.Image = global::Cupscale.Properties.Resources.questmark; + this.pictureBox2.Location = new System.Drawing.Point(78, 136); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(22, 22); + this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox2.TabIndex = 27; + this.pictureBox2.TabStop = false; + this.toolTip.SetToolTip(this.pictureBox2, "Color Depth of the alpha channel.\r\nUse Binary or Ternary for platforms and format" + + "s that have a limited alpha depth.\r\nFor example, GIFs or PSX sprites."); + // + // pictureBox10 + // + this.pictureBox10.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.pictureBox10.Image = global::Cupscale.Properties.Resources.questmark; + this.pictureBox10.Location = new System.Drawing.Point(82, 106); + this.pictureBox10.Name = "pictureBox10"; + this.pictureBox10.Size = new System.Drawing.Size(22, 22); + this.pictureBox10.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox10.TabIndex = 26; + this.pictureBox10.TabStop = false; + this.toolTip.SetToolTip(this.pictureBox10, "Enables support for upscaling transparency.\r\nMode 1 should work for most images, " + + "but if you are unhappy with the result, try 2 or 3."); + // + // alphaDepth + // + this.alphaDepth.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.alphaDepth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.alphaDepth.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.alphaDepth.ForeColor = System.Drawing.Color.White; + this.alphaDepth.FormattingEnabled = true; + this.alphaDepth.Items.AddRange(new object[] { + "Full (8-Bit)", + "Binary (1-Bit)", + "Ternary (2-Bit)"}); + this.alphaDepth.Location = new System.Drawing.Point(220, 137); + this.alphaDepth.Margin = new System.Windows.Forms.Padding(8); + this.alphaDepth.Name = "alphaDepth"; + this.alphaDepth.Size = new System.Drawing.Size(225, 21); + this.alphaDepth.TabIndex = 24; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(6, 140); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(66, 13); + this.label6.TabIndex = 23; + this.label6.Text = "Alpha Depth"; + // + // alphaMode + // + this.alphaMode.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.alphaMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.alphaMode.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.alphaMode.ForeColor = System.Drawing.Color.White; + this.alphaMode.FormattingEnabled = true; + this.alphaMode.Items.AddRange(new object[] { + "0 (Disabled)", + "1 (Differential Alpha)", + "2 (Separated Alpha)", + "3 (Channel Alpha)"}); + this.alphaMode.Location = new System.Drawing.Point(220, 107); + this.alphaMode.Margin = new System.Windows.Forms.Padding(8); + this.alphaMode.Name = "alphaMode"; + this.alphaMode.Size = new System.Drawing.Size(225, 21); + this.alphaMode.TabIndex = 22; + // // pythonRuntime // this.pythonRuntime.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); @@ -373,6 +476,8 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.panel6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel6.Controls.Add(this.modelSelectAutoExpand); + this.panel6.Controls.Add(this.label35); this.panel6.Controls.Add(this.comparisonUseScaling); this.panel6.Controls.Add(this.label31); this.panel6.Controls.Add(this.reloadImageBeforeUpscale); @@ -1401,106 +1506,23 @@ private void InitializeComponent() this.logTbox.TabIndex = 12; this.logTbox.VisibleChanged += new System.EventHandler(this.logTbox_VisibleChanged); // - // alphaMode + // modelSelectAutoExpand // - this.alphaMode.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.alphaMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.alphaMode.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.alphaMode.ForeColor = System.Drawing.Color.White; - this.alphaMode.FormattingEnabled = true; - this.alphaMode.Items.AddRange(new object[] { - "0 (Disabled)", - "1 (Differential Alpha)", - "2 (Separated Alpha)", - "3 (Channel Alpha)"}); - this.alphaMode.Location = new System.Drawing.Point(220, 107); - this.alphaMode.Margin = new System.Windows.Forms.Padding(8); - this.alphaMode.Name = "alphaMode"; - this.alphaMode.Size = new System.Drawing.Size(225, 21); - this.alphaMode.TabIndex = 22; + this.modelSelectAutoExpand.AutoSize = true; + this.modelSelectAutoExpand.Location = new System.Drawing.Point(220, 260); + this.modelSelectAutoExpand.Name = "modelSelectAutoExpand"; + this.modelSelectAutoExpand.Size = new System.Drawing.Size(15, 14); + this.modelSelectAutoExpand.TabIndex = 24; + this.modelSelectAutoExpand.UseVisualStyleBackColor = true; // - // label6 + // label35 // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(6, 140); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(66, 13); - this.label6.TabIndex = 23; - this.label6.Text = "Alpha Depth"; - // - // alphaDepth - // - this.alphaDepth.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.alphaDepth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.alphaDepth.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.alphaDepth.ForeColor = System.Drawing.Color.White; - this.alphaDepth.FormattingEnabled = true; - this.alphaDepth.Items.AddRange(new object[] { - "Full (8-Bit)", - "Binary (1-Bit)", - "Ternary (2-Bit)"}); - this.alphaDepth.Location = new System.Drawing.Point(220, 137); - this.alphaDepth.Margin = new System.Windows.Forms.Padding(8); - this.alphaDepth.Name = "alphaDepth"; - this.alphaDepth.Size = new System.Drawing.Size(225, 21); - this.alphaDepth.TabIndex = 24; - // - // pictureBox10 - // - this.pictureBox10.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.pictureBox10.Image = global::Cupscale.Properties.Resources.questmark; - this.pictureBox10.Location = new System.Drawing.Point(82, 106); - this.pictureBox10.Name = "pictureBox10"; - this.pictureBox10.Size = new System.Drawing.Size(22, 22); - this.pictureBox10.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox10.TabIndex = 26; - this.pictureBox10.TabStop = false; - this.toolTip.SetToolTip(this.pictureBox10, "Enables support for upscaling transparency.\r\nMode 1 should work for most images, " + - "but if you are unhappy with the result, try 2 or 3."); - // - // pictureBox2 - // - this.pictureBox2.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.pictureBox2.Image = global::Cupscale.Properties.Resources.questmark; - this.pictureBox2.Location = new System.Drawing.Point(78, 136); - this.pictureBox2.Name = "pictureBox2"; - this.pictureBox2.Size = new System.Drawing.Size(22, 22); - this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox2.TabIndex = 27; - this.pictureBox2.TabStop = false; - this.toolTip.SetToolTip(this.pictureBox2, "Color Depth of the alpha channel.\r\nUse Binary or Ternary for platforms and format" + - "s that have a limited alpha depth.\r\nFor example, GIFs or PSX sprites."); - // - // label16 - // - this.label16.AutoSize = true; - this.label16.Location = new System.Drawing.Point(6, 200); - this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(83, 13); - this.label16.TabIndex = 28; - this.label16.Text = "GPU ID (CUDA)"; - // - // gpuId - // - this.gpuId.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.gpuId.ForeColor = System.Drawing.Color.White; - this.gpuId.Location = new System.Drawing.Point(220, 197); - this.gpuId.Name = "gpuId"; - this.gpuId.Size = new System.Drawing.Size(225, 20); - this.gpuId.TabIndex = 29; - // - // pictureBox14 - // - this.pictureBox14.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.pictureBox14.Image = global::Cupscale.Properties.Resources.questmark; - this.pictureBox14.Location = new System.Drawing.Point(95, 196); - this.pictureBox14.Name = "pictureBox14"; - this.pictureBox14.Size = new System.Drawing.Size(22, 22); - this.pictureBox14.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox14.TabIndex = 30; - this.pictureBox14.TabStop = false; - this.toolTip.SetToolTip(this.pictureBox14, "Set which GPU will be used for upscaling.\r\n0 is the first device, 1 the second, a" + - "nd so on."); + this.label35.AutoSize = true; + this.label35.Location = new System.Drawing.Point(6, 260); + this.label35.Name = "label35"; + this.label35.Size = new System.Drawing.Size(172, 13); + this.label35.TabIndex = 23; + this.label35.Text = "Auto-Expand Model Selection Tree"; // // SettingsForm // @@ -1520,6 +1542,9 @@ private void InitializeComponent() this.tableLayoutPanel3.ResumeLayout(false); this.panel7.ResumeLayout(false); this.panel7.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox14)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox10)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.panel6.ResumeLayout(false); @@ -1557,9 +1582,6 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.pictureBox9)).EndInit(); this.logPage.ResumeLayout(false); this.logPage.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox10)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox14)).EndInit(); this.ResumeLayout(false); } @@ -1677,5 +1699,7 @@ private void InitializeComponent() private System.Windows.Forms.TextBox gpuId; private System.Windows.Forms.Label label16; private System.Windows.Forms.PictureBox pictureBox14; + private System.Windows.Forms.CheckBox modelSelectAutoExpand; + private System.Windows.Forms.Label label35; } } \ No newline at end of file diff --git a/Code/Forms/SettingsForm.cs b/Code/Forms/SettingsForm.cs index 8529023..36d87a9 100644 --- a/Code/Forms/SettingsForm.cs +++ b/Code/Forms/SettingsForm.cs @@ -50,6 +50,7 @@ void LoadSettings() Config.LoadGuiElement(reloadImageBeforeUpscale); Config.LoadComboxIndex(pythonRuntime); Config.LoadComboxIndex(comparisonUseScaling); + Config.LoadGuiElement(modelSelectAutoExpand); // Formats Config.LoadGuiElement(jpegQ); Config.LoadGuiElement(webpQ); @@ -100,6 +101,7 @@ void SaveSettings() Config.SaveGuiElement(reloadImageBeforeUpscale); Config.SaveComboxIndex(pythonRuntime); Config.SaveComboxIndex(comparisonUseScaling); + Config.SaveGuiElement(modelSelectAutoExpand); // Formats Config.SaveGuiElement(jpegQ, true); Config.SaveGuiElement(webpQ, true); diff --git a/Code/IO/Config.cs b/Code/IO/Config.cs index 31d5449..3763bb8 100644 --- a/Code/IO/Config.cs +++ b/Code/IO/Config.cs @@ -8,166 +8,189 @@ namespace Cupscale { - internal class Config - { - private static string configPath; - - private static string[] cachedLines; - - public static bool disable; - - public static void Init() - { - configPath = Path.Combine(IOUtils.GetAppDataDir(), "config.ini"); - if (!File.Exists(configPath)) - { - File.Create(configPath).Close(); - } - Reload(); - } - - public static void Set(string key, string value) - { - if (disable) return; - - string[] lines = File.ReadAllLines(configPath); - for (int i = 0; i < lines.Length; i++) - { - if (lines[i].Split('|')[0] == key) - { - lines[i] = key + "|" + value; - File.WriteAllLines(configPath, lines); - cachedLines = lines; - return; - } - } - List list = lines.ToList(); - list.Add(key + "|" + value); - File.WriteAllLines(configPath, list.ToArray()); - cachedLines = list.ToArray(); - } - - public static string Get(string key) - { - for (int i = 0; i < cachedLines.Length; i++) - { - string[] keyValuePair = cachedLines[i].Split('|'); - if (keyValuePair[0] == key) - return keyValuePair[1]; - } - return WriteDefaultValIfExists(key); - } - - public static bool GetBool (string key) - { - return bool.Parse(Get(key)); - } - - public static int GetInt (string key) - { - for (int i = 0; i < cachedLines.Length; i++) - { - string[] keyValuePair = cachedLines[i].Split('|'); - if (keyValuePair[0] == key) - return int.Parse(keyValuePair[1].Trim()); - } - return int.Parse(WriteDefaultValIfExists(key).Trim()); - } - - private static string WriteDefaultValIfExists(string key) - { - return key switch - { - "esrganPath" => WriteDefault(key, Installer.path), - "esrganVer" => WriteDefault(key, "0"), - "tilesize" => WriteDefault(key, "1024"), - "alpha" => WriteDefault(key, "False"), - "alphaMode" => WriteDefault(key, "1"), - "alphaDepth" => WriteDefault(key, "0"), - "seamlessMode" => WriteDefault(key, "0"), - "alphaBgColor" => WriteDefault(key, "000000FF"), - "jpegExtension" => WriteDefault(key, "jpg"), - "jpegQ" => WriteDefault(key, "95"), - "webpQ" => WriteDefault(key, "95"), - "dxtMode" => WriteDefault(key, "BC1 (DXT1)"), - "ddsEnableMips" => WriteDefault(key, "True"), - "previewFormat" => WriteDefault(key, "0"), - "cudaFallback" => WriteDefault(key, "0"), - "gpuId" => WriteDefault(key, "0"), - "reloadImageBeforeUpscale" => WriteDefault(key, "False"), - "cmdDebug" => WriteDefault(key, "False"), - "flipTga" => WriteDefault(key, "True"), - "logIo" => WriteDefault(key, "False"), - "logStatus" => WriteDefault(key, "False"), - "cmdDebugMode" => WriteDefault(key, "0"), - "pythonRuntime" => WriteDefault(key, "0"), - "useMozJpeg" => WriteDefault(key, "True"), - "comparisonUseScaling" => WriteDefault(key, "0"), - "joeyAlphaMode" => WriteDefault(key, "1"), - // Video - "h265" => WriteDefault(key, "False"), - "crf" => WriteDefault(key, "18"), - "gifskiQ" => WriteDefault(key, "100"), - "vidEnableAudio" => WriteDefault(key, "True"), - _ => null, - }; - } - - private static string WriteDefault(string key, string def) - { - Set(key, def); - return def; - } - - private static void Reload() - { - cachedLines = File.ReadAllLines(configPath); - } - - public static void SaveGuiElement(TextBox textbox, bool onlyAllowNumbers = false) - { - if(onlyAllowNumbers) - Set(textbox.Name, textbox.Text.GetInt().ToString()); - else - Set(textbox.Name, textbox.Text); - } - - public static void SaveGuiElement(ComboBox comboBox, bool onlyAllowNumbers = false) - { - if (onlyAllowNumbers) - Set(comboBox.Name, comboBox.Text.GetInt().ToString()); - else - Set(comboBox.Name, comboBox.Text); - } - - public static void SaveGuiElement(CheckBox checkbox) - { - Set(checkbox.Name, checkbox.Checked.ToString()); - } - - public static void SaveComboxIndex(ComboBox comboBox) - { - Set(comboBox.Name, comboBox.SelectedIndex.ToString()); - } - - public static void LoadGuiElement(ComboBox comboBox) - { - comboBox.Text = Get(comboBox.Name); - } - - public static void LoadGuiElement (TextBox textbox) - { - textbox.Text = Get(textbox.Name); - } - - public static void LoadGuiElement (CheckBox checkbox) - { - checkbox.Checked = bool.Parse(Get(checkbox.Name)); - } - - public static void LoadComboxIndex (ComboBox comboBox) - { - comboBox.SelectedIndex = GetInt(comboBox.Name); - } - } + internal class Config + { + private static string configPath; + + private static string[] cachedLines; + + public static bool disable; + + public static void Init() + { + configPath = Path.Combine(IOUtils.GetAppDataDir(), "config.ini"); + if (!File.Exists(configPath)) + { + File.Create(configPath).Close(); + } + Reload(); + } + + public static void Set(string key, string value) + { + if (disable) return; + + string[] lines = File.ReadAllLines(configPath); + for (int i = 0; i < lines.Length; i++) + { + if (lines[i].Split('|')[0] == key) + { + lines[i] = key + "|" + value; + File.WriteAllLines(configPath, lines); + cachedLines = lines; + return; + } + } + List list = lines.ToList(); + list.Add(key + "|" + value); + File.WriteAllLines(configPath, list.ToArray()); + cachedLines = list.ToArray(); + } + + public static string Get(string key, Type type = Type.String) + { + try + { + for (int i = 0; i < cachedLines.Length; i++) + { + string[] keyValuePair = cachedLines[i].Split('|'); + if (keyValuePair[0] == key && !string.IsNullOrWhiteSpace(keyValuePair[1])) + return keyValuePair[1]; + } + return WriteDefaultValIfExists(key, type); + } + catch (Exception e) + { + Logger.Log($"Failed to get {key.Wrap()} from config! {e.Message}"); + } + return null; + } + + public static bool GetBool(string key) + { + return bool.Parse(Get(key)); + } + + public static bool GetBool(string key, bool defaultVal) + { + WriteIfDoesntExist(key, (defaultVal ? "True" : "False")); + return bool.Parse(Get(key, Type.Bool)); + } + + public static int GetInt(string key) + { + for (int i = 0; i < cachedLines.Length; i++) + { + string[] keyValuePair = cachedLines[i].Split('|'); + if (keyValuePair[0] == key) + return int.Parse(keyValuePair[1].Trim()); + } + return int.Parse(WriteDefaultValIfExists(key, Type.Int).Trim()); + } + + static void WriteIfDoesntExist(string key, string val) + { + foreach (string line in cachedLines) + if (line.Contains(key + "|")) + return; + Set(key, val); + } + + public enum Type { String, Int, Float, Bool } + private static string WriteDefaultValIfExists(string key, Type type) + { + if (key == "esrganPath") return WriteDefault(key, Installer.path); + if (key == "esrganVer") return WriteDefault(key, "0"); + if (key == "tilesize") return WriteDefault(key, "1024"); + if (key == "alpha") return WriteDefault(key, "False"); + if (key == "alphaMode") return WriteDefault(key, "1"); + if (key == "alphaDepth") return WriteDefault(key, "0"); + if (key == "seamlessMode") return WriteDefault(key, "0"); + if (key == "alphaBgColor") return WriteDefault(key, "000000FF"); + if (key == "jpegExtension") return WriteDefault(key, "jpg"); + if (key == "jpegQ") return WriteDefault(key, "95"); + if (key == "webpQ") return WriteDefault(key, "95"); + if (key == "dxtMode") return WriteDefault(key, "BC1 (DXT1)"); + if (key == "ddsEnableMips") return WriteDefault(key, "True"); + if (key == "previewFormat") return WriteDefault(key, "0"); + if (key == "cudaFallback") return WriteDefault(key, "0"); + if (key == "gpuId") return WriteDefault(key, "0"); + if (key == "reloadImageBeforeUpscale") return WriteDefault(key, "False"); + if (key == "cmdDebug") return WriteDefault(key, "False"); + if (key == "flipTga") return WriteDefault(key, "True"); + if (key == "logIo") return WriteDefault(key, "False"); + if (key == "logStatus") return WriteDefault(key, "False"); + if (key == "cmdDebugMode") return WriteDefault(key, "0"); + if (key == "pythonRuntime") return WriteDefault(key, "0"); + if (key == "useMozJpeg") return WriteDefault(key, "True"); + if (key == "comparisonUseScaling") return WriteDefault(key, "0"); + if (key == "joeyAlphaMode") return WriteDefault(key, "1"); + // Video + if (key == "h265") return WriteDefault(key, "False"); + if (key == "crf") return WriteDefault(key, "18"); + if (key == "gifskiQ") return WriteDefault(key, "100"); + if (key == "vidEnableAudio") return WriteDefault(key, "True"); + + if (type == Type.Int || type == Type.Float) return WriteDefault(key, "0"); // Write default int/float (0) + if (type == Type.Bool) return WriteDefault(key, "False"); // Write default bool (False) + return WriteDefault(key, "0"); + } + + private static string WriteDefault(string key, string def) + { + Set(key, def); + return def; + } + + private static void Reload() + { + cachedLines = File.ReadAllLines(configPath); + } + + public static void SaveGuiElement(TextBox textbox, bool onlyAllowNumbers = false) + { + if (onlyAllowNumbers) + Set(textbox.Name, textbox.Text.GetInt().ToString()); + else + Set(textbox.Name, textbox.Text); + } + + public static void SaveGuiElement(ComboBox comboBox, bool onlyAllowNumbers = false) + { + if (onlyAllowNumbers) + Set(comboBox.Name, comboBox.Text.GetInt().ToString()); + else + Set(comboBox.Name, comboBox.Text); + } + + public static void SaveGuiElement(CheckBox checkbox) + { + Set(checkbox.Name, checkbox.Checked.ToString()); + } + + public static void SaveComboxIndex(ComboBox comboBox) + { + Set(comboBox.Name, comboBox.SelectedIndex.ToString()); + } + + public static void LoadGuiElement(ComboBox comboBox) + { + comboBox.Text = Get(comboBox.Name); + } + + public static void LoadGuiElement(TextBox textbox) + { + textbox.Text = Get(textbox.Name); + } + + public static void LoadGuiElement(CheckBox checkbox) + { + checkbox.Checked = bool.Parse(Get(checkbox.Name)); + } + + public static void LoadComboxIndex(ComboBox comboBox) + { + comboBox.SelectedIndex = GetInt(comboBox.Name); + } + } } diff --git a/Code/Main/MainForm.Designer.cs b/Code/Main/MainForm.Designer.cs index 0c835ea..1be5b75 100644 --- a/Code/Main/MainForm.Designer.cs +++ b/Code/Main/MainForm.Designer.cs @@ -184,6 +184,8 @@ private void InitializeComponent() this.interpRbtn = new System.Windows.Forms.RadioButton(); this.singleModelRbtn = new System.Windows.Forms.RadioButton(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.label24 = new System.Windows.Forms.Label(); + this.batchCacheSplitDepth = new System.Windows.Forms.ComboBox(); this.mainTableLayoutPanel.SuspendLayout(); this.tableLayoutPanel4.SuspendLayout(); this.tableLayoutPanel5.SuspendLayout(); @@ -539,6 +541,8 @@ private void InitializeComponent() // // panel12 // + this.panel12.Controls.Add(this.label24); + this.panel12.Controls.Add(this.batchCacheSplitDepth); this.panel12.Controls.Add(this.tableLayoutPanel10); this.panel12.Controls.Add(this.label19); this.panel12.Controls.Add(this.preprocessMode); @@ -2429,6 +2433,35 @@ private void InitializeComponent() this.singleModelRbtn.UseVisualStyleBackColor = true; this.singleModelRbtn.CheckedChanged += new System.EventHandler(this.singleModelRbtn_CheckedChanged); // + // label24 + // + this.label24.AutoSize = true; + this.label24.ForeColor = System.Drawing.Color.White; + this.label24.Location = new System.Drawing.Point(8, 167); + this.label24.Margin = new System.Windows.Forms.Padding(8, 8, 8, 2); + this.label24.Name = "label24"; + this.label24.Size = new System.Drawing.Size(104, 15); + this.label24.TabIndex = 21; + this.label24.Text = "Auto-Tiling Mode:"; + // + // batchCacheSplitDepth + // + this.batchCacheSplitDepth.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.batchCacheSplitDepth.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.batchCacheSplitDepth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.batchCacheSplitDepth.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.batchCacheSplitDepth.ForeColor = System.Drawing.Color.White; + this.batchCacheSplitDepth.FormattingEnabled = true; + this.batchCacheSplitDepth.Items.AddRange(new object[] { + "Check Tile Size For Each Image", + "Cache Tile Size (If all images are the same size)"}); + this.batchCacheSplitDepth.Location = new System.Drawing.Point(8, 186); + this.batchCacheSplitDepth.Margin = new System.Windows.Forms.Padding(8, 2, 8, 2); + this.batchCacheSplitDepth.Name = "batchCacheSplitDepth"; + this.batchCacheSplitDepth.Size = new System.Drawing.Size(255, 23); + this.batchCacheSplitDepth.TabIndex = 20; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2651,5 +2684,7 @@ private void InitializeComponent() private Label label30; private ComboBox videoPreprocessMode; private HTAlt.WinForms.HTButton patreonBtn; + private Label label24; + private ComboBox batchCacheSplitDepth; } } diff --git a/Code/Main/MainForm.cs b/Code/Main/MainForm.cs index 54746ea..da935d1 100644 --- a/Code/Main/MainForm.cs +++ b/Code/Main/MainForm.cs @@ -55,6 +55,7 @@ private async void MainForm_Load(object sender, EventArgs e) // Batch Upscale UIHelpers.InitCombox(batchOutMode, 0); UIHelpers.InitCombox(preprocessMode, 0); + UIHelpers.InitCombox(batchCacheSplitDepth, 0); // Video Upscale UIHelpers.InitCombox(videoPreprocessMode, 1); @@ -376,10 +377,10 @@ private async void upscaleBtn_Click(object sender, EventArgs e) if (Config.GetBool("reloadImageBeforeUpscale")) ReloadImage(); + UpdateResizeMode(); - ESRGAN.cacheTiling = (htTabControl.SelectedIndex == 2); if (htTabControl.SelectedIndex == 0) await PreviewUI.UpscaleImage(); - if (htTabControl.SelectedIndex == 1) await BatchUpscaleUI.Run(preprocessMode.SelectedIndex == 0); + if (htTabControl.SelectedIndex == 1) await BatchUpscaleUI.Run(preprocessMode.SelectedIndex == 0, true, batchCacheSplitDepth.SelectedIndex == 1); if (htTabControl.SelectedIndex == 2) await VideoUpscaleUI.Run(videoPreprocessMode.SelectedIndex == 0); } diff --git a/Code/OS/ESRGAN.cs b/Code/OS/ESRGAN.cs index 50bb262..a6c2703 100644 --- a/Code/OS/ESRGAN.cs +++ b/Code/OS/ESRGAN.cs @@ -21,12 +21,11 @@ internal class ESRGAN { public enum PreviewMode { None, Cutout, FullImage } public enum Backend { CUDA, CPU, NCNN }; - public static bool cacheTiling = false; + //public static bool cacheTiling = false; - public static async Task DoUpscale(string inpath, string outpath, ModelData mdl, string tilesize, bool alpha, PreviewMode mode, Backend backend, bool showTileProgress = true) + public static async Task DoUpscale(string inpath, string outpath, ModelData mdl, bool cacheSplitDepth, bool alpha, PreviewMode mode, Backend backend, bool showTileProgress = true) { Program.cancelled = false; // Reset cancel flag - bool useJoey = true; //Config.GetInt("esrganVer") == 0; try { if (backend == Backend.NCNN) @@ -38,11 +37,8 @@ public static async Task DoUpscale(string inpath, string outpath, ModelData mdl, { Program.mainForm.SetProgress(2f, "Starting ESRGAN..."); File.Delete(Paths.progressLogfile); - string modelArg = GetModelArg(mdl, useJoey); - if (useJoey) - await RunJoey(inpath, outpath, modelArg, alpha, showTileProgress); - else - await Run(inpath, outpath, modelArg, tilesize, alpha, showTileProgress); + string modelArg = GetModelArg(mdl); + await RunJoey(inpath, outpath, modelArg, cacheSplitDepth, alpha, showTileProgress); } if (mode == PreviewMode.Cutout) @@ -97,7 +93,7 @@ public static async Task ScalePreviewOutput() ImageProcessing.ResizeImagePost(img); } - public static string GetModelArg(ModelData mdl, bool joey) + public static string GetModelArg(ModelData mdl, bool joey = true) { string mdl1 = mdl.model1Path; string mdl2 = mdl.model2Path; @@ -189,7 +185,7 @@ public static async Task Run(string inpath, string outpath, string modelArg, str File.Delete(Paths.progressLogfile); } - public static async Task RunJoey(string inpath, string outpath, string modelArg, bool alpha, bool showTileProgress) + public static async Task RunJoey(string inpath, string outpath, string modelArg, bool cacheSplitDepth, bool alpha, bool showTileProgress) { bool showWindow = Config.GetInt("cmdDebugMode") > 0; bool stayOpen = Config.GetInt("cmdDebugMode") == 2; @@ -216,7 +212,7 @@ public static async Task RunJoey(string inpath, string outpath, string modelArg, case 4: seam += "alpha_pad"; break; } - string cache = cacheTiling ? "--cache_max_split_depth" : ""; + string cache = cacheSplitDepth ? "--cache_max_split_depth" : ""; string opt = stayOpen ? "/K" : "/C"; @@ -329,7 +325,6 @@ public static async Task RunNcnn(string inpath, string outpath, string modelPath await NcnnUtils.ConvertNcnnModel(modelPath); Logger.Log("[ESRGAN] NCNN Model is ready: " + currentNcnnModel); Program.mainForm.SetProgress(3f, "Loading ESRGAN-NCNN..."); - //DialogForm dialog = new DialogForm("Loading ESRGAN-NCNN...\nThis should take 10-25 seconds.", 14); int scale = NcnnUtils.GetNcnnModelScale(currentNcnnModel); string opt = stayOpen ? "/K" : "/C"; @@ -340,18 +335,22 @@ public static async Task RunNcnn(string inpath, string outpath, string modelPath Process ncnnProcess = OSUtils.NewProcess(!showWindow); ncnnProcess.StartInfo.Arguments = cmd; + if (!showWindow) { ncnnProcess.OutputDataReceived += NcnnOutputHandler; ncnnProcess.ErrorDataReceived += NcnnOutputHandler; } + Program.currentEsrganProcess = ncnnProcess; ncnnProcess.Start(); + if (!showWindow) { ncnnProcess.BeginOutputReadLine(); ncnnProcess.BeginErrorReadLine(); } + while (!ncnnProcess.HasExited) await Task.Delay(50); @@ -361,6 +360,7 @@ public static async Task RunNcnn(string inpath, string outpath, string modelPath Program.mainForm.SetProgress(100f, "[ESRGAN] Post-Processing..."); PostProcessingQueue.Stop(); } + File.Delete(Paths.progressLogfile); } diff --git a/Code/UI/BatchUpscaleUI.cs b/Code/UI/BatchUpscaleUI.cs index ed49e68..6d41975 100644 --- a/Code/UI/BatchUpscaleUI.cs +++ b/Code/UI/BatchUpscaleUI.cs @@ -141,7 +141,7 @@ static void FillFileList (string[] files, bool relativePath) fileList.AppendText(text); } - public static async Task Run (bool preprocess, bool postProcess = true, string overrideOutDir = "") + public static async Task Run (bool preprocess, bool postProcess = true, bool cacheSplitDepth = false, string overrideOutDir = "") { int cudaFallback = Config.Get("cudaFallback").GetInt(); bool useNcnn = (cudaFallback == 2 || cudaFallback == 3); @@ -186,7 +186,7 @@ public static async Task Run (bool preprocess, bool postProcess = true, string o ESRGAN.Backend backend = ESRGAN.Backend.CUDA; if (useCpu) backend = ESRGAN.Backend.CPU; if (useNcnn) backend = ESRGAN.Backend.NCNN; - tasks.Add(ESRGAN.DoUpscale(Paths.imgInPath, Paths.imgOutPath, mdl, Config.Get("tilesize"), bool.Parse(Config.Get("alpha")), ESRGAN.PreviewMode.None, backend, false)); + tasks.Add(ESRGAN.DoUpscale(Paths.imgInPath, Paths.imgOutPath, mdl, cacheSplitDepth, bool.Parse(Config.Get("alpha")), ESRGAN.PreviewMode.None, backend, false)); if (postProcess) { tasks.Add(PostProcessingQueue.Update()); diff --git a/Code/UI/PreviewUI.cs b/Code/UI/PreviewUI.cs index 3571695..dd15670 100644 --- a/Code/UI/PreviewUI.cs +++ b/Code/UI/PreviewUI.cs @@ -79,7 +79,7 @@ public static async Task UpscaleImage() ESRGAN.Backend backend = ESRGAN.Backend.CUDA; if (useCpu) backend = ESRGAN.Backend.CPU; if (useNcnn) backend = ESRGAN.Backend.NCNN; - await ESRGAN.DoUpscale(Paths.imgInPath, Paths.imgOutPath, mdl, Config.Get("tilesize"), Config.GetBool("alpha"), ESRGAN.PreviewMode.None, backend); + await ESRGAN.DoUpscale(Paths.imgInPath, Paths.imgOutPath, mdl, false, Config.GetBool("alpha"), ESRGAN.PreviewMode.None, backend); if (backend == ESRGAN.Backend.NCNN) outImg = Directory.GetFiles(Paths.imgOutPath, "*.png*", SearchOption.AllDirectories)[0]; else @@ -191,7 +191,7 @@ public static async void UpscalePreview(bool fullImage = false) string mdl1 = Program.currentModel1; if (string.IsNullOrWhiteSpace(mdl1)) return; ModelData mdl = new ModelData(mdl1, null, ModelData.ModelMode.Single); - await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, tilesize, alpha, prevMode, backend); + await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, false, alpha, prevMode, backend); } if (currentMode == Mode.Interp) { @@ -199,7 +199,7 @@ public static async void UpscalePreview(bool fullImage = false) string mdl2 = Program.currentModel2; if (string.IsNullOrWhiteSpace(mdl1) || string.IsNullOrWhiteSpace(mdl2)) return; ModelData mdl = new ModelData(mdl1, mdl2, ModelData.ModelMode.Interp, interpValue); - await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, tilesize, alpha, prevMode, backend); + await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, false, alpha, prevMode, backend); } if (currentMode == Mode.Chain) { @@ -207,12 +207,12 @@ public static async void UpscalePreview(bool fullImage = false) string mdl2 = Program.currentModel2; if (string.IsNullOrWhiteSpace(mdl1) || string.IsNullOrWhiteSpace(mdl2)) return; ModelData mdl = new ModelData(mdl1, mdl2, ModelData.ModelMode.Chain); - await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, tilesize, alpha, prevMode, backend); + await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, false, alpha, prevMode, backend); } if (currentMode == Mode.Advanced) { ModelData mdl = new ModelData(null, null, ModelData.ModelMode.Advanced); - await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, tilesize, alpha, prevMode, backend); + await ESRGAN.DoUpscale(Paths.previewPath, Paths.previewOutPath, mdl, false, alpha, prevMode, backend); } if (!Program.cancelled) Program.mainForm.SetProgress(0, $"Done - Upscaling took {(sw.ElapsedMilliseconds / 1000f).ToString("0.0")}s"); diff --git a/Code/UI/VideoUpscaleUI.cs b/Code/UI/VideoUpscaleUI.cs index d6a6c16..7359b98 100644 --- a/Code/UI/VideoUpscaleUI.cs +++ b/Code/UI/VideoUpscaleUI.cs @@ -61,26 +61,29 @@ public static async Task Run(bool preprocess) { logBox.Clear(); Print("Starting upscale of " + Path.GetFileName(currentInPath)); + if (string.IsNullOrWhiteSpace(currentInPath) || !File.Exists(currentInPath)) { Program.ShowMessage("No valid file loaded.", "Error"); return; } + if (!IOUtils.HasEnoughDiskSpace(IOUtils.GetAppDataDir(), 10.0f)) { Program.ShowMessage($"Not enough disk space on {IOUtils.GetAppDataDir().Substring(0, 3)} to store temporary files!", "Error"); return; } + Program.mainForm.SetBusy(true); LoadVideo(); Print("Extracting frames..."); await FFmpegCommands.VideoToFrames(currentInPath, Paths.imgInPath, false, false, false); int amountFrames = IOUtils.GetAmountOfCompatibleFiles(Paths.imgInPath, false); - Print($"Done - Extracted {amountFrames} frames."); + Print($"Done - Extracted {amountFrames} frames."); await PreprocessIfNeeded(preprocess); BatchUpscaleUI.LoadDir(Paths.imgInPath, true); Print("Upscaling frames..."); - await BatchUpscaleUI.Run(false, true, Paths.framesOutPath); + await BatchUpscaleUI.Run(false, true, false, Paths.framesOutPath); RenameOutFiles(); Print($"Done upscaling all frames."); BatchUpscaleUI.Reset();