diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index daffe59a4..b6cf25e6d 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -43,9 +43,9 @@ - - - + + + diff --git a/src/Artemis.Core/RGB.NET/SKTexture.cs b/src/Artemis.Core/RGB.NET/SKTexture.cs index 70d6a1f84..9664318ae 100644 --- a/src/Artemis.Core/RGB.NET/SKTexture.cs +++ b/src/Artemis.Core/RGB.NET/SKTexture.cs @@ -1,6 +1,6 @@ using System; -using System.Buffers; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Artemis.Core.SkiaSharp; using RGB.NET.Core; @@ -56,31 +56,12 @@ public sealed class SKTexture : PixelTexture, IDisposable if (skRectI.Width <= 0 || skRectI.Height <= 0) return Color.Transparent; - int bufferSize = skRectI.Width * skRectI.Height * DATA_PER_PIXEL; - if (bufferSize <= STACK_ALLOC_LIMIT) - { - Span buffer = stackalloc byte[bufferSize]; - GetRegionData(skRectI.Left, skRectI.Top, skRectI.Width, skRectI.Height, buffer); + SamplerInfo samplerInfo = new(skRectI.Left, skRectI.Top, skRectI.Width, skRectI.Height, Stride, DataPerPixel, Data); - Span pixelData = stackalloc byte[DATA_PER_PIXEL]; - Sampler.Sample(new SamplerInfo(skRectI.Width, skRectI.Height, buffer), pixelData); + Span pixelData = stackalloc byte[DATA_PER_PIXEL]; + Sampler.Sample(samplerInfo, pixelData); - return GetColor(pixelData); - } - else - { - byte[] rent = ArrayPool.Shared.Rent(bufferSize); - - Span buffer = new Span(rent).Slice(0, bufferSize); - GetRegionData(skRectI.Left, skRectI.Top, skRectI.Width, skRectI.Height, buffer); - - Span pixelData = stackalloc byte[DATA_PER_PIXEL]; - Sampler.Sample(new SamplerInfo(skRectI.Width, skRectI.Height, buffer), pixelData); - - ArrayPool.Shared.Return(rent); - - return GetColor(pixelData); - } + return GetColor(pixelData); } private void ReleaseUnmanagedResources() @@ -106,7 +87,6 @@ public sealed class SKTexture : PixelTexture, IDisposable #region Constants - private const int STACK_ALLOC_LIMIT = 1024; private const int DATA_PER_PIXEL = 4; #endregion @@ -128,10 +108,8 @@ public sealed class SKTexture : PixelTexture, IDisposable } /// - protected override Color GetColor(in ReadOnlySpan pixel) - { - return new Color(pixel[2], pixel[1], pixel[0]); - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected override Color GetColor(in ReadOnlySpan pixel) => new(pixel[2], pixel[1], pixel[0]); /// public override Color this[in Rectangle rectangle] => Color.Transparent; diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 4c5b91ce8..c297f372f 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 75fa4b7da..309fe78fa 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -33,8 +33,8 @@ - - + +