From 6eaf51d450d346345836e541d3da3a9730424455 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 18 Oct 2020 15:22:18 +0100 Subject: [PATCH] CursorManager avoids use of BitConverter. Avoid allocating a small temp array via BitConverter.GetBytes, and instead use bitwise ops to isolate the components of the color. --- OpenRA.Game/Graphics/CursorManager.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Graphics/CursorManager.cs b/OpenRA.Game/Graphics/CursorManager.cs index db922b0388..60ceb1e2d1 100644 --- a/OpenRA.Game/Graphics/CursorManager.cs +++ b/OpenRA.Game/Graphics/CursorManager.cs @@ -236,15 +236,14 @@ namespace OpenRA.Graphics { for (var i = 0; i < width; i++) { - var bytes = BitConverter.GetBytes(palette[frame.Data[j * width + i]]); - var c = palette[frame.Data[j * width + i]]; + var rgba = palette[frame.Data[j * width + i]]; var k = 4 * (j * width + i); // Convert RGBA to BGRA - data[k] = bytes[2]; - data[k + 1] = bytes[1]; - data[k + 2] = bytes[0]; - data[k + 3] = bytes[3]; + data[k] = (byte)(rgba >> 16); + data[k + 1] = (byte)(rgba >> 8); + data[k + 2] = (byte)(rgba >> 0); + data[k + 3] = (byte)(rgba >> 24); } }