API reference
Struct ColorF
Namespace: MicroEngine
Assembly: MicroEngine.Kernel.dll
Guide: Graphics
A floating-point RGBA colour in linear light, for blending, lighting and anything that adds or scales colours. Channels are not clamped (values above 1 are brighter than white). Color is the 8-bit sRGB form used to store and name colours; convert with FromSrgb and ToSrgb.
public readonly struct ColorF : IEquatable<ColorF>Implements
Remarks
The colour is straight (not premultiplied) unless it came from Premultiply; nothing in the type records which, so keep premultiplied values in variables that say so. Premultiplied colours blend and filter without dark fringes: a red-to-transparent edge sampled halfway over white stays red.
Constructors
ColorF(float, float, float, float)
A floating-point RGBA colour in linear light, for blending, lighting and anything that adds or scales colours. Channels are not clamped (values above 1 are brighter than white). Color is the 8-bit sRGB form used to store and name colours; convert with FromSrgb and ToSrgb.
public ColorF(float R, float G, float B, float A = 1)Parameters
R float
Red in linear light, 0..1 for displayable colours.
G float
Green in linear light.
B float
Blue in linear light.
A float
Opacity, 0 (transparent) to 1 (opaque, the default).
Remarks
The colour is straight (not premultiplied) unless it came from Premultiply; nothing in the type records which, so keep premultiplied values in variables that say so. Premultiplied colours blend and filter without dark fringes: a red-to-transparent edge sampled halfway over white stays red.
Fields
Black
Opaque black (0, 0, 0, 1).
public static readonly ColorF BlackField Value
Transparent
Fully transparent black (0, 0, 0, 0).
public static readonly ColorF TransparentField Value
White
Opaque white (1, 1, 1, 1).
public static readonly ColorF WhiteField Value
Properties
A
Opacity, 0 (transparent) to 1 (opaque, the default).
public float A { get; init; }Property Value
B
Blue in linear light.
public float B { get; init; }Property Value
G
Green in linear light.
public float G { get; init; }Property Value
R
Red in linear light, 0..1 for displayable colours.
public float R { get; init; }Property Value
Methods
Deconstruct(out float, out float, out float, out float)
public void Deconstruct(out float R, out float G, out float B, out float A)Parameters
R float
G float
B float
A float
Equals(object)
public override bool Equals(object obj)Parameters
obj object
Returns
Equals(ColorF)
public bool Equals(ColorF other)Parameters
other ColorF
Returns
FromSrgb(Color)
The linear-light value of an 8-bit sRGB colour: each colour channel through the sRGB transfer function (IEC 61966-2-1), opacity divided by 255.
public static ColorF FromSrgb(Color color)Parameters
color Color
Returns
GetHashCode()
public override int GetHashCode()Returns
Lerp(ColorF, ColorF, float)
Linear interpolation of every channel; t is clamped to 0..1.
public static ColorF Lerp(ColorF a, ColorF b, float t)Parameters
a ColorF
b ColorF
t float
Returns
LinearToSrgb(float)
The sRGB transfer function: linear light (0..1) to an sRGB-encoded value.
public static float LinearToSrgb(float value)Parameters
value float
Returns
Premultiply()
The colour with its colour channels multiplied by its opacity: (R·A, G·A, B·A, A).
public ColorF Premultiply()Returns
SrgbToLinear(float)
The sRGB transfer function decoded: an sRGB-encoded value (0..1) to linear light.
public static float SrgbToLinear(float value)Parameters
value float
Returns
ToSrgb()
The nearest 8-bit sRGB colour: each channel clamped to 0..1, encoded with the sRGB transfer function and rounded.
FromSrgb(c).ToSrgb() returns c for every 8-bit colour.
public Color ToSrgb()Returns
ToString()
public override string ToString()Returns
Unpremultiply()
The straight colour of a premultiplied one: colour channels divided by opacity. A fully transparent colour has no colour left to recover and gives Transparent.
public ColorF Unpremultiply()Returns
Operators
operator +(ColorF, ColorF)
Channel-by-channel sum (additive light).
public static ColorF operator +(ColorF a, ColorF b)Parameters
a ColorF
b ColorF
Returns
operator ==(ColorF, ColorF)
public static bool operator ==(ColorF left, ColorF right)Parameters
left ColorF
right ColorF
Returns
operator !=(ColorF, ColorF)
public static bool operator !=(ColorF left, ColorF right)Parameters
left ColorF
right ColorF
Returns
operator *(ColorF, float)
Every channel multiplied by factor, opacity included.
public static ColorF operator *(ColorF color, float factor)Parameters
color ColorF
factor float
Returns
operator *(ColorF, ColorF)
Channel-by-channel product (modulation): a tint applied to a colour.
public static ColorF operator *(ColorF a, ColorF b)Parameters
a ColorF
b ColorF