diff --git a/SS14.MapServer.Tests/ImageProcessingServiceTests.cs b/SS14.MapServer.Tests/ImageProcessingServiceTests.cs index 0fe2849..5f77d48 100644 --- a/SS14.MapServer.Tests/ImageProcessingServiceTests.cs +++ b/SS14.MapServer.Tests/ImageProcessingServiceTests.cs @@ -6,7 +6,7 @@ namespace SS14.MapServer.Tests; public class ImageProcessingServiceTests { - private const string ResourcePath = "resources/tiling_test_source.png"; + private const string ResourcePath = "resources/saltern.webp"; private const string OutputPath = "test"; private ImageProcessingService? _processingService; @@ -33,11 +33,11 @@ public void Setup() [Test] public async Task ImageTilingTest() { - var tiles = await _processingService!.TileImage(Guid.NewGuid(), 0, _sourcePath!, _targetPath!, 512); + var tiles = await _processingService!.TileImage(Guid.NewGuid(), 0, _sourcePath!, _targetPath!, 256); Assert.Multiple(() => { - Assert.That(tiles, Has.Count.EqualTo(60)); + Assert.That(tiles, Has.Count.EqualTo(198)); Assert.That(File.Exists(tiles[0].Path), Is.True); }); } diff --git a/SS14.MapServer.Tests/resources/saltern.webp b/SS14.MapServer.Tests/resources/saltern.webp new file mode 100644 index 0000000..ccc3b00 Binary files /dev/null and b/SS14.MapServer.Tests/resources/saltern.webp differ diff --git a/SS14.MapServer/MapProcessing/Services/ImageProcessingService.cs b/SS14.MapServer/MapProcessing/Services/ImageProcessingService.cs index 8e21f8d..e778b1a 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 = bounds.Height / tileSize; - var widthSteps = 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); @@ -46,6 +46,8 @@ public async Task> TileImage(Guid mapGuid, int gridId, string sourceP for (var x = 0; x < widthSteps; x++) { var rectangle = new Rectangle(tileSize * x, tileSize * y, tileSize, tileSize); + rectangle.Intersect(bounds); + var tile = image.Clone(img => img.Crop(rectangle)); var preview = tile.Clone(img => img.Pixelate(8)); diff --git a/SS14.MapServer/SS14.MapServer.csproj b/SS14.MapServer/SS14.MapServer.csproj index 763f9fd..419375f 100644 --- a/SS14.MapServer/SS14.MapServer.csproj +++ b/SS14.MapServer/SS14.MapServer.csproj @@ -5,7 +5,7 @@ enable enable Linux - 1.1.6 + 1.1.7