Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024.06.05 release v1.1.8 #25

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading