diff --git a/project/code/LGS/Database/Chunks/WorldRep.cs b/project/code/LGS/Database/Chunks/WorldRep.cs index 32ec6d2..7f22d81 100644 --- a/project/code/LGS/Database/Chunks/WorldRep.cs +++ b/project/code/LGS/Database/Chunks/WorldRep.cs @@ -151,20 +151,18 @@ public class WorldRep : IChunk public readonly byte[] AsBytesRgba(int layer) { - if (layer >= Layers) - { - throw new ArgumentOutOfRangeException(nameof(layer)); - } + ArgumentOutOfRangeException.ThrowIfLessThan(layer, 0, nameof(layer)); + ArgumentOutOfRangeException.ThrowIfGreaterThan(layer, Layers, nameof(layer)); + + var bIdx = 0; + var pIdx = layer * Bpp * Width * Height; var length = Width * Height * 4; - var layerOffset = layer * Bpp * Width * Height; var bytes = new byte[length]; for (var y = 0; y < Height; y++) { for (var x = 0; x < Width; x++) { - var bIdx = x * 4 + y * 4 * Width; - var pIdx = x * Bpp + y * Bpp * Width + layerOffset; switch (Bpp) { case 1: @@ -188,6 +186,9 @@ public class WorldRep : IChunk bytes[bIdx + 3] = Pixels[pIdx + 3]; break; } + + bIdx += 4; + pIdx += Bpp; } }