2 // The Open Toolkit Library License
4 // Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
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:
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
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.
31 namespace OpenTK.Graphics
34 /// Represents a color with 4 floating-point components (R, G, B, A).
37 public struct Color4 : IEquatable<Color4>
40 /// The red component of this Color4 structure.
45 /// The green component of this Color4 structure.
50 /// The blue component of this Color4 structure.
55 /// The alpha component of this Color4 structure.
60 /// Constructs a new Color4 structure from the specified components.
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)
75 /// Constructs a new Color4 structure from the specified components.
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)
83 R = r / (float)Byte.MaxValue;
84 G = g / (float)Byte.MaxValue;
85 B = b / (float)Byte.MaxValue;
86 A = a / (float)Byte.MaxValue;
90 /// Converts this color to an integer representation with 8 bits per channel.
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>
97 (uint)(A * Byte.MaxValue) << 24 |
98 (uint)(R * Byte.MaxValue) << 16 |
99 (uint)(G * Byte.MaxValue) << 8 |
100 (uint)(B * Byte.MaxValue);
102 return unchecked((int)value);
106 /// Compares the specified Color4 structures for equality.
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)
113 return left.Equals(right);
117 /// Compares the specified Color4 structures for inequality.
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)
124 return !left.Equals(right);
128 /// Converts the specified System.Drawing.Color to a Color4 structure.
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)
134 return new Color4(color.R, color.G, color.B, color.A);
138 /// Converts the specified Color4 to a System.Drawing.Color structure.
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)
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));
152 /// Compares whether this Color4 structure is equal to the specified object.
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)
158 if (!(obj is Color4))
163 return Equals((Color4)obj);
167 /// Calculates the hash code for this Color4 structure.
169 /// <returns>A System.Int32 containing the hashcode of this Color4 structure.</returns>
170 public override int GetHashCode()
176 /// Creates a System.String that describes this Color4 structure.
178 /// <returns>A System.String that describes this Color4 structure.</returns>
179 public override string ToString()
181 return String.Format("{{(R, G, B, A) = ({0}, {1}, {2}, {3})}}", R.ToString(), G.ToString(), B.ToString(), A.ToString());
185 /// Gets the system color with (R, G, B, A) = (255, 255, 255, 0).
187 public static Color4 Transparent { get { return new Color4(255, 255, 255, 0); } }
190 /// Gets the system color with (R, G, B, A) = (240, 248, 255, 255).
192 public static Color4 AliceBlue { get { return new Color4(240, 248, 255, 255); } }
195 /// Gets the system color with (R, G, B, A) = (250, 235, 215, 255).
197 public static Color4 AntiqueWhite { get { return new Color4(250, 235, 215, 255); } }
200 /// Gets the system color with (R, G, B, A) = (0, 255, 255, 255).
202 public static Color4 Aqua { get { return new Color4(0, 255, 255, 255); } }
205 /// Gets the system color with (R, G, B, A) = (127, 255, 212, 255).
207 public static Color4 Aquamarine { get { return new Color4(127, 255, 212, 255); } }
210 /// Gets the system color with (R, G, B, A) = (240, 255, 255, 255).
212 public static Color4 Azure { get { return new Color4(240, 255, 255, 255); } }
215 /// Gets the system color with (R, G, B, A) = (245, 245, 220, 255).
217 public static Color4 Beige { get { return new Color4(245, 245, 220, 255); } }
220 /// Gets the system color with (R, G, B, A) = (255, 228, 196, 255).
222 public static Color4 Bisque { get { return new Color4(255, 228, 196, 255); } }
225 /// Gets the system color with (R, G, B, A) = (0, 0, 0, 255).
227 public static Color4 Black { get { return new Color4(0, 0, 0, 255); } }
230 /// Gets the system color with (R, G, B, A) = (255, 235, 205, 255).
232 public static Color4 BlanchedAlmond { get { return new Color4(255, 235, 205, 255); } }
235 /// Gets the system color with (R, G, B, A) = (0, 0, 255, 255).
237 public static Color4 Blue { get { return new Color4(0, 0, 255, 255); } }
240 /// Gets the system color with (R, G, B, A) = (138, 43, 226, 255).
242 public static Color4 BlueViolet { get { return new Color4(138, 43, 226, 255); } }
245 /// Gets the system color with (R, G, B, A) = (165, 42, 42, 255).
247 public static Color4 Brown { get { return new Color4(165, 42, 42, 255); } }
250 /// Gets the system color with (R, G, B, A) = (222, 184, 135, 255).
252 public static Color4 BurlyWood { get { return new Color4(222, 184, 135, 255); } }
255 /// Gets the system color with (R, G, B, A) = (95, 158, 160, 255).
257 public static Color4 CadetBlue { get { return new Color4(95, 158, 160, 255); } }
260 /// Gets the system color with (R, G, B, A) = (127, 255, 0, 255).
262 public static Color4 Chartreuse { get { return new Color4(127, 255, 0, 255); } }
265 /// Gets the system color with (R, G, B, A) = (210, 105, 30, 255).
267 public static Color4 Chocolate { get { return new Color4(210, 105, 30, 255); } }
270 /// Gets the system color with (R, G, B, A) = (255, 127, 80, 255).
272 public static Color4 Coral { get { return new Color4(255, 127, 80, 255); } }
275 /// Gets the system color with (R, G, B, A) = (100, 149, 237, 255).
277 public static Color4 CornflowerBlue { get { return new Color4(100, 149, 237, 255); } }
280 /// Gets the system color with (R, G, B, A) = (255, 248, 220, 255).
282 public static Color4 Cornsilk { get { return new Color4(255, 248, 220, 255); } }
285 /// Gets the system color with (R, G, B, A) = (220, 20, 60, 255).
287 public static Color4 Crimson { get { return new Color4(220, 20, 60, 255); } }
290 /// Gets the system color with (R, G, B, A) = (0, 255, 255, 255).
292 public static Color4 Cyan { get { return new Color4(0, 255, 255, 255); } }
295 /// Gets the system color with (R, G, B, A) = (0, 0, 139, 255).
297 public static Color4 DarkBlue { get { return new Color4(0, 0, 139, 255); } }
300 /// Gets the system color with (R, G, B, A) = (0, 139, 139, 255).
302 public static Color4 DarkCyan { get { return new Color4(0, 139, 139, 255); } }
305 /// Gets the system color with (R, G, B, A) = (184, 134, 11, 255).
307 public static Color4 DarkGoldenrod { get { return new Color4(184, 134, 11, 255); } }
310 /// Gets the system color with (R, G, B, A) = (169, 169, 169, 255).
312 public static Color4 DarkGray { get { return new Color4(169, 169, 169, 255); } }
315 /// Gets the system color with (R, G, B, A) = (0, 100, 0, 255).
317 public static Color4 DarkGreen { get { return new Color4(0, 100, 0, 255); } }
320 /// Gets the system color with (R, G, B, A) = (189, 183, 107, 255).
322 public static Color4 DarkKhaki { get { return new Color4(189, 183, 107, 255); } }
325 /// Gets the system color with (R, G, B, A) = (139, 0, 139, 255).
327 public static Color4 DarkMagenta { get { return new Color4(139, 0, 139, 255); } }
330 /// Gets the system color with (R, G, B, A) = (85, 107, 47, 255).
332 public static Color4 DarkOliveGreen { get { return new Color4(85, 107, 47, 255); } }
335 /// Gets the system color with (R, G, B, A) = (255, 140, 0, 255).
337 public static Color4 DarkOrange { get { return new Color4(255, 140, 0, 255); } }
340 /// Gets the system color with (R, G, B, A) = (153, 50, 204, 255).
342 public static Color4 DarkOrchid { get { return new Color4(153, 50, 204, 255); } }
345 /// Gets the system color with (R, G, B, A) = (139, 0, 0, 255).
347 public static Color4 DarkRed { get { return new Color4(139, 0, 0, 255); } }
350 /// Gets the system color with (R, G, B, A) = (233, 150, 122, 255).
352 public static Color4 DarkSalmon { get { return new Color4(233, 150, 122, 255); } }
355 /// Gets the system color with (R, G, B, A) = (143, 188, 139, 255).
357 public static Color4 DarkSeaGreen { get { return new Color4(143, 188, 139, 255); } }
360 /// Gets the system color with (R, G, B, A) = (72, 61, 139, 255).
362 public static Color4 DarkSlateBlue { get { return new Color4(72, 61, 139, 255); } }
365 /// Gets the system color with (R, G, B, A) = (47, 79, 79, 255).
367 public static Color4 DarkSlateGray { get { return new Color4(47, 79, 79, 255); } }
370 /// Gets the system color with (R, G, B, A) = (0, 206, 209, 255).
372 public static Color4 DarkTurquoise { get { return new Color4(0, 206, 209, 255); } }
375 /// Gets the system color with (R, G, B, A) = (148, 0, 211, 255).
377 public static Color4 DarkViolet { get { return new Color4(148, 0, 211, 255); } }
380 /// Gets the system color with (R, G, B, A) = (255, 20, 147, 255).
382 public static Color4 DeepPink { get { return new Color4(255, 20, 147, 255); } }
385 /// Gets the system color with (R, G, B, A) = (0, 191, 255, 255).
387 public static Color4 DeepSkyBlue { get { return new Color4(0, 191, 255, 255); } }
390 /// Gets the system color with (R, G, B, A) = (105, 105, 105, 255).
392 public static Color4 DimGray { get { return new Color4(105, 105, 105, 255); } }
395 /// Gets the system color with (R, G, B, A) = (30, 144, 255, 255).
397 public static Color4 DodgerBlue { get { return new Color4(30, 144, 255, 255); } }
400 /// Gets the system color with (R, G, B, A) = (178, 34, 34, 255).
402 public static Color4 Firebrick { get { return new Color4(178, 34, 34, 255); } }
405 /// Gets the system color with (R, G, B, A) = (255, 250, 240, 255).
407 public static Color4 FloralWhite { get { return new Color4(255, 250, 240, 255); } }
410 /// Gets the system color with (R, G, B, A) = (34, 139, 34, 255).
412 public static Color4 ForestGreen { get { return new Color4(34, 139, 34, 255); } }
415 /// Gets the system color with (R, G, B, A) = (255, 0, 255, 255).
417 public static Color4 Fuchsia { get { return new Color4(255, 0, 255, 255); } }
420 /// Gets the system color with (R, G, B, A) = (220, 220, 220, 255).
422 public static Color4 Gainsboro { get { return new Color4(220, 220, 220, 255); } }
425 /// Gets the system color with (R, G, B, A) = (248, 248, 255, 255).
427 public static Color4 GhostWhite { get { return new Color4(248, 248, 255, 255); } }
430 /// Gets the system color with (R, G, B, A) = (255, 215, 0, 255).
432 public static Color4 Gold { get { return new Color4(255, 215, 0, 255); } }
435 /// Gets the system color with (R, G, B, A) = (218, 165, 32, 255).
437 public static Color4 Goldenrod { get { return new Color4(218, 165, 32, 255); } }
440 /// Gets the system color with (R, G, B, A) = (128, 128, 128, 255).
442 public static Color4 Gray { get { return new Color4(128, 128, 128, 255); } }
445 /// Gets the system color with (R, G, B, A) = (0, 128, 0, 255).
447 public static Color4 Green { get { return new Color4(0, 128, 0, 255); } }
450 /// Gets the system color with (R, G, B, A) = (173, 255, 47, 255).
452 public static Color4 GreenYellow { get { return new Color4(173, 255, 47, 255); } }
455 /// Gets the system color with (R, G, B, A) = (240, 255, 240, 255).
457 public static Color4 Honeydew { get { return new Color4(240, 255, 240, 255); } }
460 /// Gets the system color with (R, G, B, A) = (255, 105, 180, 255).
462 public static Color4 HotPink { get { return new Color4(255, 105, 180, 255); } }
465 /// Gets the system color with (R, G, B, A) = (205, 92, 92, 255).
467 public static Color4 IndianRed { get { return new Color4(205, 92, 92, 255); } }
470 /// Gets the system color with (R, G, B, A) = (75, 0, 130, 255).
472 public static Color4 Indigo { get { return new Color4(75, 0, 130, 255); } }
475 /// Gets the system color with (R, G, B, A) = (255, 255, 240, 255).
477 public static Color4 Ivory { get { return new Color4(255, 255, 240, 255); } }
480 /// Gets the system color with (R, G, B, A) = (240, 230, 140, 255).
482 public static Color4 Khaki { get { return new Color4(240, 230, 140, 255); } }
485 /// Gets the system color with (R, G, B, A) = (230, 230, 250, 255).
487 public static Color4 Lavender { get { return new Color4(230, 230, 250, 255); } }
490 /// Gets the system color with (R, G, B, A) = (255, 240, 245, 255).
492 public static Color4 LavenderBlush { get { return new Color4(255, 240, 245, 255); } }
495 /// Gets the system color with (R, G, B, A) = (124, 252, 0, 255).
497 public static Color4 LawnGreen { get { return new Color4(124, 252, 0, 255); } }
500 /// Gets the system color with (R, G, B, A) = (255, 250, 205, 255).
502 public static Color4 LemonChiffon { get { return new Color4(255, 250, 205, 255); } }
505 /// Gets the system color with (R, G, B, A) = (173, 216, 230, 255).
507 public static Color4 LightBlue { get { return new Color4(173, 216, 230, 255); } }
510 /// Gets the system color with (R, G, B, A) = (240, 128, 128, 255).
512 public static Color4 LightCoral { get { return new Color4(240, 128, 128, 255); } }
515 /// Gets the system color with (R, G, B, A) = (224, 255, 255, 255).
517 public static Color4 LightCyan { get { return new Color4(224, 255, 255, 255); } }
520 /// Gets the system color with (R, G, B, A) = (250, 250, 210, 255).
522 public static Color4 LightGoldenrodYellow { get { return new Color4(250, 250, 210, 255); } }
525 /// Gets the system color with (R, G, B, A) = (144, 238, 144, 255).
527 public static Color4 LightGreen { get { return new Color4(144, 238, 144, 255); } }
530 /// Gets the system color with (R, G, B, A) = (211, 211, 211, 255).
532 public static Color4 LightGray { get { return new Color4(211, 211, 211, 255); } }
535 /// Gets the system color with (R, G, B, A) = (255, 182, 193, 255).
537 public static Color4 LightPink { get { return new Color4(255, 182, 193, 255); } }
540 /// Gets the system color with (R, G, B, A) = (255, 160, 122, 255).
542 public static Color4 LightSalmon { get { return new Color4(255, 160, 122, 255); } }
545 /// Gets the system color with (R, G, B, A) = (32, 178, 170, 255).
547 public static Color4 LightSeaGreen { get { return new Color4(32, 178, 170, 255); } }
550 /// Gets the system color with (R, G, B, A) = (135, 206, 250, 255).
552 public static Color4 LightSkyBlue { get { return new Color4(135, 206, 250, 255); } }
555 /// Gets the system color with (R, G, B, A) = (119, 136, 153, 255).
557 public static Color4 LightSlateGray { get { return new Color4(119, 136, 153, 255); } }
560 /// Gets the system color with (R, G, B, A) = (176, 196, 222, 255).
562 public static Color4 LightSteelBlue { get { return new Color4(176, 196, 222, 255); } }
565 /// Gets the system color with (R, G, B, A) = (255, 255, 224, 255).
567 public static Color4 LightYellow { get { return new Color4(255, 255, 224, 255); } }
570 /// Gets the system color with (R, G, B, A) = (0, 255, 0, 255).
572 public static Color4 Lime { get { return new Color4(0, 255, 0, 255); } }
575 /// Gets the system color with (R, G, B, A) = (50, 205, 50, 255).
577 public static Color4 LimeGreen { get { return new Color4(50, 205, 50, 255); } }
580 /// Gets the system color with (R, G, B, A) = (250, 240, 230, 255).
582 public static Color4 Linen { get { return new Color4(250, 240, 230, 255); } }
585 /// Gets the system color with (R, G, B, A) = (255, 0, 255, 255).
587 public static Color4 Magenta { get { return new Color4(255, 0, 255, 255); } }
590 /// Gets the system color with (R, G, B, A) = (128, 0, 0, 255).
592 public static Color4 Maroon { get { return new Color4(128, 0, 0, 255); } }
595 /// Gets the system color with (R, G, B, A) = (102, 205, 170, 255).
597 public static Color4 MediumAquamarine { get { return new Color4(102, 205, 170, 255); } }
600 /// Gets the system color with (R, G, B, A) = (0, 0, 205, 255).
602 public static Color4 MediumBlue { get { return new Color4(0, 0, 205, 255); } }
605 /// Gets the system color with (R, G, B, A) = (186, 85, 211, 255).
607 public static Color4 MediumOrchid { get { return new Color4(186, 85, 211, 255); } }
610 /// Gets the system color with (R, G, B, A) = (147, 112, 219, 255).
612 public static Color4 MediumPurple { get { return new Color4(147, 112, 219, 255); } }
615 /// Gets the system color with (R, G, B, A) = (60, 179, 113, 255).
617 public static Color4 MediumSeaGreen { get { return new Color4(60, 179, 113, 255); } }
620 /// Gets the system color with (R, G, B, A) = (123, 104, 238, 255).
622 public static Color4 MediumSlateBlue { get { return new Color4(123, 104, 238, 255); } }
625 /// Gets the system color with (R, G, B, A) = (0, 250, 154, 255).
627 public static Color4 MediumSpringGreen { get { return new Color4(0, 250, 154, 255); } }
630 /// Gets the system color with (R, G, B, A) = (72, 209, 204, 255).
632 public static Color4 MediumTurquoise { get { return new Color4(72, 209, 204, 255); } }
635 /// Gets the system color with (R, G, B, A) = (199, 21, 133, 255).
637 public static Color4 MediumVioletRed { get { return new Color4(199, 21, 133, 255); } }
640 /// Gets the system color with (R, G, B, A) = (25, 25, 112, 255).
642 public static Color4 MidnightBlue { get { return new Color4(25, 25, 112, 255); } }
645 /// Gets the system color with (R, G, B, A) = (245, 255, 250, 255).
647 public static Color4 MintCream { get { return new Color4(245, 255, 250, 255); } }
650 /// Gets the system color with (R, G, B, A) = (255, 228, 225, 255).
652 public static Color4 MistyRose { get { return new Color4(255, 228, 225, 255); } }
655 /// Gets the system color with (R, G, B, A) = (255, 228, 181, 255).
657 public static Color4 Moccasin { get { return new Color4(255, 228, 181, 255); } }
660 /// Gets the system color with (R, G, B, A) = (255, 222, 173, 255).
662 public static Color4 NavajoWhite { get { return new Color4(255, 222, 173, 255); } }
665 /// Gets the system color with (R, G, B, A) = (0, 0, 128, 255).
667 public static Color4 Navy { get { return new Color4(0, 0, 128, 255); } }
670 /// Gets the system color with (R, G, B, A) = (253, 245, 230, 255).
672 public static Color4 OldLace { get { return new Color4(253, 245, 230, 255); } }
675 /// Gets the system color with (R, G, B, A) = (128, 128, 0, 255).
677 public static Color4 Olive { get { return new Color4(128, 128, 0, 255); } }
680 /// Gets the system color with (R, G, B, A) = (107, 142, 35, 255).
682 public static Color4 OliveDrab { get { return new Color4(107, 142, 35, 255); } }
685 /// Gets the system color with (R, G, B, A) = (255, 165, 0, 255).
687 public static Color4 Orange { get { return new Color4(255, 165, 0, 255); } }
690 /// Gets the system color with (R, G, B, A) = (255, 69, 0, 255).
692 public static Color4 OrangeRed { get { return new Color4(255, 69, 0, 255); } }
695 /// Gets the system color with (R, G, B, A) = (218, 112, 214, 255).
697 public static Color4 Orchid { get { return new Color4(218, 112, 214, 255); } }
700 /// Gets the system color with (R, G, B, A) = (238, 232, 170, 255).
702 public static Color4 PaleGoldenrod { get { return new Color4(238, 232, 170, 255); } }
705 /// Gets the system color with (R, G, B, A) = (152, 251, 152, 255).
707 public static Color4 PaleGreen { get { return new Color4(152, 251, 152, 255); } }
710 /// Gets the system color with (R, G, B, A) = (175, 238, 238, 255).
712 public static Color4 PaleTurquoise { get { return new Color4(175, 238, 238, 255); } }
715 /// Gets the system color with (R, G, B, A) = (219, 112, 147, 255).
717 public static Color4 PaleVioletRed { get { return new Color4(219, 112, 147, 255); } }
720 /// Gets the system color with (R, G, B, A) = (255, 239, 213, 255).
722 public static Color4 PapayaWhip { get { return new Color4(255, 239, 213, 255); } }
725 /// Gets the system color with (R, G, B, A) = (255, 218, 185, 255).
727 public static Color4 PeachPuff { get { return new Color4(255, 218, 185, 255); } }
730 /// Gets the system color with (R, G, B, A) = (205, 133, 63, 255).
732 public static Color4 Peru { get { return new Color4(205, 133, 63, 255); } }
735 /// Gets the system color with (R, G, B, A) = (255, 192, 203, 255).
737 public static Color4 Pink { get { return new Color4(255, 192, 203, 255); } }
740 /// Gets the system color with (R, G, B, A) = (221, 160, 221, 255).
742 public static Color4 Plum { get { return new Color4(221, 160, 221, 255); } }
745 /// Gets the system color with (R, G, B, A) = (176, 224, 230, 255).
747 public static Color4 PowderBlue { get { return new Color4(176, 224, 230, 255); } }
750 /// Gets the system color with (R, G, B, A) = (128, 0, 128, 255).
752 public static Color4 Purple { get { return new Color4(128, 0, 128, 255); } }
755 /// Gets the system color with (R, G, B, A) = (255, 0, 0, 255).
757 public static Color4 Red { get { return new Color4(255, 0, 0, 255); } }
760 /// Gets the system color with (R, G, B, A) = (188, 143, 143, 255).
762 public static Color4 RosyBrown { get { return new Color4(188, 143, 143, 255); } }
765 /// Gets the system color with (R, G, B, A) = (65, 105, 225, 255).
767 public static Color4 RoyalBlue { get { return new Color4(65, 105, 225, 255); } }
770 /// Gets the system color with (R, G, B, A) = (139, 69, 19, 255).
772 public static Color4 SaddleBrown { get { return new Color4(139, 69, 19, 255); } }
775 /// Gets the system color with (R, G, B, A) = (250, 128, 114, 255).
777 public static Color4 Salmon { get { return new Color4(250, 128, 114, 255); } }
780 /// Gets the system color with (R, G, B, A) = (244, 164, 96, 255).
782 public static Color4 SandyBrown { get { return new Color4(244, 164, 96, 255); } }
785 /// Gets the system color with (R, G, B, A) = (46, 139, 87, 255).
787 public static Color4 SeaGreen { get { return new Color4(46, 139, 87, 255); } }
790 /// Gets the system color with (R, G, B, A) = (255, 245, 238, 255).
792 public static Color4 SeaShell { get { return new Color4(255, 245, 238, 255); } }
795 /// Gets the system color with (R, G, B, A) = (160, 82, 45, 255).
797 public static Color4 Sienna { get { return new Color4(160, 82, 45, 255); } }
800 /// Gets the system color with (R, G, B, A) = (192, 192, 192, 255).
802 public static Color4 Silver { get { return new Color4(192, 192, 192, 255); } }
805 /// Gets the system color with (R, G, B, A) = (135, 206, 235, 255).
807 public static Color4 SkyBlue { get { return new Color4(135, 206, 235, 255); } }
810 /// Gets the system color with (R, G, B, A) = (106, 90, 205, 255).
812 public static Color4 SlateBlue { get { return new Color4(106, 90, 205, 255); } }
815 /// Gets the system color with (R, G, B, A) = (112, 128, 144, 255).
817 public static Color4 SlateGray { get { return new Color4(112, 128, 144, 255); } }
820 /// Gets the system color with (R, G, B, A) = (255, 250, 250, 255).
822 public static Color4 Snow { get { return new Color4(255, 250, 250, 255); } }
825 /// Gets the system color with (R, G, B, A) = (0, 255, 127, 255).
827 public static Color4 SpringGreen { get { return new Color4(0, 255, 127, 255); } }
830 /// Gets the system color with (R, G, B, A) = (70, 130, 180, 255).
832 public static Color4 SteelBlue { get { return new Color4(70, 130, 180, 255); } }
835 /// Gets the system color with (R, G, B, A) = (210, 180, 140, 255).
837 public static Color4 Tan { get { return new Color4(210, 180, 140, 255); } }
840 /// Gets the system color with (R, G, B, A) = (0, 128, 128, 255).
842 public static Color4 Teal { get { return new Color4(0, 128, 128, 255); } }
845 /// Gets the system color with (R, G, B, A) = (216, 191, 216, 255).
847 public static Color4 Thistle { get { return new Color4(216, 191, 216, 255); } }
850 /// Gets the system color with (R, G, B, A) = (255, 99, 71, 255).
852 public static Color4 Tomato { get { return new Color4(255, 99, 71, 255); } }
855 /// Gets the system color with (R, G, B, A) = (64, 224, 208, 255).
857 public static Color4 Turquoise { get { return new Color4(64, 224, 208, 255); } }
860 /// Gets the system color with (R, G, B, A) = (238, 130, 238, 255).
862 public static Color4 Violet { get { return new Color4(238, 130, 238, 255); } }
865 /// Gets the system color with (R, G, B, A) = (245, 222, 179, 255).
867 public static Color4 Wheat { get { return new Color4(245, 222, 179, 255); } }
870 /// Gets the system color with (R, G, B, A) = (255, 255, 255, 255).
872 public static Color4 White { get { return new Color4(255, 255, 255, 255); } }
875 /// Gets the system color with (R, G, B, A) = (245, 245, 245, 255).
877 public static Color4 WhiteSmoke { get { return new Color4(245, 245, 245, 255); } }
880 /// Gets the system color with (R, G, B, A) = (255, 255, 0, 255).
882 public static Color4 Yellow { get { return new Color4(255, 255, 0, 255); } }
885 /// Gets the system color with (R, G, B, A) = (154, 205, 50, 255).
887 public static Color4 YellowGreen { get { return new Color4(154, 205, 50, 255); } }
890 /// Converts sRGB color values to RGB color values.
893 /// Returns the converted color value.
895 /// <param name="srgb">
896 /// Color value to convert in sRGB.
898 public static Color4 FromSrgb(Color4 srgb)
902 if (srgb.R <= 0.04045f)
908 r = (float)Math.Pow((srgb.R + 0.055f) / (1.0f + 0.055f), 2.4f);
911 if (srgb.G <= 0.04045f)
917 g = (float)Math.Pow((srgb.G + 0.055f) / (1.0f + 0.055f), 2.4f);
920 if (srgb.B <= 0.04045f)
926 b = (float)Math.Pow((srgb.B + 0.055f) / (1.0f + 0.055f), 2.4f);
929 return new Color4(r, g, b, srgb.A);
933 /// Converts RGB color values to sRGB color values.
936 /// Returns the converted color value.
938 /// <param name="rgb">Color value to convert.</param>
939 public static Color4 ToSrgb(Color4 rgb)
943 if (rgb.R <= 0.0031308)
949 r = (1.0f + 0.055f) * (float)Math.Pow(rgb.R, 1.0f / 2.4f) - 0.055f;
952 if (rgb.G <= 0.0031308)
958 g = (1.0f + 0.055f) * (float)Math.Pow(rgb.G, 1.0f / 2.4f) - 0.055f;
961 if (rgb.B <= 0.0031308)
967 b = (1.0f + 0.055f) * (float)Math.Pow(rgb.B, 1.0f / 2.4f) - 0.055f;
970 return new Color4(r, g, b, rgb.A);
974 /// Converts HSL color values to RGB color values.
977 /// Returns the converted color value.
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.
984 public static Color4 FromHsl(Vector4 hsl)
986 var hue = hsl.X * 360.0f;
987 var saturation = hsl.Y;
988 var lightness = hsl.Z;
990 var C = (1.0f - Math.Abs(2.0f * lightness - 1.0f)) * saturation;
993 var X = C * (1.0f - Math.Abs(h % 2.0f - 1.0f));
996 if (0.0f <= h && h < 1.0f)
1002 else if (1.0f <= h && h < 2.0f)
1008 else if (2.0f <= h && h < 3.0f)
1014 else if (3.0f <= h && h < 4.0f)
1020 else if (4.0f <= h && h < 5.0f)
1026 else if (5.0f <= h && h < 6.0f)
1039 var m = lightness - (C / 2.0f);
1040 return new Color4(r + m, g + m, b + m, hsl.W);
1044 /// Converts RGB color values to HSL color values.
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.
1051 /// <param name="rgb">Color value to convert.</param>
1052 public static Vector4 ToHsl(Color4 rgb)
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));
1061 h = ((rgb.G - rgb.B) / C);
1063 else if (M == rgb.G)
1065 h = ((rgb.B - rgb.R) / C) + 2.0f;
1067 else if (M == rgb.B)
1069 h = ((rgb.R - rgb.G) / C) + 4.0f;
1078 var lightness = (M + m) / 2.0f;
1080 var saturation = 0.0f;
1081 if (0.0f != lightness && lightness != 1.0f)
1083 saturation = C / (1.0f - Math.Abs(2.0f * lightness - 1.0f));
1086 return new Vector4(hue, saturation, lightness, rgb.A);
1090 /// Converts HSV color values to RGB color values.
1093 /// Returns the converted color value.
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.
1100 public static Color4 FromHsv(Vector4 hsv)
1102 var hue = hsv.X * 360.0f;
1103 var saturation = hsv.Y;
1106 var C = value * saturation;
1108 var h = hue / 60.0f;
1109 var X = C * (1.0f - Math.Abs(h % 2.0f - 1.0f));
1112 if (0.0f <= h && h < 1.0f)
1118 else if (1.0f <= h && h < 2.0f)
1124 else if (2.0f <= h && h < 3.0f)
1130 else if (3.0f <= h && h < 4.0f)
1136 else if (4.0f <= h && h < 5.0f)
1142 else if (5.0f <= h && h < 6.0f)
1156 return new Color4(r + m, g + m, b + m, hsv.W);
1160 /// Converts RGB color values to HSV color values.
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.
1167 /// <param name="rgb">Color value to convert.</param>
1168 public static Vector4 ToHsv(Color4 rgb)
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));
1177 h = ((rgb.G - rgb.B) / C) % 6.0f;
1179 else if (M == rgb.G)
1181 h = ((rgb.B - rgb.R) / C) + 2.0f;
1183 else if (M == rgb.B)
1185 h = ((rgb.R - rgb.G) / C) + 4.0f;
1188 var hue = (h * 60.0f) / 360.0f;
1190 var saturation = 0.0f;
1196 return new Vector4(hue, saturation, M, rgb.A);
1200 /// Converts XYZ color values to RGB color values.
1203 /// Returns the converted color value.
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.
1209 /// <remarks>Uses the CIE XYZ colorspace.</remarks>
1210 public static Color4 FromXyz(Vector4 xyz)
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);
1219 /// Converts RGB color values to XYZ color values.
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.
1225 /// <param name="rgb">Color value to convert.</param>
1226 /// <remarks>Uses the CIE XYZ colorspace.</remarks>
1227 public static Vector4 ToXyz(Color4 rgb)
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);
1236 /// Converts YCbCr color values to RGB color values.
1239 /// Returns the converted color value.
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).
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)
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);
1255 /// Converts RGB color values to YUV color values.
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.
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)
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);
1273 /// Converts HCY color values to RGB color values.
1276 /// Returns the converted color value.
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.
1283 public static Color4 FromHcy(Vector4 hcy)
1285 var hue = hcy.X * 360.0f;
1287 var luminance = hcy.Z;
1289 var h = hue / 60.0f;
1290 var X = C * (1.0f - Math.Abs(h % 2.0f - 1.0f));
1293 if (0.0f <= h && h < 1.0f)
1299 else if (1.0f <= h && h < 2.0f)
1305 else if (2.0f <= h && h < 3.0f)
1311 else if (3.0f <= h && h < 4.0f)
1317 else if (4.0f <= h && h < 5.0f)
1323 else if (5.0f <= h && h < 6.0f)
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);
1341 /// Converts RGB color values to HCY color values.
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.
1348 /// <param name="rgb">Color value to convert.</param>
1349 public static Vector4 ToHcy(Color4 rgb)
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));
1358 h = ((rgb.G - rgb.B) / C) % 6.0f;
1360 else if (M == rgb.G)
1362 h = ((rgb.B - rgb.R) / C) + 2.0f;
1364 else if (M == rgb.B)
1366 h = ((rgb.R - rgb.G) / C) + 4.0f;
1369 var hue = (h * 60.0f) / 360.0f;
1371 var luminance = 0.30f * rgb.R + 0.59f * rgb.G + 0.11f * rgb.B;
1373 return new Vector4(hue, C, luminance, rgb.A);
1377 /// Compares whether this Color4 structure is equal to the specified Color4.
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)
1384 this.R == other.R &&
1385 this.G == other.G &&
1386 this.B == other.B &&