1
0
mirror of synced 2024-12-11 23:36:01 +01:00

Some fixes to texture importer and auto flip bffnt bitmaps on import

This commit is contained in:
KillzXGaming 2020-03-23 21:13:58 -04:00
parent 446568f641
commit 0096dd95c2
4 changed files with 19 additions and 4 deletions

View File

@ -134,7 +134,7 @@ namespace FirstPlugin
short idx = reader.ReadInt16(); short idx = reader.ReadInt16();
if (idx != -1) header.FontSection.CodeMapDictionary[i] = idx; if (idx != -1) header.FontSection.CodeMapDictionary[i] = idx;
Console.WriteLine($"direct {i} {idx}"); Console.WriteLine($"table {i} {idx}");
table.Add(idx); table.Add(idx);
} }

View File

@ -23,6 +23,7 @@ namespace FirstPlugin
TextureTGLP = texture; TextureTGLP = texture;
Height = TextureTGLP.SheetHeight; Height = TextureTGLP.SheetHeight;
Width = TextureTGLP.SheetWidth; Width = TextureTGLP.SheetWidth;
MipCount = 1;
var BFNTFormat = (Gx2ImageFormats)TextureTGLP.Format; var BFNTFormat = (Gx2ImageFormats)TextureTGLP.Format;
Format = ConvertToGeneric(BFNTFormat); Format = ConvertToGeneric(BFNTFormat);
if (Format == TEX_FORMAT.BC4_UNORM) if (Format == TEX_FORMAT.BC4_UNORM)
@ -67,7 +68,7 @@ namespace FirstPlugin
public override void Replace(string FileName) public override void Replace(string FileName)
{ {
Bfres.Structs.FTEX ftex = new Bfres.Structs.FTEX(); 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) if (ftex.texture != null)
{ {
TextureTGLP.Format = (ushort)ConvertToGx2(ftex.Format); TextureTGLP.Format = (ushort)ConvertToGx2(ftex.Format);

View File

@ -13,6 +13,8 @@ namespace FirstPlugin
{ {
public class GTXImporterSettings public class GTXImporterSettings
{ {
public bool FlipY = false;
public string TexName; public string TexName;
public uint TexWidth; public uint TexWidth;
public uint TexHeight; public uint TexHeight;
@ -136,6 +138,10 @@ namespace FirstPlugin
public List<byte[]> GenerateMipList(int SurfaceLevel = 0) public List<byte[]> GenerateMipList(int SurfaceLevel = 0)
{ {
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);
if (FlipY)
Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
Console.WriteLine($"FlipY {FlipY}");
List<byte[]> mipmaps = new List<byte[]>(); List<byte[]> mipmaps = new List<byte[]>();
for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
@ -158,6 +164,9 @@ namespace FirstPlugin
{ {
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);
if (FlipY)
Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
List<byte[]> mipmaps = new List<byte[]>(); List<byte[]> mipmaps = new List<byte[]>();
for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
{ {
@ -177,6 +186,9 @@ namespace FirstPlugin
public void Compress() public void Compress()
{ {
if (IsFinishedCompressing)
return;
DataBlockOutput.Clear(); DataBlockOutput.Clear();
foreach (var surface in DecompressedData) foreach (var surface in DecompressedData)
{ {

View File

@ -201,13 +201,15 @@ namespace FirstPlugin
setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray())); setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray()));
ToggleOkButton(true); ToggleOkButton(true);
setting.IsFinishedCompressing = true;
setting.Compress();
bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting. bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting.
TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format( TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format(
(Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]); (Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]);
if (setting.FlipY)
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
if (setting.UseBc4Alpha) { if (setting.UseBc4Alpha) {
bitmap = BitmapExtension.SetChannel(bitmap, bitmap = BitmapExtension.SetChannel(bitmap,
STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.Red); STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.Red);