From 1b23607d92c93fb81bd20d1e3d1e89a90b336c70 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Apr 2023 18:30:34 +0200 Subject: [PATCH 1/2] Meta: Updated RGB.NET to 2.0.0-prerelease.53 and adapted the SKTexture to the changes --- src/Artemis.Core/Artemis.Core.csproj | 6 ++-- src/Artemis.Core/RGB.NET/SKTexture.cs | 29 +++---------------- .../Artemis.UI.Shared.csproj | 2 +- src/Artemis.UI/Artemis.UI.csproj | 4 +-- 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index f4e4d85f2..01eb20f15 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..3cb3a249c 100644 --- a/src/Artemis.Core/RGB.NET/SKTexture.cs +++ b/src/Artemis.Core/RGB.NET/SKTexture.cs @@ -1,5 +1,4 @@ using System; -using System.Buffers; using System.Collections.Generic; using System.Runtime.InteropServices; using Artemis.Core.SkiaSharp; @@ -56,31 +55,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 +86,6 @@ public sealed class SKTexture : PixelTexture, IDisposable #region Constants - private const int STACK_ALLOC_LIMIT = 1024; private const int DATA_PER_PIXEL = 4; #endregion diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 35cf357d8..dc4d46327 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 4e5a5ccde..54ed78f98 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -33,8 +33,8 @@ - - + + From 8cb551ebc2f0a423ded271fabdaade9be401e231 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Apr 2023 18:33:01 +0200 Subject: [PATCH 2/2] Added aggresive inline to GetColor in SKTexture --- src/Artemis.Core/RGB.NET/SKTexture.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Artemis.Core/RGB.NET/SKTexture.cs b/src/Artemis.Core/RGB.NET/SKTexture.cs index 3cb3a249c..9664318ae 100644 --- a/src/Artemis.Core/RGB.NET/SKTexture.cs +++ b/src/Artemis.Core/RGB.NET/SKTexture.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Artemis.Core.SkiaSharp; using RGB.NET.Core; @@ -107,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;