Hwb Struct
A color given by its hue, whiteness and blackness (HWB), a cylindrical form of the encoded RGB values of a device.
public readonly struct Hwb : IEquatable<Hwb>Remarks
HWB describes RGB values, not colors: it has no color space of its own, and its conversions read and write the stored RGB values as they are, whatever their color space. The equations are those of CSS Color 4 (hwbToRgb and rgbToHwb): when the whiteness and the blackness add up to 1 or more, the color is the gray of their ratio. The conversions from RGB give the hue in [0, 360); a gray has no hue: it is 0.
The values are not validated: the conversion to RGB clips each component to [0, 1].
- Implements
Constructors
| Name | Description |
|---|---|
| Hwb(double, double, double) | Initializes a new instance of the Hwb struct. |
Hwb(double, double, double)
Hwb.csProperties
| Name | Description |
|---|---|
| B | Gets the blackness, the amount of black mixed in, from 0 to 1. |
| H | Gets the hue angle, in degrees: 0 is red, 120 green, 240 blue. |
| W | Gets the whiteness, the amount of white mixed in, from 0 to 1. |
Methods
| Name | Description |
|---|---|
| Equals(Hwb) | 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) | Converts an 8-bit RGB color to HWB. Alpha is ignored. |
| FromRgb(Rgba64) | Converts a 16-bit RGB color to HWB. Alpha is ignored. |
| GetHashCode() | Returns the hash code for this instance. |
| Parse(ReadOnlySpan<char>, double) | Parses a color written with the CSS Color 4 hwb() function, such as hwb(120 20% 30%). |
| ToCssString(double) | Formats this color with the CSS Color 4 hwb() function, the components after the hue as percentages: hwb(120 20% 30%). |
| ToRgba32() | Converts this color to an opaque 8-bit RGB color, each component clipped to [0, 1]. |
| ToRgba64() | Converts this color to an opaque 16-bit RGB color, each component clipped to [0, 1]. |
| ToString() | Returns the fully qualified type name of this instance. |
| TryParse(ReadOnlySpan<char>, Hwb, double) | Tries to parse a color written with the CSS Color 4 hwb() function, as Hwb.Parse does. |
GetHashCode()
Hwb.csParse(ReadOnlySpan<char>, double)
Hwb.csParses a color written with the CSS Color 4 hwb() function, such as hwb(120 20% 30%).
public static Hwb 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
Hwb The color.
Exceptions
FormatExceptionvalueis not ahwb()color.
Remarks
The hue is a number of degrees or an angle (deg, grad, rad, turn), brought to [0, 360); the whiteness and the blackness are percentages, or numbers of the same value. 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)
Hwb.csFormats this color with the CSS Color 4 hwb() function, the components after the hue as percentages: hwb(120 20% 30%).
Parameters
alphadouble- The alpha, in [0, 1]. It is written after a
/when it is not 1.
Returns
string The text; Hwb.Parse reads it back.
Exceptions
ArgumentOutOfRangeExceptionalphais not in [0, 1], or a component is not a finite number.
ToRgba32()
Hwb.csToRgba64()
Hwb.csToString()
Hwb.csTryParse(ReadOnlySpan<char>, Hwb, double)
Hwb.csTries to parse a color written with the CSS Color 4 hwb() function, as Hwb.Parse does.
public static bool TryParse(ReadOnlySpan<char> value, out Hwb result, out double alpha)Parameters
valueReadOnlySpan<char>- The text.
resultHwb- The color, or the default value when the text is not a
hwb()color. alphadouble- The alpha of the color, in [0, 1]: 1 when the text has none.
Returns
bool true if the text is a hwb() color.
Operators
| Name | Description |
|---|---|
| operator ==(Hwb, Hwb) | Compares two colors for equality, component by component. |
| operator !=(Hwb, Hwb) | Compares two colors for inequality, component by component. |