Cleanup BTI, Finalize TXE with the help of KILLZ

This commit is contained in:
JohnFiddleystein 2019-08-04 15:27:00 +01:00
parent 7a4a443b5c
commit 3011a153aa
7 changed files with 143 additions and 135 deletions

Binary file not shown.

View file

@ -5,10 +5,12 @@ using Toolbox.Library;
using Toolbox.Library.Forms;
using Toolbox.Library.IO;
namespace AmbrosiaPikmin1.FileFormats.BTI
namespace FirstPlugin
{
class BTI : TreeNodeFile, IFileFormat
class BTI : STGenericTexture, IFileFormat, ISingleTextureIconLoader
{
public STGenericTexture IconTexture { get { return this; } }
public FileType FileType { get; set; } = FileType.Image;
public bool CanSave { get; set; }
@ -47,29 +49,38 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
return height + ((BlockHeight - (height % BlockHeight)) % BlockHeight);
}
private void Read(System.IO.Stream stream)
{
}
public void Load(System.IO.Stream stream)
{
//Set this if you want to save the file format
CanSave = true;
CanEdit = false;
ImageKey = "Texture";
SelectedImageKey = "Texture";
Text = FileName;
//You can add a FileReader with Toolbox.Library.IO namespace
using (var reader = new FileReader(stream))
{
Texture tex = new Texture();
tex.CanEdit = false;
CanEdit = false;
reader.SetByteOrder(true);
//Turn this format into a common format used by this tool
byte texFormat = reader.ReadByte();
tex.Format = Decode_Gamecube.ToGenericFormat((Decode_Gamecube.TextureFormats)texFormat);
Format = Decode_Gamecube.ToGenericFormat((Decode_Gamecube.TextureFormats)texFormat);
_ = reader.ReadByte(); // enable alpha
tex.Width = reader.ReadUInt16();
tex.Height = reader.ReadUInt16();
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();
_ = reader.ReadByte(); // wrap s
_ = reader.ReadByte(); // wrap t
tex.PaletteFormat = (PALETTE_FORMAT)reader.ReadInt16();
PaletteFormat = (PALETTE_FORMAT)reader.ReadInt16();
_ = reader.ReadInt16(); // num of palette entries
_ = reader.ReadInt32(); // offset to palette data
_ = reader.ReadInt32(); // border colour
@ -77,23 +88,19 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
_ = reader.ReadByte(); // mag filter type
_ = reader.ReadInt16();
tex.MipCount = reader.ReadByte();
MipCount = reader.ReadByte();
_ = reader.ReadByte();
_ = reader.ReadInt16();
uint offsetToImageData = reader.ReadUInt32(); // offset to image data
//Lets set our method of decoding
tex.PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
reader.Seek(offsetToImageData, System.IO.SeekOrigin.Begin);
int imageDataSize = RoundWidth((int)tex.Width, (int)STGenericTexture.GetBlockWidth(tex.Format)) * RoundHeight((int)tex.Height, (int)STGenericTexture.GetBlockHeight(tex.Format))
* (int)STGenericTexture.GetBytesPerPixel(tex.Format) >> 3;
int imageDataSize = RoundWidth((int)Width, (int)GetBlockWidth(Format)) *
RoundHeight((int)Height, (int)GetBlockHeight(Format)) * (int)GetBytesPerPixel(Format) >> 3;
tex.ImageData = reader.ReadBytes(imageDataSize);
tex.Name = FileName;
tex.ToolTipText = "Binary Texture Image, used for 2D textures like fonts";
_ = Nodes.Add(tex);
ImageData = reader.ReadBytes(imageDataSize);
}
}
@ -107,8 +114,6 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
}
public class Texture : STGenericTexture
{
public byte[] ImageData { get; set; }
//A list of supported formats
@ -172,4 +177,3 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
}
}
}
}

View file

@ -5,10 +5,12 @@ using Toolbox.Library;
using Toolbox.Library.Forms;
using Toolbox.Library.IO;
namespace AmbrosiaPikmin1.FileFormats.TXE
namespace FirstPlugin
{
class TXE : TreeNodeFile, IFileFormat
class TXE : STGenericTexture, IFileFormat, ISingleTextureIconLoader
{
public STGenericTexture IconTexture { get { return this; } }
public FileType FileType { get; set; } = FileType.Image;
public bool CanSave { get; set; }
@ -43,33 +45,18 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
stream.Seek((~(offset - 1) & (stream.Position + offset - 1)) - stream.Position);
}
private Texture Read(System.IO.Stream stream)
public static Dictionary<ushort, TEX_FORMAT> FormatsTXE = new Dictionary<ushort, TEX_FORMAT>()
{
//You can add a FileReader with Toolbox.Library.IO namespace
using (var reader = new FileReader(stream))
{
Texture tex = new Texture();
[0] = TEX_FORMAT.RGB5A3,
[1] = TEX_FORMAT.CMPR,
[2] = TEX_FORMAT.RGB565,
[3] = TEX_FORMAT.I4,
[4] = TEX_FORMAT.I8,
[5] = TEX_FORMAT.IA4,
[6] = TEX_FORMAT.IA8,
[7] = TEX_FORMAT.RGBA32,
};
reader.SetByteOrder(true);
tex.Width = reader.ReadUInt16();
tex.Height = reader.ReadUInt16();
_ = reader.ReadInt16();
//Turn this format into a common format used by this tool
short texFormat = reader.ReadInt16();
tex.Format = Decode_Gamecube.ToGenericFormat((Decode_Gamecube.TextureFormats)texFormat);
//Lets set our method of decoding
tex.PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
int imageDataSize = reader.ReadInt32();
SkipPadding(reader, 0x20);
tex.ImageData = reader.ReadBytes(imageDataSize);
tex.Name = FileName;
return tex;
}
}
public void Load(System.IO.Stream stream)
{
@ -77,12 +64,33 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
//Set this if you want to save the file format
CanSave = false;
Texture tex = Read(stream);
ImageKey = "Texture";
SelectedImageKey = "Texture";
Nodes.Add(tex);
//You can add a FileReader with Toolbox.Library.IO namespace
using (var reader = new FileReader(stream))
{
reader.SetByteOrder(true);
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();
_ = reader.ReadInt16();
//Turn this format into a common format used by this tool
ushort texFormat = reader.ReadUInt16();
Format = FormatsTXE[texFormat];
//Lets set our method of decoding
PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
int imageDataSize = reader.ReadInt32();
SkipPadding(reader, 0x20);
reader.SeekBegin(32);
ImageData = reader.ReadBytes(imageDataSize);
Text = FileName;
}
}
public byte[] Save()
@ -95,8 +103,6 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
}
public class Texture : STGenericTexture
{
public byte[] ImageData { get; set; }
//A list of supported formats
@ -122,6 +128,7 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
}
}
public override bool CanEdit { get; set; } = false;
//This gets used in the image editor if the image gets edited
@ -160,4 +167,3 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
}
}
}
}

View file

@ -8,8 +8,6 @@ using Toolbox.Library.Forms;
using Toolbox.Library.IO;
using FirstPlugin.Forms;
using FirstPlugin.LuigisMansion.DarkMoon;
using AmbrosiaPikmin1.FileFormats.BTI;
using AmbrosiaPikmin1.FileFormats.TXE;
namespace FirstPlugin
{