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();
if (idx != -1) header.FontSection.CodeMapDictionary[i] = idx;
Console.WriteLine($"direct {i} {idx}");
Console.WriteLine($"table {i} {idx}");
table.Add(idx);
}

View file

@ -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);

View file

@ -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<byte[]> 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<byte[]> mipmaps = new List<byte[]>();
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<byte[]> mipmaps = new List<byte[]>();
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)
{

View file

@ -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);