Skip to main content

Oklch struct

Namespace: Arlecchino.Rendering.Colors · Assembly: Arlecchino.Core

A color as lightness, chroma and hue, in the space where those three come apart. Moving the lightness of an Rgb here leaves the color recognizably itself, which moving it in HSL does not.

public readonly struct Oklch : IEquatable<Oklch>

Implements IEquatable<T><Oklch>

Constructors

MemberSummary
Oklch(double, double, double)A color as lightness, chroma and hue, in the space where those three come apart. Moving the lightness of an Rgb here leaves the color recognizably itself, which moving it in HSL does not.

Properties

MemberSummary
ChromaHow far the color stands from gray, up to about 0.4 within sRGB.
FitsScreenWhether sRGB holds this color, or whether showing it would want channels it has not got.
HueDegrees around the wheel.
LightnessPerceived lightness, 0 for black and 1 for white.

Methods

MemberSummary
Deconstruct(out double, out double, out double)
Of(Rgb)Splits a color into the three.
ToRgb()The color as the screen shows it, trimmed to sRGB on the way.
ToString()Writes the three parts out, which is what a log of a derived palette holds.
Trimmed()The same lightness and hue with the chroma cut back to the most sRGB holds. Cutting the chroma keeps the hue, where clamping the channels turns a color that is too vivid into a different color.

Constructors in detail

Oklch(double, double, double)

public Oklch(double Lightness, double Chroma, double Hue);

A color as lightness, chroma and hue, in the space where those three come apart. Moving the lightness of an Rgb here leaves the color recognizably itself, which moving it in HSL does not.

Parameters

NameTypeDescription
LightnessdoublePerceived lightness, 0 for black and 1 for white.
ChromadoubleHow far the color stands from gray, up to about 0.4 within sRGB.
HuedoubleDegrees around the wheel.

Properties in detail

Chroma

public double Chroma { get; init; }

How far the color stands from gray, up to about 0.4 within sRGB.

Type double

FitsScreen

public bool FitsScreen { get; }

Whether sRGB holds this color, or whether showing it would want channels it has not got.

Type bool

Hue

public double Hue { get; init; }

Degrees around the wheel.

Type double

Lightness

public double Lightness { get; init; }

Perceived lightness, 0 for black and 1 for white.

Type double

Methods in detail

Deconstruct(out double, out double, out double)

public void Deconstruct(out double Lightness, out double Chroma, out double Hue);

Parameters

NameTypeDescription
Lightnessdouble
Chromadouble
Huedouble

Of(Rgb)

public static Oklch Of(Rgb color);

Splits a color into the three.

Parameters

NameTypeDescription
colorRgbThe color to read.

Returns Oklch — The same color, said the other way round.

ToRgb()

public Rgb ToRgb();

The color as the screen shows it, trimmed to sRGB on the way.

Returns Rgb — The 24-bit color.

ToString()

public override string ToString();

Writes the three parts out, which is what a log of a derived palette holds.

Returns string — Lightness, chroma and hue.

Trimmed()

public Oklch Trimmed();

The same lightness and hue with the chroma cut back to the most sRGB holds. Cutting the chroma keeps the hue, where clamping the channels turns a color that is too vivid into a different color.

Returns Oklch — A color the screen can show.