CieLch Struct
A color in the cylindrical form of CIELAB (CIELCh): its lightness, chroma and hue angle.
public readonly struct CieLch : IEquatable<CieLch>Remarks
The hue is in degrees, counterclockwise from the positive a axis; the conversions from CIELAB give it in [0, 360). The hue of a gray has no meaning: it is the angle of its tiny a and b, or 0 when they are exactly zero.
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 |
|---|---|
| CieLch(double, double, double) | Initializes a new instance of the CieLch struct. |
CieLch(double, double, double)
CieLch.csProperties
| Name | Description |
|---|---|
| C | Gets the chroma, the distance from the gray of the same lightness. |
| H | Gets the hue angle, in degrees. |
| L | Gets the lightness, from 0 (black) to 100 (the white). |
Methods
| Name | Description |
|---|---|
| Equals(CieLch) | 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. |
| FromLab(CieLab) | Converts a color from CIELAB. |
| FromRgb(Rgba32, RgbColorSpace?) | Converts an 8-bit RGB color to CieLch. Alpha is ignored. |
| FromRgb(Rgba64, RgbColorSpace?) | Converts a 16-bit RGB color to CieLch. Alpha is ignored. |
| GetHashCode() | Returns the hash code for this instance. |
| Parse(ReadOnlySpan<char>, double) | Parses a color written with the CSS Color 4 lch() function, such as lch(52.2345 72.2 56.2). |
| ToCssString(double) | Formats this color with the CSS Color 4 lch() function, every component as a number: lch(52.2345 72.2 56.2). |
| ToLab() | Converts this color to CIELAB. |
| 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. |
| TryParse(ReadOnlySpan<char>, CieLch, double) | Tries to parse a color written with the CSS Color 4 lch() function, as CieLch.Parse does. |
FromLab(CieLab)
CieLch.csFromRgb overloads
FromRgb(Rgba32, RgbColorSpace?)
CieLch.csConverts an 8-bit RGB color to CieLch. Alpha is ignored.
public static CieLch FromRgb(Rgba32 color, RgbColorSpace? colorSpace = null)Parameters
colorRgba32- The color.
colorSpaceRgbColorSpace?- The meaning of the red, green and blue values, or
nullforRgbColorSpace.Srgb.
Returns
CieLch The color.
FromRgb(Rgba64, RgbColorSpace?)
CieLch.csConverts a 16-bit RGB color to CieLch. Alpha is ignored.
public static CieLch FromRgb(Rgba64 color, RgbColorSpace? colorSpace = null)Parameters
colorRgba64- The color.
colorSpaceRgbColorSpace?- The meaning of the red, green and blue values, or
nullforRgbColorSpace.Srgb.
Returns
CieLch The color.
GetHashCode()
CieLch.csParse(ReadOnlySpan<char>, double)
CieLch.csParses a color written with the CSS Color 4 lch() function, such as lch(52.2345 72.2 56.2).
public static CieLch 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
CieLch The color.
Exceptions
FormatExceptionvalueis not alch()color.
Remarks
The lightness is a number or a percentage of 100, clamped to [0, 100]; the chroma is a number or a percentage of 150, clamped to 0 and above; the hue is a number of degrees or an angle (deg, grad, rad, turn), brought to [0, 360). 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)
CieLch.csFormats this color with the CSS Color 4 lch() function, every component as a number: lch(52.2345 72.2 56.2).
Parameters
alphadouble- The alpha, in [0, 1]. It is written after a
/when it is not 1.
Returns
string The text; CieLch.Parse reads it back.
Exceptions
ArgumentOutOfRangeExceptionalphais not in [0, 1], or a component is not a finite number.
ToLab()
CieLch.csToRgba32(RgbColorSpace?)
CieLch.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?)
CieLch.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()
CieLch.csTryParse(ReadOnlySpan<char>, CieLch, double)
CieLch.csTries to parse a color written with the CSS Color 4 lch() function, as CieLch.Parse does.
public static bool TryParse(ReadOnlySpan<char> value, out CieLch result, out double alpha)Parameters
valueReadOnlySpan<char>- The text.
resultCieLch- The color, or the default value when the text is not a
lch()color. alphadouble- The alpha of the color, in [0, 1]: 1 when the text has none.
Returns
bool true if the text is a lch() color.
Operators
| Name | Description |
|---|---|
| operator ==(CieLch, CieLch) | Compares two colors for equality, component by component. |
| operator !=(CieLch, CieLch) | Compares two colors for inequality, component by component. |