Added image pixel type option

This commit is contained in:
Tretiner 2024-07-28 00:00:10 +05:00
parent 1e533e6420
commit bde95026ce
2 changed files with 16 additions and 4 deletions

View File

@ -0,0 +1,7 @@
namespace SoulstormReplayReader.Core.Enums;
public enum PixelType : byte
{
Argb8888,
Bgra8888
}

View File

@ -44,6 +44,8 @@ public sealed class SsReplayReader(Stream stream) : IDisposable
/// </summary>
public bool CheckForBugs { get; set; }
public PixelType ImagePixelType { get; set; } = PixelType.Bgra8888;
public ReplayDescriptor Descriptor { get; } = new();
public ReplayModel Replay { get; set; }
public int CurrentTick { get; set; }
@ -357,12 +359,15 @@ public sealed class SsReplayReader(Stream stream) : IDisposable
for (var y = height - 1; y >= 0; y--)
{
var line = playerImage.GetLine(y);
_binaryReader.ReadBytes(MemoryMarshal.AsBytes(line));
var uintLine = MemoryMarshal.Cast<ReplayColor, uint>(line);
for (var x = 0; x < uintLine.Length; x++)
uintLine[x] = BinaryPrimitives.ReverseEndianness(uintLine[x]);
if (ImagePixelType == PixelType.Argb8888)
{
var uintLine = MemoryMarshal.Cast<ReplayColor, uint>(line);
for (var x = 0; x < uintLine.Length; x++)
uintLine[x] = BinaryPrimitives.ReverseEndianness(uintLine[x]);
}
}
}
}