[OpenTK] Introduce OpenTK (#336)
[platform/core/csapi/tizenfx.git] / external / src / OpenTK / OpenTK / Graphics / Color4.cs
1 //
2 // The Open Toolkit Library License
3 //
4 // Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights to
9 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 // the Software, and to permit persons to whom the Software is furnished to do
11 // so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 // OTHER DEALINGS IN THE SOFTWARE.
24 //
25
26 using System;
27 #if !MINIMAL
28 using System.Drawing;
29 #endif
30
31 namespace OpenTK.Graphics
32 {
33     /// <summary>
34     /// Represents a color with 4 floating-point components (R, G, B, A).
35     /// </summary>
36     [Serializable]
37     public struct Color4 : IEquatable<Color4>
38     {
39         /// <summary>
40         /// The red component of this Color4 structure.
41         /// </summary>
42         public float R;
43
44         /// <summary>
45         /// The green component of this Color4 structure.
46         /// </summary>
47         public float G;
48
49         /// <summary>
50         /// The blue component of this Color4 structure.
51         /// </summary>
52         public float B;
53
54         /// <summary>
55         /// The alpha component of this Color4 structure.
56         /// </summary>
57         public float A;
58
59         /// <summary>
60         /// Constructs a new Color4 structure from the specified components.
61         /// </summary>
62         /// <param name="r">The red component of the new Color4 structure.</param>
63         /// <param name="g">The green component of the new Color4 structure.</param>
64         /// <param name="b">The blue component of the new Color4 structure.</param>
65         /// <param name="a">The alpha component of the new Color4 structure.</param>
66         public Color4(float r, float g, float b, float a)
67         {
68             R = r;
69             G = g;
70             B = b;
71             A = a;
72         }
73
74         /// <summary>
75         /// Constructs a new Color4 structure from the specified components.
76         /// </summary>
77         /// <param name="r">The red component of the new Color4 structure.</param>
78         /// <param name="g">The green component of the new Color4 structure.</param>
79         /// <param name="b">The blue component of the new Color4 structure.</param>
80         /// <param name="a">The alpha component of the new Color4 structure.</param>
81         public Color4(byte r, byte g, byte b, byte a)
82         {
83             R = r / (float)Byte.MaxValue;
84             G = g / (float)Byte.MaxValue;
85             B = b / (float)Byte.MaxValue;
86             A = a / (float)Byte.MaxValue;
87         }
88
89         /// <summary>
90         /// Converts this color to an integer representation with 8 bits per channel.
91         /// </summary>
92         /// <returns>A <see cref="System.Int32"/> that represents this instance.</returns>
93         /// <remarks>This method is intended only for compatibility with System.Drawing. It compresses the color into 8 bits per channel, which means color information is lost.</remarks>
94         public int ToArgb()
95         {
96             uint value =
97                 (uint)(A * Byte.MaxValue) << 24 |
98                 (uint)(R * Byte.MaxValue) << 16 |
99                 (uint)(G * Byte.MaxValue) << 8 |
100                 (uint)(B * Byte.MaxValue);
101
102             return unchecked((int)value);
103         }
104
105         /// <summary>
106         /// Compares the specified Color4 structures for equality.
107         /// </summary>
108         /// <param name="left">The left-hand side of the comparison.</param>
109         /// <param name="right">The right-hand side of the comparison.</param>
110         /// <returns>True if left is equal to right; false otherwise.</returns>
111         public static bool operator ==(Color4 left, Color4 right)
112         {
113             return left.Equals(right);
114         }
115
116         /// <summary>
117         /// Compares the specified Color4 structures for inequality.
118         /// </summary>
119         /// <param name="left">The left-hand side of the comparison.</param>
120         /// <param name="right">The right-hand side of the comparison.</param>
121         /// <returns>True if left is not equal to right; false otherwise.</returns>
122         public static bool operator !=(Color4 left, Color4 right)
123         {
124             return !left.Equals(right);
125         }
126
127         /// <summary>
128         /// Converts the specified System.Drawing.Color to a Color4 structure.
129         /// </summary>
130         /// <param name="color">The System.Drawing.Color to convert.</param>
131         /// <returns>A new Color4 structure containing the converted components.</returns>
132         public static implicit operator Color4(Color color)
133         {
134             return new Color4(color.R, color.G, color.B, color.A);
135         }
136
137         /// <summary>
138         /// Converts the specified Color4 to a System.Drawing.Color structure.
139         /// </summary>
140         /// <param name="color">The Color4 to convert.</param>
141         /// <returns>A new System.Drawing.Color structure containing the converted components.</returns>
142         public static explicit operator Color(Color4 color)
143         {
144             return Color.FromArgb(
145                 (int)(color.A * Byte.MaxValue),
146                 (int)(color.R * Byte.MaxValue),
147                 (int)(color.G * Byte.MaxValue),
148                 (int)(color.B * Byte.MaxValue));
149         }
150
151         /// <summary>
152         /// Compares whether this Color4 structure is equal to the specified object.
153         /// </summary>
154         /// <param name="obj">An object to compare to.</param>
155         /// <returns>True obj is a Color4 structure with the same components as this Color4; false otherwise.</returns>
156         public override bool Equals(object obj)
157         {
158             if (!(obj is Color4))
159             {
160                 return false;
161             }
162
163             return Equals((Color4)obj);
164         }
165
166         /// <summary>
167         /// Calculates the hash code for this Color4 structure.
168         /// </summary>
169         /// <returns>A System.Int32 containing the hashcode of this Color4 structure.</returns>
170         public override int GetHashCode()
171         {
172             return ToArgb();
173         }
174
175         /// <summary>
176         /// Creates a System.String that describes this Color4 structure.
177         /// </summary>
178         /// <returns>A System.String that describes this Color4 structure.</returns>
179         public override string ToString()
180         {
181             return String.Format("{{(R, G, B, A) = ({0}, {1}, {2}, {3})}}", R.ToString(), G.ToString(), B.ToString(), A.ToString());
182         }
183
184         /// <summary>
185         /// Gets the system color with (R, G, B, A) = (255, 255, 255, 0).
186         /// </summary>
187         public static Color4 Transparent { get { return new Color4(255, 255, 255, 0); } }
188
189         /// <summary>
190         /// Gets the system color with (R, G, B, A) = (240, 248, 255, 255).
191         /// </summary>
192         public static Color4 AliceBlue { get { return new Color4(240, 248, 255, 255); } }
193
194         /// <summary>
195         /// Gets the system color with (R, G, B, A) = (250, 235, 215, 255).
196         /// </summary>
197         public static Color4 AntiqueWhite { get { return new Color4(250, 235, 215, 255); } }
198
199         /// <summary>
200         /// Gets the system color with (R, G, B, A) = (0, 255, 255, 255).
201         /// </summary>
202         public static Color4 Aqua { get { return new Color4(0, 255, 255, 255); } }
203
204         /// <summary>
205         /// Gets the system color with (R, G, B, A) = (127, 255, 212, 255).
206         /// </summary>
207         public static Color4 Aquamarine { get { return new Color4(127, 255, 212, 255); } }
208
209         /// <summary>
210         /// Gets the system color with (R, G, B, A) = (240, 255, 255, 255).
211         /// </summary>
212         public static Color4 Azure { get { return new Color4(240, 255, 255, 255); } }
213
214         /// <summary>
215         /// Gets the system color with (R, G, B, A) = (245, 245, 220, 255).
216         /// </summary>
217         public static Color4 Beige { get { return new Color4(245, 245, 220, 255); } }
218
219         /// <summary>
220         /// Gets the system color with (R, G, B, A) = (255, 228, 196, 255).
221         /// </summary>
222         public static Color4 Bisque { get { return new Color4(255, 228, 196, 255); } }
223
224         /// <summary>
225         /// Gets the system color with (R, G, B, A) = (0, 0, 0, 255).
226         /// </summary>
227         public static Color4 Black { get { return new Color4(0, 0, 0, 255); } }
228
229         /// <summary>
230         /// Gets the system color with (R, G, B, A) = (255, 235, 205, 255).
231         /// </summary>
232         public static Color4 BlanchedAlmond { get { return new Color4(255, 235, 205, 255); } }
233
234         /// <summary>
235         /// Gets the system color with (R, G, B, A) = (0, 0, 255, 255).
236         /// </summary>
237         public static Color4 Blue { get { return new Color4(0, 0, 255, 255); } }
238
239         /// <summary>
240         /// Gets the system color with (R, G, B, A) = (138, 43, 226, 255).
241         /// </summary>
242         public static Color4 BlueViolet { get { return new Color4(138, 43, 226, 255); } }
243
244         /// <summary>
245         /// Gets the system color with (R, G, B, A) = (165, 42, 42, 255).
246         /// </summary>
247         public static Color4 Brown { get { return new Color4(165, 42, 42, 255); } }
248
249         /// <summary>
250         /// Gets the system color with (R, G, B, A) = (222, 184, 135, 255).
251         /// </summary>
252         public static Color4 BurlyWood { get { return new Color4(222, 184, 135, 255); } }
253
254         /// <summary>
255         /// Gets the system color with (R, G, B, A) = (95, 158, 160, 255).
256         /// </summary>
257         public static Color4 CadetBlue { get { return new Color4(95, 158, 160, 255); } }
258
259         /// <summary>
260         /// Gets the system color with (R, G, B, A) = (127, 255, 0, 255).
261         /// </summary>
262         public static Color4 Chartreuse { get { return new Color4(127, 255, 0, 255); } }
263
264         /// <summary>
265         /// Gets the system color with (R, G, B, A) = (210, 105, 30, 255).
266         /// </summary>
267         public static Color4 Chocolate { get { return new Color4(210, 105, 30, 255); } }
268
269         /// <summary>
270         /// Gets the system color with (R, G, B, A) = (255, 127, 80, 255).
271         /// </summary>
272         public static Color4 Coral { get { return new Color4(255, 127, 80, 255); } }
273
274         /// <summary>
275         /// Gets the system color with (R, G, B, A) = (100, 149, 237, 255).
276         /// </summary>
277         public static Color4 CornflowerBlue { get { return new Color4(100, 149, 237, 255); } }
278
279         /// <summary>
280         /// Gets the system color with (R, G, B, A) = (255, 248, 220, 255).
281         /// </summary>
282         public static Color4 Cornsilk { get { return new Color4(255, 248, 220, 255); } }
283
284         /// <summary>
285         /// Gets the system color with (R, G, B, A) = (220, 20, 60, 255).
286         /// </summary>
287         public static Color4 Crimson { get { return new Color4(220, 20, 60, 255); } }
288
289         /// <summary>
290         /// Gets the system color with (R, G, B, A) = (0, 255, 255, 255).
291         /// </summary>
292         public static Color4 Cyan { get { return new Color4(0, 255, 255, 255); } }
293
294         /// <summary>
295         /// Gets the system color with (R, G, B, A) = (0, 0, 139, 255).
296         /// </summary>
297         public static Color4 DarkBlue { get { return new Color4(0, 0, 139, 255); } }
298
299         /// <summary>
300         /// Gets the system color with (R, G, B, A) = (0, 139, 139, 255).
301         /// </summary>
302         public static Color4 DarkCyan { get { return new Color4(0, 139, 139, 255); } }
303
304         /// <summary>
305         /// Gets the system color with (R, G, B, A) = (184, 134, 11, 255).
306         /// </summary>
307         public static Color4 DarkGoldenrod { get { return new Color4(184, 134, 11, 255); } }
308
309         /// <summary>
310         /// Gets the system color with (R, G, B, A) = (169, 169, 169, 255).
311         /// </summary>
312         public static Color4 DarkGray { get { return new Color4(169, 169, 169, 255); } }
313
314         /// <summary>
315         /// Gets the system color with (R, G, B, A) = (0, 100, 0, 255).
316         /// </summary>
317         public static Color4 DarkGreen { get { return new Color4(0, 100, 0, 255); } }
318
319         /// <summary>
320         /// Gets the system color with (R, G, B, A) = (189, 183, 107, 255).
321         /// </summary>
322         public static Color4 DarkKhaki { get { return new Color4(189, 183, 107, 255); } }
323
324         /// <summary>
325         /// Gets the system color with (R, G, B, A) = (139, 0, 139, 255).
326         /// </summary>
327         public static Color4 DarkMagenta { get { return new Color4(139, 0, 139, 255); } }
328
329         /// <summary>
330         /// Gets the system color with (R, G, B, A) = (85, 107, 47, 255).
331         /// </summary>
332         public static Color4 DarkOliveGreen { get { return new Color4(85, 107, 47, 255); } }
333
334         /// <summary>
335         /// Gets the system color with (R, G, B, A) = (255, 140, 0, 255).
336         /// </summary>
337         public static Color4 DarkOrange { get { return new Color4(255, 140, 0, 255); } }
338
339         /// <summary>
340         /// Gets the system color with (R, G, B, A) = (153, 50, 204, 255).
341         /// </summary>
342         public static Color4 DarkOrchid { get { return new Color4(153, 50, 204, 255); } }
343
344         /// <summary>
345         /// Gets the system color with (R, G, B, A) = (139, 0, 0, 255).
346         /// </summary>
347         public static Color4 DarkRed { get { return new Color4(139, 0, 0, 255); } }
348
349         /// <summary>
350         /// Gets the system color with (R, G, B, A) = (233, 150, 122, 255).
351         /// </summary>
352         public static Color4 DarkSalmon { get { return new Color4(233, 150, 122, 255); } }
353
354         /// <summary>
355         /// Gets the system color with (R, G, B, A) = (143, 188, 139, 255).
356         /// </summary>
357         public static Color4 DarkSeaGreen { get { return new Color4(143, 188, 139, 255); } }
358
359         /// <summary>
360         /// Gets the system color with (R, G, B, A) = (72, 61, 139, 255).
361         /// </summary>
362         public static Color4 DarkSlateBlue { get { return new Color4(72, 61, 139, 255); } }
363
364         /// <summary>
365         /// Gets the system color with (R, G, B, A) = (47, 79, 79, 255).
366         /// </summary>
367         public static Color4 DarkSlateGray { get { return new Color4(47, 79, 79, 255); } }
368
369         /// <summary>
370         /// Gets the system color with (R, G, B, A) = (0, 206, 209, 255).
371         /// </summary>
372         public static Color4 DarkTurquoise { get { return new Color4(0, 206, 209, 255); } }
373
374         /// <summary>
375         /// Gets the system color with (R, G, B, A) = (148, 0, 211, 255).
376         /// </summary>
377         public static Color4 DarkViolet { get { return new Color4(148, 0, 211, 255); } }
378
379         /// <summary>
380         /// Gets the system color with (R, G, B, A) = (255, 20, 147, 255).
381         /// </summary>
382         public static Color4 DeepPink { get { return new Color4(255, 20, 147, 255); } }
383
384         /// <summary>
385         /// Gets the system color with (R, G, B, A) = (0, 191, 255, 255).
386         /// </summary>
387         public static Color4 DeepSkyBlue { get { return new Color4(0, 191, 255, 255); } }
388
389         /// <summary>
390         /// Gets the system color with (R, G, B, A) = (105, 105, 105, 255).
391         /// </summary>
392         public static Color4 DimGray { get { return new Color4(105, 105, 105, 255); } }
393
394         /// <summary>
395         /// Gets the system color with (R, G, B, A) = (30, 144, 255, 255).
396         /// </summary>
397         public static Color4 DodgerBlue { get { return new Color4(30, 144, 255, 255); } }
398
399         /// <summary>
400         /// Gets the system color with (R, G, B, A) = (178, 34, 34, 255).
401         /// </summary>
402         public static Color4 Firebrick { get { return new Color4(178, 34, 34, 255); } }
403
404         /// <summary>
405         /// Gets the system color with (R, G, B, A) = (255, 250, 240, 255).
406         /// </summary>
407         public static Color4 FloralWhite { get { return new Color4(255, 250, 240, 255); } }
408
409         /// <summary>
410         /// Gets the system color with (R, G, B, A) = (34, 139, 34, 255).
411         /// </summary>
412         public static Color4 ForestGreen { get { return new Color4(34, 139, 34, 255); } }
413
414         /// <summary>
415         /// Gets the system color with (R, G, B, A) = (255, 0, 255, 255).
416         /// </summary>
417         public static Color4 Fuchsia { get { return new Color4(255, 0, 255, 255); } }
418
419         /// <summary>
420         /// Gets the system color with (R, G, B, A) = (220, 220, 220, 255).
421         /// </summary>
422         public static Color4 Gainsboro { get { return new Color4(220, 220, 220, 255); } }
423
424         /// <summary>
425         /// Gets the system color with (R, G, B, A) = (248, 248, 255, 255).
426         /// </summary>
427         public static Color4 GhostWhite { get { return new Color4(248, 248, 255, 255); } }
428
429         /// <summary>
430         /// Gets the system color with (R, G, B, A) = (255, 215, 0, 255).
431         /// </summary>
432         public static Color4 Gold { get { return new Color4(255, 215, 0, 255); } }
433
434         /// <summary>
435         /// Gets the system color with (R, G, B, A) = (218, 165, 32, 255).
436         /// </summary>
437         public static Color4 Goldenrod { get { return new Color4(218, 165, 32, 255); } }
438
439         /// <summary>
440         /// Gets the system color with (R, G, B, A) = (128, 128, 128, 255).
441         /// </summary>
442         public static Color4 Gray { get { return new Color4(128, 128, 128, 255); } }
443
444         /// <summary>
445         /// Gets the system color with (R, G, B, A) = (0, 128, 0, 255).
446         /// </summary>
447         public static Color4 Green { get { return new Color4(0, 128, 0, 255); } }
448
449         /// <summary>
450         /// Gets the system color with (R, G, B, A) = (173, 255, 47, 255).
451         /// </summary>
452         public static Color4 GreenYellow { get { return new Color4(173, 255, 47, 255); } }
453
454         /// <summary>
455         /// Gets the system color with (R, G, B, A) = (240, 255, 240, 255).
456         /// </summary>
457         public static Color4 Honeydew { get { return new Color4(240, 255, 240, 255); } }
458
459         /// <summary>
460         /// Gets the system color with (R, G, B, A) = (255, 105, 180, 255).
461         /// </summary>
462         public static Color4 HotPink { get { return new Color4(255, 105, 180, 255); } }
463
464         /// <summary>
465         /// Gets the system color with (R, G, B, A) = (205, 92, 92, 255).
466         /// </summary>
467         public static Color4 IndianRed { get { return new Color4(205, 92, 92, 255); } }
468
469         /// <summary>
470         /// Gets the system color with (R, G, B, A) = (75, 0, 130, 255).
471         /// </summary>
472         public static Color4 Indigo { get { return new Color4(75, 0, 130, 255); } }
473
474         /// <summary>
475         /// Gets the system color with (R, G, B, A) = (255, 255, 240, 255).
476         /// </summary>
477         public static Color4 Ivory { get { return new Color4(255, 255, 240, 255); } }
478
479         /// <summary>
480         /// Gets the system color with (R, G, B, A) = (240, 230, 140, 255).
481         /// </summary>
482         public static Color4 Khaki { get { return new Color4(240, 230, 140, 255); } }
483
484         /// <summary>
485         /// Gets the system color with (R, G, B, A) = (230, 230, 250, 255).
486         /// </summary>
487         public static Color4 Lavender { get { return new Color4(230, 230, 250, 255); } }
488
489         /// <summary>
490         /// Gets the system color with (R, G, B, A) = (255, 240, 245, 255).
491         /// </summary>
492         public static Color4 LavenderBlush { get { return new Color4(255, 240, 245, 255); } }
493
494         /// <summary>
495         /// Gets the system color with (R, G, B, A) = (124, 252, 0, 255).
496         /// </summary>
497         public static Color4 LawnGreen { get { return new Color4(124, 252, 0, 255); } }
498
499         /// <summary>
500         /// Gets the system color with (R, G, B, A) = (255, 250, 205, 255).
501         /// </summary>
502         public static Color4 LemonChiffon { get { return new Color4(255, 250, 205, 255); } }
503
504         /// <summary>
505         /// Gets the system color with (R, G, B, A) = (173, 216, 230, 255).
506         /// </summary>
507         public static Color4 LightBlue { get { return new Color4(173, 216, 230, 255); } }
508
509         /// <summary>
510         /// Gets the system color with (R, G, B, A) = (240, 128, 128, 255).
511         /// </summary>
512         public static Color4 LightCoral { get { return new Color4(240, 128, 128, 255); } }
513
514         /// <summary>
515         /// Gets the system color with (R, G, B, A) = (224, 255, 255, 255).
516         /// </summary>
517         public static Color4 LightCyan { get { return new Color4(224, 255, 255, 255); } }
518
519         /// <summary>
520         /// Gets the system color with (R, G, B, A) = (250, 250, 210, 255).
521         /// </summary>
522         public static Color4 LightGoldenrodYellow { get { return new Color4(250, 250, 210, 255); } }
523
524         /// <summary>
525         /// Gets the system color with (R, G, B, A) = (144, 238, 144, 255).
526         /// </summary>
527         public static Color4 LightGreen { get { return new Color4(144, 238, 144, 255); } }
528
529         /// <summary>
530         /// Gets the system color with (R, G, B, A) = (211, 211, 211, 255).
531         /// </summary>
532         public static Color4 LightGray { get { return new Color4(211, 211, 211, 255); } }
533
534         /// <summary>
535         /// Gets the system color with (R, G, B, A) = (255, 182, 193, 255).
536         /// </summary>
537         public static Color4 LightPink { get { return new Color4(255, 182, 193, 255); } }
538
539         /// <summary>
540         /// Gets the system color with (R, G, B, A) = (255, 160, 122, 255).
541         /// </summary>
542         public static Color4 LightSalmon { get { return new Color4(255, 160, 122, 255); } }
543
544         /// <summary>
545         /// Gets the system color with (R, G, B, A) = (32, 178, 170, 255).
546         /// </summary>
547         public static Color4 LightSeaGreen { get { return new Color4(32, 178, 170, 255); } }
548
549         /// <summary>
550         /// Gets the system color with (R, G, B, A) = (135, 206, 250, 255).
551         /// </summary>
552         public static Color4 LightSkyBlue { get { return new Color4(135, 206, 250, 255); } }
553
554         /// <summary>
555         /// Gets the system color with (R, G, B, A) = (119, 136, 153, 255).
556         /// </summary>
557         public static Color4 LightSlateGray { get { return new Color4(119, 136, 153, 255); } }
558
559         /// <summary>
560         /// Gets the system color with (R, G, B, A) = (176, 196, 222, 255).
561         /// </summary>
562         public static Color4 LightSteelBlue { get { return new Color4(176, 196, 222, 255); } }
563
564         /// <summary>
565         /// Gets the system color with (R, G, B, A) = (255, 255, 224, 255).
566         /// </summary>
567         public static Color4 LightYellow { get { return new Color4(255, 255, 224, 255); } }
568
569         /// <summary>
570         /// Gets the system color with (R, G, B, A) = (0, 255, 0, 255).
571         /// </summary>
572         public static Color4 Lime { get { return new Color4(0, 255, 0, 255); } }
573
574         /// <summary>
575         /// Gets the system color with (R, G, B, A) = (50, 205, 50, 255).
576         /// </summary>
577         public static Color4 LimeGreen { get { return new Color4(50, 205, 50, 255); } }
578
579         /// <summary>
580         /// Gets the system color with (R, G, B, A) = (250, 240, 230, 255).
581         /// </summary>
582         public static Color4 Linen { get { return new Color4(250, 240, 230, 255); } }
583
584         /// <summary>
585         /// Gets the system color with (R, G, B, A) = (255, 0, 255, 255).
586         /// </summary>
587         public static Color4 Magenta { get { return new Color4(255, 0, 255, 255); } }
588
589         /// <summary>
590         /// Gets the system color with (R, G, B, A) = (128, 0, 0, 255).
591         /// </summary>
592         public static Color4 Maroon { get { return new Color4(128, 0, 0, 255); } }
593
594         /// <summary>
595         /// Gets the system color with (R, G, B, A) = (102, 205, 170, 255).
596         /// </summary>
597         public static Color4 MediumAquamarine { get { return new Color4(102, 205, 170, 255); } }
598
599         /// <summary>
600         /// Gets the system color with (R, G, B, A) = (0, 0, 205, 255).
601         /// </summary>
602         public static Color4 MediumBlue { get { return new Color4(0, 0, 205, 255); } }
603
604         /// <summary>
605         /// Gets the system color with (R, G, B, A) = (186, 85, 211, 255).
606         /// </summary>
607         public static Color4 MediumOrchid { get { return new Color4(186, 85, 211, 255); } }
608
609         /// <summary>
610         /// Gets the system color with (R, G, B, A) = (147, 112, 219, 255).
611         /// </summary>
612         public static Color4 MediumPurple { get { return new Color4(147, 112, 219, 255); } }
613
614         /// <summary>
615         /// Gets the system color with (R, G, B, A) = (60, 179, 113, 255).
616         /// </summary>
617         public static Color4 MediumSeaGreen { get { return new Color4(60, 179, 113, 255); } }
618
619         /// <summary>
620         /// Gets the system color with (R, G, B, A) = (123, 104, 238, 255).
621         /// </summary>
622         public static Color4 MediumSlateBlue { get { return new Color4(123, 104, 238, 255); } }
623
624         /// <summary>
625         /// Gets the system color with (R, G, B, A) = (0, 250, 154, 255).
626         /// </summary>
627         public static Color4 MediumSpringGreen { get { return new Color4(0, 250, 154, 255); } }
628
629         /// <summary>
630         /// Gets the system color with (R, G, B, A) = (72, 209, 204, 255).
631         /// </summary>
632         public static Color4 MediumTurquoise { get { return new Color4(72, 209, 204, 255); } }
633
634         /// <summary>
635         /// Gets the system color with (R, G, B, A) = (199, 21, 133, 255).
636         /// </summary>
637         public static Color4 MediumVioletRed { get { return new Color4(199, 21, 133, 255); } }
638
639         /// <summary>
640         /// Gets the system color with (R, G, B, A) = (25, 25, 112, 255).
641         /// </summary>
642         public static Color4 MidnightBlue { get { return new Color4(25, 25, 112, 255); } }
643
644         /// <summary>
645         /// Gets the system color with (R, G, B, A) = (245, 255, 250, 255).
646         /// </summary>
647         public static Color4 MintCream { get { return new Color4(245, 255, 250, 255); } }
648
649         /// <summary>
650         /// Gets the system color with (R, G, B, A) = (255, 228, 225, 255).
651         /// </summary>
652         public static Color4 MistyRose { get { return new Color4(255, 228, 225, 255); } }
653
654         /// <summary>
655         /// Gets the system color with (R, G, B, A) = (255, 228, 181, 255).
656         /// </summary>
657         public static Color4 Moccasin { get { return new Color4(255, 228, 181, 255); } }
658
659         /// <summary>
660         /// Gets the system color with (R, G, B, A) = (255, 222, 173, 255).
661         /// </summary>
662         public static Color4 NavajoWhite { get { return new Color4(255, 222, 173, 255); } }
663
664         /// <summary>
665         /// Gets the system color with (R, G, B, A) = (0, 0, 128, 255).
666         /// </summary>
667         public static Color4 Navy { get { return new Color4(0, 0, 128, 255); } }
668
669         /// <summary>
670         /// Gets the system color with (R, G, B, A) = (253, 245, 230, 255).
671         /// </summary>
672         public static Color4 OldLace { get { return new Color4(253, 245, 230, 255); } }
673
674         /// <summary>
675         /// Gets the system color with (R, G, B, A) = (128, 128, 0, 255).
676         /// </summary>
677         public static Color4 Olive { get { return new Color4(128, 128, 0, 255); } }
678
679         /// <summary>
680         /// Gets the system color with (R, G, B, A) = (107, 142, 35, 255).
681         /// </summary>
682         public static Color4 OliveDrab { get { return new Color4(107, 142, 35, 255); } }
683
684         /// <summary>
685         /// Gets the system color with (R, G, B, A) = (255, 165, 0, 255).
686         /// </summary>
687         public static Color4 Orange { get { return new Color4(255, 165, 0, 255); } }
688
689         /// <summary>
690         /// Gets the system color with (R, G, B, A) = (255, 69, 0, 255).
691         /// </summary>
692         public static Color4 OrangeRed { get { return new Color4(255, 69, 0, 255); } }
693
694         /// <summary>
695         /// Gets the system color with (R, G, B, A) = (218, 112, 214, 255).
696         /// </summary>
697         public static Color4 Orchid { get { return new Color4(218, 112, 214, 255); } }
698
699         /// <summary>
700         /// Gets the system color with (R, G, B, A) = (238, 232, 170, 255).
701         /// </summary>
702         public static Color4 PaleGoldenrod { get { return new Color4(238, 232, 170, 255); } }
703
704         /// <summary>
705         /// Gets the system color with (R, G, B, A) = (152, 251, 152, 255).
706         /// </summary>
707         public static Color4 PaleGreen { get { return new Color4(152, 251, 152, 255); } }
708
709         /// <summary>
710         /// Gets the system color with (R, G, B, A) = (175, 238, 238, 255).
711         /// </summary>
712         public static Color4 PaleTurquoise { get { return new Color4(175, 238, 238, 255); } }
713
714         /// <summary>
715         /// Gets the system color with (R, G, B, A) = (219, 112, 147, 255).
716         /// </summary>
717         public static Color4 PaleVioletRed { get { return new Color4(219, 112, 147, 255); } }
718
719         /// <summary>
720         /// Gets the system color with (R, G, B, A) = (255, 239, 213, 255).
721         /// </summary>
722         public static Color4 PapayaWhip { get { return new Color4(255, 239, 213, 255); } }
723
724         /// <summary>
725         /// Gets the system color with (R, G, B, A) = (255, 218, 185, 255).
726         /// </summary>
727         public static Color4 PeachPuff { get { return new Color4(255, 218, 185, 255); } }
728
729         /// <summary>
730         /// Gets the system color with (R, G, B, A) = (205, 133, 63, 255).
731         /// </summary>
732         public static Color4 Peru { get { return new Color4(205, 133, 63, 255); } }
733
734         /// <summary>
735         /// Gets the system color with (R, G, B, A) = (255, 192, 203, 255).
736         /// </summary>
737         public static Color4 Pink { get { return new Color4(255, 192, 203, 255); } }
738
739         /// <summary>
740         /// Gets the system color with (R, G, B, A) = (221, 160, 221, 255).
741         /// </summary>
742         public static Color4 Plum { get { return new Color4(221, 160, 221, 255); } }
743
744         /// <summary>
745         /// Gets the system color with (R, G, B, A) = (176, 224, 230, 255).
746         /// </summary>
747         public static Color4 PowderBlue { get { return new Color4(176, 224, 230, 255); } }
748
749         /// <summary>
750         /// Gets the system color with (R, G, B, A) = (128, 0, 128, 255).
751         /// </summary>
752         public static Color4 Purple { get { return new Color4(128, 0, 128, 255); } }
753
754         /// <summary>
755         /// Gets the system color with (R, G, B, A) = (255, 0, 0, 255).
756         /// </summary>
757         public static Color4 Red { get { return new Color4(255, 0, 0, 255); } }
758
759         /// <summary>
760         /// Gets the system color with (R, G, B, A) = (188, 143, 143, 255).
761         /// </summary>
762         public static Color4 RosyBrown { get { return new Color4(188, 143, 143, 255); } }
763
764         /// <summary>
765         /// Gets the system color with (R, G, B, A) = (65, 105, 225, 255).
766         /// </summary>
767         public static Color4 RoyalBlue { get { return new Color4(65, 105, 225, 255); } }
768
769         /// <summary>
770         /// Gets the system color with (R, G, B, A) = (139, 69, 19, 255).
771         /// </summary>
772         public static Color4 SaddleBrown { get { return new Color4(139, 69, 19, 255); } }
773
774         /// <summary>
775         /// Gets the system color with (R, G, B, A) = (250, 128, 114, 255).
776         /// </summary>
777         public static Color4 Salmon { get { return new Color4(250, 128, 114, 255); } }
778
779         /// <summary>
780         /// Gets the system color with (R, G, B, A) = (244, 164, 96, 255).
781         /// </summary>
782         public static Color4 SandyBrown { get { return new Color4(244, 164, 96, 255); } }
783
784         /// <summary>
785         /// Gets the system color with (R, G, B, A) = (46, 139, 87, 255).
786         /// </summary>
787         public static Color4 SeaGreen { get { return new Color4(46, 139, 87, 255); } }
788
789         /// <summary>
790         /// Gets the system color with (R, G, B, A) = (255, 245, 238, 255).
791         /// </summary>
792         public static Color4 SeaShell { get { return new Color4(255, 245, 238, 255); } }
793
794         /// <summary>
795         /// Gets the system color with (R, G, B, A) = (160, 82, 45, 255).
796         /// </summary>
797         public static Color4 Sienna { get { return new Color4(160, 82, 45, 255); } }
798
799         /// <summary>
800         /// Gets the system color with (R, G, B, A) = (192, 192, 192, 255).
801         /// </summary>
802         public static Color4 Silver { get { return new Color4(192, 192, 192, 255); } }
803
804         /// <summary>
805         /// Gets the system color with (R, G, B, A) = (135, 206, 235, 255).
806         /// </summary>
807         public static Color4 SkyBlue { get { return new Color4(135, 206, 235, 255); } }
808
809         /// <summary>
810         /// Gets the system color with (R, G, B, A) = (106, 90, 205, 255).
811         /// </summary>
812         public static Color4 SlateBlue { get { return new Color4(106, 90, 205, 255); } }
813
814         /// <summary>
815         /// Gets the system color with (R, G, B, A) = (112, 128, 144, 255).
816         /// </summary>
817         public static Color4 SlateGray { get { return new Color4(112, 128, 144, 255); } }
818
819         /// <summary>
820         /// Gets the system color with (R, G, B, A) = (255, 250, 250, 255).
821         /// </summary>
822         public static Color4 Snow { get { return new Color4(255, 250, 250, 255); } }
823
824         /// <summary>
825         /// Gets the system color with (R, G, B, A) = (0, 255, 127, 255).
826         /// </summary>
827         public static Color4 SpringGreen { get { return new Color4(0, 255, 127, 255); } }
828
829         /// <summary>
830         /// Gets the system color with (R, G, B, A) = (70, 130, 180, 255).
831         /// </summary>
832         public static Color4 SteelBlue { get { return new Color4(70, 130, 180, 255); } }
833
834         /// <summary>
835         /// Gets the system color with (R, G, B, A) = (210, 180, 140, 255).
836         /// </summary>
837         public static Color4 Tan { get { return new Color4(210, 180, 140, 255); } }
838
839         /// <summary>
840         /// Gets the system color with (R, G, B, A) = (0, 128, 128, 255).
841         /// </summary>
842         public static Color4 Teal { get { return new Color4(0, 128, 128, 255); } }
843
844         /// <summary>
845         /// Gets the system color with (R, G, B, A) = (216, 191, 216, 255).
846         /// </summary>
847         public static Color4 Thistle { get { return new Color4(216, 191, 216, 255); } }
848
849         /// <summary>
850         /// Gets the system color with (R, G, B, A) = (255, 99, 71, 255).
851         /// </summary>
852         public static Color4 Tomato { get { return new Color4(255, 99, 71, 255); } }
853
854         /// <summary>
855         /// Gets the system color with (R, G, B, A) = (64, 224, 208, 255).
856         /// </summary>
857         public static Color4 Turquoise { get { return new Color4(64, 224, 208, 255); } }
858
859         /// <summary>
860         /// Gets the system color with (R, G, B, A) = (238, 130, 238, 255).
861         /// </summary>
862         public static Color4 Violet { get { return new Color4(238, 130, 238, 255); } }
863
864         /// <summary>
865         /// Gets the system color with (R, G, B, A) = (245, 222, 179, 255).
866         /// </summary>
867         public static Color4 Wheat { get { return new Color4(245, 222, 179, 255); } }
868
869         /// <summary>
870         /// Gets the system color with (R, G, B, A) = (255, 255, 255, 255).
871         /// </summary>
872         public static Color4 White { get { return new Color4(255, 255, 255, 255); } }
873
874         /// <summary>
875         /// Gets the system color with (R, G, B, A) = (245, 245, 245, 255).
876         /// </summary>
877         public static Color4 WhiteSmoke { get { return new Color4(245, 245, 245, 255); } }
878
879         /// <summary>
880         /// Gets the system color with (R, G, B, A) = (255, 255, 0, 255).
881         /// </summary>
882         public static Color4 Yellow { get { return new Color4(255, 255, 0, 255); } }
883
884         /// <summary>
885         /// Gets the system color with (R, G, B, A) = (154, 205, 50, 255).
886         /// </summary>
887         public static Color4 YellowGreen { get { return new Color4(154, 205, 50, 255); } }
888
889         /// <summary>
890         /// Converts sRGB color values to RGB color values.
891         /// </summary>
892         /// <returns>
893         /// Returns the converted color value.
894         /// </returns>
895         /// <param name="srgb">
896         /// Color value to convert in sRGB.
897         /// </param>
898         public static Color4 FromSrgb(Color4 srgb)
899         {
900             float r, g, b;
901
902             if (srgb.R <= 0.04045f)
903             {
904                 r = srgb.R / 12.92f;
905             }
906             else
907             {
908                 r = (float)Math.Pow((srgb.R + 0.055f) / (1.0f + 0.055f), 2.4f);
909             }
910
911             if (srgb.G <= 0.04045f)
912             {
913                 g = srgb.G / 12.92f;
914             }
915             else
916             {
917                 g = (float)Math.Pow((srgb.G + 0.055f) / (1.0f + 0.055f), 2.4f);
918             }
919
920             if (srgb.B <= 0.04045f)
921             {
922                 b = srgb.B / 12.92f;
923             }
924             else
925             {
926                 b = (float)Math.Pow((srgb.B + 0.055f) / (1.0f + 0.055f), 2.4f);
927             }
928
929             return new Color4(r, g, b, srgb.A);
930         }
931
932         /// <summary>
933         /// Converts RGB color values to sRGB color values.
934         /// </summary>
935         /// <returns>
936         /// Returns the converted color value.
937         /// </returns>
938         /// <param name="rgb">Color value to convert.</param>
939         public static Color4 ToSrgb(Color4 rgb)
940         {
941             float r, g, b;
942
943             if (rgb.R <= 0.0031308)
944             {
945                 r = 12.92f * rgb.R;
946             }
947             else
948             {
949                 r = (1.0f + 0.055f) * (float)Math.Pow(rgb.R, 1.0f / 2.4f) - 0.055f;
950             }
951
952             if (rgb.G <= 0.0031308)
953             {
954                 g = 12.92f * rgb.G;
955             }
956             else
957             {
958                 g = (1.0f + 0.055f) * (float)Math.Pow(rgb.G, 1.0f / 2.4f) - 0.055f;
959             }
960
961             if (rgb.B <= 0.0031308)
962             {
963                 b = 12.92f * rgb.B;
964             }
965             else
966             {
967                 b = (1.0f + 0.055f) * (float)Math.Pow(rgb.B, 1.0f / 2.4f) - 0.055f;
968             }
969
970             return new Color4(r, g, b, rgb.A);
971         }
972
973         /// <summary>
974         /// Converts HSL color values to RGB color values.
975         /// </summary>
976         /// <returns>
977         /// Returns the converted color value.
978         /// </returns>
979         /// <param name="hsl">
980         /// Color value to convert in hue, saturation, lightness (HSL).
981         /// The X element is Hue (H), the Y element is Saturation (S), the Z element is Lightness (L), and the W element is Alpha (which is copied to the output's Alpha value).
982         /// Each has a range of 0.0 to 1.0.
983         /// </param>
984         public static Color4 FromHsl(Vector4 hsl)
985         {
986             var hue = hsl.X * 360.0f;
987             var saturation = hsl.Y;
988             var lightness = hsl.Z;
989
990             var C = (1.0f - Math.Abs(2.0f * lightness - 1.0f)) * saturation;
991
992             var h = hue / 60.0f;
993             var X = C * (1.0f - Math.Abs(h % 2.0f - 1.0f));
994
995             float r, g, b;
996             if (0.0f <= h && h < 1.0f)
997             {
998                 r = C;
999                 g = X;
1000                 b = 0.0f;
1001             }
1002             else if (1.0f <= h && h < 2.0f)
1003             {
1004                 r = X;
1005                 g = C;
1006                 b = 0.0f;
1007             }
1008             else if (2.0f <= h && h < 3.0f)
1009             {
1010                 r = 0.0f;
1011                 g = C;
1012                 b = X;
1013             }
1014             else if (3.0f <= h && h < 4.0f)
1015             {
1016                 r = 0.0f;
1017                 g = X;
1018                 b = C;
1019             }
1020             else if (4.0f <= h && h < 5.0f)
1021             {
1022                 r = X;
1023                 g = 0.0f;
1024                 b = C;
1025             }
1026             else if (5.0f <= h && h < 6.0f)
1027             {
1028                 r = C;
1029                 g = 0.0f;
1030                 b = X;
1031             }
1032             else
1033             {
1034                 r = 0.0f;
1035                 g = 0.0f;
1036                 b = 0.0f;
1037             }
1038
1039             var m = lightness - (C / 2.0f);
1040             return new Color4(r + m, g + m, b + m, hsl.W);
1041         }
1042
1043         /// <summary>
1044         /// Converts RGB color values to HSL color values.
1045         /// </summary>
1046         /// <returns>
1047         /// Returns the converted color value.
1048         /// The X element is Hue (H), the Y element is Saturation (S), the Z element is Lightness (L), and the W element is Alpha (a copy of the input's Alpha value).
1049         /// Each has a range of 0.0 to 1.0.
1050         /// </returns>
1051         /// <param name="rgb">Color value to convert.</param>
1052         public static Vector4 ToHsl(Color4 rgb)
1053         {
1054             var M = Math.Max(rgb.R, Math.Max(rgb.G, rgb.B));
1055             var m = Math.Min(rgb.R, Math.Min(rgb.G, rgb.B));
1056             var C = M - m;
1057
1058             float h = 0.0f;
1059             if (M == rgb.R)
1060             {
1061                 h = ((rgb.G - rgb.B) / C);
1062             }
1063             else if (M == rgb.G)
1064             {
1065                 h = ((rgb.B - rgb.R) / C) + 2.0f;
1066             }
1067             else if (M == rgb.B)
1068             {
1069                 h = ((rgb.R - rgb.G) / C) + 4.0f;
1070             }
1071
1072             var hue = h / 6.0f;
1073             if (hue < 0.0f)
1074             {
1075                 hue += 1.0f;
1076             }
1077
1078             var lightness = (M + m) / 2.0f;
1079
1080             var saturation = 0.0f;
1081             if (0.0f != lightness && lightness != 1.0f)
1082             {
1083                 saturation = C / (1.0f - Math.Abs(2.0f * lightness - 1.0f));
1084             }
1085
1086             return new Vector4(hue, saturation, lightness, rgb.A);
1087         }
1088
1089         /// <summary>
1090         /// Converts HSV color values to RGB color values.
1091         /// </summary>
1092         /// <returns>
1093         /// Returns the converted color value.
1094         /// </returns>
1095         /// <param name="hsv">
1096         /// Color value to convert in hue, saturation, value (HSV).
1097         /// The X element is Hue (H), the Y element is Saturation (S), the Z element is Value (V), and the W element is Alpha (which is copied to the output's Alpha value).
1098         /// Each has a range of 0.0 to 1.0.
1099         /// </param>
1100         public static Color4 FromHsv(Vector4 hsv)
1101         {
1102             var hue = hsv.X * 360.0f;
1103             var saturation = hsv.Y;
1104             var value = hsv.Z;
1105
1106             var C = value * saturation;
1107
1108             var h = hue / 60.0f;
1109             var X = C * (1.0f - Math.Abs(h % 2.0f - 1.0f));
1110
1111             float r, g, b;
1112             if (0.0f <= h && h < 1.0f)
1113             {
1114                 r = C;
1115                 g = X;
1116                 b = 0.0f;
1117             }
1118             else if (1.0f <= h && h < 2.0f)
1119             {
1120                 r = X;
1121                 g = C;
1122                 b = 0.0f;
1123             }
1124             else if (2.0f <= h && h < 3.0f)
1125             {
1126                 r = 0.0f;
1127                 g = C;
1128                 b = X;
1129             }
1130             else if (3.0f <= h && h < 4.0f)
1131             {
1132                 r = 0.0f;
1133                 g = X;
1134                 b = C;
1135             }
1136             else if (4.0f <= h && h < 5.0f)
1137             {
1138                 r = X;
1139                 g = 0.0f;
1140                 b = C;
1141             }
1142             else if (5.0f <= h && h < 6.0f)
1143             {
1144                 r = C;
1145                 g = 0.0f;
1146                 b = X;
1147             }
1148             else
1149             {
1150                 r = 0.0f;
1151                 g = 0.0f;
1152                 b = 0.0f;
1153             }
1154
1155             var m = value - C;
1156             return new Color4(r + m, g + m, b + m, hsv.W);
1157         }
1158
1159         /// <summary>
1160         /// Converts RGB color values to HSV color values.
1161         /// </summary>
1162         /// <returns>
1163         /// Returns the converted color value.
1164         /// The X element is Hue (H), the Y element is Saturation (S), the Z element is Value (V), and the W element is Alpha (a copy of the input's Alpha value).
1165         /// Each has a range of 0.0 to 1.0.
1166         /// </returns>
1167         /// <param name="rgb">Color value to convert.</param>
1168         public static Vector4 ToHsv(Color4 rgb)
1169         {
1170             var M = Math.Max(rgb.R, Math.Max(rgb.G, rgb.B));
1171             var m = Math.Min(rgb.R, Math.Min(rgb.G, rgb.B));
1172             var C = M - m;
1173
1174             float h = 0.0f;
1175             if (M == rgb.R)
1176             {
1177                 h = ((rgb.G - rgb.B) / C) % 6.0f;
1178             }
1179             else if (M == rgb.G)
1180             {
1181                 h = ((rgb.B - rgb.R) / C) + 2.0f;
1182             }
1183             else if (M == rgb.B)
1184             {
1185                 h = ((rgb.R - rgb.G) / C) + 4.0f;
1186             }
1187
1188             var hue = (h * 60.0f) / 360.0f;
1189
1190             var saturation = 0.0f;
1191             if (0.0f != M)
1192             {
1193                 saturation = C / M;
1194             }
1195
1196             return new Vector4(hue, saturation, M, rgb.A);
1197         }
1198
1199         /// <summary>
1200         /// Converts XYZ color values to RGB color values.
1201         /// </summary>
1202         /// <returns>
1203         /// Returns the converted color value.
1204         /// </returns>
1205         /// <param name="xyz">
1206         /// Color value to convert with the trisimulus values of X, Y, and Z in the corresponding element, and the W element with Alpha (which is copied to the output's Alpha value).
1207         /// Each has a range of 0.0 to 1.0.
1208         /// </param>
1209         /// <remarks>Uses the CIE XYZ colorspace.</remarks>
1210         public static Color4 FromXyz(Vector4 xyz)
1211         {
1212             var r = 0.41847f * xyz.X + -0.15866f * xyz.Y + -0.082835f * xyz.Z;
1213             var g = -0.091169f * xyz.X + 0.25243f * xyz.Y + 0.015708f * xyz.Z;
1214             var b = 0.00092090f * xyz.X + -0.0025498f * xyz.Y + 0.17860f * xyz.Z;
1215             return new Color4(r, g, b, xyz.W);
1216         }
1217
1218         /// <summary>
1219         /// Converts RGB color values to XYZ color values.
1220         /// </summary>
1221         /// <returns>
1222         /// Returns the converted color value with the trisimulus values of X, Y, and Z in the corresponding element, and the W element with Alpha (a copy of the input's Alpha value).
1223         /// Each has a range of 0.0 to 1.0.
1224         /// </returns>
1225         /// <param name="rgb">Color value to convert.</param>
1226         /// <remarks>Uses the CIE XYZ colorspace.</remarks>
1227         public static Vector4 ToXyz(Color4 rgb)
1228         {
1229             var x = (0.49f * rgb.R + 0.31f * rgb.G + 0.20f * rgb.B) / 0.17697f;
1230             var y = (0.17697f * rgb.R + 0.81240f * rgb.G + 0.01063f * rgb.B) / 0.17697f;
1231             var z = (0.00f * rgb.R + 0.01f * rgb.G + 0.99f * rgb.B) / 0.17697f;
1232             return new Vector4(x, y, z, rgb.A);
1233         }
1234
1235         /// <summary>
1236         /// Converts YCbCr color values to RGB color values.
1237         /// </summary>
1238         /// <returns>
1239         /// Returns the converted color value.
1240         /// </returns>
1241         /// <param name="ycbcr">
1242         /// Color value to convert in Luma-Chrominance (YCbCr) aka YUV.
1243         /// The X element contains Luma (Y, 0.0 to 1.0), the Y element contains Blue-difference chroma (U, -0.5 to 0.5), the Z element contains the Red-difference chroma (V, -0.5 to 0.5), and the W element contains the Alpha (which is copied to the output's Alpha value).
1244         /// </param>
1245         /// <remarks>Converts using ITU-R BT.601/CCIR 601 W(r) = 0.299 W(b) = 0.114 U(max) = 0.436 V(max) = 0.615.</remarks>
1246         public static Color4 FromYcbcr(Vector4 ycbcr)
1247         {
1248             var r = 1.0f * ycbcr.X + 0.0f * ycbcr.Y + 1.402f * ycbcr.Z;
1249             var g = 1.0f * ycbcr.X + -0.344136f * ycbcr.Y + -0.714136f * ycbcr.Z;
1250             var b = 1.0f * ycbcr.X + 1.772f * ycbcr.Y + 0.0f * ycbcr.Z;
1251             return new Color4(r, g, b, ycbcr.W);
1252         }
1253
1254         /// <summary>
1255         /// Converts RGB color values to YUV color values.
1256         /// </summary>
1257         /// <returns>
1258         /// Returns the converted color value in Luma-Chrominance (YCbCr) aka YUV.
1259         /// The X element contains Luma (Y, 0.0 to 1.0), the Y element contains Blue-difference chroma (U, -0.5 to 0.5), the Z element contains the Red-difference chroma (V, -0.5 to 0.5), and the W element contains the Alpha (a copy of the input's Alpha value).
1260         /// Each has a range of 0.0 to 1.0.
1261         /// </returns>
1262         /// <param name="rgb">Color value to convert.</param>
1263         /// <remarks>Converts using ITU-R BT.601/CCIR 601 W(r) = 0.299 W(b) = 0.114 U(max) = 0.436 V(max) = 0.615.</remarks>
1264         public static Vector4 ToYcbcr(Color4 rgb)
1265         {
1266             var y = 0.299f * rgb.R + 0.587f * rgb.G + 0.114f * rgb.B;
1267             var u = -0.168736f * rgb.R + -0.331264f * rgb.G + 0.5f * rgb.B;
1268             var v = 0.5f * rgb.R + -0.418688f * rgb.G + -0.081312f * rgb.B;
1269             return new Vector4(y, u, v, rgb.A);
1270         }
1271
1272         /// <summary>
1273         /// Converts HCY color values to RGB color values.
1274         /// </summary>
1275         /// <returns>
1276         /// Returns the converted color value.
1277         /// </returns>
1278         /// <param name="hcy">
1279         /// Color value to convert in hue, chroma, luminance (HCY).
1280         /// The X element is Hue (H), the Y element is Chroma (C), the Z element is luminance (Y), and the W element is Alpha (which is copied to the output's Alpha value).
1281         /// Each has a range of 0.0 to 1.0.
1282         /// </param>
1283         public static Color4 FromHcy(Vector4 hcy)
1284         {
1285             var hue = hcy.X * 360.0f;
1286             var C = hcy.Y;
1287             var luminance = hcy.Z;
1288
1289             var h = hue / 60.0f;
1290             var X = C * (1.0f - Math.Abs(h % 2.0f - 1.0f));
1291
1292             float r, g, b;
1293             if (0.0f <= h && h < 1.0f)
1294             {
1295                 r = C;
1296                 g = X;
1297                 b = 0.0f;
1298             }
1299             else if (1.0f <= h && h < 2.0f)
1300             {
1301                 r = X;
1302                 g = C;
1303                 b = 0.0f;
1304             }
1305             else if (2.0f <= h && h < 3.0f)
1306             {
1307                 r = 0.0f;
1308                 g = C;
1309                 b = X;
1310             }
1311             else if (3.0f <= h && h < 4.0f)
1312             {
1313                 r = 0.0f;
1314                 g = X;
1315                 b = C;
1316             }
1317             else if (4.0f <= h && h < 5.0f)
1318             {
1319                 r = X;
1320                 g = 0.0f;
1321                 b = C;
1322             }
1323             else if (5.0f <= h && h < 6.0f)
1324             {
1325                 r = C;
1326                 g = 0.0f;
1327                 b = X;
1328             }
1329             else
1330             {
1331                 r = 0.0f;
1332                 g = 0.0f;
1333                 b = 0.0f;
1334             }
1335
1336             var m = luminance - (0.30f * r + 0.59f * g + 0.11f * b);
1337             return new Color4(r + m, g + m, b + m, hcy.W);
1338         }
1339
1340         /// <summary>
1341         /// Converts RGB color values to HCY color values.
1342         /// </summary>
1343         /// <returns>
1344         /// Returns the converted color value.
1345         /// The X element is Hue (H), the Y element is Chroma (C), the Z element is luminance (Y), and the W element is Alpha (a copy of the input's Alpha value).
1346         /// Each has a range of 0.0 to 1.0.
1347         /// </returns>
1348         /// <param name="rgb">Color value to convert.</param>
1349         public static Vector4 ToHcy(Color4 rgb)
1350         {
1351             var M = Math.Max(rgb.R, Math.Max(rgb.G, rgb.B));
1352             var m = Math.Min(rgb.R, Math.Min(rgb.G, rgb.B));
1353             var C = M - m;
1354
1355             float h = 0.0f;
1356             if (M == rgb.R)
1357             {
1358                 h = ((rgb.G - rgb.B) / C) % 6.0f;
1359             }
1360             else if (M == rgb.G)
1361             {
1362                 h = ((rgb.B - rgb.R) / C) + 2.0f;
1363             }
1364             else if (M == rgb.B)
1365             {
1366                 h = ((rgb.R - rgb.G) / C) + 4.0f;
1367             }
1368
1369             var hue = (h * 60.0f) / 360.0f;
1370
1371             var luminance = 0.30f * rgb.R + 0.59f * rgb.G + 0.11f * rgb.B;
1372
1373             return new Vector4(hue, C, luminance, rgb.A);
1374         }
1375
1376         /// <summary>
1377         /// Compares whether this Color4 structure is equal to the specified Color4.
1378         /// </summary>
1379         /// <param name="other">The Color4 structure to compare to.</param>
1380         /// <returns>True if both Color4 structures contain the same components; false otherwise.</returns>
1381         public bool Equals(Color4 other)
1382         {
1383             return
1384                 this.R == other.R &&
1385                 this.G == other.G &&
1386                 this.B == other.B &&
1387                 this.A == other.A;
1388         }
1389     }
1390 }