From b4fad0b7762cde0d129d381890783abff0a67a3b Mon Sep 17 00:00:00 2001 From: Miepee Date: Fri, 30 Aug 2024 20:37:07 +0200 Subject: [PATCH] Revert "Update UTMT submodule, replace imagesharp with imagemagick.net" This reverts commit 15cc72b3eda99eb44f7658e0defc52dd17cd0cde. --- UndertaleModTool | 2 +- YAMS-LIB/Program.cs | 1 + YAMS-LIB/YAMS-LIB.csproj | 1 + YAMS-LIB/patches/CosmeticRotation.cs | 41 ++++++++++++++-------------- YAMS-LIB/patches/Sprites.cs | 41 ++++++++++++++++------------ 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/UndertaleModTool b/UndertaleModTool index 147a289..43a0c3f 160000 --- a/UndertaleModTool +++ b/UndertaleModTool @@ -1 +1 @@ -Subproject commit 147a289d4729644dcbb367ba97d6429d1b7f094c +Subproject commit 43a0c3fe8a628804f41e452d6cdd35d99401e506 diff --git a/YAMS-LIB/Program.cs b/YAMS-LIB/Program.cs index 67065d8..a22e5db 100644 --- a/YAMS-LIB/Program.cs +++ b/YAMS-LIB/Program.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Reflection; using System.Text.Json; +using SixLabors.ImageSharp.Processing; using UndertaleModLib; using UndertaleModLib.Decompiler; using UndertaleModLib.Models; diff --git a/YAMS-LIB/YAMS-LIB.csproj b/YAMS-LIB/YAMS-LIB.csproj index c41cb62..fd57aca 100644 --- a/YAMS-LIB/YAMS-LIB.csproj +++ b/YAMS-LIB/YAMS-LIB.csproj @@ -16,6 +16,7 @@ + diff --git a/YAMS-LIB/patches/CosmeticRotation.cs b/YAMS-LIB/patches/CosmeticRotation.cs index 7dcb54e..da8edf8 100644 --- a/YAMS-LIB/patches/CosmeticRotation.cs +++ b/YAMS-LIB/patches/CosmeticRotation.cs @@ -1,8 +1,9 @@ -using ImageMagick; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.Processing; using UndertaleModLib; using UndertaleModLib.Decompiler; using UndertaleModLib.Models; -using UndertaleModLib.Util; namespace YAMS_LIB.patches; @@ -252,25 +253,23 @@ public class CosmeticRotation "bgWFilter2", ]; - static void RotateTextureAndSaveToTexturePage(UndertaleEmbeddedTexture texture, List> rectangleRotationTuple) + static void RotateTextureAndSaveToTexturePage(UndertaleEmbeddedTexture texture, List> rectangleRotationTuple) { - using MagickImage texturePage = texture.TextureData.Image.GetMagickImage(); + using Image texturePage = Image.Load(texture.TextureData.TextureBlob); foreach ((var rectangle, var rotation) in rectangleRotationTuple) { - using var mask = new MagickImage(MagickColors.White, texturePage.Width, texturePage.Height); - mask.Draw(new DrawableFillColor(MagickColors.Black), new DrawableRectangle(rectangle.X, rectangle.Y, rectangle.X+rectangle.Width, rectangle.Y+rectangle.Height)); - texturePage.SetWriteMask(mask); - texturePage.Modulate((Percentage)100.0, (Percentage)100.0, (Percentage)((rotation * 100 / 180) + 100)); - texturePage.RemoveWriteMask(); + texturePage.Mutate(im => im.Hue(rotation, rectangle)); } - texture.TextureData.Image = GMImage.FromPng(texturePage.ToByteArray(MagickFormat.Png)); + using MemoryStream ms = new MemoryStream(); + texturePage.Save(ms, PngFormat.Instance); + texture.TextureData.TextureBlob = ms.ToArray(); } public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileContext, SeedObject seedObject) { - var textureDict = new Dictionary>>(); + var textureDict = new Dictionary>>(); // TODO: less copypaste // Hue shift etanks @@ -281,8 +280,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC var texture = textureEntry.Texture; bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList); if (tupleList is null) - tupleList = new List>(); - tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.EtankHUDRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -299,8 +298,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC var texture = textureEntry.Texture; bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList); if (tupleList is null) - tupleList = new List>(); - tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.HealthHUDRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -317,8 +316,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC var texture = bg.Texture; bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList); if (tupleList is null) - tupleList = new List>(); - tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.DNAHUDRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -335,8 +334,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC var texture = bg.Texture; bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList); if (tupleList is null) - tupleList = new List>(); - tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.TilesetRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -353,8 +352,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC var texture = bg.Texture; bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList); if (tupleList is null) - tupleList = new List>(); - tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.BackgroundRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); diff --git a/YAMS-LIB/patches/Sprites.cs b/YAMS-LIB/patches/Sprites.cs index 07887c8..6c1a6b3 100644 --- a/YAMS-LIB/patches/Sprites.cs +++ b/YAMS-LIB/patches/Sprites.cs @@ -1,11 +1,12 @@ using System.Reflection; using System.Text.Json; -using ImageMagick; using NaturalSort.Extension; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.Processing; using UndertaleModLib; using UndertaleModLib.Decompiler; using UndertaleModLib.Models; -using UndertaleModLib.Util; namespace YAMS_LIB.patches; @@ -17,11 +18,13 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC var nameToPageItemDict = new Dictionary(); UndertaleEmbeddedTexture? utTexturePage = new UndertaleEmbeddedTexture(); - using var texturePage = new MagickImage(new FileInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/sprites/texturepage.png")); + using (MemoryStream ms = new MemoryStream()) { + var texturePage = Image.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/sprites/texturepage.png"); utTexturePage.TextureWidth = texturePage.Width; utTexturePage.TextureHeight = texturePage.Height; - utTexturePage.TextureData = new UndertaleEmbeddedTexture.TexData { Image = GMImage.FromPng(texturePage.ToByteArray(MagickFormat.Png)) }; + texturePage.Save(ms, PngFormat.Instance); + utTexturePage.TextureData = new UndertaleEmbeddedTexture.TexData { TextureBlob = ms.ToArray() }; } gmData.EmbeddedTextures.Add(utTexturePage); @@ -41,25 +44,27 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC // Replace A4 doors { UndertaleTexturePageItem? a4DoorTex = gmData.TexturePageItems[nameToPageItemDict["newA4Doors"]]; - using var a4DoorImage = a4DoorTex.TexturePage.TextureData.Image.GetMagickImage(); + Image a4DoorImage = Image.Load(a4DoorTex.TexturePage.TextureData.TextureBlob); + a4DoorImage.Mutate(i => i.Crop(new Rectangle(a4DoorTex.SourceX, a4DoorTex.SourceY, a4DoorTex.SourceWidth, a4DoorTex.SourceHeight))); + UndertaleTexturePageItem? a4Tex = gmData.Backgrounds.ByName("tlArea4Tech").Texture; + Image a4PageImage = Image.Load(a4Tex.TexturePage.TextureData.TextureBlob); + a4PageImage.Mutate(i => i.DrawImage(a4DoorImage, new Point(a4Tex.SourceX + 104, a4Tex.SourceY), 1)); + using (MemoryStream ms = new MemoryStream()) { - a4DoorImage.Crop(new MagickGeometry(a4DoorTex.SourceX, a4DoorTex.SourceY, a4DoorTex.SourceWidth, a4DoorTex.SourceHeight)); - a4DoorImage.RePage(); - UndertaleTexturePageItem? a4Tex = gmData.Backgrounds.ByName("tlArea4Tech").Texture; - using var a4PageImage = a4Tex.TexturePage.TextureData.Image.GetMagickImage(); - a4PageImage.Composite(a4DoorImage, a4Tex.SourceX + 104, a4Tex.SourceY, CompositeOperator.Over); - a4Tex.TexturePage.TextureData.Image = GMImage.FromPng(a4PageImage.ToByteArray(MagickFormat.Png)); + a4PageImage.Save(ms, PngFormat.Instance); + a4Tex.TexturePage.TextureData.TextureBlob = ms.ToArray(); } UndertaleTexturePageItem? a4door2Tex = gmData.TexturePageItems[nameToPageItemDict["newA4Doors2"]]; - using var a4Door2Image = a4door2Tex.TexturePage.TextureData.Image.GetMagickImage(); + Image a4Door2Image = Image.Load(a4door2Tex.TexturePage.TextureData.TextureBlob); + a4Door2Image.Mutate(i => i.Crop(new Rectangle(a4door2Tex.SourceX, a4door2Tex.SourceY, a4door2Tex.SourceWidth, a4door2Tex.SourceHeight))); + UndertaleTexturePageItem? a4Tex2 = gmData.Backgrounds.ByName("tlArea4Tech2").Texture; + Image a4Page2Image = Image.Load(a4Tex2.TexturePage.TextureData.TextureBlob); + a4Page2Image.Mutate(i => i.DrawImage(a4Door2Image, new Point(a4Tex2.SourceX + 104, a4Tex2.SourceY), 1)); + using (MemoryStream ms = new MemoryStream()) { - a4Door2Image.Crop(new MagickGeometry(a4door2Tex.SourceX, a4door2Tex.SourceY, a4door2Tex.SourceWidth, a4door2Tex.SourceHeight)); - a4Door2Image.RePage(); - UndertaleTexturePageItem? a4Tex2 = gmData.Backgrounds.ByName("tlArea4Tech2").Texture; - using var a4Page2Image = a4Tex2.TexturePage.TextureData.Image.GetMagickImage(); - a4Page2Image.Composite(a4Door2Image, a4Tex2.SourceX + 104, a4Tex2.SourceY, CompositeOperator.Over); - a4Tex2.TexturePage.TextureData.Image = GMImage.FromPng(a4Page2Image.ToByteArray(MagickFormat.Png)); + a4Page2Image.Save(ms, PngFormat.Instance); + a4Tex2.TexturePage.TextureData.TextureBlob = ms.ToArray(); } }