ARGB
struct ARGB
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Windows.Win32.Graphics.Gdi
{
[StructLayout(LayoutKind.Explicit)]
internal readonly struct ARGB
{
[FieldOffset(0)]
public readonly byte B;
[FieldOffset(1)]
public readonly byte G;
[FieldOffset(2)]
public readonly byte R;
[FieldOffset(3)]
public readonly byte A;
[FieldOffset(0)]
public readonly uint Value;
public ARGB(byte a, byte r, byte g, byte b)
{
Unsafe.SkipInit(out this);
A = a;
R = r;
G = g;
B = b;
}
public ARGB(uint value)
{
Unsafe.SkipInit(out this);
Value = value;
}
public static implicit operator ARGB([In] [IsReadOnly] ref Color color)
{
return new ARGB((uint)color.ToArgb());
}
public static implicit operator ARGB(uint color)
{
return new ARGB(color);
}
public static implicit operator Color(ARGB argb)
{
return Color.FromArgb((int)argb.Value);
}
public static implicit operator uint(ARGB argb)
{
return argb.Value;
}
[return: Nullable(1)]
public static Color[] ToColorArray([global::System.Runtime.CompilerServices.ParamCollection] [ScopedRef] ReadOnlySpan<ARGB> argbColors)
{
Color[] array = new Color[argbColors.Length];
for (int i = 0; i < argbColors.Length; i++) {
array[i] = argbColors[i];
}
return array;
}
[return: Nullable(1)]
public static Color[] ToColorArray([global::System.Runtime.CompilerServices.ParamCollection] [ScopedRef] ReadOnlySpan<uint> argbColors)
{
return ToColorArray(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<uint, ARGB>(ref MemoryMarshal.GetReference(argbColors)), argbColors.Length));
}
}
}