diff --git a/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs b/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs index 2375f9c6..0049df27 100644 --- a/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs +++ b/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs @@ -51,12 +51,6 @@ namespace FirstPlugin STToolStripItem EndiannessToolstrip; - STToolStripItem OdysseyPresetToolstrip; - STToolStripItem Mk8PresetToolstrip; - STToolStripItem Splatoon2PresetToolstrip; - STToolStripItem SplatoonPresetToolstrip; - STToolStripItem OtherPresetToolstrip; - public KCL() { ContextMenuStrip = new STContextMenuStrip(); diff --git a/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs b/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs index fb6405a8..93deb8df 100644 --- a/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs +++ b/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs @@ -38,7 +38,7 @@ namespace FirstPlugin } } - public BFLIMFormat ConvertFormatGenericToBflim(TEX_FORMAT Format) + public static BFLIMFormat ConvertFormatGenericToBflim(TEX_FORMAT Format) { switch (Format) { @@ -86,6 +86,7 @@ namespace FirstPlugin get { List types = new List(); + types.Add(typeof(MenuExt)); 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) { OpenFileDialog ofd = new OpenFileDialog(); - ofd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" + - "Microsoft DDS |*.dds|" + - "Portable Network Graphics |*.png|" + - "Joint Photographic Experts Group |*.jpg|" + - "Bitmap Image |*.bmp|" + - "Tagged Image File Format |*.tiff|" + - "All files(*.*)|*.*"; - + ofd.Filter = FileFilters.GTX; ofd.Multiselect = false; 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) { @@ -483,6 +530,14 @@ namespace FirstPlugin public ushort blockount; public ushort padding; + public Header() + { + ByteOrderMark = 65279; + HeaderSize = 20; + blockount = 1; + Version = 33685504; + } + public void Read(FileReader reader) { reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; @@ -517,6 +572,14 @@ namespace FirstPlugin public BFLIMFormat BflimFormat; public byte Flags; + + public Image() + { + Alignment = 8192; + Flags = 0xC4; + Size = 16; + } + public GX2.GX2TileMode TileMode { get diff --git a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs index cddd78df..633670ea 100644 --- a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs +++ b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXImporterSettings.cs @@ -21,7 +21,7 @@ namespace FirstPlugin public uint arrayLength = 1; public List DataBlockOutput = new List(); public List DecompressedData = new List(); - public GX2.GX2SurfaceFormat Format; + public GX2.GX2SurfaceFormat Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(Runtime.PreferredTexFormat); public bool GenerateMipmaps; public bool IsSRGB; public uint tileMode = 4; @@ -64,8 +64,6 @@ namespace FirstPlugin TexName = Path.GetFileNameWithoutExtension(FileName); - Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(Runtime.PreferredTexFormat); - GenerateMipmaps = true; LoadImage(new Bitmap(Image)); } @@ -76,7 +74,6 @@ namespace FirstPlugin TexName = Path.GetFileNameWithoutExtension(FileName); - Format = (GX2.GX2SurfaceFormat)FTEX.ConvertToGx2Format(Runtime.PreferredTexFormat); GenerateMipmaps = true; //If a texture is .tga, we need to convert it diff --git a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs index 950ff0dd..bf028655 100644 --- a/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs +++ b/Switch_FileFormatsMain/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs @@ -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); if (result == DialogResult.Cancel) + { tileModeCB.SelectedIndex = 0; + SelectedTexSettings.tileMode = 0; + } } } diff --git a/Switch_Toolbox_Library/Generics/GenericTexture.cs b/Switch_Toolbox_Library/Generics/GenericTexture.cs index 5fb71610..b7f94a3a 100644 --- a/Switch_Toolbox_Library/Generics/GenericTexture.cs +++ b/Switch_Toolbox_Library/Generics/GenericTexture.cs @@ -344,8 +344,10 @@ namespace Switch_Toolbox.Library throw new Exception("Data is null!"); 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); + Image.RotateFlip(RotateFlipType.RotateNoneFlipY); //It's upside down for some reason so flip it + return Image; } switch (Format)