ColourConversions

public static class ColourConversions
Provides static methods for converting one colour space into another. These methods have been implemented based on http://www.easyrgb.com/index.php?X=MATH and do not depend on code in Eto, Rhino, or any other assembly.

Fields

XLimit

#
public const float XLimit = 95.047

YLimit

#
public const float YLimit = 100

ZLimit

#
public const float ZLimit = 108.883

Methods

ApplyAdjective

#
public static Color ApplyAdjective(Color colour, ColourAdjective adjective)
Apply an adjective to a colour.
colour (Color)Colour to modify.
adjective (ColourAdjective)Adjective to apply.
Modified colour.

Cmy_Rgb

#
public static void Cmy_Rgb(double c, double m, double y, out double r, out double g, out double b)
Convert RGB channels into CMY channels.
c (double)
m (double)
y (double)
r (out double)
g (out double)
b (out double)

Cmy_Rgb

#
public static void Cmy_Rgb(float c, float m, float y, out float r, out float g, out float b)
Convert RGB channels into CMY channels.
c (float)
m (float)
y (float)
r (out float)
g (out float)
b (out float)

Cmyk_Rgb

#
public static void Cmyk_Rgb(double c, double m, double y, double k, out double r, out double g, out double b)
Convert CMYK channels into RGB channels.
c (double)
m (double)
y (double)
k (double)
r (out double)
g (out double)
b (out double)

Cmyk_Rgb

#
public static void Cmyk_Rgb(float c, float m, float y, float k, out float r, out float g, out float b)
Convert CMYK channels into RGB channels.
c (float)
m (float)
y (float)
k (float)
r (out float)
g (out float)
b (out float)

Hsl_Rgb

#
public static void Hsl_Rgb(double h, double s, double l, out double r, out double g, out double b)
Convert HSL channels into Standard RGB channels.
h (double)
s (double)
l (double)
r (out double)
g (out double)
b (out double)

Hsl_Rgb

#
public static void Hsl_Rgb(float h, float s, float l, out float r, out float g, out float b)
Convert HSL channels into Standard RGB channels.
h (float)
s (float)
l (float)
r (out float)
g (out float)
b (out float)

Hsp_Rgb

#
public static void Hsp_Rgb(double hue, double sat, double lum, out double r, out double g, out double b)
Convert HSP (perceived luminance) channels into RGB channels.
hue (double)
sat (double)
lum (double)
r (out double)
g (out double)
b (out double)

Hsp_Rgb

#
public static void Hsp_Rgb(float hue, float sat, float lum, out float r, out float g, out float b)
Convert HSP (perceived luminance) channels into RGB channels.
hue (float)
sat (float)
lum (float)
r (out float)
g (out float)
b (out float)

Hsv_Rgb

#
public static void Hsv_Rgb(double hue, double sat, double val, out double r, out double g, out double b)
Convert HSV/B channels into Standard RGB channels.
hue (double)
sat (double)
val (double)
r (out double)
g (out double)
b (out double)

Hsv_Rgb

#
public static void Hsv_Rgb(float hue, float sat, float val, out float r, out float g, out float b)
Convert HSV/B channels into Standard RGB channels.
hue (float)
sat (float)
val (float)
r (out float)
g (out float)
b (out float)

Lab_Xyz

#
public static void Lab_Xyz(double l, double a, double b, out double x, out double y, out double z)
Convert Cie L*a*b* channels into Cie XYZ channels.
l (double)Luminance channel.
a (double)Chroma a channel.
b (double)Chroma b channel.
x (out double)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (out double)Y value, up to 100.000
z (out double)Z value, up to 108.883

Lab_Xyz

#
public static void Lab_Xyz(float l, float a, float b, out float x, out float y, out float z)
Convert Cie L*a*b* channels into Cie XYZ channels.
l (float)Luminance channel.
a (float)Chroma a channel.
b (float)Chroma b channel.
x (out float)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (out float)Y value, up to 100.000
z (out float)Z value, up to 108.883

MapYxyPlanckianLoci

#
public static ColourConversions.PlanckianLocus[] MapYxyPlanckianLoci(RectangleF frame)
Compute the points for key temperatures along the black body curve of the CIE Chromaticity diagram.
frame (RectangleF)Target frame for Yxy graph.
Temperature measure array.

MapYxyPlanckianLocus

#
public static PointF[] MapYxyPlanckianLocus(RectangleF frame)
Compute the points for a degree=3 bezier curve describing the black body curve of the CIE Chromaticity diagram.
frame (RectangleF)Target frame for Yxy graph.
Point array.

MapYxyRgbGamut

#
public static void MapYxyRgbGamut(RectangleF frame, out PointF red, out PointF green, out PointF blue)
Compute the cornerpoints of the sRGB gamut triangle within the CIE Chromaticity diagram.
frame (RectangleF)Target frame for Yxy graph.
red (out PointF)Red corner.
green (out PointF)Green corner.
blue (out PointF)Blue corner.

MapYxySpectralLoci

#
public static ColourConversions.SpectralLocus[] MapYxySpectralLoci(RectangleF frame)
Compute the points for key wavelengths along the spectral curve of the CIE Chromaticity diagram.
frame (RectangleF)Target frame for Yxy graph.
Wavelength measure array.

MapYxySpectralLocus

#
public static PointF[] MapYxySpectralLocus(RectangleF frame)
Compute the points for a degree=3 bezier curve describing the spectral curve of the CIE Chromaticity diagram.
frame (RectangleF)Target frame for Yxy graph.
Point array.

MixColourNames

#
public static Color MixColourNames(Color a, Color b)
Mix two colours using the linguistic parser logic. This method interpolates between the colours inside the Sinusoidal model.
a (Color)First colour.
b (Color)Second colour.
Midway colour.

Oklab_Oklch

#
public static void Oklab_Oklch(double a, double b, out double chroma, out double hue)
Convert Oklab channels into their polar Oklch form.
a (double)Green-red opposition channel.
b (double)Blue-yellow opposition channel.
chroma (out double)Chroma, the distance from the neutral axis.
hue (out double)Hue in degrees, 0 to 360.

Oklab_RgbLinear

#
public static void Oklab_RgbLinear(double L, double a, double b, out double r, out double g, out double bʹ)
Convert Oklab channels into linear RGB channels.
L (double)Perceptual lightness, 0 to 1.
a (double)Green-red opposition channel.
b (double)Blue-yellow opposition channel.
r (out double)Linear red channel.
g (out double)Linear green channel.
bʹ (out double)Linear blue channel.

Oklab_RgbLinear

#
public static void Oklab_RgbLinear(float L, float a, float b, out float r, out float g, out float bʹ)
Convert Oklab channels into linear RGB channels.
L (float)Perceptual lightness, 0 to 1.
a (float)Green-red opposition channel.
b (float)Blue-yellow opposition channel.
r (out float)Linear red channel.
g (out float)Linear green channel.
bʹ (out float)Linear blue channel.

Oklch_Oklab

#
public static void Oklch_Oklab(double chroma, double hue, out double a, out double b)
Convert polar Oklch channels into Oklab channels.
chroma (double)Chroma, the distance from the neutral axis.
hue (double)Hue in degrees.
a (out double)Green-red opposition channel.
b (out double)Blue-yellow opposition channel.

Rgb_Cmy

#
public static void Rgb_Cmy(double r, double g, double b, out double c, out double m, out double y)
Convert RGB channels into CMY channels.
r (double)
g (double)
b (double)
c (out double)
m (out double)
y (out double)

Rgb_Cmy

#
public static void Rgb_Cmy(float r, float g, float b, out float c, out float m, out float y)
Convert RGB channels into CMY channels.
r (float)
g (float)
b (float)
c (out float)
m (out float)
y (out float)

Rgb_Cmyk

#
public static void Rgb_Cmyk(double r, double g, double b, out double c, out double m, out double y, out double k)
Convert standard RGB channels into CMYK channels.
r (double)
g (double)
b (double)
c (out double)
m (out double)
y (out double)
k (out double)

Rgb_Cmyk

#
public static void Rgb_Cmyk(float r, float g, float b, out float c, out float m, out float y, out float k)
Convert standard RGB channels into CMYK channels.
r (float)
g (float)
b (float)
c (out float)
m (out float)
y (out float)
k (out float)

Rgb_Hsl

#
public static void Rgb_Hsl(double r, double g, double b, out double h, out double s, out double l)
Convert Standard RGB channels into HSL channels.
r (double)
g (double)
b (double)
h (out double)
s (out double)
l (out double)

Rgb_Hsl

#
public static void Rgb_Hsl(float r, float g, float b, out float h, out float s, out float l)
Convert Standard RGB channels into HSL channels.
r (float)
g (float)
b (float)
h (out float)
s (out float)
l (out float)

Rgb_Hsp

#
public static void Rgb_Hsp(double r, double g, double b, out double hue, out double sat, out double lum)
Convert RGB channels into H*SP (perceived luminance) channels.
r (double)
g (double)
b (double)
hue (out double)
sat (out double)
lum (out double)

Rgb_Hsp

#
public static void Rgb_Hsp(float r, float g, float b, out float hue, out float sat, out float lum)
Convert RGB channels into H*SP (perceived luminance) channels.
r (float)
g (float)
b (float)
hue (out float)
sat (out float)
lum (out float)

Rgb_Hsv

#
public static void Rgb_Hsv(double r, double g, double b, out double h, out double s, out double v)
Convert Standard RGB channels into HSV/B channels.
r (double)
g (double)
b (double)
h (out double)
s (out double)
v (out double)

Rgb_Hsv

#
public static void Rgb_Hsv(float r, float g, float b, out float h, out float s, out float v)
Convert Standard RGB channels into HSV/B channels.
r (float)
g (float)
b (float)
h (out float)
s (out float)
v (out float)

Rgb_Hue

#
public static double Rgb_Hue(double r, double g, double b)
Convert an RGB triplet into an HSB/HSV/HSL hue.
r (double)
g (double)
b (double)
Hue angle.

Rgb_Hue

#
public static float Rgb_Hue(float r, float g, float b)
Convert an RGB triplet into an HSB/HSV/HSL hue.
r (float)
g (float)
b (float)
Hue angle.

Rgb_Xyz

#
public static void Rgb_Xyz(double r, double g, double b, out double x, out double y, out double z)
Convert Standard RGB channels into Cie XYZ channels.
r (double)
g (double)
b (double)
x (out double)
y (out double)
z (out double)

Rgb_Xyz

#
public static void Rgb_Xyz(float r, float g, float b, out float x, out float y, out float z)
Convert Standard RGB channels into Cie XYZ channels.
r (float)
g (float)
b (float)
x (out float)
y (out float)
z (out float)

RgbGammaAdjust

#
public static void RgbGammaAdjust(double r, double g, double b, double exponent, out double rʹ, out double gʹ, out double bʹ)
Perform a gamma correction on linear RGB channels.
r (double)Linear red.
g (double)Linear green.
b (double)Linear blue.
exponent (double)Exponent, 2.2 or 2.4 are common.
rʹ (out double)Gamma corrected red.
gʹ (out double)Gamma corrected green.
bʹ (out double)Gamma corrected blue.

RgbGammaAdjust

#
public static void RgbGammaAdjust(float r, float g, float b, double exponent, out float rʹ, out float gʹ, out float bʹ)
Perform a gamma correction on linear RGB channels.
r (float)Linear red.
g (float)Linear green.
b (float)Linear blue.
exponent (double)Exponent, 2.2 or 2.4 are common.
rʹ (out float)Gamma corrected red.
gʹ (out float)Gamma corrected green.
bʹ (out float)Gamma corrected blue.

RgbGammaRevert

#
public static void RgbGammaRevert(double r, double g, double b, double exponent, out double rʹ, out double gʹ, out double bʹ)
Perform an inverse gamma correction on non-linear RGB channels.
r (double)Non-linear red.
g (double)Non-linear green.
b (double)Non-linear blue.
exponent (double)Exponent, 2.2 or 2.4 are common.
rʹ (out double)Linear red.
gʹ (out double)Linear green.
bʹ (out double)Linear blue.

RgbGammaRevert

#
public static void RgbGammaRevert(float r, float g, float b, double exponent, out float rʹ, out float gʹ, out float bʹ)
Perform an inverse gamma correction on non-linear RGB channels.
r (float)Non-linear red.
g (float)Non-linear green.
b (float)Non-linear blue.
exponent (double)Exponent, 2.2 or 2.4 are common.
rʹ (out float)Linear red.
gʹ (out float)Linear green.
bʹ (out float)Linear blue.

RgbLinear_Oklab

#
public static void RgbLinear_Oklab(double r, double g, double b, out double L, out double a, out double bʹ)
Convert linear RGB channels into Oklab channels.
r (double)Linear red channel.
g (double)Linear green channel.
b (double)Linear blue channel.
L (out double)Perceptual lightness, 0 to 1.
a (out double)Green-red opposition channel.
bʹ (out double)Blue-yellow opposition channel.

RgbLinear_Oklab

#
public static void RgbLinear_Oklab(float r, float g, float b, out float L, out float a, out float bʹ)
Convert linear RGB channels into Oklab channels.
r (float)Linear red channel.
g (float)Linear green channel.
b (float)Linear blue channel.
L (out float)Perceptual lightness, 0 to 1.
a (out float)Green-red opposition channel.
bʹ (out float)Blue-yellow opposition channel.

RgbLinear_RgbStandard

#
public static void RgbLinear_RgbStandard(double r, double g, double b, out double rʹ, out double gʹ, out double bʹ)
Convert linear RGB channels to standard RGB channels.
r (double)
g (double)
b (double)
rʹ (out double)
gʹ (out double)
bʹ (out double)

RgbLinear_RgbStandard

#
public static void RgbLinear_RgbStandard(float r, float g, float b, out float rʹ, out float gʹ, out float bʹ)
Convert linear RGB channels to standard RGB channels.
r (float)
g (float)
b (float)
rʹ (out float)
gʹ (out float)
bʹ (out float)

RgbStandard_RgbLinear

#
public static void RgbStandard_RgbLinear(double r, double g, double b, out double rʹ, out double gʹ, out double bʹ)
Convert standard RGB channels to linear RGB channels.
r (double)
g (double)
b (double)
rʹ (out double)
gʹ (out double)
bʹ (out double)

RgbStandard_RgbLinear

#
public static void RgbStandard_RgbLinear(float r, float g, float b, out float rʹ, out float gʹ, out float bʹ)
Convert standard RGB channels to linear RGB channels.
r (float)
g (float)
b (float)
rʹ (out float)
gʹ (out float)
bʹ (out float)

ToAdjustedHue

#
public static double ToAdjustedHue(double hsvHue)
Convert an HSV hue into an HSP hue.
hsvHue (double)Hsv hue.
Hsp hue.

ToAdjustedHue

#
public static float ToAdjustedHue(float hsvHue)
Convert an HSV hue into an HSP hue.
hsvHue (float)Hsv hue.
Hsp hue.

ToTraditionalHue

#
public static double ToTraditionalHue(double hspHue)
Convert an HSP hue into an HSV hue.
hspHue (double)Hsp hue.
Hsp hue.

ToTraditionalHue

#
public static float ToTraditionalHue(float hspHue)
Convert an HSP hue into an HSV hue.
hspHue (float)Hsp hue.
Hsp hue.

TryParseNamedColour

#
public static ColourParseSource TryParseNamedColour(string text, out Color colour, bool includeFuzzyParsing, bool includeMixedParsing)
Try and parse a text describing a colour by name.
text (string)Text to parse.
colour (out Color)Resulting colour.
includeFuzzyParsing (bool)If true, near hits are allowed.
includeMixedParsing (bool)If true, combinations of names are allowed.

Xyz_Lab

#
public static void Xyz_Lab(double x, double y, double z, out double l, out double a, out double b)
Convert Cie XYZ channels into Cie L*a*b* channels.
x (double)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (double)Y value, up to 100.000
z (double)Z value, up to 108.883
l (out double)Luminance channel.
a (out double)Chroma a channel.
b (out double)Chroma b channel.

Xyz_Lab

#
public static void Xyz_Lab(float x, float y, float z, out float l, out float a, out float b)
Convert Cie XYZ channels into Cie L*a*b* channels.
x (float)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (float)Y value, up to 100.000
z (float)Z value, up to 108.883
l (out float)Luminance channel.
a (out float)Chroma a channel.
b (out float)Chroma b channel.

Xyz_Rgb

#
public static void Xyz_Rgb(double x, double y, double z, out double r, out double g, out double b)
Convert Cie XYZ channels into Standard RGB channels. Note that the RGB values are neither clipped nor tonemapped, so they may well exceed the [0~1] range.
x (double)
y (double)
z (double)
r (out double)
g (out double)
b (out double)

Xyz_Rgb

#
public static void Xyz_Rgb(float x, float y, float z, out float r, out float g, out float b)
Convert Cie XYZ channels into Standard RGB channels. Note that the RGB values are neither clipped nor tonemapped, so they may well exceed the [0~1] range.
x (float)
y (float)
z (float)
r (out float)
g (out float)
b (out float)

Xyz_Yxy

#
public static void Xyz_Yxy(double x, double y, double z, out double Y, out double Yx, out double Yy)
Convert Cie XYZ channels into Cie Chromaticity diagram channels.
x (double)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (double)Y value, up to 100.000
z (double)Z value, up to 108.883
Y (out double)
Yx (out double)
Yy (out double)

Xyz_Yxy

#
public static void Xyz_Yxy(float x, float y, float z, out float Y, out float Yx, out float Yy)
Convert Cie XYZ channels into Cie Chromaticity diagram channels.
x (float)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (float)Y value, up to 100.000
z (float)Z value, up to 108.883
Y (out float)
Yx (out float)
Yy (out float)

Yxy_Xyz

#
public static void Yxy_Xyz(double Y, double Yx, double Yy, out double x, out double y, out double z)
Convert Cie Chromaticity Diagram channels into Cie XYZ channels.
Y (double)Chromaticity luminance.
Yx (double)Chromaticity x.
Yy (double)Chromaticity y.
x (out double)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (out double)Y value, up to 100.000
z (out double)Z value, up to 108.883

Yxy_Xyz

#
public static void Yxy_Xyz(float Y, float Yx, float Yy, out float x, out float y, out float z)
Convert Cie Chromaticity Diagram channels into Cie XYZ channels.
Y (float)Chromaticity luminance.
Yx (float)Chromaticity x.
Yy (float)Chromaticity y.
x (out float)X value, up to 95.047, Observer= 2°, Illuminant= D65
y (out float)Y value, up to 100.000
z (out float)Z value, up to 108.883