From 5b475fa30dc37451cc7aefb1201c327faf6609b5 Mon Sep 17 00:00:00 2001 From: Saphire Date: Sun, 6 Oct 2024 13:35:02 +0600 Subject: [PATCH 1/2] Fix edge tiles not being proper size --- .../ImageProcessingServiceTests.cs | 4 ++++ .../Services/ImageProcessingService.cs | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/SS14.MapServer.Tests/ImageProcessingServiceTests.cs b/SS14.MapServer.Tests/ImageProcessingServiceTests.cs index 5f77d48..86634b4 100644 --- a/SS14.MapServer.Tests/ImageProcessingServiceTests.cs +++ b/SS14.MapServer.Tests/ImageProcessingServiceTests.cs @@ -1,3 +1,4 @@ +using SixLabors.ImageSharp; using SS14.MapServer.Helpers; using SS14.MapServer.MapProcessing.Services; using SS14.MapServer.Services; @@ -39,6 +40,9 @@ public async Task ImageTilingTest() { Assert.That(tiles, Has.Count.EqualTo(198)); Assert.That(File.Exists(tiles[0].Path), Is.True); + // Also check that the edge tiles are properly sized + Assert.That(Image.Load(tiles.First(t => t.Y == 10).Path).Height, Is.EqualTo(256)); + Assert.That(Image.Load(tiles.First(t => t.X == 17).Path).Width, Is.EqualTo(256)); }); } } diff --git a/SS14.MapServer/MapProcessing/Services/ImageProcessingService.cs b/SS14.MapServer/MapProcessing/Services/ImageProcessingService.cs index e778b1a..f76b157 100644 --- a/SS14.MapServer/MapProcessing/Services/ImageProcessingService.cs +++ b/SS14.MapServer/MapProcessing/Services/ImageProcessingService.cs @@ -24,8 +24,8 @@ public async Task> TileImage(Guid mapGuid, int gridId, string sourceP using var image = await Image.LoadAsync(file); var bounds = image.Bounds; - var heightSteps = Math.Ceiling((double)bounds.Height / tileSize); - var widthSteps = Math.Ceiling((double)bounds.Width / tileSize); + var heightSteps = Math.Ceiling((double) bounds.Height / tileSize); + var widthSteps = Math.Ceiling((double) bounds.Width / tileSize); var tiles = new List(); var extension = Path.GetExtension(sourcePath); @@ -49,6 +49,16 @@ public async Task> TileImage(Guid mapGuid, int gridId, string sourceP rectangle.Intersect(bounds); var tile = image.Clone(img => img.Crop(rectangle)); + // Make sure to pad the edge tiles to full size + if (x == widthSteps - 1 || y == heightSteps - 1) + tile.Mutate(img => img.Resize(new ResizeOptions + { + Size = new Size(tileSize, tileSize), + Mode = ResizeMode.Pad, + Sampler = KnownResamplers.NearestNeighbor, + PadColor = default, + Position = AnchorPositionMode.TopLeft + })); var preview = tile.Clone(img => img.Pixelate(8)); var path = Path.Combine(targetPath, $"tile_{Guid.NewGuid()}{extension}"); From af945d368be5c899214b57048236b224942474db Mon Sep 17 00:00:00 2001 From: Julian Giebel Date: Sun, 6 Oct 2024 19:25:22 +0200 Subject: [PATCH 2/2] Bump version --- SS14.MapServer/SS14.MapServer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SS14.MapServer/SS14.MapServer.csproj b/SS14.MapServer/SS14.MapServer.csproj index 0cf0b47..0006a54 100644 --- a/SS14.MapServer/SS14.MapServer.csproj +++ b/SS14.MapServer/SS14.MapServer.csproj @@ -5,7 +5,7 @@ enable enable Linux - 1.1.7 + 1.1.8