Skip to content

Commit

Permalink
Merge pull request #25 from juliangiebel/2024.06.05-release-v1.1.8
Browse files Browse the repository at this point in the history
2024.06.05 release v1.1.8
- Fixes tiles stretching at the edges of the map
  • Loading branch information
juliangiebel authored Oct 9, 2024
2 parents 1e1364f + af945d3 commit f5d3794
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions SS14.MapServer.Tests/ImageProcessingServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using SixLabors.ImageSharp;
using SS14.MapServer.Helpers;
using SS14.MapServer.MapProcessing.Services;
using SS14.MapServer.Services;
Expand Down Expand Up @@ -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));
});
}
}
14 changes: 12 additions & 2 deletions SS14.MapServer/MapProcessing/Services/ImageProcessingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public async Task<List<Tile>> 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<Tile>();
var extension = Path.GetExtension(sourcePath);
Expand All @@ -49,6 +49,16 @@ public async Task<List<Tile>> 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}");
Expand Down
2 changes: 1 addition & 1 deletion SS14.MapServer/SS14.MapServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>1.1.7</Version>
<Version>1.1.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit f5d3794

Please sign in to comment.