ArgbBuffer
struct ArgbBuffer
Buffer for ARGB values. Uses the stack for buffer sizes up to 16. Use in a using
statement.
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
namespace Windows.Win32.Graphics.Gdi
{
[CompilerFeatureRequired("RefStructs")]
internal ref struct ArgbBuffer
{
private const int StackSpace = 16;
private unsafe fixed uint _stackBuffer[16];
private BufferScope<ARGB> _bufferScope;
public unsafe ArgbBuffer(int length)
{
fixed (uint* ptr = _stackBuffer) {
void* pointer = ptr;
_bufferScope = new BufferScope<ARGB>(new Span<ARGB>(pointer, 16), length);
}
}
public ArgbBuffer(Span<Color> colors)
{
this = new ArgbBuffer(colors.Length);
for (int i = 0; i < colors.Length; i++) {
_bufferScope[i] = ref colors[i];
}
}
[IsReadOnly]
public ref uint GetPinnableReference()
{
return ref Unsafe.As<ARGB, uint>(ref _bufferScope.GetPinnableReference());
}
[IsReadOnly]
[NullableContext(1)]
public Color[] ToColorArray(int length)
{
return ARGB.ToColorArray(_bufferScope[Range.EndAt(length)]);
}
public void Dispose()
{
_bufferScope.Dispose();
}
}
}