BNTX : Add BC4 alpha support

This commit is contained in:
KillzXGaming 2020-01-11 18:06:34 -05:00
parent e639ac58b0
commit 7936762ec9
3 changed files with 38 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -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);
}
}
}
}

View file

@ -159,11 +159,13 @@ namespace FirstPlugin
}
public List<byte[]> GenerateMipList(STCompressionMode CompressionMode, bool multiThread, int SurfaceLevel = 0)
public List<byte[]> 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<byte[]> mipmaps = new List<byte[]>();
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));