diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index e218985a..67706485 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index bf932ad5..2eec72bd 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm index 7613ac0c..4649e6a1 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index 0a08db07..b14f2656 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/FileFormats/Archives/U8.cs b/Switch_FileFormatsMain/FileFormats/Archives/U8.cs new file mode 100644 index 00000000..28f1d26c --- /dev/null +++ b/Switch_FileFormatsMain/FileFormats/Archives/U8.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Switch_Toolbox; +using System.Windows.Forms; +using Switch_Toolbox.Library; +using Switch_Toolbox.Library.IO; + +namespace FirstPlugin +{ + public class U8 : IArchiveFile, IFileFormat, IDirectoryContainer + { + public FileType FileType { get; set; } = FileType.Archive; + + public bool CanSave { get; set; } + public string[] Description { get; set; } = new string[] { "U8" }; + public string[] Extension { get; set; } = new string[] { "*.u8"}; + public string FileName { get; set; } + public string FilePath { get; set; } + public IFileInfo IFileInfo { get; set; } + + public bool CanAddFiles { get; set; } + public bool CanRenameFiles { get; set; } + public bool CanReplaceFiles { get; set; } + public bool CanDeleteFiles { get; set; } + + public bool Identify(System.IO.Stream stream) + { + using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true)) + { + reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; + return reader.ReadUInt32() == 0x55AA382D; + } + } + + public Type[] Types + { + get + { + List types = new List(); + return types.ToArray(); + } + } + + public List nodes = new List(); + + public IEnumerable Files => null; + public IEnumerable Nodes => nodes; + + public string Name + { + get { return FileName; } + set { FileName = value; } + } + + private readonly uint Magic = 0x55AA382D; + + public void Load(System.IO.Stream stream) + { + using (var reader = new FileReader(stream)) + { + reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; + uint Signature = reader.ReadUInt32(); + uint FirstNodeOffset = reader.ReadUInt32(); + uint NodeSectionSize = reader.ReadUInt32(); + uint FileDataOffset = reader.ReadUInt32(); + byte[] Reserved = new byte[4]; + + var RootNode = new NodeEntry(); + RootNode.Read(reader); + nodes.Add(RootNode); + } + } + + public void SaveFile(FileWriter writer) + { + long pos = writer.Position; + + writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; + writer.Write(Magic); + + } + + public class NodeEntry : INode + { + public NodeType nodeType + { + get { return (NodeType)(flags >> 24); } + } + + public enum NodeType + { + Directory, + File, + } + + private uint _stringPoolOffset + { + get { return flags & 0x00ffffff; } + } + + private uint flags; + + public uint Setting1; //Offset (file) or parent index (directory) + public uint Setting2; //Size (file) or node count (directory) + + public string Name { get; set; } + + public void Read(FileReader reader) + { + flags = reader.ReadUInt32(); + Setting1 = reader.ReadUInt32(); + Setting2 = reader.ReadUInt32(); + } + } + + public void Unload() + { + + } + + public byte[] Save() + { + var mem = new System.IO.MemoryStream(); + SaveFile(new FileWriter(mem)); + return mem.ToArray(); + } + + public bool AddFile(ArchiveFileInfo archiveFileInfo) + { + return false; + } + + public bool DeleteFile(ArchiveFileInfo archiveFileInfo) + { + return false; + } + } +} diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs b/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs index 5969e3ca..bf99c5b2 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs @@ -385,6 +385,8 @@ namespace FirstPlugin return false; } + public STForm ActiveFormEditor; //For active form windows as editors + private bool DrawablesLoaded = false; public void LoadEditors(object SelectedSection) { @@ -731,20 +733,6 @@ namespace FirstPlugin OpenSubFileEditor(SelectedSection, bfresEditor); else if (SelectedSection is FVIS) OpenSubFileEditor(SelectedSection, bfresEditor); - - - /* else if (SelectedSection is FMAA && ((FMAA)SelectedSection).AnimType == MaterialAnimation.AnimationType.TexturePattern) - { - BfresTexturePatternEditor editor = (BfresTexturePatternEditor)bfresEditor.GetActiveEditor(typeof(BfresTexturePatternEditor)); - if (editor == null) - { - editor = new BfresTexturePatternEditor(); - bfresEditor.LoadEditor(editor); - } - editor.Text = Text; - editor.Dock = DockStyle.Fill; - editor.LoadAnim((FMAA)SelectedSection); - }*/ } } diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs index bebee442..86a88b70 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMAA.cs @@ -45,6 +45,15 @@ namespace Bfres.Structs name.Contains(VisibiltyAnimType2); } + public override void OnDoubleMouseClick(TreeView treeview) + { + var ParentFolder = this.Parent; + + BfresTexturePatternEditor form = new BfresTexturePatternEditor(ParentFolder.Nodes); + form.LoadAnim(this); + form.Show(); + } + public class MaterialAnimEntry : Material { public FMAA matAnimWrapper; diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs index 72082c9b..898e3512 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FTXP.cs @@ -204,6 +204,15 @@ namespace Bfres.Structs } } + public override void OnDoubleMouseClick(TreeView treeview) + { + var ParentFolder = this.Parent; + + BfresTexturePatternEditor form = new BfresTexturePatternEditor(ParentFolder.Nodes); + form.LoadAnim(this); + form.Show(); + } + public override string ExportFilter => FileFilters.GetFilter(typeof(FTXP)); public override void Export(string FileName) diff --git a/Switch_FileFormatsMain/FileFormats/Gamecube/TPL.cs b/Switch_FileFormatsMain/FileFormats/Gamecube/TPL.cs new file mode 100644 index 00000000..106b7d3b --- /dev/null +++ b/Switch_FileFormatsMain/FileFormats/Gamecube/TPL.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System.Threading.Tasks; +using Switch_Toolbox; +using System.Windows.Forms; +using Switch_Toolbox.Library; +using Switch_Toolbox.Library.Forms; +using Switch_Toolbox.Library.IO; + +namespace FirstPlugin +{ + public class TPL : TreeNodeFile, IFileFormat + { + public FileType FileType { get; set; } = FileType.Image; + + public bool CanSave { get; set; } + public string[] Description { get; set; } = new string[] { "TPL" }; + public string[] Extension { get; set; } = new string[] { "*.tpl" }; + public string FileName { get; set; } + public string FilePath { get; set; } + public IFileInfo IFileInfo { get; set; } + + public bool Identify(System.IO.Stream stream) + { + using (var reader = new FileReader(stream, true)) + { + reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; + return reader.ReadUInt32() == 0x0020AF30; + } + } + + public Type[] Types + { + get + { + List types = new List(); + return types.ToArray(); + } + } + + libWiiSharp.TPL tplFile = null; + + public void Load(System.IO.Stream stream) + { + Text = FileName; + + tplFile = libWiiSharp.TPL.Load(stream); + for (int i = 0; i < tplFile.NumOfTextures; i++) + Nodes.Add(new TPL_Texture(tplFile, i)); + } + + + public void Unload() + { + + } + + public byte[] Save() + { + MemoryStream mem = new MemoryStream(); + return mem.ToArray(); + } + + public class TPL_Texture : STGenericTexture + { + private libWiiSharp.TPL ParentTPL; + private int TextureIndex { get; set; } + + + private TextureProperties properties; + public class TextureProperties + { + private libWiiSharp.TPL ParentTPL; + private int TextureIndex { get; set; } + + public libWiiSharp.TPL_TextureFormat TextureFormat + { + get { return ParentTPL.GetTextureFormat(TextureIndex); } + } + + public libWiiSharp.TPL_PaletteFormat PaletteFormat + { + get { return ParentTPL.GetPaletteFormat(TextureIndex); } + } + + public int Width + { + get { return ParentTPL.GetImageWidth(TextureIndex); } + } + + public int Height + { + get { return ParentTPL.GetImageHeight(TextureIndex); } + } + + public TextureProperties(libWiiSharp.TPL tpl, int index) + { + ParentTPL = tpl; + TextureIndex = index; + } + } + + + + public TPL_Texture(libWiiSharp.TPL tpl, int index) + { + ParentTPL = tpl; + TextureIndex = index; + + Width = tpl.GetImageWidth(index); + Height = tpl.GetImageHeight(index); + MipCount = 1; + + Text = $"Image {index}"; + + Format = TEX_FORMAT.R8G8B8A8_UNORM; + + SelectedImageKey = "texture"; + ImageKey = "texture"; + + properties = new TextureProperties(tpl, index); + } + + public override bool CanEdit { get; set; } = false; + + public override TEX_FORMAT[] SupportedFormats + { + get + { + return new TEX_FORMAT[] + { + TEX_FORMAT.R8G8B8A8_UNORM, + }; + } + } + + public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel) + { + + } + + public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) + { + return ImageUtilty.ConvertBgraToRgba(ParentTPL.ExtractTextureByteArray(TextureIndex)); + } + + public override void OnClick(TreeView treeView) + { + UpdateEditor(); + } + + public void UpdateEditor() + { + ImageEditorBase editor = (ImageEditorBase)LibraryGUI.Instance.GetActiveContent(typeof(ImageEditorBase)); + if (editor == null) + { + editor = new ImageEditorBase(); + editor.Dock = DockStyle.Fill; + + LibraryGUI.Instance.LoadEditor(editor); + } + editor.Text = Text; + editor.LoadProperties(properties); + editor.LoadImage(this); + } + } + } +} diff --git a/Switch_FileFormatsMain/GUI/BFRES/SubFileEditor.cs b/Switch_FileFormatsMain/GUI/BFRES/SubFileEditor.cs index a97c905a..a9064b6f 100644 --- a/Switch_FileFormatsMain/GUI/BFRES/SubFileEditor.cs +++ b/Switch_FileFormatsMain/GUI/BFRES/SubFileEditor.cs @@ -84,18 +84,7 @@ namespace FirstPlugin.Forms if (anim.AnimType == MaterialAnimation.AnimationType.TexturePattern) { - BfresTexturePatternEditor editor =(BfresTexturePatternEditor)GetActiveControl(typeof(BfresTexturePatternEditor)); - if (editor == null) - { - stPanel2.Controls.Clear(); - editor = new BfresTexturePatternEditor(); - editor.Dock = DockStyle.Fill; - stPanel2.Controls.Add(editor); - } - - editor.LoadAnim(anim); - editor.Refresh(); } else { @@ -211,19 +200,6 @@ namespace FirstPlugin.Forms stPropertyGrid1.LoadProperty(anim.TexPatternAnim, OnPropertyChanged); userDataEditor1.LoadUserData(anim.TexPatternAnim.UserData); - - BfresTexturePatternEditor editor = (BfresTexturePatternEditor)GetActiveControl(typeof(BfresTexturePatternEditor)); - if (editor == null) - { - stPanel2.Controls.Clear(); - - editor = new BfresTexturePatternEditor(); - editor.Dock = DockStyle.Fill; - stPanel2.Controls.Add(editor); - } - - editor.LoadAnim(anim); - editor.Refresh(); } public void OnPropertyChanged() diff --git a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.Designer.cs b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.Designer.cs index 5ce87aec..cb8240f9 100644 --- a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.Designer.cs +++ b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.Designer.cs @@ -38,19 +38,30 @@ this.stPanel6 = new Switch_Toolbox.Library.Forms.STPanel(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.stPanel8 = new Switch_Toolbox.Library.Forms.STPanel(); + this.stToolStrip2 = new Switch_Toolbox.Library.Forms.STToolStrip(); + this.addKeyFrameToolstrip = new System.Windows.Forms.ToolStripButton(); + this.removeKeyFrameToolstrip = new System.Windows.Forms.ToolStripButton(); + this.toolstripShiftUp = new System.Windows.Forms.ToolStripButton(); + this.toolstripShiftDown = new System.Windows.Forms.ToolStripButton(); + this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); + this.stPanel2 = new Switch_Toolbox.Library.Forms.STPanel(); + this.stLabel2 = new Switch_Toolbox.Library.Forms.STLabel(); this.stLabel4 = new Switch_Toolbox.Library.Forms.STLabel(); this.textureFrameUD = new Switch_Toolbox.Library.Forms.NumericUpDownUint(); - this.btnRemove = new Switch_Toolbox.Library.Forms.STButton(); - this.btnAdd = new Switch_Toolbox.Library.Forms.STButton(); + this.stLabel1 = new Switch_Toolbox.Library.Forms.STLabel(); + this.treeView1 = new System.Windows.Forms.TreeView(); this.listViewCustom1 = new Switch_Toolbox.Library.Forms.ListViewCustom(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.stPanel7 = new Switch_Toolbox.Library.Forms.STPanel(); - this.btnEditSamplers = new Switch_Toolbox.Library.Forms.STButton(); - this.btnEditMaterial = new Switch_Toolbox.Library.Forms.STButton(); - this.stLabel2 = new Switch_Toolbox.Library.Forms.STLabel(); + this.stLabel5 = new Switch_Toolbox.Library.Forms.STLabel(); + this.activeAnimCB = new Switch_Toolbox.Library.Forms.STComboBox(); + this.stLabel3 = new Switch_Toolbox.Library.Forms.STLabel(); + this.frameCountUD = new Switch_Toolbox.Library.Forms.STNumbericUpDown(); + this.backgroundCB = new Switch_Toolbox.Library.Forms.STComboBox(); + this.stToolStrip1 = new Switch_Toolbox.Library.Forms.STToolStrip(); + this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); + this.toolStripButton4 = new System.Windows.Forms.ToolStripButton(); this.pictureBoxCustom1 = new Switch_Toolbox.Library.Forms.PictureBoxCustom(); - this.materialCB = new Switch_Toolbox.Library.Forms.STComboBox(); - this.samplerCB = new Switch_Toolbox.Library.Forms.STComboBox(); this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel(); this.loopChkBox = new Switch_Toolbox.Library.Forms.STCheckBox(); this.animationTrackBar = new ColorSlider.ColorSlider(); @@ -61,11 +72,14 @@ this.btnForward1 = new Switch_Toolbox.Library.Forms.STButton(); this.btnPlay = new Switch_Toolbox.Library.Forms.STButton(); this.btnBackward1 = new Switch_Toolbox.Library.Forms.STButton(); - this.stLabel3 = new Switch_Toolbox.Library.Forms.STLabel(); - this.stLabel1 = new Switch_Toolbox.Library.Forms.STLabel(); - this.stTextBox1 = new Switch_Toolbox.Library.Forms.STTextBox(); + this.stMenuStrip1 = new Switch_Toolbox.Library.Forms.STMenuStrip(); + this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.imageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.adjustmentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.splitter4 = new System.Windows.Forms.Splitter(); this.splitter2 = new System.Windows.Forms.Splitter(); + this.contentContainer.SuspendLayout(); this.stPanel3.SuspendLayout(); this.stPanel5.SuspendLayout(); this.stPanel6.SuspendLayout(); @@ -74,20 +88,33 @@ this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); this.stPanel8.SuspendLayout(); + this.stToolStrip2.SuspendLayout(); + this.stPanel2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.textureFrameUD)).BeginInit(); this.stPanel7.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.frameCountUD)).BeginInit(); + this.stToolStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCustom1)).BeginInit(); this.stPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.maxFrameCounterUD)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.currentFrameCounterUD)).BeginInit(); this.stPanel4.SuspendLayout(); + this.stMenuStrip1.SuspendLayout(); this.SuspendLayout(); // + // contentContainer + // + this.contentContainer.Controls.Add(this.stPanel3); + this.contentContainer.Controls.Add(this.splitter1); + this.contentContainer.Size = new System.Drawing.Size(1000, 674); + this.contentContainer.Controls.SetChildIndex(this.splitter1, 0); + this.contentContainer.Controls.SetChildIndex(this.stPanel3, 0); + // // splitter1 // - this.splitter1.Location = new System.Drawing.Point(0, 0); + this.splitter1.Location = new System.Drawing.Point(0, 25); this.splitter1.Name = "splitter1"; - this.splitter1.Size = new System.Drawing.Size(3, 837); + this.splitter1.Size = new System.Drawing.Size(3, 649); this.splitter1.TabIndex = 7; this.splitter1.TabStop = false; // @@ -100,9 +127,9 @@ this.stPanel3.Controls.Add(this.stPanel5); this.stPanel3.Controls.Add(this.splitter2); this.stPanel3.Dock = System.Windows.Forms.DockStyle.Fill; - this.stPanel3.Location = new System.Drawing.Point(3, 0); + this.stPanel3.Location = new System.Drawing.Point(3, 25); this.stPanel3.Name = "stPanel3"; - this.stPanel3.Size = new System.Drawing.Size(729, 837); + this.stPanel3.Size = new System.Drawing.Size(997, 649); this.stPanel3.TabIndex = 8; // // stPanel5 @@ -112,7 +139,7 @@ this.stPanel5.Dock = System.Windows.Forms.DockStyle.Fill; this.stPanel5.Location = new System.Drawing.Point(0, 0); this.stPanel5.Name = "stPanel5"; - this.stPanel5.Size = new System.Drawing.Size(729, 834); + this.stPanel5.Size = new System.Drawing.Size(997, 646); this.stPanel5.TabIndex = 9; // // splitter3 @@ -120,7 +147,7 @@ this.splitter3.Dock = System.Windows.Forms.DockStyle.Top; this.splitter3.Location = new System.Drawing.Point(0, 0); this.splitter3.Name = "splitter3"; - this.splitter3.Size = new System.Drawing.Size(729, 3); + this.splitter3.Size = new System.Drawing.Size(997, 3); this.splitter3.TabIndex = 17; this.splitter3.TabStop = false; // @@ -131,7 +158,7 @@ this.stPanel6.Dock = System.Windows.Forms.DockStyle.Fill; this.stPanel6.Location = new System.Drawing.Point(0, 0); this.stPanel6.Name = "stPanel6"; - this.stPanel6.Size = new System.Drawing.Size(729, 834); + this.stPanel6.Size = new System.Drawing.Size(997, 646); this.stPanel6.TabIndex = 16; // // splitContainer1 @@ -147,27 +174,113 @@ // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.stPanel7); - this.splitContainer1.Size = new System.Drawing.Size(726, 834); - this.splitContainer1.SplitterDistance = 242; + this.splitContainer1.Size = new System.Drawing.Size(994, 646); + this.splitContainer1.SplitterDistance = 201; this.splitContainer1.TabIndex = 17; // // stPanel8 // - this.stPanel8.Controls.Add(this.stLabel4); - this.stPanel8.Controls.Add(this.textureFrameUD); - this.stPanel8.Controls.Add(this.btnRemove); - this.stPanel8.Controls.Add(this.btnAdd); - this.stPanel8.Controls.Add(this.listViewCustom1); + this.stPanel8.Controls.Add(this.stToolStrip2); + this.stPanel8.Controls.Add(this.stPanel2); this.stPanel8.Dock = System.Windows.Forms.DockStyle.Fill; this.stPanel8.Location = new System.Drawing.Point(0, 0); this.stPanel8.Name = "stPanel8"; - this.stPanel8.Size = new System.Drawing.Size(242, 834); + this.stPanel8.Size = new System.Drawing.Size(201, 646); this.stPanel8.TabIndex = 15; // + // stToolStrip2 + // + this.stToolStrip2.Dock = System.Windows.Forms.DockStyle.Left; + this.stToolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addKeyFrameToolstrip, + this.removeKeyFrameToolstrip, + this.toolstripShiftUp, + this.toolstripShiftDown, + this.toolStripButton2}); + this.stToolStrip2.Location = new System.Drawing.Point(0, 0); + this.stToolStrip2.Name = "stToolStrip2"; + this.stToolStrip2.Size = new System.Drawing.Size(24, 646); + this.stToolStrip2.TabIndex = 19; + this.stToolStrip2.Text = "stToolStrip2"; + // + // addKeyFrameToolstrip + // + this.addKeyFrameToolstrip.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.addKeyFrameToolstrip.Image = global::FirstPlugin.Properties.Resources.AddIcon; + this.addKeyFrameToolstrip.ImageTransparentColor = System.Drawing.Color.Magenta; + this.addKeyFrameToolstrip.Name = "addKeyFrameToolstrip"; + this.addKeyFrameToolstrip.Size = new System.Drawing.Size(29, 20); + this.addKeyFrameToolstrip.Text = "Add Frame"; + this.addKeyFrameToolstrip.Click += new System.EventHandler(this.addKeyFrameToolstrip_Click); + // + // removeKeyFrameToolstrip + // + this.removeKeyFrameToolstrip.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.removeKeyFrameToolstrip.Image = global::FirstPlugin.Properties.Resources.RemoveIcon; + this.removeKeyFrameToolstrip.ImageTransparentColor = System.Drawing.Color.Magenta; + this.removeKeyFrameToolstrip.Name = "removeKeyFrameToolstrip"; + this.removeKeyFrameToolstrip.Size = new System.Drawing.Size(29, 20); + this.removeKeyFrameToolstrip.Text = "Remove Frame"; + this.removeKeyFrameToolstrip.Click += new System.EventHandler(this.removeKeyFrameToolstrip_Click); + // + // toolstripShiftUp + // + this.toolstripShiftUp.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolstripShiftUp.Image = global::FirstPlugin.Properties.Resources.ArrowIcon; + this.toolstripShiftUp.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolstripShiftUp.Name = "toolstripShiftUp"; + this.toolstripShiftUp.Size = new System.Drawing.Size(29, 20); + this.toolstripShiftUp.Text = "Move Up"; + this.toolstripShiftUp.Click += new System.EventHandler(this.toolstripShiftUp_Click); + // + // toolstripShiftDown + // + this.toolstripShiftDown.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolstripShiftDown.Image = global::FirstPlugin.Properties.Resources.ArrowIcon; + this.toolstripShiftDown.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolstripShiftDown.Name = "toolstripShiftDown"; + this.toolstripShiftDown.Size = new System.Drawing.Size(29, 20); + this.toolstripShiftDown.Text = "Move Down"; + this.toolstripShiftDown.Click += new System.EventHandler(this.toolstripShiftDown_Click); + // + // toolStripButton2 + // + this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image"))); + this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton2.Name = "toolStripButton2"; + this.toolStripButton2.Size = new System.Drawing.Size(21, 20); + this.toolStripButton2.Text = "toolStripButton2"; + // + // stPanel2 + // + this.stPanel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.stPanel2.Controls.Add(this.stLabel2); + this.stPanel2.Controls.Add(this.stLabel4); + this.stPanel2.Controls.Add(this.textureFrameUD); + this.stPanel2.Controls.Add(this.stLabel1); + this.stPanel2.Controls.Add(this.treeView1); + this.stPanel2.Controls.Add(this.listViewCustom1); + this.stPanel2.Location = new System.Drawing.Point(21, 6); + this.stPanel2.Name = "stPanel2"; + this.stPanel2.Size = new System.Drawing.Size(178, 634); + this.stPanel2.TabIndex = 18; + // + // stLabel2 + // + this.stLabel2.AutoSize = true; + this.stLabel2.Location = new System.Drawing.Point(6, 5); + this.stLabel2.Name = "stLabel2"; + this.stLabel2.Size = new System.Drawing.Size(48, 13); + this.stLabel2.TabIndex = 18; + this.stLabel2.Text = "Textures"; + // // stLabel4 // this.stLabel4.AutoSize = true; - this.stLabel4.Location = new System.Drawing.Point(6, 34); + this.stLabel4.Location = new System.Drawing.Point(6, 447); this.stLabel4.Name = "stLabel4"; this.stLabel4.Size = new System.Drawing.Size(39, 13); this.stLabel4.TabIndex = 15; @@ -175,7 +288,7 @@ // // textureFrameUD // - this.textureFrameUD.Location = new System.Drawing.Point(59, 32); + this.textureFrameUD.Location = new System.Drawing.Point(77, 445); this.textureFrameUD.Maximum = new decimal(new int[] { 2147483647, 0, @@ -186,27 +299,24 @@ this.textureFrameUD.TabIndex = 10; this.textureFrameUD.ValueChanged += new System.EventHandler(this.textureFrameUD_ValueChanged); // - // btnRemove + // stLabel1 // - this.btnRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnRemove.Location = new System.Drawing.Point(77, 3); - this.btnRemove.Name = "btnRemove"; - this.btnRemove.Size = new System.Drawing.Size(75, 23); - this.btnRemove.TabIndex = 8; - this.btnRemove.Text = "Remove"; - this.btnRemove.UseVisualStyleBackColor = false; - this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click); + this.stLabel1.AutoSize = true; + this.stLabel1.Location = new System.Drawing.Point(6, 478); + this.stLabel1.Name = "stLabel1"; + this.stLabel1.Size = new System.Drawing.Size(56, 13); + this.stLabel1.TabIndex = 17; + this.stLabel1.Text = "Data View"; // - // btnAdd + // treeView1 // - this.btnAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnAdd.Location = new System.Drawing.Point(3, 3); - this.btnAdd.Name = "btnAdd"; - this.btnAdd.Size = new System.Drawing.Size(75, 23); - this.btnAdd.TabIndex = 9; - this.btnAdd.Text = "Add"; - this.btnAdd.UseVisualStyleBackColor = false; - this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); + this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.treeView1.Location = new System.Drawing.Point(6, 494); + this.treeView1.Name = "treeView1"; + this.treeView1.Size = new System.Drawing.Size(164, 140); + this.treeView1.TabIndex = 16; + this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); // // listViewCustom1 // @@ -217,10 +327,11 @@ this.listViewCustom1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1}); this.listViewCustom1.FullRowSelect = true; - this.listViewCustom1.Location = new System.Drawing.Point(3, 58); + this.listViewCustom1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; + this.listViewCustom1.Location = new System.Drawing.Point(9, 21); this.listViewCustom1.Name = "listViewCustom1"; this.listViewCustom1.OwnerDraw = true; - this.listViewCustom1.Size = new System.Drawing.Size(230, 779); + this.listViewCustom1.Size = new System.Drawing.Size(172, 418); this.listViewCustom1.TabIndex = 7; this.listViewCustom1.UseCompatibleStateImageBehavior = false; this.listViewCustom1.View = System.Windows.Forms.View.Details; @@ -229,96 +340,119 @@ // // columnHeader1 // - this.columnHeader1.Width = 230; + this.columnHeader1.Width = 339; // // stPanel7 // - this.stPanel7.Controls.Add(this.btnEditSamplers); - this.stPanel7.Controls.Add(this.btnEditMaterial); - this.stPanel7.Controls.Add(this.stLabel2); - this.stPanel7.Controls.Add(this.pictureBoxCustom1); - this.stPanel7.Controls.Add(this.materialCB); - this.stPanel7.Controls.Add(this.samplerCB); - this.stPanel7.Controls.Add(this.stPanel1); + this.stPanel7.Controls.Add(this.stLabel5); + this.stPanel7.Controls.Add(this.activeAnimCB); this.stPanel7.Controls.Add(this.stLabel3); - this.stPanel7.Controls.Add(this.stLabel1); - this.stPanel7.Controls.Add(this.stTextBox1); + this.stPanel7.Controls.Add(this.frameCountUD); + this.stPanel7.Controls.Add(this.backgroundCB); + this.stPanel7.Controls.Add(this.stToolStrip1); + this.stPanel7.Controls.Add(this.pictureBoxCustom1); + this.stPanel7.Controls.Add(this.stPanel1); + this.stPanel7.Controls.Add(this.stMenuStrip1); this.stPanel7.Dock = System.Windows.Forms.DockStyle.Fill; this.stPanel7.Location = new System.Drawing.Point(0, 0); this.stPanel7.Name = "stPanel7"; - this.stPanel7.Size = new System.Drawing.Size(480, 834); + this.stPanel7.Size = new System.Drawing.Size(789, 646); this.stPanel7.TabIndex = 14; // - // btnEditSamplers + // stLabel5 // - this.btnEditSamplers.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnEditSamplers.Location = new System.Drawing.Point(299, 41); - this.btnEditSamplers.Name = "btnEditSamplers"; - this.btnEditSamplers.Size = new System.Drawing.Size(47, 23); - this.btnEditSamplers.TabIndex = 15; - this.btnEditSamplers.Text = "Edit"; - this.btnEditSamplers.UseVisualStyleBackColor = false; - this.btnEditSamplers.Click += new System.EventHandler(this.stButton1_Click); + this.stLabel5.AutoSize = true; + this.stLabel5.Location = new System.Drawing.Point(141, 34); + this.stLabel5.Name = "stLabel5"; + this.stLabel5.Size = new System.Drawing.Size(89, 13); + this.stLabel5.TabIndex = 8; + this.stLabel5.Text = "Active Animation:"; // - // btnEditMaterial + // activeAnimCB // - this.btnEditMaterial.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnEditMaterial.Location = new System.Drawing.Point(299, 12); - this.btnEditMaterial.Name = "btnEditMaterial"; - this.btnEditMaterial.Size = new System.Drawing.Size(47, 23); - this.btnEditMaterial.TabIndex = 14; - this.btnEditMaterial.Text = "Edit"; - this.btnEditMaterial.UseVisualStyleBackColor = false; - this.btnEditMaterial.Click += new System.EventHandler(this.btnEditMaterial_Click); + this.activeAnimCB.BorderColor = System.Drawing.Color.Empty; + this.activeAnimCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; + this.activeAnimCB.ButtonColor = System.Drawing.Color.Empty; + this.activeAnimCB.FormattingEnabled = true; + this.activeAnimCB.Location = new System.Drawing.Point(233, 31); + this.activeAnimCB.Name = "activeAnimCB"; + this.activeAnimCB.ReadOnly = true; + this.activeAnimCB.Size = new System.Drawing.Size(220, 21); + this.activeAnimCB.TabIndex = 7; + this.activeAnimCB.SelectedIndexChanged += new System.EventHandler(this.activeAnimCB_SelectedIndexChanged); // - // stLabel2 + // stLabel3 // - this.stLabel2.AutoSize = true; - this.stLabel2.Location = new System.Drawing.Point(3, 14); - this.stLabel2.Name = "stLabel2"; - this.stLabel2.Size = new System.Drawing.Size(81, 13); - this.stLabel2.TabIndex = 11; - this.stLabel2.Text = "Material Target:"; + this.stLabel3.AutoSize = true; + this.stLabel3.Location = new System.Drawing.Point(383, 6); + this.stLabel3.Name = "stLabel3"; + this.stLabel3.Size = new System.Drawing.Size(70, 13); + this.stLabel3.TabIndex = 6; + this.stLabel3.Text = "Frame Count:"; + // + // frameCountUD + // + this.frameCountUD.Location = new System.Drawing.Point(459, 4); + this.frameCountUD.Name = "frameCountUD"; + this.frameCountUD.Size = new System.Drawing.Size(169, 20); + this.frameCountUD.TabIndex = 5; + // + // backgroundCB + // + this.backgroundCB.BorderColor = System.Drawing.Color.Empty; + this.backgroundCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; + this.backgroundCB.ButtonColor = System.Drawing.Color.Empty; + this.backgroundCB.FormattingEnabled = true; + this.backgroundCB.Location = new System.Drawing.Point(233, 3); + this.backgroundCB.Name = "backgroundCB"; + this.backgroundCB.ReadOnly = true; + this.backgroundCB.Size = new System.Drawing.Size(144, 21); + this.backgroundCB.TabIndex = 4; + this.backgroundCB.SelectedIndexChanged += new System.EventHandler(this.backgroundCB_SelectedIndexChanged); + // + // stToolStrip1 + // + this.stToolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripButton1, + this.toolStripButton4}); + this.stToolStrip1.Location = new System.Drawing.Point(0, 24); + this.stToolStrip1.Name = "stToolStrip1"; + this.stToolStrip1.Size = new System.Drawing.Size(789, 25); + this.stToolStrip1.TabIndex = 3; + this.stToolStrip1.Text = "stToolStrip1"; + // + // toolStripButton1 + // + this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image"))); + this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton1.Name = "toolStripButton1"; + this.toolStripButton1.Size = new System.Drawing.Size(23, 22); + this.toolStripButton1.Text = "toolStripButton1"; + // + // toolStripButton4 + // + this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton4.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton4.Image"))); + this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton4.Name = "toolStripButton4"; + this.toolStripButton4.Size = new System.Drawing.Size(23, 22); + this.toolStripButton4.Text = "toolStripButton4"; // // pictureBoxCustom1 // this.pictureBoxCustom1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.pictureBoxCustom1.BackColor = System.Drawing.Color.Transparent; this.pictureBoxCustom1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBoxCustom1.BackgroundImage"))); - this.pictureBoxCustom1.Location = new System.Drawing.Point(6, 102); + this.pictureBoxCustom1.Location = new System.Drawing.Point(16, 58); this.pictureBoxCustom1.Name = "pictureBoxCustom1"; - this.pictureBoxCustom1.Size = new System.Drawing.Size(467, 658); + this.pictureBoxCustom1.Size = new System.Drawing.Size(776, 514); this.pictureBoxCustom1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBoxCustom1.TabIndex = 0; this.pictureBoxCustom1.TabStop = false; // - // materialCB - // - this.materialCB.BorderColor = System.Drawing.Color.Empty; - this.materialCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; - this.materialCB.ButtonColor = System.Drawing.Color.Empty; - this.materialCB.FormattingEnabled = true; - this.materialCB.Location = new System.Drawing.Point(90, 14); - this.materialCB.Name = "materialCB"; - this.materialCB.ReadOnly = true; - this.materialCB.Size = new System.Drawing.Size(203, 21); - this.materialCB.TabIndex = 10; - this.materialCB.SelectedIndexChanged += new System.EventHandler(this.materialCB_SelectedIndexChanged); - // - // samplerCB - // - this.samplerCB.BorderColor = System.Drawing.Color.Empty; - this.samplerCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; - this.samplerCB.ButtonColor = System.Drawing.Color.Empty; - this.samplerCB.FormattingEnabled = true; - this.samplerCB.Location = new System.Drawing.Point(90, 43); - this.samplerCB.Name = "samplerCB"; - this.samplerCB.ReadOnly = true; - this.samplerCB.Size = new System.Drawing.Size(203, 21); - this.samplerCB.TabIndex = 5; - this.samplerCB.SelectedIndexChanged += new System.EventHandler(this.samplerCB_SelectedIndexChanged); - // // stPanel1 // this.stPanel1.Controls.Add(this.loopChkBox); @@ -327,9 +461,9 @@ this.stPanel1.Controls.Add(this.currentFrameCounterUD); this.stPanel1.Controls.Add(this.stPanel4); this.stPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.stPanel1.Location = new System.Drawing.Point(0, 766); + this.stPanel1.Location = new System.Drawing.Point(0, 578); this.stPanel1.Name = "stPanel1"; - this.stPanel1.Size = new System.Drawing.Size(480, 68); + this.stPanel1.Size = new System.Drawing.Size(789, 68); this.stPanel1.TabIndex = 1; // // loopChkBox @@ -338,7 +472,7 @@ this.loopChkBox.AutoSize = true; this.loopChkBox.Checked = true; this.loopChkBox.CheckState = System.Windows.Forms.CheckState.Checked; - this.loopChkBox.Location = new System.Drawing.Point(355, 11); + this.loopChkBox.Location = new System.Drawing.Point(662, 5); this.loopChkBox.Name = "loopChkBox"; this.loopChkBox.Size = new System.Drawing.Size(50, 17); this.loopChkBox.TabIndex = 17; @@ -367,7 +501,7 @@ this.animationTrackBar.ScaleSubDivisions = 5; this.animationTrackBar.ShowDivisionsText = true; this.animationTrackBar.ShowSmallScale = false; - this.animationTrackBar.Size = new System.Drawing.Size(456, 19); + this.animationTrackBar.Size = new System.Drawing.Size(765, 19); this.animationTrackBar.SmallChange = ((uint)(1u)); this.animationTrackBar.TabIndex = 16; this.animationTrackBar.Text = "colorSlider1"; @@ -385,7 +519,7 @@ // maxFrameCounterUD // this.maxFrameCounterUD.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.maxFrameCounterUD.Location = new System.Drawing.Point(353, 28); + this.maxFrameCounterUD.Location = new System.Drawing.Point(662, 25); this.maxFrameCounterUD.Name = "maxFrameCounterUD"; this.maxFrameCounterUD.Size = new System.Drawing.Size(109, 20); this.maxFrameCounterUD.TabIndex = 15; @@ -394,7 +528,7 @@ // currentFrameCounterUD // this.currentFrameCounterUD.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.currentFrameCounterUD.Location = new System.Drawing.Point(9, 28); + this.currentFrameCounterUD.Location = new System.Drawing.Point(8, 25); this.currentFrameCounterUD.Name = "currentFrameCounterUD"; this.currentFrameCounterUD.Size = new System.Drawing.Size(109, 20); this.currentFrameCounterUD.TabIndex = 14; @@ -409,9 +543,9 @@ this.stPanel4.Controls.Add(this.btnForward1); this.stPanel4.Controls.Add(this.btnPlay); this.stPanel4.Controls.Add(this.btnBackward1); - this.stPanel4.Location = new System.Drawing.Point(123, 11); + this.stPanel4.Location = new System.Drawing.Point(123, 7); this.stPanel4.Name = "stPanel4"; - this.stPanel4.Size = new System.Drawing.Size(225, 37); + this.stPanel4.Size = new System.Drawing.Size(534, 41); this.stPanel4.TabIndex = 13; // // btnStop @@ -421,7 +555,7 @@ this.btnStop.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.btnStop.FlatAppearance.BorderSize = 0; this.btnStop.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnStop.Location = new System.Drawing.Point(159, 6); + this.btnStop.Location = new System.Drawing.Point(314, 6); this.btnStop.Name = "btnStop"; this.btnStop.Size = new System.Drawing.Size(35, 27); this.btnStop.TabIndex = 3; @@ -435,7 +569,7 @@ this.btnForward1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.btnForward1.FlatAppearance.BorderSize = 0; this.btnForward1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnForward1.Location = new System.Drawing.Point(116, 10); + this.btnForward1.Location = new System.Drawing.Point(271, 10); this.btnForward1.Name = "btnForward1"; this.btnForward1.Size = new System.Drawing.Size(23, 20); this.btnForward1.TabIndex = 2; @@ -449,7 +583,7 @@ this.btnPlay.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.btnPlay.FlatAppearance.BorderSize = 0; this.btnPlay.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnPlay.Location = new System.Drawing.Point(64, 6); + this.btnPlay.Location = new System.Drawing.Point(219, 6); this.btnPlay.Name = "btnPlay"; this.btnPlay.Size = new System.Drawing.Size(35, 28); this.btnPlay.TabIndex = 0; @@ -463,55 +597,65 @@ this.btnBackward1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.btnBackward1.FlatAppearance.BorderSize = 0; this.btnBackward1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnBackward1.Location = new System.Drawing.Point(25, 10); + this.btnBackward1.Location = new System.Drawing.Point(180, 10); this.btnBackward1.Name = "btnBackward1"; this.btnBackward1.Size = new System.Drawing.Size(20, 20); this.btnBackward1.TabIndex = 1; this.btnBackward1.UseVisualStyleBackColor = false; this.btnBackward1.Click += new System.EventHandler(this.btnBackward1_Click); // - // stLabel3 + // stMenuStrip1 // - this.stLabel3.AutoSize = true; - this.stLabel3.Location = new System.Drawing.Point(3, 72); - this.stLabel3.Name = "stLabel3"; - this.stLabel3.Size = new System.Drawing.Size(70, 13); - this.stLabel3.TabIndex = 13; - this.stLabel3.Text = "Sampler Hint:"; + this.stMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.editToolStripMenuItem, + this.viewToolStripMenuItem, + this.imageToolStripMenuItem, + this.adjustmentsToolStripMenuItem}); + this.stMenuStrip1.Location = new System.Drawing.Point(0, 0); + this.stMenuStrip1.Name = "stMenuStrip1"; + this.stMenuStrip1.Size = new System.Drawing.Size(789, 24); + this.stMenuStrip1.TabIndex = 2; + this.stMenuStrip1.Text = "stMenuStrip1"; // - // stLabel1 + // editToolStripMenuItem // - this.stLabel1.AutoSize = true; - this.stLabel1.Location = new System.Drawing.Point(6, 43); - this.stLabel1.Name = "stLabel1"; - this.stLabel1.Size = new System.Drawing.Size(82, 13); - this.stLabel1.TabIndex = 6; - this.stLabel1.Text = "Sampler Target:"; + this.editToolStripMenuItem.Name = "editToolStripMenuItem"; + this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20); + this.editToolStripMenuItem.Text = "Edit"; // - // stTextBox1 + // viewToolStripMenuItem // - this.stTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.stTextBox1.Location = new System.Drawing.Point(90, 70); - this.stTextBox1.Name = "stTextBox1"; - this.stTextBox1.ReadOnly = true; - this.stTextBox1.Size = new System.Drawing.Size(203, 20); - this.stTextBox1.TabIndex = 12; + this.viewToolStripMenuItem.Name = "viewToolStripMenuItem"; + this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20); + this.viewToolStripMenuItem.Text = "View"; + // + // imageToolStripMenuItem + // + this.imageToolStripMenuItem.Name = "imageToolStripMenuItem"; + this.imageToolStripMenuItem.Size = new System.Drawing.Size(52, 20); + this.imageToolStripMenuItem.Text = "Image"; + // + // adjustmentsToolStripMenuItem + // + this.adjustmentsToolStripMenuItem.Name = "adjustmentsToolStripMenuItem"; + this.adjustmentsToolStripMenuItem.Size = new System.Drawing.Size(86, 20); + this.adjustmentsToolStripMenuItem.Text = "Adjustments"; // // splitter4 // this.splitter4.Dock = System.Windows.Forms.DockStyle.Right; - this.splitter4.Location = new System.Drawing.Point(726, 0); + this.splitter4.Location = new System.Drawing.Point(994, 0); this.splitter4.Name = "splitter4"; - this.splitter4.Size = new System.Drawing.Size(3, 834); + this.splitter4.Size = new System.Drawing.Size(3, 646); this.splitter4.TabIndex = 16; this.splitter4.TabStop = false; // // splitter2 // this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom; - this.splitter2.Location = new System.Drawing.Point(0, 834); + this.splitter2.Location = new System.Drawing.Point(0, 646); this.splitter2.Name = "splitter2"; - this.splitter2.Size = new System.Drawing.Size(729, 3); + this.splitter2.Size = new System.Drawing.Size(997, 3); this.splitter2.TabIndex = 8; this.splitter2.TabStop = false; // @@ -519,10 +663,10 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.stPanel3); - this.Controls.Add(this.splitter1); + this.ClientSize = new System.Drawing.Size(1006, 679); + this.MainMenuStrip = this.stMenuStrip1; this.Name = "BfresTexturePatternEditor"; - this.Size = new System.Drawing.Size(732, 837); + this.contentContainer.ResumeLayout(false); this.stPanel3.ResumeLayout(false); this.stPanel5.ResumeLayout(false); this.stPanel6.ResumeLayout(false); @@ -532,15 +676,24 @@ this.splitContainer1.ResumeLayout(false); this.stPanel8.ResumeLayout(false); this.stPanel8.PerformLayout(); + this.stToolStrip2.ResumeLayout(false); + this.stToolStrip2.PerformLayout(); + this.stPanel2.ResumeLayout(false); + this.stPanel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.textureFrameUD)).EndInit(); this.stPanel7.ResumeLayout(false); this.stPanel7.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.frameCountUD)).EndInit(); + this.stToolStrip1.ResumeLayout(false); + this.stToolStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCustom1)).EndInit(); this.stPanel1.ResumeLayout(false); this.stPanel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.maxFrameCounterUD)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.currentFrameCounterUD)).EndInit(); this.stPanel4.ResumeLayout(false); + this.stMenuStrip1.ResumeLayout(false); + this.stMenuStrip1.PerformLayout(); this.ResumeLayout(false); } @@ -561,26 +714,39 @@ private Switch_Toolbox.Library.Forms.STButton btnPlay; private Switch_Toolbox.Library.Forms.STButton btnBackward1; private Switch_Toolbox.Library.Forms.PictureBoxCustom pictureBoxCustom1; - private Switch_Toolbox.Library.Forms.STLabel stLabel1; - private Switch_Toolbox.Library.Forms.STComboBox samplerCB; - private Switch_Toolbox.Library.Forms.STButton btnAdd; - private Switch_Toolbox.Library.Forms.STButton btnRemove; private System.Windows.Forms.ColumnHeader columnHeader1; - private Switch_Toolbox.Library.Forms.STLabel stLabel3; - private Switch_Toolbox.Library.Forms.STTextBox stTextBox1; - private Switch_Toolbox.Library.Forms.STLabel stLabel2; - private Switch_Toolbox.Library.Forms.STComboBox materialCB; private System.Windows.Forms.Splitter splitter3; private Switch_Toolbox.Library.Forms.STPanel stPanel6; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Splitter splitter4; private Switch_Toolbox.Library.Forms.STPanel stPanel8; private Switch_Toolbox.Library.Forms.STPanel stPanel7; - private Switch_Toolbox.Library.Forms.STButton btnEditMaterial; private Switch_Toolbox.Library.Forms.STCheckBox loopChkBox; private System.Windows.Forms.SplitContainer splitContainer1; private Switch_Toolbox.Library.Forms.NumericUpDownUint textureFrameUD; private Switch_Toolbox.Library.Forms.STLabel stLabel4; - private Switch_Toolbox.Library.Forms.STButton btnEditSamplers; + private Switch_Toolbox.Library.Forms.STToolStrip stToolStrip1; + private System.Windows.Forms.ToolStripButton toolStripButton1; + private Switch_Toolbox.Library.Forms.STMenuStrip stMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; + private System.Windows.Forms.TreeView treeView1; + private Switch_Toolbox.Library.Forms.STLabel stLabel1; + private Switch_Toolbox.Library.Forms.STPanel stPanel2; + private Switch_Toolbox.Library.Forms.STLabel stLabel2; + private Switch_Toolbox.Library.Forms.STToolStrip stToolStrip2; + private System.Windows.Forms.ToolStripButton addKeyFrameToolstrip; + private System.Windows.Forms.ToolStripButton removeKeyFrameToolstrip; + private System.Windows.Forms.ToolStripButton toolstripShiftUp; + private System.Windows.Forms.ToolStripButton toolstripShiftDown; + private Switch_Toolbox.Library.Forms.STLabel stLabel3; + private Switch_Toolbox.Library.Forms.STNumbericUpDown frameCountUD; + private Switch_Toolbox.Library.Forms.STComboBox backgroundCB; + private System.Windows.Forms.ToolStripButton toolStripButton4; + private System.Windows.Forms.ToolStripMenuItem imageToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem adjustmentsToolStripMenuItem; + private Switch_Toolbox.Library.Forms.STLabel stLabel5; + private Switch_Toolbox.Library.Forms.STComboBox activeAnimCB; + private System.Windows.Forms.ToolStripButton toolStripButton2; } } diff --git a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs index 6a35daae..848c8276 100644 --- a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs +++ b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Drawing; +using System.Drawing.Imaging; using System.Data; using System.Linq; using System.Text; @@ -13,7 +14,7 @@ using Bfres.Structs; namespace FirstPlugin.Forms { - public partial class BfresTexturePatternEditor : UserControl + public partial class BfresTexturePatternEditor : STForm { public PlayerState AnimationPlayerState = PlayerState.Stop; @@ -40,11 +41,11 @@ namespace FirstPlugin.Forms ImageList imgList = new ImageList(); - public BfresTexturePatternEditor() + private List MaterialAnimations; + public BfresTexturePatternEditor(TreeNodeCollection materialAnimations) { InitializeComponent(); - btnEditSamplers.Enabled = false; listViewCustom1.HeaderStyle = ColumnHeaderStyle.None; listViewCustom1.BackColor = FormThemes.BaseTheme.TextEditorBackColor; imgList = new ImageList() @@ -56,23 +57,40 @@ namespace FirstPlugin.Forms stPanel4.BackColor = FormThemes.BaseTheme.FormBackColor; timer1.Interval = 100 / 60; + + treeView1.BackColor = FormThemes.BaseTheme.FormBackColor; + treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor; + + toolstripShiftUp.Image.RotateFlip(RotateFlipType.RotateNoneFlipY); + + backgroundCB.Items.Add("Checkerboard"); + backgroundCB.Items.Add("Black"); + backgroundCB.Items.Add("White"); + + backgroundCB.SelectedIndex = 0; + + MaterialAnimations = new List(); + foreach (TreeNode matAnim in materialAnimations) + { + MaterialAnimations.Add((MaterialAnimation)matAnim); + activeAnimCB.Items.Add(matAnim.Text); + } } - MaterialAnimation.Material material; FMAA.BfresSamplerAnim activeSampler; FTXP.BfresSamplerAnim activeSampleU; - MaterialAnimation activeMaterialAnim; + MaterialAnimation _activeMaterialAnim; MaterialAnimation ActiveMaterialAnim { get { - return activeMaterialAnim; + return _activeMaterialAnim; } set { - activeMaterialAnim = value; + _activeMaterialAnim = value; maxFrameCounterUD.Maximum = value.FrameCount; maxFrameCounterUD.Value = value.FrameCount; @@ -88,90 +106,68 @@ namespace FirstPlugin.Forms { } - - public void LoadAnim(FTXP materialAnim) + + public bool IsLoaded = false; + public void LoadAnim(MaterialAnimation materialAnim) { if (materialAnim.Materials.Count <= 0) return; IsLoaded = false; - ActiveMaterialAnim = materialAnim; - - - materialCB.Items.Clear(); - samplerCB.Items.Clear(); - - foreach (var mat in materialAnim.Materials) - materialCB.Items.Add(mat.Text); - - materialCB.SelectedIndex = 0; - - material = materialAnim.Materials[materialCB.SelectedIndex]; - - if (material.Samplers.Count <= 0) - return; - - foreach (var sampler in material.Samplers) - samplerCB.Items.Add(sampler.Text); - - samplerCB.SelectedIndex = 0; - - activeSampleU = (FTXP.BfresSamplerAnim)material.Samplers[samplerCB.SelectedIndex]; - - listViewCustom1.SuspendLayout(); - listViewCustom1.Items.Clear(); - - LoadAniamtion(materialAnim, activeSampleU); - - listViewCustom1.ResumeLayout(); + ReloadAnimationView(materialAnim); IsLoaded = true; + + activeAnimCB.SelectItemByText(materialAnim.Text); animationTrackBar.Value = 0; } - - - public bool IsLoaded = false; - public void LoadAnim(FMAA materialAnim) + private void ReloadAnimationView(MaterialAnimation materialAnim) { - if (materialAnim.Materials.Count <= 0) - return; + frameCountUD.Maximum = materialAnim.FrameCount; + frameCountUD.Bind(materialAnim, "FrameCount"); - IsLoaded = false; - - ActiveMaterialAnim = materialAnim; - - - materialCB.Items.Clear(); - samplerCB.Items.Clear(); + treeView1.Nodes.Clear(); + int Index = 0; foreach (var mat in materialAnim.Materials) - materialCB.Items.Add(mat.Text); + { + mat.Nodes.Clear(); - materialCB.SelectedIndex = 0; + var matWrapper = new TreeNode(mat.Text) { Tag = mat, }; + treeView1.Nodes.Add(matWrapper); - material = materialAnim.Materials[materialCB.SelectedIndex]; + foreach (var sampler in mat.Samplers) + matWrapper.Nodes.Add(new TreeNode(sampler.Text) { Tag = sampler, }); - if (material.Samplers.Count <= 0) - return; + if (matWrapper.Nodes.Count > 0 && Index == 0) + treeView1.SelectedNode = matWrapper.Nodes[0]; - foreach (var sampler in material.Samplers) - samplerCB.Items.Add(sampler.Text); + Index++; + } - samplerCB.SelectedIndex = 0; - activeSampler = (FMAA.BfresSamplerAnim)material.Samplers[samplerCB.SelectedIndex]; + ReloadAnimationView(); + } + private void ReloadAnimationView() + { listViewCustom1.SuspendLayout(); listViewCustom1.Items.Clear(); - LoadAniamtion(materialAnim, activeSampler); + if (activeSampleU != null) + LoadAniamtion(ActiveMaterialAnim, activeSampleU); + else + LoadAniamtion(ActiveMaterialAnim, activeSampler); listViewCustom1.ResumeLayout(); - IsLoaded = true; - animationTrackBar.Value = 0; + if (listViewCustom1.Items.Count > 0) + { + listViewCustom1.Items[0].Selected = true; + listViewCustom1.Select(); + } } Dictionary Images = new Dictionary(); @@ -253,48 +249,6 @@ namespace FirstPlugin.Forms } - private void materialCB_SelectedIndexChanged(object sender, EventArgs e) - { - if (material == null || !IsLoaded) - return; - - if (materialCB.SelectedIndex >= 0) - { - btnEditSamplers.Enabled = true; - - material = ActiveMaterialAnim.Materials[materialCB.SelectedIndex]; - - if (activeSampleU != null) - LoadAniamtion(ActiveMaterialAnim, activeSampleU); - else - LoadAniamtion(ActiveMaterialAnim, activeSampler); - } - else - { - btnEditSamplers.Enabled = false; - } - } - - private void samplerCB_SelectedIndexChanged(object sender, EventArgs e) - { - if (material == null || !IsLoaded) - return; - - if (samplerCB.SelectedIndex >= 0) - { - if (activeSampleU != null) - { - activeSampleU = (FTXP.BfresSamplerAnim)material.Samplers[samplerCB.SelectedIndex]; - LoadAniamtion(ActiveMaterialAnim, activeSampleU); - } - else - { - activeSampler = (FMAA.BfresSamplerAnim)material.Samplers[samplerCB.SelectedIndex]; - LoadAniamtion(ActiveMaterialAnim, activeSampler); - } - } - } - private void btnPlay_Click(object sender, EventArgs e) { if (AnimationPlayerState == PlayerState.Playing) @@ -515,19 +469,6 @@ namespace FirstPlugin.Forms } } - private void stButton1_Click(object sender, EventArgs e) - { - if (materialCB.SelectedIndex < 0) - return; - - TexPatternInfoEditor editor = new TexPatternInfoEditor(); - editor.LoadAnim(ActiveMaterialAnim, ActiveMaterialAnim.Materials[materialCB.SelectedIndex]); - if (editor.ShowDialog() == DialogResult.OK) - { - - } - } - private void textureFrameUD_ValueChanged(object sender, EventArgs e) { if (listViewCustom1.SelectedItems.Count > 0 && KeyFrames.Count > 0) @@ -536,5 +477,60 @@ namespace FirstPlugin.Forms } } + + private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) + { + if (ActiveMaterialAnim == null || !IsLoaded) + return; + + var node = treeView1.SelectedNode; + if (node.Tag is MaterialAnimation.Material) + { + + } + if (node.Tag is MaterialAnimation.SamplerKeyGroup) + { + if (ActiveMaterialAnim is FMAA) + activeSampler = (FMAA.BfresSamplerAnim)node.Tag; + else + activeSampleU = (FTXP.BfresSamplerAnim)node.Tag; + + ReloadAnimationView(); + } + } + + private void addKeyFrameToolstrip_Click(object sender, EventArgs e) + { + + } + + private void removeKeyFrameToolstrip_Click(object sender, EventArgs e) + { + + } + + private void toolstripShiftUp_Click(object sender, EventArgs e) + { + + } + + private void toolstripShiftDown_Click(object sender, EventArgs e) + { + + } + + private void activeAnimCB_SelectedIndexChanged(object sender, EventArgs e) + { + if (activeAnimCB.SelectedIndex != -1 && IsLoaded) + { + ActiveMaterialAnim = MaterialAnimations[activeAnimCB.SelectedIndex]; + ReloadAnimationView(ActiveMaterialAnim); + } + } + + private void backgroundCB_SelectedIndexChanged(object sender, EventArgs e) + { + + } } } diff --git a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.resx b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.resx index 01ff3dcf..c2d4b482 100644 --- a/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.resx +++ b/Switch_FileFormatsMain/GUI/BFRES/TexturePattern/BfresTexturePatternEditor.resx @@ -117,10 +117,28 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 + + 345, 17 + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + 228, 17 + iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAMAAACJuGjuAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 @@ -326,6 +344,42 @@ UbGMiuVULFKxnIpFKpZTsYyKZVQso2KZH1Is/D4jM+80LrRKBLQZIoHmCIFJmoigv0FAZZjRKRDQqYuE kvArnu7TMGOwQkBrBGaOgI59BJSFX8p1KhBQJ17HuoWEyvhbosYIaBiu4xxnNGq/GayHAJq139oVZ/QQ mGk4zW7tt3aFGa0JAhPXKv5Grfv8ckaj93+veSuXxEAIUwAAAABJRU5ErkJggg== + + + + 104, 17 + + + 17, 17 + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== @@ -1490,4 +1544,7 @@ IYwAAAAASUVORK5CYII= + + 25 + \ No newline at end of file diff --git a/Switch_FileFormatsMain/Main.cs b/Switch_FileFormatsMain/Main.cs index 6cc30bfe..0975b0a0 100644 --- a/Switch_FileFormatsMain/Main.cs +++ b/Switch_FileFormatsMain/Main.cs @@ -336,7 +336,7 @@ namespace FirstPlugin Formats.Add(typeof(ME01)); Formats.Add(typeof(LM2_DICT)); Formats.Add(typeof(GMX)); - + // Formats.Add(typeof(TPL)); //Formats.Add(typeof(GFA)); //Unfinished wip formats not ready for use diff --git a/Switch_FileFormatsMain/Properties/Resources.Designer.cs b/Switch_FileFormatsMain/Properties/Resources.Designer.cs index 238a8390..dfe69589 100644 --- a/Switch_FileFormatsMain/Properties/Resources.Designer.cs +++ b/Switch_FileFormatsMain/Properties/Resources.Designer.cs @@ -70,6 +70,16 @@ namespace FirstPlugin.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowIcon { + get { + object obj = ResourceManager.GetObject("ArrowIcon", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Switch_FileFormatsMain/Properties/Resources.resx b/Switch_FileFormatsMain/Properties/Resources.resx index 45a6bd8a..ec132dec 100644 --- a/Switch_FileFormatsMain/Properties/Resources.resx +++ b/Switch_FileFormatsMain/Properties/Resources.resx @@ -127,6 +127,12 @@ ..\Resources\Black.dds;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\ViewportIconDisable.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ViewportIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\AddIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -157,10 +163,7 @@ ..\Resources\arrowMinimize .png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\ViewportIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\ViewportIconDisable.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\ArrowIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/Switch_FileFormatsMain/Resources/ArrowIcon.png b/Switch_FileFormatsMain/Resources/ArrowIcon.png new file mode 100644 index 00000000..6696884b Binary files /dev/null and b/Switch_FileFormatsMain/Resources/ArrowIcon.png differ diff --git a/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj b/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj index 678a5516..49527f4a 100644 --- a/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj +++ b/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj @@ -209,6 +209,7 @@ + @@ -243,6 +244,8 @@ + + @@ -674,7 +677,7 @@ RenderInfoDataEditor.cs - UserControl + Form BfresTexturePatternEditor.cs @@ -919,7 +922,9 @@ + + @@ -1280,5 +1285,8 @@ + + + \ No newline at end of file diff --git a/Switch_FileFormatsMain/YAML/YamlFmaa.cs b/Switch_FileFormatsMain/YAML/YamlFmaa.cs new file mode 100644 index 00000000..3b48aa9e --- /dev/null +++ b/Switch_FileFormatsMain/YAML/YamlFmaa.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Bfres.Structs; +using SharpYaml; +using SharpYaml.Serialization; +using Syroot.NintenTools.NSW.Bfres; + +namespace FirstPlugin +{ + public class YamlFmaa + { + public class AnimConfig + { + public string Name { get; set; } + public string Path { get; set; } + public int FrameCount { get; set; } + } + + public class MatAnimConfig + { + public string Name { get; set; } + + public List TexturePatternInfos { get; set; } + public List ParamInfos { get; set; } + public List TexturePatternInfo { get; set; } + } + + public class ParamInfo + { + public string Name { get; set; } + + public bool IsConstant { get; set; } + + public AnimCurve Curve { get; set; } + } + + public class PatternInfo + { + public string Name { get; set; } + + public bool IsConstant { get; set; } + } + + public static string ToYaml(string Name, FMAA anim) + { + var serializerSettings = new SerializerSettings() + { + EmitTags = false + }; + + var MatAnim = anim.MaterialAnim; + var config = new AnimConfig(); + + var serializer = new Serializer(serializerSettings); + return serializer.Serialize(anim); + } + } +} diff --git a/Switch_FileFormatsMain/YAML/YamlFmat.cs b/Switch_FileFormatsMain/YAML/YamlFmat.cs index f7566574..448df0f1 100644 --- a/Switch_FileFormatsMain/YAML/YamlFmat.cs +++ b/Switch_FileFormatsMain/YAML/YamlFmat.cs @@ -8,7 +8,7 @@ using SharpYaml; using SharpYaml.Serialization; using Syroot.NintenTools.NSW.Bfres; -namespace FirstPlugin.YAML +namespace FirstPlugin { public class YamlFmat { diff --git a/Switch_FileFormatsMain/YAML/YamlFska.cs b/Switch_FileFormatsMain/YAML/YamlFska.cs new file mode 100644 index 00000000..aae5ceb8 --- /dev/null +++ b/Switch_FileFormatsMain/YAML/YamlFska.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Bfres.Structs; +using SharpYaml; +using SharpYaml.Serialization; +using Syroot.NintenTools.NSW.Bfres; + +namespace FirstPlugin +{ + public class YamlFska + { + public static string ToYaml(string Name, FSKA skeletalAnim) + { + var serializerSettings = new SerializerSettings() + { + EmitTags = false + }; + + var serializer = new Serializer(serializerSettings); + return serializer.Serialize(skeletalAnim); + } + } +} diff --git a/Switch_FileFormatsMain/libWiiSharp/TPL.cs b/Switch_FileFormatsMain/libWiiSharp/TPL.cs new file mode 100644 index 00000000..e7e6bff6 --- /dev/null +++ b/Switch_FileFormatsMain/libWiiSharp/TPL.cs @@ -0,0 +1,2654 @@ +/* This file is part of libWiiSharp + * Copyright (C) 2009 Leathl + * + * libWiiSharp is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libWiiSharp is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +//TPL conversion based on Wii.py by Xuzz, SquidMan, megazig, Matt_P, Omega and The Lemon Man. +//Zetsubou by SquidMan was also a reference. +//Thanks to the authors! + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Net; + +namespace libWiiSharp +{ + #region Enums + public enum TPL_TextureFormat : int + { + /// + /// Intensity, 4bpp + /// + I4 = 0, + /// + /// Intensity, 8bpp + /// + I8 = 1, + /// + /// Intensity, Alpha, 8bpp + /// + IA4 = 2, + /// + /// Intensity, Alpha, 16bpp + /// + IA8 = 3, + /// + /// RGB, 16bpp + /// + RGB565 = 4, + /// + /// RGB, Alpha, 16bpp + /// + RGB5A3 = 5, + /// + /// RGB, Alpha, 32bpp + /// + RGBA8 = 6, + /// + /// Indexed, 4bpp + /// + CI4 = 8, + /// + /// Indexed, 8bpp + /// + CI8 = 9, + /// + /// Indexed, 14bpp + /// + CI14X2 = 10, + /// + /// S3TC Compressed + /// + CMP = 14, + } + + public enum TPL_PaletteFormat : int + { + /// + /// No Palette + /// + None = 255, + /// + /// Intensity, Alpha, 16bpp + /// + IA8 = 0, + /// + /// RGB, 16bpp + /// + RGB565 = 1, + /// + /// RGB, Alpha, 16bpp + /// + RGB5A3 = 2, + } + #endregion + + public class TPL : IDisposable + { + private TPL_Header tplHeader = new TPL_Header(); + private List tplTextureEntries = new List(); + private List tplTextureHeaders = new List(); + private List tplPaletteHeaders = new List(); + private List textureData = new List(); + private List paletteData = new List(); + + /// + /// The Number of Textures in the TPL. + /// + public int NumOfTextures { get { return (int)tplHeader.NumOfTextures; } } + + #region IDisposable Members + private bool isDisposed = false; + + ~TPL() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing && !isDisposed) + { + tplHeader = null; + + tplTextureEntries.Clear(); + tplTextureEntries = null; + + tplTextureHeaders.Clear(); + tplTextureHeaders = null; + + tplPaletteHeaders.Clear(); + tplPaletteHeaders = null; + + textureData.Clear(); + textureData = null; + + paletteData.Clear(); + paletteData = null; + } + + isDisposed = true; + } + #endregion + + #region Public Functions + /// + /// Loads a TPL file. + /// + /// + /// + public static TPL Load(string pathToTpl) + { + TPL tmpTpl = new TPL(); + + MemoryStream ms = new MemoryStream(File.ReadAllBytes(pathToTpl)); + + try { tmpTpl.parseTpl(ms); } + catch { ms.Dispose(); throw; } + + ms.Dispose(); + return tmpTpl; + } + + /// + /// Loads a TPL file. + /// + /// + /// + public static TPL Load(byte[] tplFile) + { + TPL tmpTpl = new TPL(); + MemoryStream ms = new MemoryStream(tplFile); + + try { tmpTpl.parseTpl(ms); } + catch { ms.Dispose(); throw; } + + ms.Dispose(); + return tmpTpl; + } + + /// + /// Loads a TPL file. + /// + /// + /// + public static TPL Load(Stream tpl) + { + TPL t = new TPL(); + t.parseTpl(tpl); + return t; + } + + public static Bitmap ToImage(byte[] imageData, int width, int height, TPL_TextureFormat format, byte[] paletteData, int count, TPL_PaletteFormat paletteFormat) + { + TPL t = new TPL(); + uint[] paletteRgba = new uint[0]; + byte[] rgba; + + if (paletteData != null) + { + var tmpHeader = new TPL_PaletteHeader + { + NumberOfItems = (ushort)count, + PaletteFormat = (uint)paletteFormat + }; + + paletteRgba = t.paletteToRgba(tmpHeader, paletteData); + } + + switch (format) + { + case TPL_TextureFormat.I4: + rgba = t.fromI4(imageData, width, height); + break; + case TPL_TextureFormat.I8: + rgba = t.fromI8(imageData, width, height); + break; + case TPL_TextureFormat.IA4: + rgba = t.fromIA4(imageData, width, height); + break; + case TPL_TextureFormat.IA8: + rgba = t.fromIA8(imageData, width, height); + break; + case TPL_TextureFormat.RGB565: + rgba = t.fromRGB565(imageData, width, height); + break; + case TPL_TextureFormat.RGB5A3: + rgba = t.fromRGB5A3(imageData, width, height); + break; + case TPL_TextureFormat.RGBA8: + rgba = t.fromRGBA8(imageData, width, height); + break; + case TPL_TextureFormat.CI4: + rgba = new byte[0]; + rgba = t.fromCI4(imageData, paletteRgba, width, height); + break; + case TPL_TextureFormat.CI8: + rgba = new byte[0]; + rgba = t.fromCI8(imageData, paletteRgba, width, height); + break; + case TPL_TextureFormat.CI14X2: + rgba = new byte[0]; + rgba = t.fromCI14X2(imageData, paletteRgba, width, height); + break; + case TPL_TextureFormat.CMP: + rgba = t.fromCMP(imageData, width, height); + break; + default: + rgba = new byte[0]; + break; + } + + return t.rgbaToImage(rgba, width, height); + } + + /// + /// Creates a TPL from an image. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// + /// + /// + /// + public static TPL FromImage(string pathToImage, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3) + { + return FromImages(new string[] { pathToImage }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat }); + } + + /// + /// Creates a TPL from an image. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// + /// + /// + /// + public static TPL FromImage(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3) + { + return FromImages(new Image[] { img }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat }); + } + + /// + /// Creates a TPL from multiple images. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// If you use a color indexed format, please provide at least one palette format. + /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format! + /// + /// + /// + /// + public static TPL FromImages(string[] imagePaths, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats) + { + if (tplFormats.Length < imagePaths.Length) + throw new Exception("You must specify a format for each image!"); + + List images = new List(); + foreach (string imagePath in imagePaths) + images.Add(Image.FromFile(imagePath)); + + TPL tmpTpl = new TPL(); + tmpTpl.createFromImages(images.ToArray(), tplFormats, paletteFormats); + return tmpTpl; + } + + /// + /// Creates a TPL from multiple images. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// If you use a color indexed format, please provide at least one palette format. + /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format! + /// + /// + /// + /// + public static TPL FromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats) + { + if (tplFormats.Length < images.Length) + throw new Exception("You must specify a format for each image!"); + + TPL tmpTpl = new TPL(); + tmpTpl.createFromImages(images, tplFormats, paletteFormats); + return tmpTpl; + } + + + + /// + /// Loads a TPL file. + /// + /// + public void LoadFile(string pathToTpl) + { + MemoryStream ms = new MemoryStream(File.ReadAllBytes(pathToTpl)); + + try { parseTpl(ms); } + catch { ms.Dispose(); throw; } + + ms.Dispose(); + } + + /// + /// Loads a TPL file. + /// + /// + public void LoadFile(byte[] tplFile) + { + MemoryStream ms = new MemoryStream(tplFile); + + try { parseTpl(ms); } + catch { ms.Dispose(); throw; } + + ms.Dispose(); + } + + /// + /// Loads a TPL file. + /// + /// + public void LoadFile(Stream tpl) + { + parseTpl(tpl); + } + + /// + /// Creates a TPL from an image. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// + /// + /// + public void CreateFromImage(string pathToImage, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3) + { + CreateFromImages(new string[] { pathToImage }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat }); + } + + /// + /// Creates a TPL from an image. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// + /// + /// + public void CreateFromImage(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3) + { + CreateFromImages(new Image[] { img }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat }); + } + + /// + /// Creates a TPL from multiple images. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// If you use a color indexed format, please provide at least one palette format. + /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format! + /// + /// + /// + public void CreateFromImages(string[] imagePaths, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats) + { + if (tplFormats.Length < imagePaths.Length) + throw new Exception("You must specify a format for each image!"); + + List images = new List(); + foreach (string imagePath in imagePaths) + images.Add(Image.FromFile(imagePath)); + + createFromImages(images.ToArray(), tplFormats, paletteFormats); + } + + /// + /// Creates a TPL from multiple images. + /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)! + /// If you use a color indexed format, please provide at least one palette format. + /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format! + /// + /// + /// + public void CreateFromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats) + { + if (tplFormats.Length < images.Length) + throw new Exception("You must specify a format for each image!"); + + createFromImages(images, tplFormats, paletteFormats); + } + + + + /// + /// Saves the TPL. + /// + /// + public void Save(string savePath) + { + if (File.Exists(savePath)) File.Delete(savePath); + FileStream fs = new FileStream(savePath, FileMode.Create); + + try { writeToStream(fs); } + catch { fs.Dispose(); throw; } + + fs.Dispose(); + } + + /// + /// Returns the TPL as a memory stream. + /// + /// + public MemoryStream ToMemoryStream() + { + MemoryStream ms = new MemoryStream(); + + try { writeToStream(ms); } + catch { ms.Dispose(); throw; } + + return ms; + } + + /// + /// Returns the TPL as a byte array. + /// + /// + public byte[] ToByteArray() + { + return ToMemoryStream().ToArray(); + } + + /// + /// Extracts the first Texture of the TPL. + /// + /// + public Image ExtractTexture() + { + return ExtractTexture(0); + } + + /// + /// Extracts the Texture with the given index. + /// + /// + /// + public Image ExtractTexture(int index) + { + byte[] rgbaData; + + switch ((TPL_TextureFormat)tplTextureHeaders[index].TextureFormat) + { + case TPL_TextureFormat.I4: + rgbaData = fromI4(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.I8: + rgbaData = fromI8(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.IA4: + rgbaData = fromIA4(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.IA8: + rgbaData = fromIA8(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.RGB565: + rgbaData = fromRGB565(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.RGB5A3: + rgbaData = fromRGB5A3(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.RGBA8: + rgbaData = fromRGBA8(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CI4: + rgbaData = fromCI4(textureData[index], paletteToRgba(index), tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CI8: + rgbaData = fromCI8(textureData[index], paletteToRgba(index), tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CI14X2: + rgbaData = fromCI14X2(textureData[index], paletteToRgba(index), tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CMP: + rgbaData = fromCMP(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + default: + throw new FormatException("Unsupported Texture Format!"); + } + + return rgbaToImage(rgbaData, tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + } + + public ushort GetImageWidth(int index) + { + return tplTextureHeaders[index].TextureWidth; + } + + public ushort GetImageHeight(int index) + { + return tplTextureHeaders[index].TextureHeight; + } + + public byte[] ExtractTextureByteArray(int index) + { + byte[] rgbaData; + + switch ((TPL_TextureFormat)tplTextureHeaders[index].TextureFormat) + { + case TPL_TextureFormat.I4: + rgbaData = fromI4(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.I8: + rgbaData = fromI8(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.IA4: + rgbaData = fromIA4(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.IA8: + rgbaData = fromIA8(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.RGB565: + rgbaData = fromRGB565(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.RGB5A3: + rgbaData = fromRGB5A3(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.RGBA8: + rgbaData = fromRGBA8(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CI4: + rgbaData = fromCI4(textureData[index], paletteToRgba(index), tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CI8: + rgbaData = fromCI8(textureData[index], paletteToRgba(index), tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CI14X2: + rgbaData = fromCI14X2(textureData[index], paletteToRgba(index), tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + case TPL_TextureFormat.CMP: + rgbaData = fromCMP(textureData[index], tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + break; + default: + throw new FormatException("Unsupported Texture Format!"); + } + + return rgbaData; + } + + /// + /// Extracts the first Texture of the TPL. + /// + /// + public void ExtractTexture(string savePath) + { + ExtractTexture(0, savePath); + } + + /// + /// Extracts the Texture with the given index. + /// + /// + /// + public void ExtractTexture(int index, string savePath) + { + if (File.Exists(savePath)) File.Delete(savePath); + Image img = ExtractTexture(index); + + switch (Path.GetExtension(savePath).ToLower()) + { + case ".tif": + case ".tiff": + img.Save(savePath, System.Drawing.Imaging.ImageFormat.Tiff); + break; + case ".bmp": + img.Save(savePath, System.Drawing.Imaging.ImageFormat.Bmp); + break; + case ".gif": + img.Save(savePath, System.Drawing.Imaging.ImageFormat.Gif); + break; + case ".jpg": + case ".jpeg": + img.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg); + break; + default: + img.Save(savePath, System.Drawing.Imaging.ImageFormat.Png); + break; + } + } + + /// + /// Extracts all Textures of the TPL. + /// + /// + public Image[] ExtractAllTextures() + { + List imgList = new List(); + + for (int i = 0; i < tplHeader.NumOfTextures; i++) + imgList.Add(ExtractTexture(i)); + + return imgList.ToArray(); + } + + /// + /// Extracts all Textures of the TPL. + /// + /// + public void ExtractAllTextures(string saveDir) + { + if (Directory.Exists(saveDir)) Directory.CreateDirectory(saveDir); + + for (int i = 0; i < tplHeader.NumOfTextures; i++) + ExtractTexture(i, saveDir + Path.DirectorySeparatorChar + "Texture_" + i.ToString("x2") + ".png"); + } + + /// + /// Adds a Texture to the TPL. + /// + /// + /// + public void AddTexture(string imagePath, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3) + { + Image img = Image.FromFile(imagePath); + AddTexture(img, tplFormat, paletteFormat); + } + + /// + /// Adds a Texture to the TPL. + /// + /// + /// + public void AddTexture(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3) + { + TPL_TextureEntry tempTexture = new TPL_TextureEntry(); + TPL_TextureHeader tempTextureHeader = new TPL_TextureHeader(); + TPL_PaletteHeader tempPaletteHeader = new TPL_PaletteHeader(); + byte[] tempTextureData = imageToTpl(img, tplFormat); + byte[] tempPaletteData = new byte[0]; + + tempTextureHeader.TextureHeight = (ushort)img.Height; + tempTextureHeader.TextureWidth = (ushort)img.Width; + tempTextureHeader.TextureFormat = (uint)tplFormat; + + if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8 || tplFormat == TPL_TextureFormat.CI14X2) + { + ColorIndexConverter cic = new ColorIndexConverter(imageToRgba(img), img.Width, img.Height, tplFormat, paletteFormat); + + tempTextureData = cic.Data; + tempPaletteData = cic.Palette; + + tempPaletteHeader.NumberOfItems = (ushort)(tempPaletteData.Length / 2); + tempPaletteHeader.PaletteFormat = (uint)paletteFormat; + } + + tplTextureEntries.Add(tempTexture); + tplTextureHeaders.Add(tempTextureHeader); + tplPaletteHeaders.Add(tempPaletteHeader); + textureData.Add(tempTextureData); + paletteData.Add(tempPaletteData); + + tplHeader.NumOfTextures++; + } + + /// + /// Removes a Texture from the TPL. + /// + /// + public void RemoveTexture(int index) + { + if (tplHeader.NumOfTextures > index) + { + tplTextureEntries.RemoveAt(index); + tplTextureHeaders.RemoveAt(index); + tplPaletteHeaders.RemoveAt(index); + textureData.RemoveAt(index); + paletteData.RemoveAt(index); + + tplHeader.NumOfTextures--; + } + } + + /// + /// Gets the format of the Texture with the given index. + /// + /// + /// + public TPL_TextureFormat GetTextureFormat(int index) + { + return (TPL_TextureFormat)tplTextureHeaders[index].TextureFormat; + } + + /// + /// Gets the palette format of the Texture with the given index. + /// + /// + /// + public TPL_PaletteFormat GetPaletteFormat(int index) + { + return (TPL_PaletteFormat)tplPaletteHeaders[index].PaletteFormat; + } + + /// + /// Gets the size of the Texture with the given index. + /// + /// + /// + public Size GetTextureSize(int index) + { + return new Size(tplTextureHeaders[index].TextureWidth, tplTextureHeaders[index].TextureHeight); + } + #endregion + + #region Private Functions + private void writeToStream(Stream writeStream) + { + fireDebug("Writing TPL..."); + + writeStream.Seek(0, SeekOrigin.Begin); + + fireDebug(" Writing TPL Header... (Offset: 0x{0})", writeStream.Position); + tplHeader.Write(writeStream); + + int textureEntriesPosition = (int)writeStream.Position; + writeStream.Seek(tplHeader.NumOfTextures * 8, SeekOrigin.Current); + + //Get Number of Palettes + int paletteCount = 0; + for (int i = 0; i < tplHeader.NumOfTextures; i++) + if ((TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI4 || + (TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI8 || + (TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI14X2) + paletteCount++; + + int paletteHeaderPosition = (int)writeStream.Position; + writeStream.Seek(paletteCount * 12, SeekOrigin.Current); + + //Write Palette Data + for (int i = 0; i < tplHeader.NumOfTextures; i++) + { + if ((TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI4 || + (TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI8 || + (TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI14X2) + { + fireDebug(" Writing Palette of Texture #{1}... (Offset: 0x{0})", writeStream.Position, i + 1); + + writeStream.Seek(Shared.AddPadding(writeStream.Position, 32), SeekOrigin.Begin); + + tplPaletteHeaders[i].PaletteDataOffset = (uint)writeStream.Position; + writeStream.Write(paletteData[i], 0, paletteData[i].Length); + } + } + + int textureHeaderPosition = (int)writeStream.Position; + writeStream.Seek(tplHeader.NumOfTextures * 36, SeekOrigin.Current); + + //Write textureData + for (int i = 0; i < tplHeader.NumOfTextures; i++) + { + fireDebug(" Writing Texture #{1} of {2}... (Offset: 0x{0})", writeStream.Position, i + 1, tplHeader.NumOfTextures); + + writeStream.Seek(Shared.AddPadding((int)writeStream.Position, 32), SeekOrigin.Begin); + + tplTextureHeaders[i].TextureDataOffset = (uint)writeStream.Position; + writeStream.Write(textureData[i], 0, textureData[i].Length); + } + + while (writeStream.Position % 32 != 0) + writeStream.WriteByte(0x00); + + writeStream.Seek(paletteHeaderPosition, SeekOrigin.Begin); + + //Write Palette Headers + for (int i = 0; i < tplHeader.NumOfTextures; i++) + { + if ((TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI4 || + (TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI8 || + (TPL_TextureFormat)tplTextureHeaders[i].TextureFormat == TPL_TextureFormat.CI14X2) + { + fireDebug(" Writing Palette Header of Texture #{1}... (Offset: 0x{0})", writeStream.Position, i + 1); + + tplTextureEntries[i].PaletteHeaderOffset = (uint)writeStream.Position; + tplPaletteHeaders[i].Write(writeStream); + } + } + + writeStream.Seek(textureHeaderPosition, SeekOrigin.Begin); + + //Write Texture Headers + for (int i = 0; i < tplHeader.NumOfTextures; i++) + { + fireDebug(" Writing Texture Header #{1} of {2}... (Offset: 0x{0})", writeStream.Position, i + 1, tplHeader.NumOfTextures); + + tplTextureEntries[i].TextureHeaderOffset = (uint)writeStream.Position; + tplTextureHeaders[i].Write(writeStream); + } + + writeStream.Seek(textureEntriesPosition, SeekOrigin.Begin); + + //Write Texture Entries + for (int i = 0; i < tplHeader.NumOfTextures; i++) + { + fireDebug(" Writing Texture Entry #{1} of {2}... (Offset: 0x{0})", writeStream.Position, i + 1, tplHeader.NumOfTextures); + + tplTextureEntries[i].Write(writeStream); + } + + fireDebug("Writing TPL Finished..."); + } + + private void parseTpl(Stream tplFile) + { + fireDebug("Parsing TPL..."); + + tplHeader = new TPL_Header(); + tplTextureEntries = new List(); + tplTextureHeaders = new List(); + tplPaletteHeaders = new List(); + textureData = new List(); + paletteData = new List(); + + tplFile.Seek(0, SeekOrigin.Begin); + byte[] temp = new byte[4]; + + fireDebug(" Reading TPL Header: Magic... (Offset: 0x{0})", tplFile.Position); + tplFile.Read(temp, 0, 4); + if (Shared.Swap(BitConverter.ToUInt32(temp, 0)) != tplHeader.TplMagic) + { + fireDebug(" -> Invalid Magic: 0x{0}", Shared.Swap(BitConverter.ToUInt32(temp, 0))); + throw new Exception("TPL Header: Invalid Magic!"); + } + + fireDebug(" Reading TPL Header: NumOfTextures... (Offset: 0x{0})", tplFile.Position); + tplFile.Read(temp, 0, 4); + tplHeader.NumOfTextures = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + fireDebug(" Reading TPL Header: Headersize... (Offset: 0x{0})", tplFile.Position); + tplFile.Read(temp, 0, 4); + if (Shared.Swap(BitConverter.ToUInt32(temp, 0)) != tplHeader.HeaderSize) + { + fireDebug(" -> Invalid Headersize: 0x{0}", Shared.Swap(BitConverter.ToUInt32(temp, 0))); + throw new Exception("TPL Header: Invalid Headersize!"); + } + + for (int i = 0; i < tplHeader.NumOfTextures; i++) + { + fireDebug(" Reading Texture Entry #{1} of {2}... (Offset: 0x{0})", tplFile.Position, i + 1, tplHeader.NumOfTextures); + + TPL_TextureEntry tempTexture = new TPL_TextureEntry(); + + tplFile.Read(temp, 0, 4); + tempTexture.TextureHeaderOffset = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTexture.PaletteHeaderOffset = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplTextureEntries.Add(tempTexture); + } + + for (int i = 0; i < tplHeader.NumOfTextures; i++) + { + fireDebug(" Reading Texture Header #{1} of {2}... (Offset: 0x{0})", tplFile.Position, i + 1, tplHeader.NumOfTextures); + + TPL_TextureHeader tempTextureHeader = new TPL_TextureHeader(); + TPL_PaletteHeader tempPaletteHeader = new TPL_PaletteHeader(); + tplFile.Seek(tplTextureEntries[i].TextureHeaderOffset, SeekOrigin.Begin); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.TextureHeight = Shared.Swap(BitConverter.ToUInt16(temp, 0)); + tempTextureHeader.TextureWidth = Shared.Swap(BitConverter.ToUInt16(temp, 2)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.TextureFormat = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.TextureDataOffset = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.WrapS = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.WrapT = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.MinFilter = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.MagFilter = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.LodBias = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempTextureHeader.EdgeLod = temp[0]; + tempTextureHeader.MinLod = temp[1]; + tempTextureHeader.MaxLod = temp[2]; + tempTextureHeader.Unpacked = temp[3]; + + if (tplTextureEntries[i].PaletteHeaderOffset != 0) + { + fireDebug(" Reading Palette Header #{1} of {2}... (Offset: 0x{0})", tplFile.Position, i + 1, tplHeader.NumOfTextures); + + tplFile.Seek(tplTextureEntries[i].PaletteHeaderOffset, SeekOrigin.Begin); + + tplFile.Read(temp, 0, 4); + tempPaletteHeader.NumberOfItems = Shared.Swap(BitConverter.ToUInt16(temp, 0)); + tempPaletteHeader.Unpacked = temp[2]; + tempPaletteHeader.Pad = temp[3]; + + tplFile.Read(temp, 0, 4); + tempPaletteHeader.PaletteFormat = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + + tplFile.Read(temp, 0, 4); + tempPaletteHeader.PaletteDataOffset = Shared.Swap(BitConverter.ToUInt32(temp, 0)); + } + + tplFile.Seek(tempTextureHeader.TextureDataOffset, SeekOrigin.Begin); + byte[] tempTextureData = new byte[textureByteSize((TPL_TextureFormat)tempTextureHeader.TextureFormat, tempTextureHeader.TextureWidth, tempTextureHeader.TextureHeight)]; + byte[] tempPaletteData = new byte[tempPaletteHeader.NumberOfItems * 2]; + + fireDebug(" Reading Texture #{1} of {2}... (Offset: 0x{0})", tplFile.Position, i + 1, tplHeader.NumOfTextures); + tplFile.Read(tempTextureData, 0, tempTextureData.Length); + + if (tplTextureEntries[i].PaletteHeaderOffset > 0) + { + fireDebug(" Reading Palette #{1} of {2}... (Offset: 0x{0})", tplFile.Position, i + 1, tplHeader.NumOfTextures); + + tplFile.Seek(tempPaletteHeader.PaletteDataOffset, SeekOrigin.Begin); + tplFile.Read(tempPaletteData, 0, tempPaletteData.Length); + } + else tempPaletteData = new byte[0]; + + tplTextureHeaders.Add(tempTextureHeader); + tplPaletteHeaders.Add(tempPaletteHeader); + textureData.Add(tempTextureData); + paletteData.Add(tempPaletteData); + } + } + + private int textureByteSize(TPL_TextureFormat tplFormat, int width, int height) + { + switch (tplFormat) + { + case TPL_TextureFormat.I4: + return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 8) / 2; + case TPL_TextureFormat.I8: + case TPL_TextureFormat.IA4: + return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 4); + case TPL_TextureFormat.IA8: + case TPL_TextureFormat.RGB565: + case TPL_TextureFormat.RGB5A3: + return Shared.AddPadding(width, 4) * Shared.AddPadding(height, 4) * 2; + case TPL_TextureFormat.RGBA8: + return Shared.AddPadding(width, 4) * Shared.AddPadding(height, 4) * 4; + case TPL_TextureFormat.CI4: + return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 8) / 2; + case TPL_TextureFormat.CI8: + return Shared.AddPadding(width, 8) * Shared.AddPadding(height, 4); + case TPL_TextureFormat.CI14X2: + return Shared.AddPadding(width, 4) * Shared.AddPadding(height, 4) * 2; + case TPL_TextureFormat.CMP: + return width * height; + default: + throw new FormatException("Unsupported Texture Format!"); + } + } + + private void createFromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats) + { + tplHeader = new TPL_Header(); + tplTextureEntries = new List(); + tplTextureHeaders = new List(); + tplPaletteHeaders = new List(); + textureData = new List(); + paletteData = new List(); + + tplHeader.NumOfTextures = (uint)images.Length; + + for (int i = 0; i < images.Length; i++) + { + Image img = images[i]; + + TPL_TextureEntry tempTexture = new TPL_TextureEntry(); + TPL_TextureHeader tempTextureHeader = new TPL_TextureHeader(); + TPL_PaletteHeader tempPaletteHeader = new TPL_PaletteHeader(); + byte[] tempTextureData = imageToTpl(img, tplFormats[i]); + byte[] tempPaletteData = new byte[0]; + + tempTextureHeader.TextureHeight = (ushort)img.Height; + tempTextureHeader.TextureWidth = (ushort)img.Width; + tempTextureHeader.TextureFormat = (uint)tplFormats[i]; + + if (tplFormats[i] == TPL_TextureFormat.CI4 || tplFormats[i] == TPL_TextureFormat.CI8 || tplFormats[i] == TPL_TextureFormat.CI14X2) + { + ColorIndexConverter cic = new ColorIndexConverter(imageToRgba(img), img.Width, img.Height, tplFormats[i], paletteFormats[i]); + + tempTextureData = cic.Data; + tempPaletteData = cic.Palette; + + tempPaletteHeader.NumberOfItems = (ushort)(tempPaletteData.Length / 2); + tempPaletteHeader.PaletteFormat = (uint)paletteFormats[i]; + } + + tplTextureEntries.Add(tempTexture); + tplTextureHeaders.Add(tempTextureHeader); + tplPaletteHeaders.Add(tempPaletteHeader); + textureData.Add(tempTextureData); + paletteData.Add(tempPaletteData); + } + } + + private byte[] imageToTpl(Image img, TPL_TextureFormat tplFormat) + { + switch (tplFormat) + { + case TPL_TextureFormat.I4: + return toI4((Bitmap)img); + case TPL_TextureFormat.I8: + return toI8((Bitmap)img); + case TPL_TextureFormat.IA4: + return toIA4((Bitmap)img); + case TPL_TextureFormat.IA8: + return toIA8((Bitmap)img); + case TPL_TextureFormat.RGB565: + return toRGB565((Bitmap)img); + case TPL_TextureFormat.RGB5A3: + return toRGB5A3((Bitmap)img); + case TPL_TextureFormat.RGBA8: + return toRGBA8((Bitmap)img); + case TPL_TextureFormat.CI4: + case TPL_TextureFormat.CI8: + case TPL_TextureFormat.CI14X2: + return new byte[0]; + case TPL_TextureFormat.CMP: + default: + throw new FormatException("Format not supported!\nCurrently, images can only be converted to the following formats:\nI4, I8, IA4, IA8, RGB565, RGB5A3, RGBA8, CI4, CI8 , CI14X2."); + } + } + + private uint[] imageToRgba(Image img) + { + Bitmap bmp = (Bitmap)img; + System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), + System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + byte[] pixelData = new byte[bmpData.Height * (int)Math.Abs(bmpData.Stride)]; + System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, pixelData, 0, pixelData.Length); + + bmp.UnlockBits(bmpData); + return Shared.ByteArrayToUIntArray(pixelData); + } + + private Bitmap rgbaToImage(byte[] data, int width, int height) + { + if (width == 0) width = 1; + if (height == 0) height = 1; + + Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + try + { + System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits( + new Rectangle(0, 0, bmp.Width, bmp.Height), + System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat); + + System.Runtime.InteropServices.Marshal.Copy(data, 0, bmpData.Scan0, data.Length); + bmp.UnlockBits(bmpData); + } + catch { bmp.Dispose(); throw; } + + return bmp; + } + + private uint[] paletteToRgba(int index) + { + TPL_PaletteFormat paletteformat = (TPL_PaletteFormat)tplPaletteHeaders[index].PaletteFormat; + int itemcount = tplPaletteHeaders[index].NumberOfItems; + int r, g, b, a; + + uint[] output = new uint[itemcount]; + for (int i = 0; i < itemcount; i++) + { + if (i >= itemcount) continue; + + ushort pixel = BitConverter.ToUInt16(new byte[] { paletteData[index][i * 2 + 1], paletteData[index][i * 2] }, 0); + + if (paletteformat == TPL_PaletteFormat.IA8) //IA8 + { + r = pixel & 0xff; + b = r; + g = r; + a = pixel >> 8; + } + else if (paletteformat == TPL_PaletteFormat.RGB565) //RGB565 + { + b = (((pixel >> 11) & 0x1F) << 3) & 0xff; + g = (((pixel >> 5) & 0x3F) << 2) & 0xff; + r = (((pixel >> 0) & 0x1F) << 3) & 0xff; + a = 255; + } + else //RGB5A3 + { + if ((pixel & (1 << 15)) != 0) //RGB555 + { + a = 255; + b = (((pixel >> 10) & 0x1F) * 255) / 31; + g = (((pixel >> 5) & 0x1F) * 255) / 31; + r = (((pixel >> 0) & 0x1F) * 255) / 31; + } + else //RGB4A3 + { + a = (((pixel >> 12) & 0x07) * 255) / 7; + b = (((pixel >> 8) & 0x0F) * 255) / 15; + g = (((pixel >> 4) & 0x0F) * 255) / 15; + r = (((pixel >> 0) & 0x0F) * 255) / 15; + } + } + + output[i] = (uint)((r << 0) | (g << 8) | (b << 16) | (a << 24)); + } + + return output; + } + + private uint[] paletteToRgba(TPL_PaletteHeader header, byte[] data) + { + TPL_PaletteFormat paletteformat = (TPL_PaletteFormat)header.PaletteFormat; + int itemcount = header.NumberOfItems; + int r, g, b, a; + + uint[] output = new uint[itemcount]; + for (int i = 0; i < itemcount; i++) + { + if (i >= itemcount) continue; + + ushort pixel = BitConverter.ToUInt16(new byte[] { data[i * 2 + 1], data[i * 2] }, 0); + + if (paletteformat == TPL_PaletteFormat.IA8) //IA8 + { + r = pixel & 0xff; + b = r; + g = r; + a = pixel >> 8; + } + else if (paletteformat == TPL_PaletteFormat.RGB565) //RGB565 + { + b = (((pixel >> 11) & 0x1F) << 3) & 0xff; + g = (((pixel >> 5) & 0x3F) << 2) & 0xff; + r = (((pixel >> 0) & 0x1F) << 3) & 0xff; + a = 255; + } + else //RGB5A3 + { + if ((pixel & (1 << 15)) != 0) //RGB555 + { + a = 255; + b = (((pixel >> 10) & 0x1F) * 255) / 31; + g = (((pixel >> 5) & 0x1F) * 255) / 31; + r = (((pixel >> 0) & 0x1F) * 255) / 31; + } + else //RGB4A3 + { + a = (((pixel >> 12) & 0x07) * 255) / 7; + b = (((pixel >> 8) & 0x0F) * 255) / 15; + g = (((pixel >> 4) & 0x0F) * 255) / 15; + r = (((pixel >> 0) & 0x0F) * 255) / 15; + } + } + + output[i] = (uint)((r << 0) | (g << 8) | (b << 16) | (a << 24)); + } + + return output; + } + + private int avg(int w0, int w1, int c0, int c1) + { + int a0 = c0 >> 11; + int a1 = c1 >> 11; + int a = (w0 * a0 + w1 * a1) / (w0 + w1); + int c = (a << 11) & 0xffff; + + a0 = (c0 >> 5) & 63; + a1 = (c1 >> 5) & 63; + a = (w0 * a0 + w1 * a1) / (w0 + w1); + c = c | ((a << 5) & 0xffff); + + a0 = c0 & 31; + a1 = c1 & 31; + a = (w0 * a0 + w1 * a1) / (w0 + w1); + c = c | a; + + return c; + } + #endregion + + #region Conversions + #region RGBA8 + private byte[] fromRGBA8(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + int inp = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 4) + { + for (int k = 0; k < 2; k++) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 4; x1++) + { + ushort pixel = Shared.Swap(BitConverter.ToUInt16(tpl, inp++ * 2)); + + if ((x1 >= width) || (y1 >= height)) + continue; + + if (k == 0) + { + int a = (pixel >> 8) & 0xff; + int r = (pixel >> 0) & 0xff; + output[x1 + (y1 * width)] |= (uint)((r << 16) | (a << 24)); + } + else + { + int g = (pixel >> 8) & 0xff; + int b = (pixel >> 0) & 0xff; + output[x1 + (y1 * width)] |= (uint)((g << 8) | (b << 0)); + } + } + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + private byte[] toRGBA8(Bitmap img) + { + uint[] pixeldata = imageToRgba(img); + int w = img.Width; + int h = img.Height; + int z = 0, iv = 0; + byte[] output = new byte[Shared.AddPadding(w, 4) * Shared.AddPadding(h, 4) * 4]; + uint[] lr = new uint[32], lg = new uint[32], lb = new uint[32], la = new uint[32]; + + for (int y1 = 0; y1 < h; y1 += 4) + { + for (int x1 = 0; x1 < w; x1 += 4) + { + for (int y = y1; y < (y1 + 4); y++) + { + for (int x = x1; x < (x1 + 4); x++) + { + uint rgba; + + if (y >= h || x >= w) + rgba = 0; + else + rgba = pixeldata[x + (y * w)]; + + lr[z] = (uint)(rgba >> 16) & 0xff; + lg[z] = (uint)(rgba >> 8) & 0xff; + lb[z] = (uint)(rgba >> 0) & 0xff; + la[z] = (uint)(rgba >> 24) & 0xff; + + z++; + } + } + + if (z == 16) + { + for (int i = 0; i < 16; i++) + { + output[iv++] = (byte)(la[i]); + output[iv++] = (byte)(lr[i]); + } + for (int i = 0; i < 16; i++) + { + output[iv++] = (byte)(lg[i]); + output[iv++] = (byte)(lb[i]); + } + + z = 0; + } + } + } + + return output; + } + #endregion + + #region RGB5A3 + private byte[] fromRGB5A3(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + int inp = 0; + int r, g, b; + int a = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 4) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 4; x1++) + { + ushort pixel = Shared.Swap(BitConverter.ToUInt16(tpl, inp++ * 2)); + + if (y1 >= height || x1 >= width) + continue; + + if ((pixel & (1 << 15)) != 0) + { + b = (((pixel >> 10) & 0x1F) * 255) / 31; + g = (((pixel >> 5) & 0x1F) * 255) / 31; + r = (((pixel >> 0) & 0x1F) * 255) / 31; + a = 255; + } + else + { + a = (((pixel >> 12) & 0x07) * 255) / 7; + b = (((pixel >> 8) & 0x0F) * 255) / 15; + g = (((pixel >> 4) & 0x0F) * 255) / 15; + r = (((pixel >> 0) & 0x0F) * 255) / 15; + } + + output[(y1 * width) + x1] = (uint)((r << 0) | (g << 8) | (b << 16) | (a << 24)); + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + private byte[] toRGB5A3(Bitmap img) + { + uint[] pixeldata = imageToRgba(img); + int w = img.Width; + int h = img.Height; + int z = -1; + byte[] output = new byte[Shared.AddPadding(w, 4) * Shared.AddPadding(h, 4) * 2]; + + for (int y1 = 0; y1 < h; y1 += 4) + { + for (int x1 = 0; x1 < w; x1 += 4) + { + for (int y = y1; y < y1 + 4; y++) + { + for (int x = x1; x < x1 + 4; x++) + { + int newpixel; + + if (y >= h || x >= w) + newpixel = 0; + else + { + int rgba = (int)pixeldata[x + (y * w)]; + newpixel = 0; + + int r = (rgba >> 16) & 0xff; + int g = (rgba >> 8) & 0xff; + int b = (rgba >> 0) & 0xff; + int a = (rgba >> 24) & 0xff; + + if (a <= 0xda) //RGB4A3 + { + newpixel &= ~(1 << 15); + + r = ((r * 15) / 255) & 0xf; + g = ((g * 15) / 255) & 0xf; + b = ((b * 15) / 255) & 0xf; + a = ((a * 7) / 255) & 0x7; + + newpixel |= (a << 12) | (r << 8) | (g << 4) | b; + } + else //RGB5 + { + newpixel |= (1 << 15); + + r = ((r * 31) / 255) & 0x1f; + g = ((g * 31) / 255) & 0x1f; + b = ((b * 31) / 255) & 0x1f; + + newpixel |= (r << 10) | (g << 5) | b; + } + } + + output[++z] = (byte)(newpixel >> 8); + output[++z] = (byte)(newpixel & 0xff); + } + } + } + } + + return output; + } + #endregion + + #region RGB565 + private byte[] fromRGB565(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + int inp = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 4) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 4; x1++) + { + ushort pixel = Shared.Swap(BitConverter.ToUInt16(tpl, inp++ * 2)); + + if (y1 >= height || x1 >= width) + continue; + + int b = (((pixel >> 11) & 0x1F) << 3) & 0xff; + int g = (((pixel >> 5) & 0x3F) << 2) & 0xff; + int r = (((pixel >> 0) & 0x1F) << 3) & 0xff; + + output[y1 * width + x1] = (uint)((r << 0) | (g << 8) | (b << 16) | (255 << 24)); + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + private byte[] toRGB565(Bitmap img) + { + uint[] pixeldata = imageToRgba(img); + int w = img.Width; + int h = img.Height; + int z = -1; + byte[] output = new byte[Shared.AddPadding(w, 4) * Shared.AddPadding(h, 4) * 2]; + + for (int y1 = 0; y1 < h; y1 += 4) + { + for (int x1 = 0; x1 < w; x1 += 4) + { + for (int y = y1; y < y1 + 4; y++) + { + for (int x = x1; x < x1 + 4; x++) + { + ushort newpixel; + + if (y >= h || x >= w) + newpixel = 0; + else + { + uint rgba = pixeldata[x + (y * w)]; + + uint b = (rgba >> 16) & 0xff; + uint g = (rgba >> 8) & 0xff; + uint r = (rgba >> 0) & 0xff; + + newpixel = (ushort)(((b >> 3) << 11) | ((g >> 2) << 5) | ((r >> 3) << 0)); + } + + output[++z] = (byte)(newpixel >> 8); + output[++z] = (byte)(newpixel & 0xff); + } + } + } + } + + return output; + } + #endregion + + #region I4 + private byte[] fromI4(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + int inp = 0; + + for (int y = 0; y < height; y += 8) + { + for (int x = 0; x < width; x += 8) + { + for (int y1 = y; y1 < y + 8; y1++) + { + for (int x1 = x; x1 < x + 8; x1 += 2) + { + int pixel = tpl[inp++]; + + if (y1 >= height || x1 >= width) + continue; + + int i = (pixel >> 4) * 255 / 15; + output[y1 * width + x1] = (uint)((i << 0) | (i << 8) | (i << 16) | (255 << 24)); + + i = (pixel & 0x0F) * 255 / 15; + if (y1 * width + x1 + 1 < output.Length) output[y1 * width + x1 + 1] = (uint)((i << 0) | (i << 8) | (i << 16) | (255 << 24)); + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + private byte[] toI4(Bitmap img) + { + uint[] pixeldata = imageToRgba(img); + int w = img.Width; + int h = img.Height; + int inp = 0; + byte[] output = new byte[Shared.AddPadding(w, 8) * Shared.AddPadding(h, 8) / 2]; + + for (int y1 = 0; y1 < h; y1 += 8) + { + for (int x1 = 0; x1 < w; x1 += 8) + { + for (int y = y1; y < y1 + 8; y++) + { + for (int x = x1; x < x1 + 8; x += 2) + { + byte newpixel; + + if (x >= w || y >= h) + newpixel = 0; + else + { + uint rgba = pixeldata[x + (y * w)]; + + uint r = (rgba >> 0) & 0xff; + uint g = (rgba >> 8) & 0xff; + uint b = (rgba >> 16) & 0xff; + + uint i1 = ((r + g + b) / 3) & 0xff; + + if ((x + (y * w) + 1) >= pixeldata.Length) rgba = 0; + else rgba = pixeldata[x + (y * w) + 1]; + + r = (rgba >> 0) & 0xff; + g = (rgba >> 8) & 0xff; + b = (rgba >> 16) & 0xff; + + uint i2 = ((r + g + b) / 3) & 0xff; + + newpixel = (byte)((((i1 * 15) / 255) << 4) | (((i2 * 15) / 255) & 0xf)); + } + + output[inp++] = newpixel; + } + } + } + } + + return output; + } + #endregion + + #region I8 + private byte[] fromI8(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + int inp = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 8) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 8; x1++) + { + int pixel = tpl[inp++]; + + if (y1 >= height || x1 >= width) + continue; + + output[y1 * width + x1] = (uint)((pixel << 0) | (pixel << 8) | (pixel << 16) | (255 << 24)); + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + private byte[] toI8(Bitmap img) + { + uint[] pixeldata = imageToRgba(img); + int w = img.Width; + int h = img.Height; + int inp = 0; + byte[] output = new byte[Shared.AddPadding(w, 8) * Shared.AddPadding(h, 4)]; + + for (int y1 = 0; y1 < h; y1 += 4) + { + for (int x1 = 0; x1 < w; x1 += 8) + { + for (int y = y1; y < y1 + 4; y++) + { + for (int x = x1; x < x1 + 8; x++) + { + byte newpixel; + + if (x >= w || y >= h) + newpixel = 0; + else + { + uint rgba = pixeldata[x + (y * w)]; + + uint r = (rgba >> 0) & 0xff; + uint g = (rgba >> 8) & 0xff; + uint b = (rgba >> 16) & 0xff; + + newpixel = (byte)(((r + g + b) / 3) & 0xff); + } + + output[inp++] = newpixel; + } + } + } + } + + return output; + } + #endregion + + #region IA4 + private byte[] fromIA4(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + int inp = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 8) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 8; x1++) + { + int pixel = tpl[inp++]; + + if (y1 >= height || x1 >= width) + continue; + + int i = ((pixel & 0x0F) * 255 / 15) & 0xff; + int a = (((pixel >> 4) * 255) / 15) & 0xff; + + output[y1 * width + x1] = (uint)((i << 0) | (i << 8) | (i << 16) | (a << 24)); + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + private byte[] toIA4(Bitmap img) + { + uint[] pixeldata = imageToRgba(img); + int w = img.Width; + int h = img.Height; + int inp = 0; + byte[] output = new byte[Shared.AddPadding(w, 8) * Shared.AddPadding(h, 4)]; + + for (int y1 = 0; y1 < h; y1 += 4) + { + for (int x1 = 0; x1 < w; x1 += 8) + { + for (int y = y1; y < y1 + 4; y++) + { + for (int x = x1; x < x1 + 8; x++) + { + byte newpixel; + + if (x >= w || y >= h) + newpixel = 0; + else + { + uint rgba = pixeldata[x + (y * w)]; + + uint r = (rgba >> 0) & 0xff; + uint g = (rgba >> 8) & 0xff; + uint b = (rgba >> 16) & 0xff; + + uint i = ((r + g + b) / 3) & 0xff; + uint a = (rgba >> 24) & 0xff; + + newpixel = (byte)((((i * 15) / 255) & 0xf) | (((a * 15) / 255) << 4)); + } + + output[inp++] = newpixel; + } + } + } + } + + return output; + } + #endregion + + #region IA8 + private byte[] fromIA8(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + int inp = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 4) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 4; x1++) + { + int pixel = Shared.Swap(BitConverter.ToUInt16(tpl, inp++ * 2)); + + if (y1 >= height || x1 >= width) + continue; + + uint a = (uint)(pixel >> 8); + uint i = (uint)(pixel & 0xff); + + output[y1 * width + x1] = (i << 0) | (i << 8) | (i << 16) | (a << 24); + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + private byte[] toIA8(Bitmap img) + { + uint[] pixeldata = imageToRgba(img); + int w = img.Width; + int h = img.Height; + int inp = 0; + byte[] output = new byte[Shared.AddPadding(w, 4) * Shared.AddPadding(h, 4) * 2]; + + for (int y1 = 0; y1 < h; y1 += 4) + { + for (int x1 = 0; x1 < w; x1 += 4) + { + for (int y = y1; y < y1 + 4; y++) + { + for (int x = x1; x < x1 + 4; x++) + { + ushort newpixel; + + if (x >= w || y >= h) + newpixel = 0; + else + { + uint rgba = pixeldata[x + (y * w)]; + + uint r = (rgba >> 0) & 0xff; + uint g = (rgba >> 8) & 0xff; + uint b = (rgba >> 16) & 0xff; + + uint i = ((r + g + b) / 3) & 0xff; + uint a = (rgba >> 24) & 0xff; + + newpixel = (ushort)((a << 8) | i); + } + + byte[] temp = BitConverter.GetBytes(newpixel); + Array.Reverse(temp); + + output[inp++] = (byte)(newpixel >> 8); + output[inp++] = (byte)(newpixel & 0xff); + } + } + } + } + + return output; + } + #endregion + + #region CI4 + private byte[] fromCI4(byte[] tpl, uint[] paletteData, int width, int height) + { + uint[] output = new uint[width * height]; + int i = 0; + + for (int y = 0; y < height; y += 8) + { + for (int x = 0; x < width; x += 8) + { + for (int y1 = y; y1 < y + 8; y1++) + { + for (int x1 = x; x1 < x + 8; x1 += 2) + { + byte pixel = tpl[i++]; + + if (y1 >= height || x1 >= width) + continue; + + output[y1 * width + x1] = paletteData[pixel >> 4]; ; + if (y1 * width + x1 + 1 < output.Length) output[y1 * width + x1 + 1] = paletteData[pixel & 0x0F]; + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + //toCI4 done in class ColorIndexConverter + #endregion + + #region CI8 + private byte[] fromCI8(byte[] tpl, uint[] paletteData, int width, int height) + { + uint[] output = new uint[width * height]; + int i = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 8) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 8; x1++) + { + ushort pixel = tpl[i++]; + + if (y1 >= height || x1 >= width) + continue; + + output[y1 * width + x1] = paletteData[pixel]; + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + //toCI8 done in class ColorIndexConverter + #endregion + + #region CI14X2 + private byte[] fromCI14X2(byte[] tpl, uint[] paletteData, int width, int height) + { + uint[] output = new uint[width * height]; + int i = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 4) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 4; x1++) + { + ushort pixel = Shared.Swap(BitConverter.ToUInt16(tpl, i++ * 2)); + + if (y1 >= height || x1 >= width) + continue; + + output[y1 * width + x1] = paletteData[pixel & 0x3FFF]; + } + } + } + } + + return Shared.UIntArrayToByteArray(output); + } + + //toCI14X2 done in class ColorIndexConverter + #endregion + + #region CMP + private byte[] fromCMP(byte[] tpl, int width, int height) + { + uint[] output = new uint[width * height]; + ushort[] c = new ushort[4]; + int[] pix = new int[4]; + int inp = 0; + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + int ww = Shared.AddPadding(width, 8); + + int x0 = x & 0x03; + int x1 = (x >> 2) & 0x01; + int x2 = x >> 3; + + int y0 = y & 0x03; + int y1 = (y >> 2) & 0x01; + int y2 = y >> 3; + + int off = (8 * x1) + (16 * y1) + (32 * x2) + (4 * ww * y2); + + c[0] = Shared.Swap(BitConverter.ToUInt16(tpl, off)); + c[1] = Shared.Swap(BitConverter.ToUInt16(tpl, off + 2)); + + if (c[0] > c[1]) + { + c[2] = (ushort)avg(2, 1, c[0], c[1]); + c[3] = (ushort)avg(1, 2, c[0], c[1]); + } + else + { + c[2] = (ushort)avg(1, 1, c[0], c[1]); + c[3] = 0; + } + + uint pixel = Shared.Swap(BitConverter.ToUInt32(tpl, off + 4)); + + int ix = x0 + (4 * y0); + int raw = c[(pixel >> (30 - (2 * ix))) & 0x03]; + + pix[0] = (raw >> 8) & 0xf8; + pix[1] = (raw >> 3) & 0xf8; + pix[2] = (raw << 3) & 0xf8; + pix[3] = 0xff; + if (((pixel >> (30 - (2 * ix))) & 0x03) == 3 && c[0] <= c[1]) pix[3] = 0x00; + + output[inp] = (uint)((pix[0] << 16) | (pix[1] << 8) | (pix[2] << 0) | (pix[3] << 24)); + inp++; + } + } + + return Shared.UIntArrayToByteArray(output); + } + + //There's currently no conversion to CMP + #endregion + #endregion + + #region Events + /// + /// Fires debugging messages. You may write them into a log file or log textbox. + /// + private void fireDebug(string debugMessage, params object[] args) + { + System.Diagnostics.Debug.WriteLine($"{debugMessage}"); + } + #endregion + } + + public class TPL_Header + { + private uint tplMagic = 0x0020AF30; + private uint numOfTextures = 0; + private uint headerSize = 0x0C; + + public uint TplMagic { get { return tplMagic; } } + public uint NumOfTextures { get { return numOfTextures; } set { numOfTextures = value; } } + public uint HeaderSize { get { return headerSize; } } + + public void Write(Stream writeStream) + { + writeStream.Write(BitConverter.GetBytes(Shared.Swap(tplMagic)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(numOfTextures)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(headerSize)), 0, 4); + } + } + + public class TPL_TextureEntry + { + private uint textureHeaderOffset = 0x00000000; + private uint paletteHeaderOffset = 0x00000000; + + public uint TextureHeaderOffset { get { return textureHeaderOffset; } set { textureHeaderOffset = value; } } + public uint PaletteHeaderOffset { get { return paletteHeaderOffset; } set { paletteHeaderOffset = value; } } + + public void Write(Stream writeStream) + { + writeStream.Write(BitConverter.GetBytes(Shared.Swap(textureHeaderOffset)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(paletteHeaderOffset)), 0, 4); + } + } + + public class TPL_TextureHeader + { + private ushort textureHeight; + private ushort textureWidth; + private uint textureFormat; + private uint textureDataOffset; + private uint wrapS = 0x00000000; + private uint wrapT = 0x00000000; + private uint minFilter = 0x00000001; + private uint magFilter = 0x00000001; + private uint lodBias = 0x00000000; + private byte edgeLod = 0x00; + private byte minLod = 0x00; + private byte maxLod = 0x00; + private byte unpacked = 0x00; + + public ushort TextureHeight { get { return textureHeight; } set { textureHeight = value; } } + public ushort TextureWidth { get { return textureWidth; } set { textureWidth = value; } } + public uint TextureFormat { get { return textureFormat; } set { textureFormat = value; } } + public uint TextureDataOffset { get { return textureDataOffset; } set { textureDataOffset = value; } } + public uint WrapS { get { return wrapS; } set { wrapS = value; } } + public uint WrapT { get { return wrapT; } set { wrapT = value; } } + public uint MinFilter { get { return minFilter; } set { minFilter = value; } } + public uint MagFilter { get { return magFilter; } set { magFilter = value; } } + public uint LodBias { get { return lodBias; } set { lodBias = value; } } + public byte EdgeLod { get { return edgeLod; } set { edgeLod = value; } } + public byte MinLod { get { return minLod; } set { minLod = value; } } + public byte MaxLod { get { return maxLod; } set { maxLod = value; } } + public byte Unpacked { get { return unpacked; } set { unpacked = value; } } + + public void Write(Stream writeStream) + { + writeStream.Write(BitConverter.GetBytes(Shared.Swap(textureHeight)), 0, 2); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(textureWidth)), 0, 2); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(textureFormat)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(textureDataOffset)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(wrapS)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(wrapT)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(minFilter)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(magFilter)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(lodBias)), 0, 4); + writeStream.WriteByte(edgeLod); + writeStream.WriteByte(minLod); + writeStream.WriteByte(maxLod); + writeStream.WriteByte(unpacked); + } + } + + public class TPL_PaletteHeader + { + private ushort numberOfItems = 0x0000; + private byte unpacked = 0x00; + private byte pad = 0x00; + private uint paletteFormat = 255; + private uint paletteDataOffset; + + public ushort NumberOfItems { get { return numberOfItems; } set { numberOfItems = value; } } + public byte Unpacked { get { return unpacked; } set { unpacked = value; } } + public byte Pad { get { return pad; } set { pad = value; } } + public uint PaletteFormat { get { return paletteFormat; } set { paletteFormat = value; } } + public uint PaletteDataOffset { get { return paletteDataOffset; } set { paletteDataOffset = value; } } + + public void Write(Stream writeStream) + { + writeStream.Write(BitConverter.GetBytes(Shared.Swap(numberOfItems)), 0, 2); + writeStream.WriteByte(unpacked); + writeStream.WriteByte(pad); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(paletteFormat)), 0, 4); + writeStream.Write(BitConverter.GetBytes(Shared.Swap(paletteDataOffset)), 0, 4); + } + } + + internal class ColorIndexConverter + { + private uint[] rgbaPalette; + private byte[] tplPalette; + private uint[] rgbaData; + private byte[] tplData; + private TPL_TextureFormat tplFormat; + private TPL_PaletteFormat paletteFormat; + private int width; + private int height; + + public byte[] Palette { get { return tplPalette; } } + public byte[] Data { get { return tplData; } } + + public ColorIndexConverter(uint[] rgbaData, int width, int height, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat) + { + if (tplFormat != TPL_TextureFormat.CI4 && tplFormat != TPL_TextureFormat.CI8) // && tplFormat != TPL_TextureFormat.CI14X2) + throw new Exception("Texture format must be either CI4 or CI8"); // or CI14X2!"); + if (paletteFormat != TPL_PaletteFormat.IA8 && paletteFormat != TPL_PaletteFormat.RGB565 && paletteFormat != TPL_PaletteFormat.RGB5A3) + throw new Exception("Palette format must be either IA8, RGB565 or RGB5A3!"); + + this.rgbaData = rgbaData; + this.width = width; + this.height = height; + this.tplFormat = tplFormat; + this.paletteFormat = paletteFormat; + + buildPalette(); + + if (tplFormat == TPL_TextureFormat.CI4) toCI4(); + else if (tplFormat == TPL_TextureFormat.CI8) toCI8(); + else toCI14X2(); + } + + #region Private Functions + private void toCI4() + { + byte[] indexData = new byte[libWiiSharp.Shared.AddPadding(width, 8) * libWiiSharp.Shared.AddPadding(height, 8) / 2]; + int i = 0; + + for (int y = 0; y < height; y += 8) + { + for (int x = 0; x < width; x += 8) + { + for (int y1 = y; y1 < y + 8; y1++) + { + for (int x1 = x; x1 < x + 8; x1 += 2) + { + uint pixel; + + if (y1 >= height || x1 >= width) + pixel = 0; + else + pixel = rgbaData[y1 * width + x1]; + + uint index1 = getColorIndex(pixel); + + if (y1 >= height || x1 >= width) + pixel = 0; + else if (y1 * width + x1 + 1 >= rgbaData.Length) + pixel = 0; + else + pixel = rgbaData[y1 * width + x1 + 1]; + + uint index2 = getColorIndex(pixel); + + indexData[i++] = (byte)(((byte)index1 << 4) | (byte)index2); + } + } + } + } + + this.tplData = indexData; + } + + private void toCI8() + { + byte[] indexData = new byte[libWiiSharp.Shared.AddPadding(width, 8) * libWiiSharp.Shared.AddPadding(height, 4)]; + int i = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 8) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 8; x1++) + { + uint pixel; + + if (y1 >= height || x1 >= width) + pixel = 0; + else + pixel = rgbaData[y1 * width + x1]; + + indexData[i++] = (byte)getColorIndex(pixel); + } + } + } + } + + this.tplData = indexData; + } + + private void toCI14X2() + { + byte[] indexData = new byte[libWiiSharp.Shared.AddPadding(width, 4) * libWiiSharp.Shared.AddPadding(height, 4) * 2]; + int i = 0; + + for (int y = 0; y < height; y += 4) + { + for (int x = 0; x < width; x += 4) + { + for (int y1 = y; y1 < y + 4; y1++) + { + for (int x1 = x; x1 < x + 4; x1++) + { + uint pixel; + + if (y1 >= height || x1 >= width) + pixel = 0; + else + pixel = rgbaData[y1 * width + x1]; + + byte[] temp = BitConverter.GetBytes((ushort)getColorIndex(pixel)); + indexData[i++] = temp[1]; + indexData[i++] = temp[0]; + } + } + } + } + + this.tplData = indexData; + } + + private void buildPalette() + { + int palLength = 256; + if (tplFormat == TPL_TextureFormat.CI4) palLength = 16; + else if (tplFormat == TPL_TextureFormat.CI14X2) palLength = 16384; + + List palette = new List(); + List tPalette = new List(); + + palette.Add(0); + tPalette.Add(0); + + for (int i = 1; i < rgbaData.Length; i++) + { + if (palette.Count == palLength) break; + if (((rgbaData[i] >> 24) & 0xff) < ((tplFormat == TPL_TextureFormat.CI14X2) ? 1 : 25)) continue; + + ushort tplValue = libWiiSharp.Shared.Swap(convertToPaletteValue((int)rgbaData[i])); + + if (!palette.Contains(rgbaData[i]) && !tPalette.Contains(tplValue)) + { + palette.Add(rgbaData[i]); + tPalette.Add(tplValue); + } + } + + while (palette.Count % 16 != 0) + { palette.Add(0xffffffff); tPalette.Add(0xffff); } + + tplPalette = libWiiSharp.Shared.UShortArrayToByteArray(tPalette.ToArray()); + rgbaPalette = palette.ToArray(); + } + + private ushort convertToPaletteValue(int rgba) + { + int newpixel = 0, r, g, b, a; + + if (paletteFormat == TPL_PaletteFormat.IA8) + { + int intensity = ((((rgba >> 0) & 0xff) + ((rgba >> 8) & 0xff) + ((rgba >> 16) & 0xff)) / 3) & 0xff; + int alpha = (rgba >> 24) & 0xff; + + newpixel = (ushort)((alpha << 8) | intensity); + } + else if (paletteFormat == TPL_PaletteFormat.RGB565) + { + newpixel = (ushort)(((((rgba >> 16) & 0xff) >> 3) << 11) | ((((rgba >> 8) & 0xff) >> 2) << 5) | ((((rgba >> 0) & 0xff) >> 3) << 0)); + } + else + { + r = (rgba >> 16) & 0xff; + g = (rgba >> 8) & 0xff; + b = (rgba >> 0) & 0xff; + a = (rgba >> 24) & 0xff; + + if (a <= 0xda) //RGB4A3 + { + newpixel &= ~(1 << 15); + + r = ((r * 15) / 255) & 0xf; + g = ((g * 15) / 255) & 0xf; + b = ((b * 15) / 255) & 0xf; + a = ((a * 7) / 255) & 0x7; + + newpixel |= a << 12; + newpixel |= b << 0; + newpixel |= g << 4; + newpixel |= r << 8; + } + else //RGB5 + { + newpixel |= (1 << 15); + + r = ((r * 31) / 255) & 0x1f; + g = ((g * 31) / 255) & 0x1f; + b = ((b * 31) / 255) & 0x1f; + + newpixel |= b << 0; + newpixel |= g << 5; + newpixel |= r << 10; + } + } + + return (ushort)newpixel; + } + + private uint getColorIndex(uint value) + { + uint minDistance = 0x7FFFFFFF; + uint colorIndex = 0; + + if (((value >> 24) & 0xFF) < ((tplFormat == TPL_TextureFormat.CI14X2) ? 1 : 25)) return 0; + ushort color = convertToPaletteValue((int)value); + + for (int i = 0; i < rgbaPalette.Length; i++) + { + ushort curPal = convertToPaletteValue((int)rgbaPalette[i]); + + if (color == curPal) return (uint)i; + uint curDistance = getDistance(color, curPal); //(uint)Math.Abs(Math.Abs(color) - Math.Abs(curVal)); + + if (curDistance < minDistance) + { + minDistance = curDistance; + colorIndex = (uint)i; + } + } + + return colorIndex; + } + + private uint getDistance(ushort color, ushort paletteColor) + { + uint curCol = convertToRgbaValue(color); + uint palCol = convertToRgbaValue(paletteColor); + + uint curA = (curCol >> 24) & 0xFF; + uint curR = (curCol >> 16) & 0xFF; + uint curG = (curCol >> 8) & 0xFF; + uint curB = (curCol >> 0) & 0xFF; + + uint palA = (palCol >> 24) & 0xFF; + uint palR = (palCol >> 16) & 0xFF; + uint palG = (palCol >> 8) & 0xFF; + uint palB = (palCol >> 0) & 0xFF; + + uint distA = Math.Max(curA, palA) - Math.Min(curA, palA); + uint distR = Math.Max(curR, palR) - Math.Min(curR, palR); + uint distG = Math.Max(curG, palG) - Math.Min(curG, palG); + uint distB = Math.Max(curB, palB) - Math.Min(curB, palB); + + return distA + distR + distG + distB; + } + + private uint convertToRgbaValue(ushort pixel) + { + int rgba = 0, r, g, b, a; + + if (paletteFormat == TPL_PaletteFormat.IA8) + { + int i = (pixel >> 8); + a = pixel & 0xff; + + rgba = (i << 0) | (i << 8) | (i << 16) | (a << 24); + } + else if (paletteFormat == TPL_PaletteFormat.RGB565) + { + b = (((pixel >> 11) & 0x1F) << 3) & 0xff; + g = (((pixel >> 5) & 0x3F) << 2) & 0xff; + r = (((pixel >> 0) & 0x1F) << 3) & 0xff; + a = 255; + + rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24); + } + else + { + if ((pixel & (1 << 15)) != 0) + { + b = (((pixel >> 10) & 0x1F) * 255) / 31; + g = (((pixel >> 5) & 0x1F) * 255) / 31; + r = (((pixel >> 0) & 0x1F) * 255) / 31; + a = 255; + } + else + { + a = (((pixel >> 12) & 0x07) * 255) / 7; + b = (((pixel >> 8) & 0x0F) * 255) / 15; + g = (((pixel >> 4) & 0x0F) * 255) / 15; + r = (((pixel >> 0) & 0x0F) * 255) / 15; + } + + rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24); + } + + return (uint)rgba; + } + #endregion + } + + + + public static class Shared + { + /// + /// Merges two string arrays into one without double entries. + /// + /// + /// + /// + public static string[] MergeStringArrays(string[] a, string[] b) + { + List sList = new List(a); + + foreach (string currentString in b) + if (!sList.Contains(currentString)) sList.Add(currentString); + + sList.Sort(); + return sList.ToArray(); + } + + /// + /// Compares two byte arrays. + /// + /// + /// + /// + /// + /// + /// + public static bool CompareByteArrays(byte[] first, int firstIndex, byte[] second, int secondIndex, int length) + { + if (first.Length < length || second.Length < length) return false; + + for (int i = 0; i < length; i++) + if (first[firstIndex + i] != second[secondIndex + i]) return false; + + return true; + } + + /// + /// Compares two byte arrays. + /// + /// + /// + /// + public static bool CompareByteArrays(byte[] first, byte[] second) + { + if (first.Length != second.Length) return false; + else + for (int i = 0; i < first.Length; i++) + if (first[i] != second[i]) return false; + + return true; + } + + /// + /// Turns a byte array into a string, default separator is a space. + /// + /// + /// + /// + public static string ByteArrayToString(byte[] byteArray, char separator = ' ') + { + string res = string.Empty; + + foreach (byte b in byteArray) + res += b.ToString("x2").ToUpper() + separator; + + return res.Remove(res.Length - 1); + } + + /// + /// Turns a hex string into a byte array. + /// + /// + /// + public static byte[] HexStringToByteArray(string hexString) + { + byte[] ba = new byte[hexString.Length / 2]; + + for (int i = 0; i < hexString.Length / 2; i++) + ba[i] = byte.Parse(hexString.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber); + + return ba; + } + + /// + /// Counts how often the given char exists in the given string. + /// + /// + /// + /// + public static int CountCharsInString(string theString, char theChar) + { + int count = 0; + + foreach (char thisChar in theString) + if (thisChar == theChar) + count++; + + return count; + } + + /// + /// Pads the given value to a multiple of the given padding value, default padding value is 64. + /// + /// + /// + public static long AddPadding(long value) + { + return AddPadding(value, 64); + } + + /// + /// Pads the given value to a multiple of the given padding value, default padding value is 64. + /// + /// + /// + /// + public static long AddPadding(long value, int padding) + { + if (value % padding != 0) + { + value = value + (padding - (value % padding)); + } + + return value; + } + + /// + /// Pads the given value to a multiple of the given padding value, default padding value is 64. + /// + /// + /// + public static int AddPadding(int value) + { + return AddPadding(value, 64); + } + + /// + /// Pads the given value to a multiple of the given padding value, default padding value is 64. + /// + /// + /// + /// + public static int AddPadding(int value, int padding) + { + if (value % padding != 0) + { + value = value + (padding - (value % padding)); + } + + return value; + } + + /// + /// Swaps endianness. + /// + /// + /// + public static ushort Swap(ushort value) + { + return (ushort)IPAddress.HostToNetworkOrder((short)value); + } + + /// + /// Swaps endianness. + /// + /// + /// + public static uint Swap(uint value) + { + return (uint)IPAddress.HostToNetworkOrder((int)value); + } + + /// + /// Swaps endianness + /// + /// + /// + public static ulong Swap(ulong value) + { + return (ulong)IPAddress.HostToNetworkOrder((long)value); + } + + /// + /// Turns a ushort array into a byte array. + /// + /// + /// + public static byte[] UShortArrayToByteArray(ushort[] array) + { + List results = new List(); + foreach (ushort value in array) + { + byte[] converted = BitConverter.GetBytes(value); + results.AddRange(converted); + } + return results.ToArray(); + } + + /// + /// Turns a uint array into a byte array. + /// + /// + /// + public static byte[] UIntArrayToByteArray(uint[] array) + { + List results = new List(); + foreach (uint value in array) + { + byte[] converted = BitConverter.GetBytes(value); + results.AddRange(converted); + } + return results.ToArray(); + } + + /// + /// Turns a byte array into a uint array. + /// + /// + /// + public static uint[] ByteArrayToUIntArray(byte[] array) + { + UInt32[] converted = new UInt32[array.Length / 4]; + int j = 0; + + for (int i = 0; i < array.Length; i += 4) + converted[j++] = BitConverter.ToUInt32(array, i); + + return converted; + } + + /// + /// Turns a byte array into a ushort array. + /// + /// + /// + public static ushort[] ByteArrayToUShortArray(byte[] array) + { + ushort[] converted = new ushort[array.Length / 2]; + int j = 0; + + for (int i = 0; i < array.Length; i += 2) + converted[j++] = BitConverter.ToUInt16(array, i); + + return converted; + } + } +} \ No newline at end of file diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index d167d1cf..d11fb7c3 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache index 87371ec8..94775d45 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache index 540f2cb2..76645d97 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/TempPE/Properties.Resources.Designer.cs.dll b/Switch_FileFormatsMain/obj/Release/TempPE/Properties.Resources.Designer.cs.dll index e734e2ae..f9a34208 100644 Binary files a/Switch_FileFormatsMain/obj/Release/TempPE/Properties.Resources.Designer.cs.dll and b/Switch_FileFormatsMain/obj/Release/TempPE/Properties.Resources.Designer.cs.dll differ diff --git a/Switch_Toolbox_Library/Animations/Animation.cs b/Switch_Toolbox_Library/Animations/Animation.cs index e555391f..384d6332 100644 --- a/Switch_Toolbox_Library/Animations/Animation.cs +++ b/Switch_Toolbox_Library/Animations/Animation.cs @@ -39,7 +39,7 @@ namespace Switch_Toolbox.Library.Animations public bool IsBaked { get; set; } public float Frame = 0; - public int FrameCount = 0; + public int FrameCount { get; set; } = 0; public List Bones = new List(); diff --git a/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj b/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj index 07f15794..71c88ef9 100644 --- a/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj @@ -729,6 +729,7 @@ + diff --git a/Switch_Toolbox_Library/Util/ImageUtilty.cs b/Switch_Toolbox_Library/Util/ImageUtilty.cs new file mode 100644 index 00000000..91989bf3 --- /dev/null +++ b/Switch_Toolbox_Library/Util/ImageUtilty.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Switch_Toolbox.Library +{ + public class ImageUtilty + { + public static byte[] ConvertBgraToRgba(byte[] bytes) + { + if (bytes == null) + throw new Exception("Data block returned null. Make sure the parameters and image properties are correct!"); + + for (int i = 0; i < bytes.Length; i += 4) + { + var temp = bytes[i]; + bytes[i] = bytes[i + 2]; + bytes[i + 2] = temp; + } + return bytes; + } + } +}