Switch to .net method for endian swap

This commit is contained in:
Infi
2024-05-03 19:37:39 +02:00
parent 2e1e54b395
commit 8709c35ff1
2 changed files with 8 additions and 8 deletions
+4
View File
@@ -92,6 +92,7 @@ internal class MessageManager : IAsyncDisposable
while (!token.IsCancellationRequested) while (!token.IsCancellationRequested)
{ {
if (Pending.TryDequeue(out var pendingMessage)) if (Pending.TryDequeue(out var pendingMessage))
{
try try
{ {
ProcessMessage(pendingMessage); ProcessMessage(pendingMessage);
@@ -100,8 +101,11 @@ internal class MessageManager : IAsyncDisposable
{ {
Plugin.Log.Error(ex, "Error processing pending message"); Plugin.Log.Error(ex, "Error processing pending message");
} }
}
else else
{
Thread.Sleep(1); Thread.Sleep(1);
}
} }
} }
+4 -8
View File
@@ -1,3 +1,4 @@
using System.Buffers.Binary;
using System.Numerics; using System.Numerics;
namespace ChatTwo.Util; namespace ChatTwo.Util;
@@ -11,10 +12,7 @@ internal static class ColourUtil {
return (r, g, b, a); return (r, g, b, a);
} }
internal static uint RgbaToAbgr(uint rgba) { internal static uint RgbaToAbgr(uint rgba) => BinaryPrimitives.ReverseEndianness(rgba);
var tmp = ((rgba << 8) & 0xFF00FF00) | ((rgba >> 8) & 0xFF00FF);
return (tmp << 16) | (tmp >> 16);
}
internal static Vector3 RgbaToVector3(uint rgba) { internal static Vector3 RgbaToVector3(uint rgba) {
var (r, g, b, _) = RgbaToComponents(rgba); var (r, g, b, _) = RgbaToComponents(rgba);
@@ -45,8 +43,6 @@ internal static class ColourUtil {
return x; return x;
} }
internal static uint ComponentsToRgba(byte red, byte green, byte blue, byte alpha = 0xFF) => alpha internal static uint ComponentsToRgba(byte red, byte green, byte blue, byte alpha = 0xFF)
| (uint) (red << 24) => alpha | (uint) (red << 24) | (uint) (green << 16) | (uint) (blue << 8);
| (uint) (green << 16)
| (uint) (blue << 8);
} }