CieLab Struct
A color in the CIE 1976 L*a*b* color space (CIELAB), relative to a white, CieXyz.D50 by default.
public readonly struct CieLab : IEquatable<CieLab>Remarks
The equations are those of CIE 15:2004 with the exact constants (6/29)^3 and (29/3)^3, as CSS Color 4 writes them. The conversions from and to RGB go through CIEXYZ relative to D50, as the lab() colors of CSS and the CIELAB colors of ICC profiles do.
The values are not validated: colors outside the gamut of every display and values that are not numbers are kept as they are.
- Implements
Constructors
| Name | Description |
|---|---|
| CieLab(double, double, double) | Initializes a new instance of the CieLab struct. |
CieLab(double, double, double)
CieLab.csProperties
| Name | Description |
|---|---|
| A | Gets the green (negative) to red (positive) axis. |
| B | Gets the blue (negative) to yellow (positive) axis. |
| L | Gets the lightness, from 0 (black) to 100 (the white). |
Methods
| Name | Description |
|---|---|
| Equals(CieLab) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object?) | Indicates whether this instance and a specified object are equal. |
| FromRgb(Rgba32, RgbColorSpace?) | Converts an 8-bit RGB color to CieLab. Alpha is ignored. |
| FromRgb(Rgba64, RgbColorSpace?) | Converts a 16-bit RGB color to CieLab. Alpha is ignored. |
| FromXyz(CieXyz) | Converts a color from CIEXYZ relative to CieXyz.D50. |
| FromXyz(CieXyz, CieXyz) | Converts a color from CIEXYZ relative to a white. |
| GetHashCode() | Returns the hash code for this instance. |
| Parse(ReadOnlySpan<char>, double) | Parses a color written with the CSS Color 4 lab() function, such as lab(52.2345 40.1645 59.9971). |
| ToCssString(double) | Formats this color with the CSS Color 4 lab() function, every component as a number: lab(52.2345 40.1645 59.9971). |
| ToLch() | Converts this color to its cylindrical form, CIELCh. |
| ToRgba32(RgbColorSpace?) | Converts this color to an opaque 8-bit RGB color, clipped to the gamut of the space component by component. |
| ToRgba64(RgbColorSpace?) | Converts this color to an opaque 16-bit RGB color, clipped to the gamut of the space component by component. |
| ToString() | Returns the fully qualified type name of this instance. |
| ToXyz() | Converts this color to CIEXYZ relative to CieXyz.D50. |
| ToXyz(CieXyz) | Converts this color to CIEXYZ relative to a white. |
| TryParse(ReadOnlySpan<char>, CieLab, double) | Tries to parse a color written with the CSS Color 4 lab() function, as CieLab.Parse does. |
FromRgb overloads
FromRgb(Rgba32, RgbColorSpace?)
CieLab.csConverts an 8-bit RGB color to CieLab. Alpha is ignored.
public static CieLab FromRgb(Rgba32 color, RgbColorSpace? colorSpace = null)Parameters
colorRgba32- The color.
colorSpaceRgbColorSpace?- The meaning of the red, green and blue values, or
nullforRgbColorSpace.Srgb.
Returns
CieLab The color.
FromRgb(Rgba64, RgbColorSpace?)
CieLab.csConverts a 16-bit RGB color to CieLab. Alpha is ignored.
public static CieLab FromRgb(Rgba64 color, RgbColorSpace? colorSpace = null)Parameters
colorRgba64- The color.
colorSpaceRgbColorSpace?- The meaning of the red, green and blue values, or
nullforRgbColorSpace.Srgb.
Returns
CieLab The color.
FromXyz overloads
FromXyz(CieXyz)
CieLab.csConverts a color from CIEXYZ relative to CieXyz.D50.
FromXyz(CieXyz, CieXyz)
CieLab.csGetHashCode()
CieLab.csParse(ReadOnlySpan<char>, double)
CieLab.csParses a color written with the CSS Color 4 lab() function, such as lab(52.2345 40.1645 59.9971).
public static CieLab Parse(ReadOnlySpan<char> value, out double alpha)Parameters
valueReadOnlySpan<char>- The text.
alphadouble- The alpha of the color, in [0, 1]: 1 when the text has none.
Returns
CieLab The color.
Exceptions
FormatExceptionvalueis not alab()color.
Remarks
The lightness is a number or a percentage of 100, clamped to [0, 100]; a and b are numbers, or percentages of 125. Each component may be none, read as 0. Function names, units and keywords are ASCII case-insensitive, and white space may surround the text; calc() and relative colors are not supported.
ToCssString(double)
CieLab.csFormats this color with the CSS Color 4 lab() function, every component as a number: lab(52.2345 40.1645 59.9971).
Parameters
alphadouble- The alpha, in [0, 1]. It is written after a
/when it is not 1.
Returns
string The text; CieLab.Parse reads it back.
Exceptions
ArgumentOutOfRangeExceptionalphais not in [0, 1], or a component is not a finite number.
ToLch()
CieLab.csToRgba32(RgbColorSpace?)
CieLab.csConverts this color to an opaque 8-bit RGB color, clipped to the gamut of the space component by component.
public Rgba32 ToRgba32(RgbColorSpace? colorSpace = null)Parameters
colorSpaceRgbColorSpace?- The meaning of the red, green and blue values, or
nullforRgbColorSpace.Srgb.
Returns
Rgba32 The color.
Exceptions
UnsupportedImageFeatureException- The space cannot convert colors to RGB values (
RgbColorSpace.CanConvertFromXyz).
ToRgba64(RgbColorSpace?)
CieLab.csConverts this color to an opaque 16-bit RGB color, clipped to the gamut of the space component by component.
public Rgba64 ToRgba64(RgbColorSpace? colorSpace = null)Parameters
colorSpaceRgbColorSpace?- The meaning of the red, green and blue values, or
nullforRgbColorSpace.Srgb.
Returns
Rgba64 The color.
Exceptions
UnsupportedImageFeatureException- The space cannot convert colors to RGB values (
RgbColorSpace.CanConvertFromXyz).
ToString()
CieLab.csTryParse(ReadOnlySpan<char>, CieLab, double)
CieLab.csTries to parse a color written with the CSS Color 4 lab() function, as CieLab.Parse does.
public static bool TryParse(ReadOnlySpan<char> value, out CieLab result, out double alpha)Parameters
valueReadOnlySpan<char>- The text.
resultCieLab- The color, or the default value when the text is not a
lab()color. alphadouble- The alpha of the color, in [0, 1]: 1 when the text has none.
Returns
bool true if the text is a lab() color.
Operators
| Name | Description |
|---|---|
| operator ==(CieLab, CieLab) | Compares two colors for equality, component by component. |
| operator !=(CieLab, CieLab) | Compares two colors for inequality, component by component. |