public readonly struct ColorA colour as four bytes, RGBA: the storage and interchange form. Vertex colours, UI palettes, hex codes, texture texels.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
This type does not declare a colour space, because the bytes on their own do not have one — the same #808080 is a mid grey to a designer and 0.216 linear to a renderer. Every conversion here says which it means: ToColor4 only divides by 255, while ToLinear also decodes sRGB. Guessing is what produces washed out or crushed output that nobody can trace.
Colours typed by a human, and every hex code, are sRGB. Use ToLinear on them, and reach for ToColor4 only for data that was already linear.
Fields and properties (7)
public readonly byte RThe red component.
public readonly byte GThe green component.
public readonly byte BThe blue component.
public readonly byte AThe alpha component.
public static Color BlackOpaque black.
public static Color WhiteOpaque white.
public static Color TransparentFully transparent black — all four bytes zero.
Methods (21)
public Color(byte r, byte g, byte b, byte a)Builds a colour from its components.
public Color(byte r, byte g, byte b)Builds an opaque colour.
public ReadOnlySpan<byte> AsSpan()The components as a span. Valid as long as the colour it came from.
public uint ToRgba()The four bytes packed with red in the least significant byte.
public uint ToArgb()The four bytes packed as 0xAARRGGBB, the order a hex literal reads in.
public static Color FromRgba(uint packed)Unpacks a colour written red in the least significant byte.
public static Color FromArgb(uint packed)Unpacks a colour written 0xAARRGGBB.
public static bool TryParseHex(ReadOnlySpan<char> text, out Color color)Parses #RGB, #RGBA, #RRGGBB or #RRGGBBAA, with or without the leading hash. Alpha defaults to opaque.
public string ToHex(bool includeAlpha = true)Renders the colour as #RRGGBBAA.
public Color4 ToColor4()Divides each byte by 255. A numeric widening only — no colour-space conversion. Right for data that was already linear, wrong for anything a person picked.
public Color4 ToLinear()Treats the bytes as sRGB and decodes them to linear — the conversion a hex code, a colour picker value or a palette entry needs before it reaches a shader.
public static Color FromColor4(Color4 color)Quantises a colour to bytes without any colour-space conversion.
public static Color FromLinear(Color4 linear)Encodes a linear colour as sRGB and quantises it to bytes.
public static bool operator ==(Color left, Color right)Component-wise equality.
public static bool operator !=(Color left, Color right)The negation of op_Equality.
public void Deconstruct(out byte r, out byte g, out byte b, out byte a)Splits the colour into its components.
public bool Equals(Color other)Indicates whether the current object is equal to another object of the same type.
public override bool Equals(object? obj)Indicates whether this instance and a specified object are equal.
public override int GetHashCode()Returns the hash code for this instance.
public override string ToString()Returns the fully qualified type name of this instance.
public string ToString(string? format, IFormatProvider? formatProvider)Formats the value of the current instance using the specified format.
Used by (6)
- ColorTestsVixen.Core.Mathematics.Tests
- NamedColorsVixen.Ui.Styling
- StyleValueParserVixen.Ui.Styling
- TypeRegistrationVixen.Core.Mathematics
- UtilityFamiliesVixen.Ui.Styling.Utilities
- Vixen_Core_Mathematics_ColorSerializerVixen.Core.Mathematics