Hsv Struct

A color given by its hue, saturation and value (HSV, also called HSB), a cylindrical form of the encoded RGB values of a device.

public readonly struct Hsv : IEquatable<Hsv>

Remarks

HSV 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 value is the largest RGB value and the saturation is the range of the RGB values relative to it. 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

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

Hsv(double, double, double)

Hsv.cs

Initializes a new instance of the Hsv struct.

public Hsv(double h, double s, double v)

Parameters

h double
The hue angle, in degrees: 0 is red, 120 green, 240 blue.
s double
The saturation, from 0 (gray) to 1 (the pure hue).
v double
The value, the largest of the red, green and blue values, from 0 (black) to 1.

Properties

NameDescription
HGets the hue angle, in degrees: 0 is red, 120 green, 240 blue.
SGets the saturation, from 0 (gray) to 1 (the pure hue).
VGets the value, the largest of the red, green and blue values, from 0 (black) to 1.

Gets the hue angle, in degrees: 0 is red, 120 green, 240 blue.

public double H { get; }

Property value

double

Gets the saturation, from 0 (gray) to 1 (the pure hue).

public double S { get; }

Property value

double

Gets the value, the largest of the red, green and blue values, from 0 (black) to 1.

public double V { get; }

Property value

double

Methods

NameDescription
Equals(Hsv)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 HSV. Alpha is ignored.
FromRgb(Rgba64)Converts a 16-bit RGB color to HSV. Alpha is ignored.
GetHashCode()Returns the hash code for this instance.
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.

Equals overloads

Equals(Hsv)

Hsv.cs

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

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

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

Equals(object?)

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

FromRgb overloads

FromRgb(Rgba32)

Hsv.cs

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

public static Hsv FromRgb(Rgba32 color)
Parameters
color Rgba32
The color.
Returns

Hsv The color.

FromRgb(Rgba64)

Hsv.cs

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

public static Hsv FromRgb(Rgba64 color)
Parameters
color Rgba64
The color.
Returns

Hsv The color.

GetHashCode()

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

ToRgba32()

Hsv.cs

Converts this color to an opaque 8-bit RGB color, each component clipped to [0, 1].

public Rgba32 ToRgba32()

Returns

Rgba32 The color.

ToRgba64()

Hsv.cs

Converts this color to an opaque 16-bit RGB color, each component clipped to [0, 1].

public Rgba64 ToRgba64()

Returns

Rgba64 The color.

ToString()

Hsv.cs

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string The fully qualified type name.

Operators

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

operator ==(Hsv, Hsv)

Hsv.cs

Compares two colors for equality, component by component.

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

Parameters

left Hsv
The first color.
right Hsv
The second color.

Returns

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

operator !=(Hsv, Hsv)

Hsv.cs

Compares two colors for inequality, component by component.

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

Parameters

left Hsv
The first color.
right Hsv
The second color.

Returns

bool true if a component differs; otherwise false.