Skip to content

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.

C#
public readonly struct ColorF : IEquatable<ColorF>

Implements

IEquatable<ColorF>

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.

C#
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).

C#
public static readonly ColorF Black

Field Value

ColorF

Transparent

Fully transparent black (0, 0, 0, 0).

C#
public static readonly ColorF Transparent

Field Value

ColorF

White

Opaque white (1, 1, 1, 1).

C#
public static readonly ColorF White

Field Value

ColorF

Properties

A

Opacity, 0 (transparent) to 1 (opaque, the default).

C#
public float A { get; init; }

Property Value

float

B

Blue in linear light.

C#
public float B { get; init; }

Property Value

float

G

Green in linear light.

C#
public float G { get; init; }

Property Value

float

R

Red in linear light, 0..1 for displayable colours.

C#
public float R { get; init; }

Property Value

float

Methods

Deconstruct(out float, out float, out float, out float)

C#
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)

C#
public override bool Equals(object obj)

Parameters

obj object

Returns

bool

Equals(ColorF)

C#
public bool Equals(ColorF other)

Parameters

other ColorF

Returns

bool

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.

C#
public static ColorF FromSrgb(Color color)

Parameters

color Color

Returns

ColorF

GetHashCode()

C#
public override int GetHashCode()

Returns

int

Lerp(ColorF, ColorF, float)

Linear interpolation of every channel; t is clamped to 0..1.

C#
public static ColorF Lerp(ColorF a, ColorF b, float t)

Parameters

a ColorF

b ColorF

t float

Returns

ColorF

LinearToSrgb(float)

The sRGB transfer function: linear light (0..1) to an sRGB-encoded value.

C#
public static float LinearToSrgb(float value)

Parameters

value float

Returns

float

Premultiply()

The colour with its colour channels multiplied by its opacity: (R·A, G·A, B·A, A).

C#
public ColorF Premultiply()

Returns

ColorF

SrgbToLinear(float)

The sRGB transfer function decoded: an sRGB-encoded value (0..1) to linear light.

C#
public static float SrgbToLinear(float value)

Parameters

value float

Returns

float

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.

C#
public Color ToSrgb()

Returns

Color

ToString()

C#
public override string ToString()

Returns

string

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.

C#
public ColorF Unpremultiply()

Returns

ColorF

Operators

operator +(ColorF, ColorF)

Channel-by-channel sum (additive light).

C#
public static ColorF operator +(ColorF a, ColorF b)

Parameters

a ColorF

b ColorF

Returns

ColorF

operator ==(ColorF, ColorF)

C#
public static bool operator ==(ColorF left, ColorF right)

Parameters

left ColorF

right ColorF

Returns

bool

operator !=(ColorF, ColorF)

C#
public static bool operator !=(ColorF left, ColorF right)

Parameters

left ColorF

right ColorF

Returns

bool

operator *(ColorF, float)

Every channel multiplied by factor, opacity included.

C#
public static ColorF operator *(ColorF color, float factor)

Parameters

color ColorF

factor float

Returns

ColorF

operator *(ColorF, ColorF)

Channel-by-channel product (modulation): a tint applied to a colour.

C#
public static ColorF operator *(ColorF a, ColorF b)

Parameters

a ColorF

b ColorF

Returns

ColorF