4 using System.Globalization;
5 using System.Runtime.InteropServices;
6 using SiliconStudio.Core.Serialization;
8 namespace SiliconStudio.Core.Mathematics
14 [StructLayout(LayoutKind.Sequential, Pack = 4)]
62 int hi = Convert.ToInt32(Math.Floor(H / 60)) % 6;
63 float f = H / 60 - (float)Math.Floor(H / 60);
66 float p = V * (1 - S);
67 float q = V * (1 - f * S);
68 float t = V * (1 - (1 - f) * S);
73 return new Color4(v, t, p, A);
75 return new Color4(q, v, p, A);
77 return new Color4(p, v, t, A);
79 return new Color4(p, q, v, A);
81 return new Color4(t, p, v, A);
83 return new Color4(v, p, q, A);
94 float max = Math.Max(color.R, Math.Max(color.G, color.B));
95 float min = Math.Min(color.R, Math.Min(color.G, color.B));
97 float delta = max - min;
102 if (max == color.
R && max != color.
G)
103 h += (color.G - color.B) / delta;
104 if (max == color.
G && max != color.
B)
105 h += (2.0f + (color.B - color.R) / delta);
106 if (max == color.
B && max != color.
R)
107 h += (4.0f + (color.R - color.G) / delta);
111 return new ColorHSV(h, (max != 0.0f) ? 1.0f - min / max : 0.0f, max, color.
A);
116 return other.H.Equals(H) && other.
S.Equals(S) && other.V.Equals(V) && other.
A.Equals(A);
121 if (ReferenceEquals(null, obj))
return false;
122 if (obj.GetType() != typeof(
ColorHSV))
return false;
130 int result = H.GetHashCode();
131 result = (result * 397) ^ S.GetHashCode();
132 result = (result * 397) ^ V.GetHashCode();
133 result = (result * 397) ^ A.GetHashCode();
138 private const string ColorHSVFormat =
"Hue:{0} Saturation:{1} Value:{2} Alpha:{3}";
148 return string.Format(CultureInfo.CurrentCulture, ColorHSVFormat, H, S, V, A);
163 return string.Format(CultureInfo.CurrentCulture, ColorHSVFormat, H.ToString(
format, CultureInfo.CurrentCulture),
164 S.ToString(format, CultureInfo.CurrentCulture), V.ToString(
format, CultureInfo.CurrentCulture), A.ToString(format, CultureInfo.CurrentCulture));
174 public string ToString(IFormatProvider formatProvider)
176 return string.Format(formatProvider, ColorHSVFormat, H, S, V, A);
190 return ToString(formatProvider);
192 return string.Format(formatProvider, ColorHSVFormat, H.ToString(
format, formatProvider),
193 S.ToString(format, formatProvider), V.ToString(
format, formatProvider), A.ToString(format, formatProvider));
float A
The alpha component of the color.
float H
The Hue of the color.
float V
The Value of the color.
float B
The blue component of the color.
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
float G
The green component of the color.
Represents a color in the form of rgba.
bool Equals(ColorHSV other)
float S
The Saturation of the color.
override int GetHashCode()
string ToString(string format)
Returns a System.String that represents this instance.
override bool Equals(object obj)
static ColorHSV FromColor(Color4 color)
Converts the color into a HSV color.
float R
The red component of the color.
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
float A
The alpha component of the color.
ColorHSV(float h, float s, float v, float a)
Initializes a new instance of the ColorHSV struct.
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Color4 ToColor()
Converts the color into a three component vector.
override string ToString()
Returns a System.String that represents this instance.
Represents a color in the form of Hue, Saturation, Value, Alpha.