From 93b4d815057648887b8902209d86ae528f2e6f4e Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Mon, 8 Mar 2021 11:15:33 +0100 Subject: [PATCH] Optimize ImageSharp blitting. --- Robust.Client/Utility/ImageSharpExt.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Robust.Client/Utility/ImageSharpExt.cs b/Robust.Client/Utility/ImageSharpExt.cs index 7164139e2..56b67f2ef 100644 --- a/Robust.Client/Utility/ImageSharpExt.cs +++ b/Robust.Client/Utility/ImageSharpExt.cs @@ -42,19 +42,20 @@ namespace Robust.Client.Utility { var dstSpan = destination.GetPixelSpan(); var dstWidth = destination.Width; + var srcHeight = sourceRect.Height; + var srcWidth = sourceRect.Width; var (ox, oy) = destinationOffset; - for (var y = 0; y < sourceRect.Height; y++) + for (var y = 0; y < srcHeight; y++) { var sourceRowOffset = sourceWidth * (y + sourceRect.Top) + sourceRect.Left; var destRowOffset = dstWidth * (y + oy) + ox; - for (var x = 0; x < sourceRect.Width; x++) - { - var pixel = source[x + sourceRowOffset]; - dstSpan[x + destRowOffset] = pixel; - } + var srcRow = source[sourceRowOffset..(sourceRowOffset + srcWidth)]; + var dstRow = dstSpan[destRowOffset..(destRowOffset + srcWidth)]; + + srcRow.CopyTo(dstRow); } }