More lightmap asbytes cleanup

This commit is contained in:
Jarrod Doyle 2024-08-29 16:58:20 +01:00
parent 5b53d03ae6
commit c0666a5404
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 25 additions and 33 deletions

View File

@ -154,42 +154,34 @@ public class WorldRep : IChunk
ArgumentOutOfRangeException.ThrowIfLessThan(layer, 0, nameof(layer)); ArgumentOutOfRangeException.ThrowIfLessThan(layer, 0, nameof(layer));
ArgumentOutOfRangeException.ThrowIfGreaterThan(layer, Layers, nameof(layer)); ArgumentOutOfRangeException.ThrowIfGreaterThan(layer, Layers, nameof(layer));
var bIdx = 0; var pixelCount = Width * Height;
var pIdx = layer * Bpp * Width * Height; var pIdx = layer * Bpp * pixelCount;
var bytes = new byte[pixelCount * 4];
var length = Width * Height * 4; for (var i = 0; i < pixelCount; i += 4, pIdx += Bpp)
var bytes = new byte[length];
for (var y = 0; y < Height; y++)
{
for (var x = 0; x < Width; x++)
{ {
switch (Bpp) switch (Bpp)
{ {
case 1: case 1:
var raw1 = Pixels[pIdx]; var raw1 = Pixels[pIdx];
bytes[bIdx] = raw1; bytes[i] = raw1;
bytes[bIdx + 1] = raw1; bytes[i + 1] = raw1;
bytes[bIdx + 2] = raw1; bytes[i + 2] = raw1;
bytes[bIdx + 3] = 255; bytes[i + 3] = 255;
break; break;
case 2: case 2:
var raw2 = Pixels[pIdx] + (Pixels[pIdx + 1] << 8); var raw2 = Pixels[pIdx] + (Pixels[pIdx + 1] << 8);
bytes[bIdx] = (byte)(255 * (raw2 & 31) / 31.0f); bytes[i] = (byte)(255 * (raw2 & 31) / 31.0f);
bytes[bIdx + 1] = (byte)(255 * ((raw2 >> 5) & 31) / 31.0f); bytes[i + 1] = (byte)(255 * ((raw2 >> 5) & 31) / 31.0f);
bytes[bIdx + 2] = (byte)(255 * ((raw2 >> 10) & 31) / 31.0f); bytes[i + 2] = (byte)(255 * ((raw2 >> 10) & 31) / 31.0f);
bytes[bIdx + 3] = 255; bytes[i + 3] = 255;
break; break;
case 4: case 4:
bytes[bIdx] = Pixels[pIdx + 2]; bytes[i] = Pixels[pIdx + 2];
bytes[bIdx + 1] = Pixels[pIdx + 1]; bytes[i + 1] = Pixels[pIdx + 1];
bytes[bIdx + 2] = Pixels[pIdx]; bytes[i + 2] = Pixels[pIdx];
bytes[bIdx + 3] = Pixels[pIdx + 3]; bytes[i + 3] = Pixels[pIdx + 3];
break; break;
} }
bIdx += 4;
pIdx += Bpp;
}
} }
return bytes; return bytes;