11using System ;
2- using System . Buffers ;
32using System . Collections . Generic ;
3+ using System . Runtime . CompilerServices ;
44using System . Runtime . InteropServices ;
55using Artemis . Core . SkiaSharp ;
66using RGB . NET . Core ;
@@ -56,31 +56,12 @@ internal Color GetColorAtRenderTarget(in RenderTarget renderTarget)
5656 if ( skRectI . Width <= 0 || skRectI . Height <= 0 )
5757 return Color . Transparent ;
5858
59- int bufferSize = skRectI . Width * skRectI . Height * DATA_PER_PIXEL ;
60- if ( bufferSize <= STACK_ALLOC_LIMIT )
61- {
62- Span < byte > buffer = stackalloc byte [ bufferSize ] ;
63- GetRegionData ( skRectI . Left , skRectI . Top , skRectI . Width , skRectI . Height , buffer ) ;
64-
65- Span < byte > pixelData = stackalloc byte [ DATA_PER_PIXEL ] ;
66- Sampler . Sample ( new SamplerInfo < byte > ( skRectI . Width , skRectI . Height , buffer ) , pixelData ) ;
67-
68- return GetColor ( pixelData ) ;
69- }
70- else
71- {
72- byte [ ] rent = ArrayPool < byte > . Shared . Rent ( bufferSize ) ;
59+ SamplerInfo < byte > samplerInfo = new ( skRectI . Left , skRectI . Top , skRectI . Width , skRectI . Height , Stride , DataPerPixel , Data ) ;
7360
74- Span < byte > buffer = new Span < byte > ( rent ) . Slice ( 0 , bufferSize ) ;
75- GetRegionData ( skRectI . Left , skRectI . Top , skRectI . Width , skRectI . Height , buffer ) ;
61+ Span < byte > pixelData = stackalloc byte [ DATA_PER_PIXEL ] ;
62+ Sampler . Sample ( samplerInfo , pixelData ) ;
7663
77- Span < byte > pixelData = stackalloc byte [ DATA_PER_PIXEL ] ;
78- Sampler . Sample ( new SamplerInfo < byte > ( skRectI . Width , skRectI . Height , buffer ) , pixelData ) ;
79-
80- ArrayPool < byte > . Shared . Return ( rent ) ;
81-
82- return GetColor ( pixelData ) ;
83- }
64+ return GetColor ( pixelData ) ;
8465 }
8566
8667 private void ReleaseUnmanagedResources ( )
@@ -106,7 +87,6 @@ public void Dispose()
10687
10788 #region Constants
10889
109- private const int STACK_ALLOC_LIMIT = 1024 ;
11090 private const int DATA_PER_PIXEL = 4 ;
11191
11292 #endregion
@@ -128,10 +108,8 @@ internal void CopyPixelData()
128108 }
129109
130110 /// <inheritdoc />
131- protected override Color GetColor ( in ReadOnlySpan < byte > pixel )
132- {
133- return new Color ( pixel [ 2 ] , pixel [ 1 ] , pixel [ 0 ] ) ;
134- }
111+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
112+ protected override Color GetColor ( in ReadOnlySpan < byte > pixel ) => new ( pixel [ 2 ] , pixel [ 1 ] , pixel [ 0 ] ) ;
135113
136114 /// <inheritdoc />
137115 public override Color this [ in Rectangle rectangle ] => Color . Transparent ;
0 commit comments