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,41 +154,33 @@ 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:
{ var raw1 = Pixels[pIdx];
case 1: bytes[i] = raw1;
var raw1 = Pixels[pIdx]; bytes[i + 1] = raw1;
bytes[bIdx] = raw1; bytes[i + 2] = raw1;
bytes[bIdx + 1] = raw1; bytes[i + 3] = 255;
bytes[bIdx + 2] = raw1; break;
bytes[bIdx + 3] = 255; case 2:
break; var raw2 = Pixels[pIdx] + (Pixels[pIdx + 1] << 8);
case 2: bytes[i] = (byte)(255 * (raw2 & 31) / 31.0f);
var raw2 = Pixels[pIdx] + (Pixels[pIdx + 1] << 8); bytes[i + 1] = (byte)(255 * ((raw2 >> 5) & 31) / 31.0f);
bytes[bIdx] = (byte)(255 * (raw2 & 31) / 31.0f); bytes[i + 2] = (byte)(255 * ((raw2 >> 10) & 31) / 31.0f);
bytes[bIdx + 1] = (byte)(255 * ((raw2 >> 5) & 31) / 31.0f); bytes[i + 3] = 255;
bytes[bIdx + 2] = (byte)(255 * ((raw2 >> 10) & 31) / 31.0f); break;
bytes[bIdx + 3] = 255; case 4:
break; bytes[i] = Pixels[pIdx + 2];
case 4: bytes[i + 1] = Pixels[pIdx + 1];
bytes[bIdx] = Pixels[pIdx + 2]; bytes[i + 2] = Pixels[pIdx];
bytes[bIdx + 1] = Pixels[pIdx + 1]; bytes[i + 3] = Pixels[pIdx + 3];
bytes[bIdx + 2] = Pixels[pIdx]; break;
bytes[bIdx + 3] = Pixels[pIdx + 3];
break;
}
bIdx += 4;
pIdx += Bpp;
} }
} }