mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-30 00:10:36 +00:00
Cleanup BTI, Finalize TXE with the help of KILLZ
This commit is contained in:
parent
7a4a443b5c
commit
3011a153aa
7 changed files with 143 additions and 135 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -5,10 +5,12 @@ using Toolbox.Library;
|
||||||
using Toolbox.Library.Forms;
|
using Toolbox.Library.Forms;
|
||||||
using Toolbox.Library.IO;
|
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 FileType FileType { get; set; } = FileType.Image;
|
||||||
|
|
||||||
public bool CanSave { get; set; }
|
public bool CanSave { get; set; }
|
||||||
|
@ -47,29 +49,38 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
|
||||||
return height + ((BlockHeight - (height % BlockHeight)) % BlockHeight);
|
return height + ((BlockHeight - (height % BlockHeight)) % BlockHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Read(System.IO.Stream stream)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void Load(System.IO.Stream stream)
|
public void Load(System.IO.Stream stream)
|
||||||
{
|
{
|
||||||
//Set this if you want to save the file format
|
//Set this if you want to save the file format
|
||||||
CanSave = true;
|
CanSave = true;
|
||||||
|
CanEdit = false;
|
||||||
|
|
||||||
|
ImageKey = "Texture";
|
||||||
|
SelectedImageKey = "Texture";
|
||||||
|
Text = FileName;
|
||||||
|
|
||||||
//You can add a FileReader with Toolbox.Library.IO namespace
|
//You can add a FileReader with Toolbox.Library.IO namespace
|
||||||
using (var reader = new FileReader(stream))
|
using (var reader = new FileReader(stream))
|
||||||
{
|
{
|
||||||
Texture tex = new Texture();
|
CanEdit = false;
|
||||||
tex.CanEdit = false;
|
|
||||||
|
|
||||||
reader.SetByteOrder(true);
|
reader.SetByteOrder(true);
|
||||||
|
|
||||||
//Turn this format into a common format used by this tool
|
//Turn this format into a common format used by this tool
|
||||||
byte texFormat = reader.ReadByte();
|
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
|
_ = reader.ReadByte(); // enable alpha
|
||||||
tex.Width = reader.ReadUInt16();
|
Width = reader.ReadUInt16();
|
||||||
tex.Height = reader.ReadUInt16();
|
Height = reader.ReadUInt16();
|
||||||
_ = reader.ReadByte(); // wrap s
|
_ = reader.ReadByte(); // wrap s
|
||||||
_ = reader.ReadByte(); // wrap t
|
_ = reader.ReadByte(); // wrap t
|
||||||
tex.PaletteFormat = (PALETTE_FORMAT)reader.ReadInt16();
|
PaletteFormat = (PALETTE_FORMAT)reader.ReadInt16();
|
||||||
_ = reader.ReadInt16(); // num of palette entries
|
_ = reader.ReadInt16(); // num of palette entries
|
||||||
_ = reader.ReadInt32(); // offset to palette data
|
_ = reader.ReadInt32(); // offset to palette data
|
||||||
_ = reader.ReadInt32(); // border colour
|
_ = reader.ReadInt32(); // border colour
|
||||||
|
@ -77,23 +88,19 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
|
||||||
_ = reader.ReadByte(); // mag filter type
|
_ = reader.ReadByte(); // mag filter type
|
||||||
_ = reader.ReadInt16();
|
_ = reader.ReadInt16();
|
||||||
|
|
||||||
tex.MipCount = reader.ReadByte();
|
MipCount = reader.ReadByte();
|
||||||
_ = reader.ReadByte();
|
_ = reader.ReadByte();
|
||||||
_ = reader.ReadInt16();
|
_ = reader.ReadInt16();
|
||||||
uint offsetToImageData = reader.ReadUInt32(); // offset to image data
|
uint offsetToImageData = reader.ReadUInt32(); // offset to image data
|
||||||
|
|
||||||
//Lets set our method of decoding
|
//Lets set our method of decoding
|
||||||
tex.PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
|
PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
|
||||||
|
|
||||||
reader.Seek(offsetToImageData, System.IO.SeekOrigin.Begin);
|
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 imageDataSize = RoundWidth((int)Width, (int)GetBlockWidth(Format)) *
|
||||||
* (int)STGenericTexture.GetBytesPerPixel(tex.Format) >> 3;
|
RoundHeight((int)Height, (int)GetBlockHeight(Format)) * (int)GetBytesPerPixel(Format) >> 3;
|
||||||
|
|
||||||
tex.ImageData = reader.ReadBytes(imageDataSize);
|
ImageData = reader.ReadBytes(imageDataSize);
|
||||||
|
|
||||||
tex.Name = FileName;
|
|
||||||
tex.ToolTipText = "Binary Texture Image, used for 2D textures like fonts";
|
|
||||||
_ = Nodes.Add(tex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,18 +114,16 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Texture : STGenericTexture
|
public byte[] ImageData { get; set; }
|
||||||
{
|
|
||||||
public byte[] ImageData { get; set; }
|
|
||||||
|
|
||||||
//A list of supported formats
|
//A list of supported formats
|
||||||
//This gets used in the re encode option
|
//This gets used in the re encode option
|
||||||
public override TEX_FORMAT[] SupportedFormats
|
public override TEX_FORMAT[] SupportedFormats
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
get
|
return new TEX_FORMAT[]
|
||||||
{
|
{
|
||||||
return new TEX_FORMAT[]
|
|
||||||
{
|
|
||||||
TEX_FORMAT.I4,
|
TEX_FORMAT.I4,
|
||||||
TEX_FORMAT.I8,
|
TEX_FORMAT.I8,
|
||||||
TEX_FORMAT.I4,
|
TEX_FORMAT.I4,
|
||||||
|
@ -130,46 +135,45 @@ namespace AmbrosiaPikmin1.FileFormats.BTI
|
||||||
TEX_FORMAT.C8,
|
TEX_FORMAT.C8,
|
||||||
TEX_FORMAT.C14X2,
|
TEX_FORMAT.C14X2,
|
||||||
TEX_FORMAT.CMPR,
|
TEX_FORMAT.CMPR,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override bool CanEdit { get; set; } = false;
|
public override bool CanEdit { get; set; } = false;
|
||||||
|
|
||||||
//This gets used in the image editor if the image gets edited
|
//This gets used in the image editor if the image gets edited
|
||||||
//This wll not be ran if "CanEdit" is set to false!
|
//This wll not be ran if "CanEdit" is set to false!
|
||||||
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
|
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Gets the raw image data in bytes
|
||||||
|
//Gets decoded automatically
|
||||||
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||||
|
{
|
||||||
|
return ImageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//This is an event for when the tree is clicked on
|
||||||
|
//Load our editor
|
||||||
|
public override void OnClick(TreeView treeView)
|
||||||
|
{
|
||||||
|
//Here we check for an active editor and load a new one if not found
|
||||||
|
//This is used when a tree/object editor is used
|
||||||
|
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
|
||||||
|
if (editor == null)
|
||||||
{
|
{
|
||||||
|
editor = new ImageEditorBase();
|
||||||
|
editor.Dock = DockStyle.Fill;
|
||||||
|
LibraryGUI.LoadEditor(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gets the raw image data in bytes
|
//Load our image and any properties
|
||||||
//Gets decoded automatically
|
//If you don't make a class for properties you can use a generic class provided in STGenericTexture
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
editor.LoadProperties(GenericProperties);
|
||||||
{
|
editor.LoadImage(this);
|
||||||
return ImageData;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//This is an event for when the tree is clicked on
|
|
||||||
//Load our editor
|
|
||||||
public override void OnClick(TreeView treeView)
|
|
||||||
{
|
|
||||||
//Here we check for an active editor and load a new one if not found
|
|
||||||
//This is used when a tree/object editor is used
|
|
||||||
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
|
|
||||||
if (editor == null)
|
|
||||||
{
|
|
||||||
editor = new ImageEditorBase();
|
|
||||||
editor.Dock = DockStyle.Fill;
|
|
||||||
LibraryGUI.LoadEditor(editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Load our image and any properties
|
|
||||||
//If you don't make a class for properties you can use a generic class provided in STGenericTexture
|
|
||||||
editor.LoadProperties(GenericProperties);
|
|
||||||
editor.LoadImage(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,12 @@ using Toolbox.Library;
|
||||||
using Toolbox.Library.Forms;
|
using Toolbox.Library.Forms;
|
||||||
using Toolbox.Library.IO;
|
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 FileType FileType { get; set; } = FileType.Image;
|
||||||
|
|
||||||
public bool CanSave { get; set; }
|
public bool CanSave { get; set; }
|
||||||
|
@ -43,33 +45,18 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
|
||||||
stream.Seek((~(offset - 1) & (stream.Position + offset - 1)) - stream.Position);
|
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
|
[0] = TEX_FORMAT.RGB5A3,
|
||||||
using (var reader = new FileReader(stream))
|
[1] = TEX_FORMAT.CMPR,
|
||||||
{
|
[2] = TEX_FORMAT.RGB565,
|
||||||
Texture tex = new Texture();
|
[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)
|
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
|
//Set this if you want to save the file format
|
||||||
CanSave = false;
|
CanSave = false;
|
||||||
|
|
||||||
Texture tex = Read(stream);
|
|
||||||
|
|
||||||
ImageKey = "Texture";
|
ImageKey = "Texture";
|
||||||
SelectedImageKey = "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()
|
public byte[] Save()
|
||||||
|
@ -95,18 +103,16 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Texture : STGenericTexture
|
public byte[] ImageData { get; set; }
|
||||||
{
|
|
||||||
public byte[] ImageData { get; set; }
|
|
||||||
|
|
||||||
//A list of supported formats
|
//A list of supported formats
|
||||||
//This gets used in the re encode option
|
//This gets used in the re encode option
|
||||||
public override TEX_FORMAT[] SupportedFormats
|
public override TEX_FORMAT[] SupportedFormats
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
get
|
return new TEX_FORMAT[]
|
||||||
{
|
{
|
||||||
return new TEX_FORMAT[]
|
|
||||||
{
|
|
||||||
TEX_FORMAT.I4,
|
TEX_FORMAT.I4,
|
||||||
TEX_FORMAT.I8,
|
TEX_FORMAT.I8,
|
||||||
TEX_FORMAT.IA4,
|
TEX_FORMAT.IA4,
|
||||||
|
@ -118,46 +124,46 @@ namespace AmbrosiaPikmin1.FileFormats.TXE
|
||||||
TEX_FORMAT.C8,
|
TEX_FORMAT.C8,
|
||||||
TEX_FORMAT.C14X2,
|
TEX_FORMAT.C14X2,
|
||||||
TEX_FORMAT.CMPR,
|
TEX_FORMAT.CMPR,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override bool CanEdit { get; set; } = false;
|
|
||||||
|
|
||||||
//This gets used in the image editor if the image gets edited
|
public override bool CanEdit { get; set; } = false;
|
||||||
//This wll not be ran if "CanEdit" is set to false!
|
|
||||||
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
|
//This gets used in the image editor if the image gets edited
|
||||||
|
//This wll not be ran if "CanEdit" is set to false!
|
||||||
|
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Gets the raw image data in bytes
|
||||||
|
//Gets decoded automatically
|
||||||
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||||
|
{
|
||||||
|
return ImageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//This is an event for when the tree is clicked on
|
||||||
|
//Load our editor
|
||||||
|
public override void OnClick(TreeView treeView)
|
||||||
|
{
|
||||||
|
//Here we check for an active editor and load a new one if not found
|
||||||
|
//This is used when a tree/object editor is used
|
||||||
|
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
|
||||||
|
if (editor == null)
|
||||||
{
|
{
|
||||||
|
editor = new ImageEditorBase();
|
||||||
|
editor.Dock = DockStyle.Fill;
|
||||||
|
LibraryGUI.LoadEditor(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gets the raw image data in bytes
|
//Load our image and any properties
|
||||||
//Gets decoded automatically
|
//If you don't make a class for properties you can use a generic class provided in STGenericTexture
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
editor.LoadProperties(GenericProperties);
|
||||||
{
|
editor.LoadImage(this);
|
||||||
return ImageData;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//This is an event for when the tree is clicked on
|
|
||||||
//Load our editor
|
|
||||||
public override void OnClick(TreeView treeView)
|
|
||||||
{
|
|
||||||
//Here we check for an active editor and load a new one if not found
|
|
||||||
//This is used when a tree/object editor is used
|
|
||||||
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
|
|
||||||
if (editor == null)
|
|
||||||
{
|
|
||||||
editor = new ImageEditorBase();
|
|
||||||
editor.Dock = DockStyle.Fill;
|
|
||||||
LibraryGUI.LoadEditor(editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Load our image and any properties
|
|
||||||
//If you don't make a class for properties you can use a generic class provided in STGenericTexture
|
|
||||||
editor.LoadProperties(GenericProperties);
|
|
||||||
editor.LoadImage(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ using Toolbox.Library.Forms;
|
||||||
using Toolbox.Library.IO;
|
using Toolbox.Library.IO;
|
||||||
using FirstPlugin.Forms;
|
using FirstPlugin.Forms;
|
||||||
using FirstPlugin.LuigisMansion.DarkMoon;
|
using FirstPlugin.LuigisMansion.DarkMoon;
|
||||||
using AmbrosiaPikmin1.FileFormats.BTI;
|
|
||||||
using AmbrosiaPikmin1.FileFormats.TXE;
|
|
||||||
|
|
||||||
namespace FirstPlugin
|
namespace FirstPlugin
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue