mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 04:23:09 +00:00
Add support for custom block height log for WTB textures
This commit is contained in:
parent
891e5e0bc3
commit
435fda17f1
8 changed files with 78 additions and 18 deletions
|
@ -56,6 +56,12 @@ namespace FirstPlugin
|
|||
public List<ImageHeader> ImageHeaders = new List<ImageHeader>();
|
||||
public List<PaletteHeader> PaletteHeaders = new List<PaletteHeader>();
|
||||
|
||||
public override void OnAfterAdded()
|
||||
{
|
||||
if (Nodes.Count > 0 && this.TreeView != null)
|
||||
this.TreeView.SelectedNode = Nodes[0];
|
||||
}
|
||||
|
||||
public void Load(System.IO.Stream stream)
|
||||
{
|
||||
Text = FileName;
|
||||
|
|
|
@ -137,8 +137,8 @@ namespace FirstPlugin
|
|||
public uint Height;
|
||||
public uint Depth;
|
||||
public uint unknown4;
|
||||
public uint unknown5;
|
||||
public uint unknown6;
|
||||
public uint textureLayout;
|
||||
public uint textureLayout2;
|
||||
}
|
||||
|
||||
public enum SurfaceType
|
||||
|
@ -322,7 +322,9 @@ namespace FirstPlugin
|
|||
|
||||
Console.WriteLine($" Texture.ImageData " + Texture.ImageData.Length);
|
||||
|
||||
return TegraX1Swizzle.GetImageData(this, Texture.ImageData, ArrayLevel, MipLevel, 1);
|
||||
var BlockHeightLog2 = Texture.Info.textureLayout & 7;
|
||||
|
||||
return TegraX1Swizzle.GetImageData(this, Texture.ImageData, ArrayLevel, MipLevel, BlockHeightLog2, 1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,12 @@ namespace FirstPlugin
|
|||
|
||||
}
|
||||
|
||||
public override void OnAfterAdded()
|
||||
{
|
||||
if (Nodes.Count > 0 && this.TreeView != null)
|
||||
this.TreeView.SelectedNode = Nodes[0];
|
||||
}
|
||||
|
||||
public void Save(System.IO.Stream stream)
|
||||
{
|
||||
SaveFile(new FileWriter(stream, true));
|
||||
|
|
|
@ -494,6 +494,9 @@ namespace Toolbox.Library
|
|||
|
||||
Load(reader);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Load(BinaryDataReader reader)
|
||||
{
|
||||
Text = FileName;
|
||||
|
@ -1338,6 +1341,20 @@ namespace Toolbox.Library
|
|||
editor.LoadImage(this);
|
||||
}
|
||||
|
||||
public override UserControl GetEditor()
|
||||
{
|
||||
ImageEditorBase editor = new ImageEditorBase();
|
||||
editor.Text = Text;
|
||||
editor.Dock = DockStyle.Fill;
|
||||
return editor;
|
||||
}
|
||||
|
||||
public override void FillEditor(UserControl control)
|
||||
{
|
||||
((ImageEditorBase)control).LoadProperties(GenericProperties);
|
||||
((ImageEditorBase)control).LoadImage(this);
|
||||
}
|
||||
|
||||
private void ApplySettings(GenericTextureImporterSettings settings)
|
||||
{
|
||||
//Combine all arrays
|
||||
|
|
|
@ -111,18 +111,8 @@ namespace Toolbox.Library.Forms
|
|||
public void SetEditorForm(IFileFormat fileFormat)
|
||||
{
|
||||
if (fileFormat == null)
|
||||
AddControl(new STUserControl() { Dock = DockStyle.Fill });
|
||||
|
||||
if (fileFormat is TreeNodeFile)
|
||||
{
|
||||
var Editor = ((TreeNodeFile)fileFormat).GetEditor();
|
||||
var ActiveEditor = GetActiveEditor(Editor.GetType());
|
||||
if (ActiveEditor == null)
|
||||
AddControl(Editor);
|
||||
else
|
||||
Editor = ActiveEditor;
|
||||
|
||||
((TreeNodeFile)fileFormat).FillEditor(Editor);
|
||||
AddControl(new STUserControl() { Dock = DockStyle.Fill });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -142,8 +132,36 @@ namespace Toolbox.Library.Forms
|
|||
Editor = ActiveEditor;
|
||||
|
||||
methodFill.Invoke(fileFormat, new object[1] { Editor });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (fileFormat is STGenericTexture)
|
||||
{
|
||||
var Editor = ((STGenericTexture)fileFormat).GetEditor();
|
||||
var ActiveEditor = GetActiveEditor(Editor.GetType());
|
||||
if (ActiveEditor == null)
|
||||
AddControl(Editor);
|
||||
else
|
||||
Editor = ActiveEditor;
|
||||
|
||||
((STGenericTexture)fileFormat).FillEditor(Editor);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileFormat is TreeNodeFile)
|
||||
{
|
||||
var Editor = ((TreeNodeFile)fileFormat).GetEditor();
|
||||
var ActiveEditor = GetActiveEditor(Editor.GetType());
|
||||
if (ActiveEditor == null)
|
||||
AddControl(Editor);
|
||||
else
|
||||
Editor = ActiveEditor;
|
||||
|
||||
((TreeNodeFile)fileFormat).FillEditor(Editor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTextView()
|
||||
|
|
|
@ -77,6 +77,10 @@ namespace Toolbox.Library
|
|||
AlphaChannel = STChannelType.Alpha;
|
||||
}
|
||||
|
||||
public virtual UserControl GetEditor() { return new UserControl(); }
|
||||
|
||||
public virtual void FillEditor(UserControl control) { }
|
||||
|
||||
//A class that configs how the image should output (on display, and on export/replace)
|
||||
public ImageParameters Parameters = new ImageParameters();
|
||||
|
||||
|
|
|
@ -69,14 +69,21 @@ namespace Toolbox.Library
|
|||
}
|
||||
|
||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, int target = 1, bool LinearTileMode = false)
|
||||
{
|
||||
uint blkHeight = STGenericTexture.GetBlockHeight(texture.Format);
|
||||
uint blkDepth = STGenericTexture.GetBlockDepth(texture.Format);
|
||||
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(texture.Height, blkHeight));
|
||||
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
|
||||
return GetImageData(texture, ImageData, ArrayLevel, MipLevel, BlockHeightLog2, target, LinearTileMode);
|
||||
}
|
||||
|
||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, uint BlockHeightLog2, int target = 1, bool LinearTileMode = false)
|
||||
{
|
||||
uint bpp = STGenericTexture.GetBytesPerPixel(texture.Format);
|
||||
uint blkWidth = STGenericTexture.GetBlockWidth(texture.Format);
|
||||
uint blkHeight = STGenericTexture.GetBlockHeight(texture.Format);
|
||||
uint blkDepth = STGenericTexture.GetBlockDepth(texture.Format);
|
||||
|
||||
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(texture.Height, blkHeight));
|
||||
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
|
||||
|
||||
uint Pitch = 0;
|
||||
uint DataAlignment = 512;
|
||||
|
|
|
@ -351,12 +351,12 @@ namespace Toolbox
|
|||
editor.Text = CheckTabDupes(((IFileFormat)file).FileName);
|
||||
editor.Show();
|
||||
|
||||
((ObjectEditor)editor).SelectFirstNode();
|
||||
|
||||
if (file is TreeNodeFile)
|
||||
{
|
||||
((TreeNodeFile)file).OnAfterAdded();
|
||||
}
|
||||
|
||||
((ObjectEditor)editor).SelectFirstNode();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue