From 15cc72b3eda99eb44f7658e0defc52dd17cd0cde Mon Sep 17 00:00:00 2001 From: Miepee Date: Fri, 23 Aug 2024 15:12:39 +0200 Subject: [PATCH] Update UTMT submodule, replace imagesharp with imagemagick.net --- 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, 40 insertions(+), 46 deletions(-) diff --git a/UndertaleModTool b/UndertaleModTool index 43a0c3f..147a289 160000 --- a/UndertaleModTool +++ b/UndertaleModTool @@ -1 +1 @@ -Subproject commit 43a0c3fe8a628804f41e452d6cdd35d99401e506 +Subproject commit 147a289d4729644dcbb367ba97d6429d1b7f094c diff --git a/YAMS-LIB/Program.cs b/YAMS-LIB/Program.cs index 668ce3e..7d10e01 100644 --- a/YAMS-LIB/Program.cs +++ b/YAMS-LIB/Program.cs @@ -2,7 +2,6 @@ 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 c3ef388..8903ea8 100644 --- a/YAMS-LIB/YAMS-LIB.csproj +++ b/YAMS-LIB/YAMS-LIB.csproj @@ -16,7 +16,6 @@ - diff --git a/YAMS-LIB/patches/CosmeticRotation.cs b/YAMS-LIB/patches/CosmeticRotation.cs index da8edf8..7dcb54e 100644 --- a/YAMS-LIB/patches/CosmeticRotation.cs +++ b/YAMS-LIB/patches/CosmeticRotation.cs @@ -1,9 +1,8 @@ -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Formats.Png; -using SixLabors.ImageSharp.Processing; +using ImageMagick; using UndertaleModLib; using UndertaleModLib.Decompiler; using UndertaleModLib.Models; +using UndertaleModLib.Util; namespace YAMS_LIB.patches; @@ -253,23 +252,25 @@ public class CosmeticRotation "bgWFilter2", ]; - static void RotateTextureAndSaveToTexturePage(UndertaleEmbeddedTexture texture, List> rectangleRotationTuple) + static void RotateTextureAndSaveToTexturePage(UndertaleEmbeddedTexture texture, List> rectangleRotationTuple) { - using Image texturePage = Image.Load(texture.TextureData.TextureBlob); + using MagickImage texturePage = texture.TextureData.Image.GetMagickImage(); foreach ((var rectangle, var rotation) in rectangleRotationTuple) { - texturePage.Mutate(im => im.Hue(rotation, rectangle)); + 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(); } - using MemoryStream ms = new MemoryStream(); - texturePage.Save(ms, PngFormat.Instance); - texture.TextureData.TextureBlob = ms.ToArray(); + texture.TextureData.Image = GMImage.FromPng(texturePage.ToByteArray(MagickFormat.Png)); } public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileContext, SeedObject seedObject) { - var textureDict = new Dictionary>>(); + var textureDict = new Dictionary>>(); // TODO: less copypaste // Hue shift etanks @@ -280,8 +281,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 Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.EtankHUDRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -298,8 +299,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 Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.HealthHUDRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -316,8 +317,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 Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.DNAHUDRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -334,8 +335,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 Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), seedObject.Cosmetics.TilesetRotation)); if (!wasInDict) textureDict.Add(texture.TexturePage, null); @@ -352,8 +353,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 Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight), + tupleList = new List>(); + tupleList.Add(new Tuple(new MagickGeometry(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 6c1a6b3..07887c8 100644 --- a/YAMS-LIB/patches/Sprites.cs +++ b/YAMS-LIB/patches/Sprites.cs @@ -1,12 +1,11 @@ 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; @@ -18,13 +17,11 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC var nameToPageItemDict = new Dictionary(); UndertaleEmbeddedTexture? utTexturePage = new UndertaleEmbeddedTexture(); - using (MemoryStream ms = new MemoryStream()) + using var texturePage = new MagickImage(new FileInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/sprites/texturepage.png")); { - var texturePage = Image.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/sprites/texturepage.png"); utTexturePage.TextureWidth = texturePage.Width; utTexturePage.TextureHeight = texturePage.Height; - texturePage.Save(ms, PngFormat.Instance); - utTexturePage.TextureData = new UndertaleEmbeddedTexture.TexData { TextureBlob = ms.ToArray() }; + utTexturePage.TextureData = new UndertaleEmbeddedTexture.TexData { Image = GMImage.FromPng(texturePage.ToByteArray(MagickFormat.Png)) }; } gmData.EmbeddedTextures.Add(utTexturePage); @@ -44,27 +41,25 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC // Replace A4 doors { UndertaleTexturePageItem? a4DoorTex = gmData.TexturePageItems[nameToPageItemDict["newA4Doors"]]; - 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()) + using var a4DoorImage = a4DoorTex.TexturePage.TextureData.Image.GetMagickImage(); { - a4PageImage.Save(ms, PngFormat.Instance); - a4Tex.TexturePage.TextureData.TextureBlob = ms.ToArray(); + 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)); } UndertaleTexturePageItem? a4door2Tex = gmData.TexturePageItems[nameToPageItemDict["newA4Doors2"]]; - 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()) + using var a4Door2Image = a4door2Tex.TexturePage.TextureData.Image.GetMagickImage(); { - a4Page2Image.Save(ms, PngFormat.Instance); - a4Tex2.TexturePage.TextureData.TextureBlob = ms.ToArray(); + 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)); } }