From 7936762ec95cb2e0b063ab8a96f8d0ee6df55380 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Sat, 11 Jan 2020 18:06:34 -0500 Subject: [PATCH] BNTX : Add BC4 alpha support --- .../BinaryTextureImporterList.Designer.cs | 17 ++++++++++++++- .../BNTX/BinaryTextureImporterList.cs | 21 ++++++++++++++++--- .../Importers/BNTX/TextureImporterSettings.cs | 6 ++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.Designer.cs b/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.Designer.cs index 00e17680..7719e7da 100644 --- a/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.Designer.cs +++ b/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.Designer.cs @@ -52,6 +52,7 @@ this.dataSizeLbl = new Toolbox.Library.Forms.STLabel(); this.cnkGammaFix = new Toolbox.Library.Forms.STCheckBox(); this.chkMultiThreading = new Toolbox.Library.Forms.STCheckBox(); + this.chkBC4Alpha = new Toolbox.Library.Forms.STCheckBox(); this.contentContainer.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.SwizzleNum)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.MipmapNum)).BeginInit(); @@ -60,6 +61,7 @@ // // contentContainer // + this.contentContainer.Controls.Add(this.chkBC4Alpha); this.contentContainer.Controls.Add(this.chkMultiThreading); this.contentContainer.Controls.Add(this.cnkGammaFix); this.contentContainer.Controls.Add(this.dataSizeLbl); @@ -103,6 +105,7 @@ this.contentContainer.Controls.SetChildIndex(this.dataSizeLbl, 0); this.contentContainer.Controls.SetChildIndex(this.cnkGammaFix, 0); this.contentContainer.Controls.SetChildIndex(this.chkMultiThreading, 0); + this.contentContainer.Controls.SetChildIndex(this.chkBC4Alpha, 0); // // button2 // @@ -316,7 +319,7 @@ // cnkGammaFix // this.cnkGammaFix.AutoSize = true; - this.cnkGammaFix.Location = new System.Drawing.Point(757, 345); + this.cnkGammaFix.Location = new System.Drawing.Point(754, 345); this.cnkGammaFix.Name = "cnkGammaFix"; this.cnkGammaFix.Size = new System.Drawing.Size(160, 17); this.cnkGammaFix.TabIndex = 32; @@ -335,6 +338,17 @@ this.chkMultiThreading.UseVisualStyleBackColor = true; this.chkMultiThreading.CheckedChanged += new System.EventHandler(this.chkMultiThreading_CheckedChanged); // + // chkBC4Alpha + // + this.chkBC4Alpha.AutoSize = true; + this.chkBC4Alpha.Location = new System.Drawing.Point(754, 368); + this.chkBC4Alpha.Name = "chkBC4Alpha"; + this.chkBC4Alpha.Size = new System.Drawing.Size(76, 17); + this.chkBC4Alpha.TabIndex = 34; + this.chkBC4Alpha.Text = "BC4 Alpha"; + this.chkBC4Alpha.UseVisualStyleBackColor = true; + this.chkBC4Alpha.CheckedChanged += new System.EventHandler(this.chkBC4Alpha_CheckedChanged); + // // BinaryTextureImporterList // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -377,5 +391,6 @@ private Toolbox.Library.Forms.STLabel compModeLbl; private Toolbox.Library.Forms.STCheckBox cnkGammaFix; private Toolbox.Library.Forms.STCheckBox chkMultiThreading; + private Toolbox.Library.Forms.STCheckBox chkBC4Alpha; } } \ No newline at end of file diff --git a/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.cs b/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.cs index 1310e017..20eab117 100644 --- a/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.cs +++ b/File_Format_Library/GUI/TextureUI/Importers/BNTX/BinaryTextureImporterList.cs @@ -53,7 +53,6 @@ namespace FirstPlugin // if (format != SurfaceFormat.Invalid) } - formatComboBox.Items.Add(SurfaceFormat.D32_FLOAT_S8X24_UINT); formatComboBox.Items.Add(SurfaceFormat.A1_B5_G5_R5_UNORM); formatComboBox.Items.Add(SurfaceFormat.A4_B4_G4_R4_UNORM); @@ -93,6 +92,7 @@ namespace FirstPlugin compressionModeCB.SelectedIndex = 0; compressionModeCB.Visible = false; compModeLbl.Visible = false; + chkBC4Alpha.Enabled = false; foreach (SurfaceDim dim in (SurfaceDim[])Enum.GetValues(typeof(SurfaceDim))) { @@ -166,6 +166,11 @@ namespace FirstPlugin compModeLbl.Visible = false; } + if (setting.Format == SurfaceFormat.BC4_UNORM || setting.Format == SurfaceFormat.BC4_SNORM) + chkBC4Alpha.Enabled = true; + else + chkBC4Alpha.Enabled = false; + Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage(); if (compressionModeCB.SelectedIndex == 0) @@ -180,7 +185,8 @@ namespace FirstPlugin pictureBox1.Image = bitmap; - var mips = setting.GenerateMipList(CompressionMode, MultiThreading); + var mips = setting.GenerateMipList(CompressionMode, MultiThreading, chkBC4Alpha.Checked); + setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray())); @@ -198,6 +204,10 @@ namespace FirstPlugin bitmap = STGenericTexture.DecodeBlockGetBitmap(mips[0], setting.TexWidth, setting.TexHeight, TextureData.ConvertFormat(setting.Format), new byte[0]); } + + if (chkBC4Alpha.Checked) + bitmap = BitmapExtension.SetChannel(bitmap, STChannelType.Red, + STChannelType.Red, STChannelType.Red, STChannelType.Red); } if (pictureBox1.InvokeRequired) @@ -253,7 +263,6 @@ namespace FirstPlugin { SetupSettings(SelectedTexSettings); } - } private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e) @@ -341,5 +350,11 @@ namespace FirstPlugin SetupSettings(SelectedTexSettings, false); } } + + private void chkBC4Alpha_CheckedChanged(object sender, EventArgs e) { + if (SelectedTexSettings != null) { + SetupSettings(SelectedTexSettings, false); + } + } } } diff --git a/File_Format_Library/GUI/TextureUI/Importers/BNTX/TextureImporterSettings.cs b/File_Format_Library/GUI/TextureUI/Importers/BNTX/TextureImporterSettings.cs index 7e5f979c..dc124aae 100644 --- a/File_Format_Library/GUI/TextureUI/Importers/BNTX/TextureImporterSettings.cs +++ b/File_Format_Library/GUI/TextureUI/Importers/BNTX/TextureImporterSettings.cs @@ -159,11 +159,13 @@ namespace FirstPlugin } - public List GenerateMipList(STCompressionMode CompressionMode, bool multiThread, int SurfaceLevel = 0) + public List GenerateMipList(STCompressionMode CompressionMode, bool multiThread, bool bc4Alpha, int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); if (GammaFix) Image = BitmapExtension.AdjustGamma(Image, 2.2f); + if (bc4Alpha) + Image = BitmapExtension.SetChannel(Image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha); List mipmaps = new List(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) @@ -172,7 +174,7 @@ namespace FirstPlugin int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); if (mipLevel != 0) - Image = BitmapExtension.ResizeImage(Image, MipWidth, MipHeight); + Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, multiThread, CompressionMode));