mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-12-03 18:00:18 +00:00
Add same improvements to the gx2 texture importer
This commit is contained in:
parent
9c6d3883cf
commit
d0fa47a959
7 changed files with 61 additions and 11 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -154,7 +154,7 @@ namespace Bfres.Structs
|
|||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
if (setting.GenerateMipmaps)
|
||||
if (setting.GenerateMipmaps && !setting.IsFinishedCompressing)
|
||||
{
|
||||
setting.DataBlockOutput.Clear();
|
||||
setting.DataBlockOutput.Add(setting.GenerateMips());
|
||||
|
@ -245,7 +245,7 @@ namespace Bfres.Structs
|
|||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
if (setting.GenerateMipmaps)
|
||||
if (setting.GenerateMipmaps && !setting.IsFinishedCompressing)
|
||||
{
|
||||
setting.DataBlockOutput.Clear();
|
||||
setting.DataBlockOutput.Add(setting.GenerateMips());
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace FirstPlugin
|
|||
public GX2AAMode AAMode = GX2AAMode.Mode1X;
|
||||
public float alphaRef = 0.5f;
|
||||
|
||||
public bool IsFinishedCompressing = false;
|
||||
|
||||
public void LoadDDS(string FileName, byte[] FileData = null)
|
||||
{
|
||||
TexName = STGenericTexture.SetNameFromPath(FileName);
|
||||
|
@ -106,27 +108,49 @@ namespace FirstPlugin
|
|||
throw new Exception("Failed to load " + Format);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<byte[]> GenerateMipList(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, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));
|
||||
}
|
||||
Image.Dispose();
|
||||
|
||||
return mipmaps;
|
||||
}
|
||||
|
||||
public byte[] GenerateMips(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, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));
|
||||
|
||||
//while (Image.Width / 2 > 0 && Image.Height / 2 > 0)
|
||||
// for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
|
||||
for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
|
||||
{
|
||||
Image = BitmapExtension.Resize(Image, Image.Width / 2, Image.Height / 2);
|
||||
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, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));
|
||||
Image.Width, Image.Height, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef));
|
||||
}
|
||||
Image.Dispose();
|
||||
|
||||
return Utils.CombineByteArray(mipmaps.ToArray());
|
||||
}
|
||||
|
||||
public void Compress()
|
||||
{
|
||||
DataBlockOutput.Clear();
|
||||
|
|
|
@ -167,10 +167,19 @@ namespace FirstPlugin
|
|||
|
||||
Thread = new Thread((ThreadStart)(() =>
|
||||
{
|
||||
SelectedTexSettings.IsFinishedCompressing = false;
|
||||
ToggleOkButton(false);
|
||||
|
||||
var mips = SelectedTexSettings.GenerateMipList();
|
||||
SelectedTexSettings.DataBlockOutput.Clear();
|
||||
SelectedTexSettings.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));
|
||||
|
||||
ToggleOkButton(true);
|
||||
|
||||
pictureBox1.Image = bitmap;
|
||||
SelectedTexSettings.Compress();
|
||||
|
||||
bitmap = FTEX.DecodeBlockGetBitmap(SelectedTexSettings.DataBlockOutput[0], SelectedTexSettings.
|
||||
bitmap = FTEX.DecodeBlockGetBitmap(mips[0], SelectedTexSettings.
|
||||
TexWidth, SelectedTexSettings.TexHeight, FTEX.ConvertFromGx2Format(
|
||||
(Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)SelectedTexSettings.Format));
|
||||
|
||||
|
@ -180,6 +189,18 @@ namespace FirstPlugin
|
|||
Thread.Start();
|
||||
}
|
||||
|
||||
private void ToggleOkButton(bool Enable)
|
||||
{
|
||||
if (button1.InvokeRequired)
|
||||
{
|
||||
button1.Invoke((MethodInvoker)delegate {
|
||||
button1.Enabled = Enable;
|
||||
});
|
||||
}
|
||||
else
|
||||
button1.Enabled = Enable;
|
||||
}
|
||||
|
||||
private void tileModeCB_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (tileModeCB.SelectedIndex > -1 && SelectedTexSettings != null)
|
||||
|
@ -549,12 +570,17 @@ namespace FirstPlugin
|
|||
private Switch_Toolbox.Library.Forms.STButton button1;
|
||||
|
||||
private void MipmapNum_ValueChanged(object sender, EventArgs e) {
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
if (SelectedTexSettings != null)
|
||||
{
|
||||
if (MipmapNum.Value > 0)
|
||||
SelectedTexSettings.MipCount = (uint)MipmapNum.Value;
|
||||
else
|
||||
SelectedTexSettings.MipCount = 1;
|
||||
|
||||
SetupSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue