public static P3Float Read(ReadOnlySpan <byte> span) { return(new P3Float( SpanExt.GetFloat(span), SpanExt.GetFloat(span.Slice(4)), SpanExt.GetFloat(span.Slice(8)))); }
/// <summary> /// Extracts a color from binary span. /// If the span more than 3 bytes, the 4th byte will be interpreted as alpha. /// Will throw an exception if there is not at least 3 bytes. /// </summary> /// <param name="span">Span to read from</param> /// <param name="binaryType">Format to read the color as</param> /// <returns>Bytes converted to a Color object</returns> public static Color ReadColor(this ReadOnlySpan <byte> span, ColorBinaryType binaryType) { switch (binaryType) { case ColorBinaryType.NoAlpha: return(Color.FromArgb( red: span[0], green: span[1], blue: span[2], alpha: 0)); case ColorBinaryType.Alpha: return(Color.FromArgb( red: span[0], green: span[1], blue: span[2], alpha: span[3])); case ColorBinaryType.NoAlphaFloat: return(Color.FromArgb( red: GetColorByte(SpanExt.GetFloat(span.Slice(0, 4))), green: GetColorByte(SpanExt.GetFloat(span.Slice(4, 4))), blue: GetColorByte(SpanExt.GetFloat(span.Slice(8, 4))), alpha: 0)); case ColorBinaryType.AlphaFloat: return(Color.FromArgb( red: GetColorByte(SpanExt.GetFloat(span.Slice(0, 4))), green: GetColorByte(SpanExt.GetFloat(span.Slice(4, 4))), blue: GetColorByte(SpanExt.GetFloat(span.Slice(8, 4))), alpha: GetColorByte(SpanExt.GetFloat(span.Slice(12, 4))))); default: throw new NotImplementedException(); } }