From 5f1c94fc87522d912663ef23535fd466787441f3 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Mon, 21 Sep 2020 16:10:50 +0200 Subject: [PATCH] Added DDS compression and mipmap options --- Code/Forms/SettingsForm.Designer.cs | 155 +++++++++++++++++++--------- Code/Forms/SettingsForm.cs | 4 + Code/IO/Config.cs | 2 + Code/ImageUtils/ImageProcessing.cs | 7 ++ 4 files changed, 121 insertions(+), 47 deletions(-) diff --git a/Code/Forms/SettingsForm.Designer.cs b/Code/Forms/SettingsForm.Designer.cs index 577d451..17918ea 100644 --- a/Code/Forms/SettingsForm.Designer.cs +++ b/Code/Forms/SettingsForm.Designer.cs @@ -49,27 +49,32 @@ private void InitializeComponent() this.label4 = new System.Windows.Forms.Label(); this.alphaBgColor = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); - this.logPage = new Cyotek.Windows.Forms.TabListPage(); - this.logTbox = new System.Windows.Forms.TextBox(); - this.alphaBgColorDialog = new System.Windows.Forms.ColorDialog(); this.formatsPage = new Cyotek.Windows.Forms.TabListPage(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.panel1 = new System.Windows.Forms.Panel(); + this.webpQ = new System.Windows.Forms.TextBox(); + this.jpegQ = new System.Windows.Forms.TextBox(); this.label10 = new System.Windows.Forms.Label(); this.label11 = new System.Windows.Forms.Label(); this.label12 = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); - this.jpegQ = new System.Windows.Forms.TextBox(); - this.webpQ = new System.Windows.Forms.TextBox(); + this.logPage = new Cyotek.Windows.Forms.TabListPage(); + this.logTbox = new System.Windows.Forms.TextBox(); + this.alphaBgColorDialog = new System.Windows.Forms.ColorDialog(); + this.label3 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); + this.ddsMipsAmount = new System.Windows.Forms.TextBox(); + this.ddsUseDxt = new System.Windows.Forms.CheckBox(); + this.label14 = new System.Windows.Forms.Label(); this.tabList1.SuspendLayout(); this.settingsPage.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout(); this.panel7.SuspendLayout(); this.panel6.SuspendLayout(); - this.logPage.SuspendLayout(); this.formatsPage.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); this.panel1.SuspendLayout(); + this.logPage.SuspendLayout(); this.SuspendLayout(); // // tabList1 @@ -297,27 +302,6 @@ private void InitializeComponent() this.label9.TabIndex = 6; this.label9.Text = "Background Color"; // - // logPage - // - this.logPage.Controls.Add(this.logTbox); - this.logPage.Name = "logPage"; - this.logPage.Size = new System.Drawing.Size(762, 469); - this.logPage.Text = "View Log"; - // - // logTbox - // - this.logTbox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); - this.logTbox.Dock = System.Windows.Forms.DockStyle.Fill; - this.logTbox.ForeColor = System.Drawing.Color.Silver; - this.logTbox.Location = new System.Drawing.Point(0, 0); - this.logTbox.Margin = new System.Windows.Forms.Padding(24); - this.logTbox.Multiline = true; - this.logTbox.Name = "logTbox"; - this.logTbox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.logTbox.Size = new System.Drawing.Size(762, 469); - this.logTbox.TabIndex = 12; - this.logTbox.VisibleChanged += new System.EventHandler(this.logTbox_VisibleChanged); - // // formatsPage // this.formatsPage.Controls.Add(this.tableLayoutPanel1); @@ -347,6 +331,11 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel1.Controls.Add(this.label14); + this.panel1.Controls.Add(this.ddsUseDxt); + this.panel1.Controls.Add(this.ddsMipsAmount); + this.panel1.Controls.Add(this.label13); + this.panel1.Controls.Add(this.label3); this.panel1.Controls.Add(this.webpQ); this.panel1.Controls.Add(this.jpegQ); this.panel1.Controls.Add(this.label10); @@ -357,23 +346,41 @@ private void InitializeComponent() this.panel1.Size = new System.Drawing.Size(375, 463); this.panel1.TabIndex = 4; // + // webpQ + // + this.webpQ.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.webpQ.ForeColor = System.Drawing.Color.White; + this.webpQ.Location = new System.Drawing.Point(160, 107); + this.webpQ.Name = "webpQ"; + this.webpQ.Size = new System.Drawing.Size(66, 20); + this.webpQ.TabIndex = 13; + // + // jpegQ + // + this.jpegQ.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.jpegQ.ForeColor = System.Drawing.Color.White; + this.jpegQ.Location = new System.Drawing.Point(160, 77); + this.jpegQ.Name = "jpegQ"; + this.jpegQ.Size = new System.Drawing.Size(66, 20); + this.jpegQ.TabIndex = 12; + // // label10 // this.label10.AutoSize = true; this.label10.Location = new System.Drawing.Point(6, 110); this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(74, 13); + this.label10.Size = new System.Drawing.Size(106, 13); this.label10.TabIndex = 4; - this.label10.Text = "WEBP Quality"; + this.label10.Text = "WEBP: Quality Level"; // // label11 // this.label11.AutoSize = true; this.label11.Location = new System.Drawing.Point(6, 80); this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(69, 13); + this.label11.Size = new System.Drawing.Size(101, 13); this.label11.TabIndex = 2; - this.label11.Text = "JPEG Quality"; + this.label11.Text = "JPEG: Quality Level"; // // label12 // @@ -396,23 +403,72 @@ private void InitializeComponent() this.panel2.Size = new System.Drawing.Size(375, 463); this.panel2.TabIndex = 3; // - // jpegQ + // logPage // - this.jpegQ.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.jpegQ.ForeColor = System.Drawing.Color.White; - this.jpegQ.Location = new System.Drawing.Point(160, 77); - this.jpegQ.Name = "jpegQ"; - this.jpegQ.Size = new System.Drawing.Size(66, 20); - this.jpegQ.TabIndex = 12; + this.logPage.Controls.Add(this.logTbox); + this.logPage.Name = "logPage"; + this.logPage.Size = new System.Drawing.Size(762, 469); + this.logPage.Text = "View Log"; // - // webpQ + // logTbox // - this.webpQ.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.webpQ.ForeColor = System.Drawing.Color.White; - this.webpQ.Location = new System.Drawing.Point(160, 107); - this.webpQ.Name = "webpQ"; - this.webpQ.Size = new System.Drawing.Size(66, 20); - this.webpQ.TabIndex = 13; + this.logTbox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); + this.logTbox.Dock = System.Windows.Forms.DockStyle.Fill; + this.logTbox.ForeColor = System.Drawing.Color.Silver; + this.logTbox.Location = new System.Drawing.Point(0, 0); + this.logTbox.Margin = new System.Windows.Forms.Padding(24); + this.logTbox.Multiline = true; + this.logTbox.Name = "logTbox"; + this.logTbox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.logTbox.Size = new System.Drawing.Size(762, 469); + this.logTbox.TabIndex = 12; + this.logTbox.VisibleChanged += new System.EventHandler(this.logTbox_VisibleChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 140); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(143, 13); + this.label3.TabIndex = 14; + this.label3.Text = "DDS: Use DXT Compression"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(6, 170); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(131, 13); + this.label13.TabIndex = 15; + this.label13.Text = "DDS: Amount Of Mipmaps"; + // + // ddsMipsAmount + // + this.ddsMipsAmount.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.ddsMipsAmount.ForeColor = System.Drawing.Color.White; + this.ddsMipsAmount.Location = new System.Drawing.Point(160, 167); + this.ddsMipsAmount.Name = "ddsMipsAmount"; + this.ddsMipsAmount.Size = new System.Drawing.Size(66, 20); + this.ddsMipsAmount.TabIndex = 16; + // + // ddsUseDxt + // + this.ddsUseDxt.AutoSize = true; + this.ddsUseDxt.Location = new System.Drawing.Point(160, 140); + this.ddsUseDxt.Name = "ddsUseDxt"; + this.ddsUseDxt.Size = new System.Drawing.Size(15, 14); + this.ddsUseDxt.TabIndex = 17; + this.ddsUseDxt.UseVisualStyleBackColor = true; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.ForeColor = System.Drawing.Color.Silver; + this.label14.Location = new System.Drawing.Point(232, 170); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(127, 13); + this.label14.TabIndex = 18; + this.label14.Text = "Use 0 to disable mipmaps"; // // SettingsForm // @@ -433,12 +489,12 @@ private void InitializeComponent() this.panel7.PerformLayout(); this.panel6.ResumeLayout(false); this.panel6.PerformLayout(); - this.logPage.ResumeLayout(false); - this.logPage.PerformLayout(); this.formatsPage.ResumeLayout(false); this.tableLayoutPanel1.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); + this.logPage.ResumeLayout(false); + this.logPage.PerformLayout(); this.ResumeLayout(false); } @@ -477,5 +533,10 @@ private void InitializeComponent() private System.Windows.Forms.Label label11; private System.Windows.Forms.Label label12; private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.CheckBox ddsUseDxt; + private System.Windows.Forms.TextBox ddsMipsAmount; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.Label label3; } } \ No newline at end of file diff --git a/Code/Forms/SettingsForm.cs b/Code/Forms/SettingsForm.cs index e8795a1..9d95d3b 100644 --- a/Code/Forms/SettingsForm.cs +++ b/Code/Forms/SettingsForm.cs @@ -43,6 +43,8 @@ void LoadSettings () Config.LoadGuiElement(jpegQ); Config.LoadGuiElement(webpQ); + Config.LoadGuiElement(ddsUseDxt); + Config.LoadGuiElement(ddsMipsAmount); } private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e) @@ -61,6 +63,8 @@ void SaveSettings() Config.SaveGuiElement(jpegQ); Config.SaveGuiElement(webpQ); + Config.SaveGuiElement(ddsUseDxt); + Config.SaveGuiElement(ddsMipsAmount); } private void confAlphaBgColorBtn_Click(object sender, EventArgs e) diff --git a/Code/IO/Config.cs b/Code/IO/Config.cs index e92ce69..0b4a5d9 100644 --- a/Code/IO/Config.cs +++ b/Code/IO/Config.cs @@ -80,6 +80,8 @@ private static string WriteDefaultValIfExists(string key) "useCpu" => WriteDefault("useCpu", "False"), "jpegQ" => WriteDefault("jpegQ", "95"), "webpQ" => WriteDefault("webpQ", "95"), + "ddsUseDxt" => WriteDefault("ddsUseDxt", "True"), + "ddsMipsAmount" => WriteDefault("ddsMipsAmount", "0"), _ => null, }; } diff --git a/Code/ImageUtils/ImageProcessing.cs b/Code/ImageUtils/ImageProcessing.cs index 74e88a9..453ffaf 100644 --- a/Code/ImageUtils/ImageProcessing.cs +++ b/Code/ImageUtils/ImageProcessing.cs @@ -5,6 +5,8 @@ using System.Windows.Forms; using Cupscale.IO; using ImageMagick; +using ImageMagick.Formats.Bmp; +using ImageMagick.Formats.Dds; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats.Png; using Paths = Cupscale.IO.Paths; @@ -147,6 +149,11 @@ public static async Task ConvertImage(string path, Format format, bool fillAlpha { img.Format = MagickFormat.Dds; ext = "dds"; + DdsCompression comp = DdsCompression.None; + if(Config.GetBool("ddsUseDxt")) + comp = DdsCompression.Dxt1; + DdsWriteDefines ddsDefines = new DdsWriteDefines { Compression = comp, Mipmaps = Config.GetInt("ddsMipsAmount") }; + img.Settings.SetDefines(ddsDefines); } if (fillAlpha) {