From aaeda546e430b88dc62b6f8bb12eddf2b4073400 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 5 Apr 2024 00:34:48 +0200 Subject: [PATCH] PckFileDataExtensions - Add SetTexture --- PCK-Studio/Extensions/PckFileDataExtensions.cs | 11 +++-------- PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs | 4 ++-- PCK-Studio/MainForm.cs | 8 ++++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/PCK-Studio/Extensions/PckFileDataExtensions.cs b/PCK-Studio/Extensions/PckFileDataExtensions.cs index 8b04efc0..2ca8b1a9 100644 --- a/PCK-Studio/Extensions/PckFileDataExtensions.cs +++ b/PCK-Studio/Extensions/PckFileDataExtensions.cs @@ -29,7 +29,7 @@ namespace PckStudio.Extensions throw new Exception("File is not suitable to contain image data."); } return file.Get(ImageDeserializer.DefaultDeserializer); - } + } internal static T Get(this PckFileData file, IPckDeserializer deserializer) { @@ -56,7 +56,7 @@ namespace PckStudio.Extensions } } - internal static void SetData(this PckFileData file, Image image, ImageFormat imageFormat) + internal static void SetTexture(this PckFileData file, Image image) { if (file.Filetype != PckFileType.SkinFile && file.Filetype != PckFileType.CapeFile && @@ -64,12 +64,7 @@ namespace PckStudio.Extensions { throw new Exception("File is not suitable to contain image data."); } - - using (var stream = new MemoryStream()) - { - image.Save(stream, imageFormat); - file.SetData(stream.ToArray()); - } + file.SetData(image, ImageSerializer.DefaultSerializer); } internal static bool IsMipmappedFile(this PckFileData file) diff --git a/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs b/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs index e0f20da2..10dc4771 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs @@ -271,7 +271,7 @@ namespace PckStudio.Popups cape.Filename = $"dlccape{skinId}.png"; skin.AddProperty("CAPEPATH", cape.Filename); } - skin.SetData(skinPictureBox.Image, ImageFormat.Png); + skin.SetTexture(skinPictureBox.Image); DialogResult = DialogResult.OK; Close(); } @@ -288,7 +288,7 @@ namespace PckStudio.Popups if (MessageBox.Show(this, "Create your own custom skin model?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) != DialogResult.Yes) return; - skin.SetData(Resources.classic_template, ImageFormat.Png); + skin.SetTexture(Resources.classic_template); using generateModel generate = new generateModel(skin); diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 7dc60190..7321d4f3 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -508,7 +508,7 @@ namespace PckStudio texture = _img; } - file.SetData(texture, ImageFormat.Png); + file.SetTexture(texture); wasModified = true; BuildMainTreeView(); } @@ -1437,10 +1437,10 @@ namespace PckStudio PckFile infoPCK = new PckFile(3); PckFileData icon = infoPCK.CreateNewFile("icon.png", PckFileType.TextureFile); - icon.SetData(Resources.TexturePackIcon, ImageFormat.Png); + icon.SetTexture(Resources.TexturePackIcon); PckFileData comparison = infoPCK.CreateNewFile("comparison.png", PckFileType.TextureFile); - comparison.SetData(Resources.Comparison, ImageFormat.Png); + comparison.SetTexture(Resources.Comparison); PckFileData texturepackInfo = pack.CreateNewFile($"{res}/{res}Info.pck", PckFileType.TexturePackInfoFile); texturepackInfo.AddProperty("PACKID", "0"); @@ -2047,7 +2047,7 @@ namespace PckStudio gfx.DrawImage(originalTexture, tileArea); } - MipMappedFile.SetData(mippedTexture, ImageFormat.Png); + MipMappedFile.SetTexture(mippedTexture); currentPCK.InsertFile(currentPCK.IndexOfFile(file) + i - 1, MipMappedFile); }