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.ThrowIfGreaterThan(layer, Layers, nameof(layer));
var bIdx = 0;
var pIdx = layer * Bpp * Width * Height;
var length = Width * Height * 4;
var bytes = new byte[length];
for (var y = 0; y < Height; y++)
var pixelCount = Width * Height;
var pIdx = layer * Bpp * pixelCount;
var bytes = new byte[pixelCount * 4];
for (var i = 0; i < pixelCount; i += 4, pIdx += Bpp)
{
for (var x = 0; x < Width; x++)
switch (Bpp)
{
switch (Bpp)
{
case 1:
var raw1 = Pixels[pIdx];
bytes[bIdx] = raw1;
bytes[bIdx + 1] = raw1;
bytes[bIdx + 2] = raw1;
bytes[bIdx + 3] = 255;
break;
case 2:
var raw2 = Pixels[pIdx] + (Pixels[pIdx + 1] << 8);
bytes[bIdx] = (byte)(255 * (raw2 & 31) / 31.0f);
bytes[bIdx + 1] = (byte)(255 * ((raw2 >> 5) & 31) / 31.0f);
bytes[bIdx + 2] = (byte)(255 * ((raw2 >> 10) & 31) / 31.0f);
bytes[bIdx + 3] = 255;
break;
case 4:
bytes[bIdx] = Pixels[pIdx + 2];
bytes[bIdx + 1] = Pixels[pIdx + 1];
bytes[bIdx + 2] = Pixels[pIdx];
bytes[bIdx + 3] = Pixels[pIdx + 3];
break;
}
bIdx += 4;
pIdx += Bpp;
case 1:
var raw1 = Pixels[pIdx];
bytes[i] = raw1;
bytes[i + 1] = raw1;
bytes[i + 2] = raw1;
bytes[i + 3] = 255;
break;
case 2:
var raw2 = Pixels[pIdx] + (Pixels[pIdx + 1] << 8);
bytes[i] = (byte)(255 * (raw2 & 31) / 31.0f);
bytes[i + 1] = (byte)(255 * ((raw2 >> 5) & 31) / 31.0f);
bytes[i + 2] = (byte)(255 * ((raw2 >> 10) & 31) / 31.0f);
bytes[i + 3] = 255;
break;
case 4:
bytes[i] = Pixels[pIdx + 2];
bytes[i + 1] = Pixels[pIdx + 1];
bytes[i + 2] = Pixels[pIdx];
bytes[i + 3] = Pixels[pIdx + 3];
break;
}
}