From 0096dd95c2b4604ffa2d699bdd0628e4ff799181 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Mon, 23 Mar 2020 21:13:58 -0400 Subject: [PATCH] Some fixes to texture importer and auto flip bffnt bitmaps on import --- File_Format_Library/FileFormats/Font/BXFNT/CMAP.cs | 2 +- .../FileFormats/Font/BXFNT/Images/Gx2ImageBlock.cs | 3 ++- .../TextureUI/Importers/GX2/GTXImporterSettings.cs | 12 ++++++++++++ .../TextureUI/Importers/GX2/GTXTextureImporter.cs | 6 ++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/File_Format_Library/FileFormats/Font/BXFNT/CMAP.cs b/File_Format_Library/FileFormats/Font/BXFNT/CMAP.cs index d545f4a3..3ede6aa5 100644 --- a/File_Format_Library/FileFormats/Font/BXFNT/CMAP.cs +++ b/File_Format_Library/FileFormats/Font/BXFNT/CMAP.cs @@ -134,7 +134,7 @@ namespace FirstPlugin short idx = reader.ReadInt16(); if (idx != -1) header.FontSection.CodeMapDictionary[i] = idx; - Console.WriteLine($"direct {i} {idx}"); + Console.WriteLine($"table {i} {idx}"); table.Add(idx); } diff --git a/File_Format_Library/FileFormats/Font/BXFNT/Images/Gx2ImageBlock.cs b/File_Format_Library/FileFormats/Font/BXFNT/Images/Gx2ImageBlock.cs index 0893dc49..a62dddde 100644 --- a/File_Format_Library/FileFormats/Font/BXFNT/Images/Gx2ImageBlock.cs +++ b/File_Format_Library/FileFormats/Font/BXFNT/Images/Gx2ImageBlock.cs @@ -23,6 +23,7 @@ namespace FirstPlugin TextureTGLP = texture; Height = TextureTGLP.SheetHeight; Width = TextureTGLP.SheetWidth; + MipCount = 1; var BFNTFormat = (Gx2ImageFormats)TextureTGLP.Format; Format = ConvertToGeneric(BFNTFormat); if (Format == TEX_FORMAT.BC4_UNORM) @@ -67,7 +68,7 @@ namespace FirstPlugin public override void Replace(string FileName) { Bfres.Structs.FTEX ftex = new Bfres.Structs.FTEX(); - ftex.ReplaceTexture(FileName, Format, 1, SwizzlePattern, SupportedFormats, true, true, false); + ftex.ReplaceTexture(FileName, Format, 1, SwizzlePattern, SupportedFormats, true, true, false, false, true); if (ftex.texture != null) { TextureTGLP.Format = (ushort)ConvertToGx2(ftex.Format); diff --git a/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs b/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs index d26061df..8f2e7528 100644 --- a/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs +++ b/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs @@ -13,6 +13,8 @@ namespace FirstPlugin { public class GTXImporterSettings { + public bool FlipY = false; + public string TexName; public uint TexWidth; public uint TexHeight; @@ -136,6 +138,10 @@ namespace FirstPlugin public List GenerateMipList(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); + if (FlipY) + Image.RotateFlip(RotateFlipType.RotateNoneFlipY); + + Console.WriteLine($"FlipY {FlipY}"); List mipmaps = new List(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) @@ -158,6 +164,9 @@ namespace FirstPlugin { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); + if (FlipY) + Image.RotateFlip(RotateFlipType.RotateNoneFlipY); + List mipmaps = new List(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { @@ -177,6 +186,9 @@ namespace FirstPlugin public void Compress() { + if (IsFinishedCompressing) + return; + DataBlockOutput.Clear(); foreach (var surface in DecompressedData) { diff --git a/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs b/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs index 059802a3..bbdbca4e 100644 --- a/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs +++ b/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs @@ -201,13 +201,15 @@ namespace FirstPlugin setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray())); ToggleOkButton(true); - - setting.Compress(); + setting.IsFinishedCompressing = true; bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting. TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format( (Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]); + + if (setting.FlipY) + bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); if (setting.UseBc4Alpha) { bitmap = BitmapExtension.SetChannel(bitmap, STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.Red);