1
1
using System ;
2
- using System . Buffers ;
3
2
using System . Collections . Generic ;
3
+ using System . Runtime . CompilerServices ;
4
4
using System . Runtime . InteropServices ;
5
5
using Artemis . Core . SkiaSharp ;
6
6
using RGB . NET . Core ;
@@ -56,31 +56,12 @@ internal Color GetColorAtRenderTarget(in RenderTarget renderTarget)
56
56
if ( skRectI . Width <= 0 || skRectI . Height <= 0 )
57
57
return Color . Transparent ;
58
58
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 ) ;
73
60
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 ) ;
76
63
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 ) ;
84
65
}
85
66
86
67
private void ReleaseUnmanagedResources ( )
@@ -106,7 +87,6 @@ public void Dispose()
106
87
107
88
#region Constants
108
89
109
- private const int STACK_ALLOC_LIMIT = 1024 ;
110
90
private const int DATA_PER_PIXEL = 4 ;
111
91
112
92
#endregion
@@ -128,10 +108,8 @@ internal void CopyPixelData()
128
108
}
129
109
130
110
/// <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 ] ) ;
135
113
136
114
/// <inheritdoc />
137
115
public override Color this [ in Rectangle rectangle ] => Color . Transparent ;
0 commit comments