Only compress a texture once if loaded in texture importer

This commit is contained in:
KillzXGaming 2019-05-20 19:21:00 -04:00
parent 02de27faad
commit 9c6d3883cf
9 changed files with 45 additions and 17 deletions

Binary file not shown.

View file

@ -19,7 +19,6 @@ namespace FirstPlugin
public STCompressionMode CompressionMode = STCompressionMode.Normal;
public int SelectedIndex = -1;
public bool ForceMipCount = false;
public uint SelectedMipCount
@ -35,6 +34,8 @@ namespace FirstPlugin
}
}
private bool IsLoaded = false;
public BinaryTextureImporterList()
{
InitializeComponent();
@ -97,6 +98,8 @@ namespace FirstPlugin
tileModeCB.SelectedIndex = 0;
formatComboBox.SelectedItem = SurfaceFormat.BC1_SRGB;
IsLoaded = true;
button1.Select();
}
TextureImporterSettings SelectedTexSettings;
@ -162,24 +165,29 @@ namespace FirstPlugin
ToggleOkButton(false);
pictureBox1.Image = bitmap;
SelectedTexSettings.Compress(CompressionMode);
var mips = SelectedTexSettings.GenerateMipList(CompressionMode);
SelectedTexSettings.DataBlockOutput.Clear();
SelectedTexSettings.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));
ToggleOkButton(true);
// SelectedTexSettings.IsFinishedCompressing = true;
SelectedTexSettings.IsFinishedCompressing = true;
if (SelectedTexSettings.DataBlockOutput.Count > 0) {
if (SelectedTexSettings.Format == SurfaceFormat.BC5_SNORM)
{
bitmap = DDSCompressor.DecompressBC5(SelectedTexSettings.DataBlockOutput[0],
bitmap = DDSCompressor.DecompressBC5(mips[0],
(int)SelectedTexSettings.TexWidth, (int)SelectedTexSettings.TexHeight, true);
}
else
{
bitmap = STGenericTexture.DecodeBlockGetBitmap(SelectedTexSettings.DataBlockOutput[0],
bitmap = STGenericTexture.DecodeBlockGetBitmap(mips[0],
SelectedTexSettings.TexWidth, SelectedTexSettings.TexHeight, TextureData.ConvertFormat(SelectedTexSettings.Format));
}
}
mips.Clear();
if (pictureBox1.InvokeRequired)
{
pictureBox1.Invoke((MethodInvoker)delegate {
@ -246,10 +254,15 @@ namespace FirstPlugin
private void MipmapNum_ValueChanged(object sender, EventArgs e)
{
if (!IsLoaded)
return;
if (MipmapNum.Value > 0)
SelectedTexSettings.MipCount = (uint)MipmapNum.Value;
else
SelectedTexSettings.MipCount = 1;
SetupSettings();
}
private void BinaryTextureImporterList_KeyDown(object sender, KeyEventArgs e)

View file

@ -148,26 +148,41 @@ namespace FirstPlugin
}
public List<byte[]> GenerateMipList(STCompressionMode CompressionMode, int SurfaceLevel = 0)
{
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);
List<byte[]> mipmaps = new List<byte[]>();
for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
{
int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel);
int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);
if (mipLevel != 0)
Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
}
Image.Dispose();
return mipmaps;
}
public byte[] GenerateMips(STCompressionMode CompressionMode, int SurfaceLevel = 0)
{
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);
List<byte[]> mipmaps = new List<byte[]>();
mipmaps.Add(STGenericTexture.CompressBlock(DecompressedData[SurfaceLevel],
(int)TexWidth, (int)TexHeight, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
//while (Image.Width / 2 > 0 && Image.Height / 2 > 0)
// for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
{
int width = Image.Width / 2;
int height = Image.Height / 2;
if (width <= 0)
width = 1;
if (height <= 0)
height = 1;
int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel);
int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);
if (mipLevel != 0)
Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
Image = BitmapExtension.Resize(Image, width, height);
mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
}