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

NameDescription
CieLch(double, double, double)Initializes a new instance of the CieLch struct.

CieLch(double, double, double)

CieLch.cs

Initializes a new instance of the CieLch struct.

public CieLch(double l, double c, double h)

Parameters

l double
The lightness, from 0 (black) to 100 (the white).
c double
The chroma, the distance from the gray of the same lightness.
h double
The hue angle, in degrees.

Properties

NameDescription
CGets the chroma, the distance from the gray of the same lightness.
HGets the hue angle, in degrees.
LGets the lightness, from 0 (black) to 100 (the white).

Gets the chroma, the distance from the gray of the same lightness.

public double C { get; }

Property value

double

Gets the hue angle, in degrees.

public double H { get; }

Property value

double

Gets the lightness, from 0 (black) to 100 (the white).

public double L { get; }

Property value

double

Methods

NameDescription
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.

Equals overloads

Equals(CieLch)

CieLch.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(CieLch other)
Parameters
other CieLch
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

CieLch.cs

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

FromLab(CieLab)

CieLch.cs

Converts a color from CIELAB.

public static CieLch FromLab(CieLab lab)

Parameters

lab CieLab
The color.

Returns

CieLch The color, with the hue in [0, 360).

FromRgb overloads

FromRgb(Rgba32, RgbColorSpace?)

CieLch.cs

Converts an 8-bit RGB color to CieLch. Alpha is ignored.

public static CieLch FromRgb(Rgba32 color, RgbColorSpace? colorSpace = null)
Parameters
color Rgba32
The color.
colorSpace RgbColorSpace?
The meaning of the red, green and blue values, or null for RgbColorSpace.Srgb.
Returns

CieLch The color.

FromRgb(Rgba64, RgbColorSpace?)

CieLch.cs

Converts a 16-bit RGB color to CieLch. Alpha is ignored.

public static CieLch FromRgb(Rgba64 color, RgbColorSpace? colorSpace = null)
Parameters
color Rgba64
The color.
colorSpace RgbColorSpace?
The meaning of the red, green and blue values, or null for RgbColorSpace.Srgb.
Returns

CieLch The color.

GetHashCode()

CieLch.cs

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

Parse(ReadOnlySpan<char>, double)

CieLch.cs

Parses 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

value ReadOnlySpan<char>
The text.
alpha double
The alpha of the color, in [0, 1]: 1 when the text has none.

Returns

CieLch The color.

Exceptions

FormatException
value is not a lch() 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.cs

Formats this color with the CSS Color 4 lch() function, every component as a number: lch(52.2345 72.2 56.2).

public string ToCssString(double alpha = 1d)

Parameters

alpha double
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

ArgumentOutOfRangeException
alpha is not in [0, 1], or a component is not a finite number.

ToLab()

CieLch.cs

Converts this color to CIELAB.

public CieLab ToLab()

Returns

CieLab The color.

ToRgba32(RgbColorSpace?)

CieLch.cs

Converts 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

colorSpace RgbColorSpace?
The meaning of the red, green and blue values, or null for RgbColorSpace.Srgb.

Returns

Rgba32 The color.

Exceptions

UnsupportedImageFeatureException
The space cannot convert colors to RGB values (RgbColorSpace.CanConvertFromXyz).

ToRgba64(RgbColorSpace?)

CieLch.cs

Converts 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

colorSpace RgbColorSpace?
The meaning of the red, green and blue values, or null for RgbColorSpace.Srgb.

Returns

Rgba64 The color.

Exceptions

UnsupportedImageFeatureException
The space cannot convert colors to RGB values (RgbColorSpace.CanConvertFromXyz).

ToString()

CieLch.cs

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string The fully qualified type name.

TryParse(ReadOnlySpan<char>, CieLch, double)

CieLch.cs

Tries 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

value ReadOnlySpan<char>
The text.
result CieLch
The color, or the default value when the text is not a lch() color.
alpha double
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

NameDescription
operator ==(CieLch, CieLch)Compares two colors for equality, component by component.
operator !=(CieLch, CieLch)Compares two colors for inequality, component by component.

operator ==(CieLch, CieLch)

CieLch.cs

Compares two colors for equality, component by component.

public static bool operator ==(CieLch left, CieLch right)

Parameters

left CieLch
The first color.
right CieLch
The second color.

Returns

bool true if all the components are equal; otherwise false.

operator !=(CieLch, CieLch)

CieLch.cs

Compares two colors for inequality, component by component.

public static bool operator !=(CieLch left, CieLch right)

Parameters

left CieLch
The first color.
right CieLch
The second color.

Returns

bool true if a component differs; otherwise false.