Switch-Toolbox/Switch_FileFormatsMain/FileFormats/BCRES/Wrappers/TXOBWrapper.cs

126 lines
3.5 KiB
C#
Raw Normal View History

2019-05-09 18:49:11 +00:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Switch_Toolbox.Library;
using BcresLibrary;
using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
public class TXOBWrapper : STGenericTexture
{
2019-05-09 20:05:17 +00:00
internal BCRES BcresParent;
internal Texture Texture;
2019-05-09 18:49:11 +00:00
public TXOBWrapper()
{
ImageKey = "Texture";
SelectedImageKey = "Texture";
}
2019-05-09 20:14:42 +00:00
public TXOBWrapper(Texture texture, BCRES bcres) : base()
{
BcresParent = bcres;
LoadTexture(texture);
}
2019-05-09 18:49:11 +00:00
public override TEX_FORMAT[] SupportedFormats
{
get
{
return new TEX_FORMAT[]
{
};
}
}
2019-05-09 20:05:17 +00:00
public override void OnClick(TreeView treeview) {
2019-05-09 18:49:11 +00:00
UpdateEditor();
}
private void UpdateEditor()
{
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.Instance.GetActiveContent(typeof(ImageEditorBase));
if (editor == null)
{
editor = new ImageEditorBase();
editor.Dock = DockStyle.Fill;
LibraryGUI.Instance.LoadEditor(editor);
}
Properties prop = new Properties();
prop.Width = Width;
prop.Height = Height;
prop.Depth = Depth;
prop.MipCount = MipCount;
prop.ArrayCount = ArrayCount;
prop.ImageSize = (uint)Texture.Images[0].ImageData.Length;
prop.Format = Format;
editor.Text = Text;
editor.LoadProperties(prop);
editor.LoadImage(this);
}
public void LoadTexture(Texture texture)
{
ImageKey = "Texture";
SelectedImageKey = "Texture";
Texture = texture;
Text = texture.Name;
//Cube maps will use multiple images
//Break at the end as we only need the first part for generic things
foreach (var image in texture.Images)
{
Width = image.Width;
Height = image.Height;
MipCount = image.MipCount;
Format = CTR_3DS.ConvertPICAToGenericFormat(
(CTR_3DS.PICASurfaceFormat)image.ImageFormat);
break;
}
}
public override bool CanEdit { get; set; } = false;
public override void SetImageData(Bitmap bitmap, int ArrayLevel)
{
throw new NotImplementedException();
}
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
{
PlatformSwizzle = PlatformSwizzle.Platform_3DS;
2019-05-09 19:41:41 +00:00
uint Offset = 0;
for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
{
2019-05-09 19:43:20 +00:00
uint _width = Math.Max(1, Width >> mipLevel);
uint _height = Math.Max(1, Height >> mipLevel);
2019-05-09 19:41:41 +00:00
uint Increment = Texture.Images[ArrayLevel].BitsPerPixel / 8;
if (Increment == 0) Increment = 1;
2019-05-09 19:43:20 +00:00
uint size = (_width * _height) * Increment;
2019-05-09 19:41:41 +00:00
if (mipLevel == MipLevel)
return Utils.SubArray(Texture.Images[ArrayLevel].ImageData, Offset, size);
Offset += size;
}
2019-05-09 18:49:11 +00:00
return Texture.Images[ArrayLevel].ImageData;
}
}
}