diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 96848cf4..a246e88d 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index 166edd5a..4a653538 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index 6ab7b0d3..a8aaa180 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs index bd6a1813..b5d3473a 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs @@ -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()); diff --git a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs index b81a2bef..cde127aa 100644 --- a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs +++ b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs @@ -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 GenerateMipList(int SurfaceLevel = 0) + { + Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); + + List mipmaps = new List(); + 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 mipmaps = new List(); - 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(); diff --git a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs index 6510b39e..443ec509 100644 --- a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs +++ b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs @@ -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(); } } } diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index 5e891cb1..6942e265 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache differ