Add bflim creation from image
This commit is contained in:
parent
781bd585b3
commit
df9ace9e0e
@ -51,12 +51,6 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
STToolStripItem EndiannessToolstrip;
|
STToolStripItem EndiannessToolstrip;
|
||||||
|
|
||||||
STToolStripItem OdysseyPresetToolstrip;
|
|
||||||
STToolStripItem Mk8PresetToolstrip;
|
|
||||||
STToolStripItem Splatoon2PresetToolstrip;
|
|
||||||
STToolStripItem SplatoonPresetToolstrip;
|
|
||||||
STToolStripItem OtherPresetToolstrip;
|
|
||||||
|
|
||||||
public KCL()
|
public KCL()
|
||||||
{
|
{
|
||||||
ContextMenuStrip = new STContextMenuStrip();
|
ContextMenuStrip = new STContextMenuStrip();
|
||||||
|
@ -38,7 +38,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BFLIMFormat ConvertFormatGenericToBflim(TEX_FORMAT Format)
|
public static BFLIMFormat ConvertFormatGenericToBflim(TEX_FORMAT Format)
|
||||||
{
|
{
|
||||||
switch (Format)
|
switch (Format)
|
||||||
{
|
{
|
||||||
@ -86,6 +86,7 @@ namespace FirstPlugin
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
List<Type> types = new List<Type>();
|
List<Type> types = new List<Type>();
|
||||||
|
types.Add(typeof(MenuExt));
|
||||||
return types.ToArray();
|
return types.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,17 +138,63 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MenuExt : IFileMenuExtension
|
||||||
|
{
|
||||||
|
public STToolStripItem[] NewFileMenuExtensions => null;
|
||||||
|
public STToolStripItem[] NewFromFileMenuExtensions => newFileExt;
|
||||||
|
public STToolStripItem[] ToolsMenuExtensions => null;
|
||||||
|
public STToolStripItem[] TitleBarExtensions => null;
|
||||||
|
public STToolStripItem[] CompressionMenuExtensions => null;
|
||||||
|
public STToolStripItem[] ExperimentalMenuExtensions => null;
|
||||||
|
public STToolStripItem[] EditMenuExtensions => null;
|
||||||
|
public ToolStripButton[] IconButtonMenuExtensions => null;
|
||||||
|
|
||||||
|
STToolStripItem[] newFileExt = new STToolStripItem[1];
|
||||||
|
|
||||||
|
public MenuExt()
|
||||||
|
{
|
||||||
|
newFileExt[0] = new STToolStripItem("BFLIM From Image", CreateNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateNew(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
BFLIM bflim = new BFLIM();
|
||||||
|
bflim.CanSave = true;
|
||||||
|
bflim.IFileInfo = new IFileInfo();
|
||||||
|
bflim.header = new Header();
|
||||||
|
|
||||||
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
|
ofd.Multiselect = false;
|
||||||
|
ofd.Filter = FileFilters.GTX;
|
||||||
|
if (ofd.ShowDialog() != DialogResult.OK) return;
|
||||||
|
|
||||||
|
FTEX ftex = new FTEX();
|
||||||
|
ftex.ReplaceTexture(ofd.FileName, 1, bflim.SupportedFormats, true, true, false, TEX_FORMAT.BC3_UNORM_SRGB);
|
||||||
|
if (ftex.texture != null)
|
||||||
|
{
|
||||||
|
bflim.Text = ftex.texture.Name;
|
||||||
|
bflim.image = new Image();
|
||||||
|
bflim.image.Swizzle = (byte)ftex.texture.Swizzle;
|
||||||
|
bflim.image.BflimFormat = BFLIM.ConvertFormatGenericToBflim(ftex.Format);
|
||||||
|
bflim.image.Height = (ushort)ftex.texture.Height;
|
||||||
|
bflim.image.Width = (ushort)ftex.texture.Width;
|
||||||
|
|
||||||
|
bflim.Format = BFLIM.GetFormat(bflim.image.BflimFormat);
|
||||||
|
bflim.Width = bflim.image.Width;
|
||||||
|
bflim.Height = bflim.image.Height;
|
||||||
|
|
||||||
|
bflim.ImageData = ftex.texture.Data;
|
||||||
|
LibraryGUI.Instance.CreateMdiWindow(bflim.OpenForm());
|
||||||
|
|
||||||
|
bflim.UpdateForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Replace(object sender, EventArgs args)
|
private void Replace(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
OpenFileDialog ofd = new OpenFileDialog();
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
ofd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
|
ofd.Filter = FileFilters.GTX;
|
||||||
"Microsoft DDS |*.dds|" +
|
|
||||||
"Portable Network Graphics |*.png|" +
|
|
||||||
"Joint Photographic Experts Group |*.jpg|" +
|
|
||||||
"Bitmap Image |*.bmp|" +
|
|
||||||
"Tagged Image File Format |*.tiff|" +
|
|
||||||
"All files(*.*)|*.*";
|
|
||||||
|
|
||||||
ofd.Multiselect = false;
|
ofd.Multiselect = false;
|
||||||
if (ofd.ShowDialog() == DialogResult.OK)
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
@ -301,7 +348,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TEX_FORMAT GetFormat(BFLIMFormat format)
|
public static TEX_FORMAT GetFormat(BFLIMFormat format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
@ -483,6 +530,14 @@ namespace FirstPlugin
|
|||||||
public ushort blockount;
|
public ushort blockount;
|
||||||
public ushort padding;
|
public ushort padding;
|
||||||
|
|
||||||
|
public Header()
|
||||||
|
{
|
||||||
|
ByteOrderMark = 65279;
|
||||||
|
HeaderSize = 20;
|
||||||
|
blockount = 1;
|
||||||
|
Version = 33685504;
|
||||||
|
}
|
||||||
|
|
||||||
public void Read(FileReader reader)
|
public void Read(FileReader reader)
|
||||||
{
|
{
|
||||||
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
||||||
@ -517,6 +572,14 @@ namespace FirstPlugin
|
|||||||
public BFLIMFormat BflimFormat;
|
public BFLIMFormat BflimFormat;
|
||||||
public byte Flags;
|
public byte Flags;
|
||||||
|
|
||||||
|
|
||||||
|
public Image()
|
||||||
|
{
|
||||||
|
Alignment = 8192;
|
||||||
|
Flags = 0xC4;
|
||||||
|
Size = 16;
|
||||||
|
}
|
||||||
|
|
||||||
public GX2.GX2TileMode TileMode
|
public GX2.GX2TileMode TileMode
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -21,7 +21,7 @@ namespace FirstPlugin
|
|||||||
public uint arrayLength = 1;
|
public uint arrayLength = 1;
|
||||||
public List<byte[]> DataBlockOutput = new List<byte[]>();
|
public List<byte[]> DataBlockOutput = new List<byte[]>();
|
||||||
public List<byte[]> DecompressedData = new List<byte[]>();
|
public List<byte[]> DecompressedData = new List<byte[]>();
|
||||||
public GX2.GX2SurfaceFormat Format;
|
public GX2.GX2SurfaceFormat Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(Runtime.PreferredTexFormat);
|
||||||
public bool GenerateMipmaps;
|
public bool GenerateMipmaps;
|
||||||
public bool IsSRGB;
|
public bool IsSRGB;
|
||||||
public uint tileMode = 4;
|
public uint tileMode = 4;
|
||||||
@ -64,8 +64,6 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
TexName = Path.GetFileNameWithoutExtension(FileName);
|
TexName = Path.GetFileNameWithoutExtension(FileName);
|
||||||
|
|
||||||
Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(Runtime.PreferredTexFormat);
|
|
||||||
|
|
||||||
GenerateMipmaps = true;
|
GenerateMipmaps = true;
|
||||||
LoadImage(new Bitmap(Image));
|
LoadImage(new Bitmap(Image));
|
||||||
}
|
}
|
||||||
@ -76,7 +74,6 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
TexName = Path.GetFileNameWithoutExtension(FileName);
|
TexName = Path.GetFileNameWithoutExtension(FileName);
|
||||||
|
|
||||||
Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(Runtime.PreferredTexFormat);
|
|
||||||
GenerateMipmaps = true;
|
GenerateMipmaps = true;
|
||||||
|
|
||||||
//If a texture is .tga, we need to convert it
|
//If a texture is .tga, we need to convert it
|
||||||
|
@ -189,7 +189,10 @@ namespace FirstPlugin
|
|||||||
{
|
{
|
||||||
var result = MessageBox.Show("Warning! Only change the tile mode unless you know what you are doing!", "Texture Importer", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
|
var result = MessageBox.Show("Warning! Only change the tile mode unless you know what you are doing!", "Texture Importer", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
|
||||||
if (result == DialogResult.Cancel)
|
if (result == DialogResult.Cancel)
|
||||||
|
{
|
||||||
tileModeCB.SelectedIndex = 0;
|
tileModeCB.SelectedIndex = 0;
|
||||||
|
SelectedTexSettings.tileMode = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,8 +344,10 @@ namespace Switch_Toolbox.Library
|
|||||||
throw new Exception("Data is null!");
|
throw new Exception("Data is null!");
|
||||||
|
|
||||||
if (PlatformSwizzle == PlatformSwizzle.Platform_3DS && !IsCompressed(Format)) {
|
if (PlatformSwizzle == PlatformSwizzle.Platform_3DS && !IsCompressed(Format)) {
|
||||||
return BitmapExtension.GetBitmap(ConvertBgraToRgba(CTR_3DS.DecodeBlock(data, (int)width, (int)height, Format)),
|
var Image = BitmapExtension.GetBitmap(ConvertBgraToRgba(CTR_3DS.DecodeBlock(data, (int)width, (int)height, Format)),
|
||||||
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||||
|
Image.RotateFlip(RotateFlipType.RotateNoneFlipY); //It's upside down for some reason so flip it
|
||||||
|
return Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Format)
|
switch (Format)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user