diff --git a/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.ConsoleTools.csproj b/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.ConsoleTools.csproj index 23df604..aded455 100644 --- a/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.ConsoleTools.csproj +++ b/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.ConsoleTools.csproj @@ -3,6 +3,16 @@ Exe netcoreapp2.1 + + + + + + + + + + diff --git a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs new file mode 100644 index 0000000..1041cfb --- /dev/null +++ b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Text; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; + +namespace RecrownedAthenaeum.ConsoleTools.TextureAtlasTools +{ + + internal class TexturePacker + { + private enum SupportedExtensions + { + jpeg, jpg, png + } + + Rectangle theoreticalSpace; + Node masterNode; + + internal TexturePacker(string rootDirectoryPath) + { + string[] paths = Directory.GetFiles(rootDirectoryPath); + + int minArea = 0; + int currentPoTArea = 2 * 2; + List theoreticalImages = new List(); + for (int pathID = 0; pathID < paths.Length; pathID++) + { + SupportedExtensions extension; + if (Enum.TryParse(Path.GetExtension(paths[pathID]), out extension)) + { + using (FileStream stream = new FileStream(paths[pathID], FileMode.Open)) + { + IImageInfo info = Image.Identify(stream); + TheoreticalImage ti = new TheoreticalImage(info.Width, info.Height, paths[pathID]); + theoreticalImages.Add(ti); + + minArea += ti.Area; + while (currentPoTArea < minArea) + { + currentPoTArea *= 2 * 2; + } + } + } + } + + } + + private class Node + { + public Node parent; + public Node[] branches = new Node[2]; + public readonly TheoreticalImage theoreticalImage; + + public Node(TheoreticalImage theoreticalImage) + { + this.theoreticalImage = theoreticalImage; + } + } + + private struct TheoreticalImage + { + public Rectangle bounds; + public readonly string path; + public int Area { get { return bounds.Width * bounds.Height; } } + + public TheoreticalImage(int width, int height, string path) + { + bounds = new Rectangle(); + bounds.Width = width; + bounds.Height = height; + this.path = path; + } + } + } +}