1
0
mirror of synced 2024-11-29 01:34:42 +01:00

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 STCompressionMode CompressionMode = STCompressionMode.Normal;
public int SelectedIndex = -1; public int SelectedIndex = -1;
public bool ForceMipCount = false; public bool ForceMipCount = false;
public uint SelectedMipCount public uint SelectedMipCount
@ -35,6 +34,8 @@ namespace FirstPlugin
} }
} }
private bool IsLoaded = false;
public BinaryTextureImporterList() public BinaryTextureImporterList()
{ {
InitializeComponent(); InitializeComponent();
@ -97,6 +98,8 @@ namespace FirstPlugin
tileModeCB.SelectedIndex = 0; tileModeCB.SelectedIndex = 0;
formatComboBox.SelectedItem = SurfaceFormat.BC1_SRGB; formatComboBox.SelectedItem = SurfaceFormat.BC1_SRGB;
IsLoaded = true;
button1.Select(); button1.Select();
} }
TextureImporterSettings SelectedTexSettings; TextureImporterSettings SelectedTexSettings;
@ -162,24 +165,29 @@ namespace FirstPlugin
ToggleOkButton(false); ToggleOkButton(false);
pictureBox1.Image = bitmap; pictureBox1.Image = bitmap;
SelectedTexSettings.Compress(CompressionMode);
var mips = SelectedTexSettings.GenerateMipList(CompressionMode);
SelectedTexSettings.DataBlockOutput.Clear();
SelectedTexSettings.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));
ToggleOkButton(true); ToggleOkButton(true);
// SelectedTexSettings.IsFinishedCompressing = true; SelectedTexSettings.IsFinishedCompressing = true;
if (SelectedTexSettings.DataBlockOutput.Count > 0) { if (SelectedTexSettings.DataBlockOutput.Count > 0) {
if (SelectedTexSettings.Format == SurfaceFormat.BC5_SNORM) if (SelectedTexSettings.Format == SurfaceFormat.BC5_SNORM)
{ {
bitmap = DDSCompressor.DecompressBC5(SelectedTexSettings.DataBlockOutput[0], bitmap = DDSCompressor.DecompressBC5(mips[0],
(int)SelectedTexSettings.TexWidth, (int)SelectedTexSettings.TexHeight, true); (int)SelectedTexSettings.TexWidth, (int)SelectedTexSettings.TexHeight, true);
} }
else else
{ {
bitmap = STGenericTexture.DecodeBlockGetBitmap(SelectedTexSettings.DataBlockOutput[0], bitmap = STGenericTexture.DecodeBlockGetBitmap(mips[0],
SelectedTexSettings.TexWidth, SelectedTexSettings.TexHeight, TextureData.ConvertFormat(SelectedTexSettings.Format)); SelectedTexSettings.TexWidth, SelectedTexSettings.TexHeight, TextureData.ConvertFormat(SelectedTexSettings.Format));
} }
} }
mips.Clear();
if (pictureBox1.InvokeRequired) if (pictureBox1.InvokeRequired)
{ {
pictureBox1.Invoke((MethodInvoker)delegate { pictureBox1.Invoke((MethodInvoker)delegate {
@ -246,10 +254,15 @@ namespace FirstPlugin
private void MipmapNum_ValueChanged(object sender, EventArgs e) private void MipmapNum_ValueChanged(object sender, EventArgs e)
{ {
if (!IsLoaded)
return;
if (MipmapNum.Value > 0) if (MipmapNum.Value > 0)
SelectedTexSettings.MipCount = (uint)MipmapNum.Value; SelectedTexSettings.MipCount = (uint)MipmapNum.Value;
else else
SelectedTexSettings.MipCount = 1; SelectedTexSettings.MipCount = 1;
SetupSettings();
} }
private void BinaryTextureImporterList_KeyDown(object sender, KeyEventArgs e) 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) public byte[] GenerateMips(STCompressionMode CompressionMode, int SurfaceLevel = 0)
{ {
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);
List<byte[]> mipmaps = new List<byte[]>(); 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++) for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
{ {
int width = Image.Width / 2; int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel);
int height = Image.Height / 2; int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);
if (width <= 0)
width = 1; if (mipLevel != 0)
if (height <= 0) Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
height = 1;
Image = BitmapExtension.Resize(Image, width, height);
mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, CompressionMode)); Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
} }