Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ColorBGRA.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under MIT License. See LICENSE.md for details.
3 using System;
4 using System.Globalization;
5 using System.Runtime.InteropServices;
6 using SiliconStudio.Core.Serialization;
7 
8 namespace SiliconStudio.Core.Mathematics
9 {
10  /// <summary>
11  /// Represents a 32-bit color (4 bytes) in the form of BGRA (in byte order: B, G, B, A).
12  /// </summary>
13  [DataContract("ColorBGRA")]
14  [DataStyle(DataStyle.Compact)]
15  [StructLayout(LayoutKind.Sequential, Size = 4)]
16  public partial struct ColorBGRA : IEquatable<ColorBGRA>, IFormattable
17  {
18  private const string toStringFormat = "A:{0} R:{1} G:{2} B:{3}";
19 
20  /// <summary>
21  /// The blue component of the color.
22  /// </summary>
23  [DataMember(0)]
24  public byte B;
25 
26  /// <summary>
27  /// The green component of the color.
28  /// </summary>
29  [DataMember(1)]
30  public byte G;
31 
32  /// <summary>
33  /// The red component of the color.
34  /// </summary>
35  [DataMember(2)]
36  public byte R;
37 
38  /// <summary>
39  /// The alpha component of the color.
40  /// </summary>
41  [DataMember(3)]
42  public byte A;
43 
44  /// <summary>
45  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
46  /// </summary>
47  /// <param name="value">The value that will be assigned to all components.</param>
48  public ColorBGRA(byte value)
49  {
50  A = R = G = B = value;
51  }
52 
53  /// <summary>
54  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
55  /// </summary>
56  /// <param name="value">The value that will be assigned to all components.</param>
57  public ColorBGRA(float value)
58  {
59  A = R = G = B = ToByte(value);
60  }
61 
62  /// <summary>
63  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
64  /// </summary>
65  /// <param name="red">The red component of the color.</param>
66  /// <param name="green">The green component of the color.</param>
67  /// <param name="blue">The blue component of the color.</param>
68  /// <param name="alpha">The alpha component of the color.</param>
69  public ColorBGRA(byte red, byte green, byte blue, byte alpha)
70  {
71  R = red;
72  G = green;
73  B = blue;
74  A = alpha;
75  }
76 
77  /// <summary>
78  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
79  /// </summary>
80  /// <param name="red">The red component of the color.</param>
81  /// <param name="green">The green component of the color.</param>
82  /// <param name="blue">The blue component of the color.</param>
83  /// <param name="alpha">The alpha component of the color.</param>
84  public ColorBGRA(float red, float green, float blue, float alpha)
85  {
86  R = ToByte(red);
87  G = ToByte(green);
88  B = ToByte(blue);
89  A = ToByte(alpha);
90  }
91 
92  /// <summary>
93  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
94  /// </summary>
95  /// <param name="value">The red, green, blue, and alpha components of the color.</param>
96  public ColorBGRA(Vector4 value)
97  {
98  R = ToByte(value.X);
99  G = ToByte(value.Y);
100  B = ToByte(value.Z);
101  A = ToByte(value.W);
102  }
103 
104  /// <summary>
105  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
106  /// </summary>
107  /// <param name="value">The red, green, and blue components of the color.</param>
108  /// <param name="alpha">The alpha component of the color.</param>
109  public ColorBGRA(Vector3 value, float alpha)
110  {
111  R = ToByte(value.X);
112  G = ToByte(value.Y);
113  B = ToByte(value.Z);
114  A = ToByte(alpha);
115  }
116 
117  /// <summary>
118  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
119  /// </summary>
120  /// <param name="bgra">A packed integer containing all four color components in BGRA order.</param>
121  public ColorBGRA(uint bgra)
122  {
123  A = (byte)((bgra >> 24) & 255);
124  R = (byte)((bgra >> 16) & 255);
125  G = (byte)((bgra >> 8) & 255);
126  B = (byte)(bgra & 255);
127  }
128 
129  /// <summary>
130  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
131  /// </summary>
132  /// <param name="bgra">A packed integer containing all four color components in BGRA.</param>
133  public ColorBGRA(int bgra)
134  {
135  A = (byte)((bgra >> 24) & 255);
136  R = (byte)((bgra >> 16) & 255);
137  G = (byte)((bgra >> 8) & 255);
138  B = (byte)(bgra & 255);
139  }
140 
141  /// <summary>
142  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
143  /// </summary>
144  /// <param name="values">The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements.</param>
145  /// <exception cref="ArgumentNullException">Thrown when <paramref name="values"/> is <c>null</c>.</exception>
146  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="values"/> contains more or less than four elements.</exception>
147  public ColorBGRA(float[] values)
148  {
149  if (values == null)
150  throw new ArgumentNullException("values");
151  if (values.Length != 4)
152  throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for ColorBGRA.");
153 
154  B = ToByte(values[0]);
155  G = ToByte(values[1]);
156  R = ToByte(values[2]);
157  A = ToByte(values[3]);
158  }
159 
160  /// <summary>
161  /// Initializes a new instance of the <see cref="ColorBGRA"/> struct.
162  /// </summary>
163  /// <param name="values">The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements.</param>
164  /// <exception cref="ArgumentNullException">Thrown when <paramref name="values"/> is <c>null</c>.</exception>
165  /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="values"/> contains more or less than four elements.</exception>
166  public ColorBGRA(byte[] values)
167  {
168  if (values == null)
169  throw new ArgumentNullException("values");
170  if (values.Length != 4)
171  throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for ColorBGRA.");
172 
173  B = values[0];
174  G = values[1];
175  R = values[2];
176  A = values[3];
177  }
178 
179  /// <summary>
180  /// Gets or sets the component at the specified index.
181  /// </summary>
182  /// <value>The value of the alpha, red, green, or blue component, depending on the index.</value>
183  /// <param name="index">The index of the component to access. Use 0 for the alpha component, 1 for the red component, 2 for the green component, and 3 for the blue component.</param>
184  /// <returns>The value of the component at the specified index.</returns>
185  /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="index"/> is out of the range [0, 3].</exception>
186  public byte this[int index]
187  {
188  get
189  {
190  switch (index)
191  {
192  case 0: return B;
193  case 1: return G;
194  case 2: return R;
195  case 3: return A;
196  }
197 
198  throw new ArgumentOutOfRangeException("index", "Indices for ColorBGRA run from 0 to 3, inclusive.");
199  }
200 
201  set
202  {
203  switch (index)
204  {
205  case 0: B = value; break;
206  case 1: G = value; break;
207  case 2: R = value; break;
208  case 3: A = value; break;
209  default: throw new ArgumentOutOfRangeException("index", "Indices for ColorBGRA run from 0 to 3, inclusive.");
210  }
211  }
212  }
213 
214  /// <summary>
215  /// Converts the color into a packed integer.
216  /// </summary>
217  /// <returns>A packed integer containing all four color components.</returns>
218  public int ToBgra()
219  {
220  int value = B;
221  value |= G << 8;
222  value |= R << 16;
223  value |= A << 24;
224 
225  return (int)value;
226  }
227 
228  /// <summary>
229  /// Converts the color into a packed integer.
230  /// </summary>
231  /// <returns>A packed integer containing all four color components.</returns>
232  public int ToRgba()
233  {
234  int value = R;
235  value |= G << 8;
236  value |= B << 16;
237  value |= A << 24;
238 
239  return (int)value;
240  }
241 
242  /// <summary>
243  /// Converts the color into a three component vector.
244  /// </summary>
245  /// <returns>A three component vector containing the red, green, and blue components of the color.</returns>
247  {
248  return new Vector3(R / 255.0f, G / 255.0f, B / 255.0f);
249  }
250 
251  /// <summary>
252  /// Converts the color into a three component color.
253  /// </summary>
254  /// <returns>A three component color containing the red, green, and blue components of the color.</returns>
255  public Color3 ToColor3()
256  {
257  return new Color3(R / 255.0f, G / 255.0f, B / 255.0f);
258  }
259 
260  /// <summary>
261  /// Converts the color into a four component vector.
262  /// </summary>
263  /// <returns>A four component vector containing all four color components.</returns>
265  {
266  return new Vector4(R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f);
267  }
268 
269  /// <summary>
270  /// Creates an array containing the elements of the color.
271  /// </summary>
272  /// <returns>A four-element array containing the components of the color in BGRA order.</returns>
273  public byte[] ToArray()
274  {
275  return new[] { B, G, R, A };
276  }
277 
278  /// <summary>
279  /// Gets the brightness.
280  /// </summary>
281  /// <returns>The Hue-Saturation-Brightness (HSB) saturation for this <see cref="Color"/></returns>
282  public float GetBrightness()
283  {
284  float r = (float)R / 255.0f;
285  float g = (float)G / 255.0f;
286  float b = (float)B / 255.0f;
287 
288  float max, min;
289 
290  max = r; min = r;
291 
292  if (g > max) max = g;
293  if (b > max) max = b;
294 
295  if (g < min) min = g;
296  if (b < min) min = b;
297 
298  return (max + min) / 2;
299  }
300 
301  /// <summary>
302  /// Gets the hue.
303  /// </summary>
304  /// <returns>The Hue-Saturation-Brightness (HSB) saturation for this <see cref="Color"/></returns>
305  public float GetHue()
306  {
307  if (R == G && G == B)
308  return 0; // 0 makes as good an UNDEFINED value as any
309 
310  float r = (float)R / 255.0f;
311  float g = (float)G / 255.0f;
312  float b = (float)B / 255.0f;
313 
314  float max, min;
315  float delta;
316  float hue = 0.0f;
317 
318  max = r; min = r;
319 
320  if (g > max) max = g;
321  if (b > max) max = b;
322 
323  if (g < min) min = g;
324  if (b < min) min = b;
325 
326  delta = max - min;
327 
328  if (r == max)
329  {
330  hue = (g - b) / delta;
331  }
332  else if (g == max)
333  {
334  hue = 2 + (b - r) / delta;
335  }
336  else if (b == max)
337  {
338  hue = 4 + (r - g) / delta;
339  }
340  hue *= 60;
341 
342  if (hue < 0.0f)
343  {
344  hue += 360.0f;
345  }
346  return hue;
347  }
348 
349  /// <summary>
350  /// Gets the saturation.
351  /// </summary>
352  /// <returns>The Hue-Saturation-Brightness (HSB) saturation for this <see cref="Color"/></returns>
353  public float GetSaturation()
354  {
355  float r = (float)R / 255.0f;
356  float g = (float)G / 255.0f;
357  float b = (float)B / 255.0f;
358 
359  float max, min;
360  float l, s = 0;
361 
362  max = r; min = r;
363 
364  if (g > max) max = g;
365  if (b > max) max = b;
366 
367  if (g < min) min = g;
368  if (b < min) min = b;
369 
370  // if max == min, then there is no color and
371  // the saturation is zero.
372  //
373  if (max != min)
374  {
375  l = (max + min) / 2;
376 
377  if (l <= .5)
378  {
379  s = (max - min) / (max + min);
380  }
381  else
382  {
383  s = (max - min) / (2 - max - min);
384  }
385  }
386  return s;
387  }
388 
389  /// <summary>
390  /// Converts the color from a packed BGRA integer.
391  /// </summary>
392  /// <param name="color">A packed integer containing all four color components in BGRA order</param>
393  /// <returns>A color.</returns>
394  public static ColorBGRA FromBgra(int color)
395  {
396  return new ColorBGRA(color);
397  }
398 
399  /// <summary>
400  /// Converts the color from a packed BGRA integer.
401  /// </summary>
402  /// <param name="color">A packed integer containing all four color components in BGRA order</param>
403  /// <returns>A color.</returns>
404  public static ColorBGRA FromBgra(uint color)
405  {
406  return new ColorBGRA(color);
407  }
408 
409  /// <summary>
410  /// Converts the color from a packed RGBA integer.
411  /// </summary>
412  /// <param name="color">A packed integer containing all four color components in RGBA order</param>
413  /// <returns>A color.</returns>
414  public static ColorBGRA FromRgba(int color)
415  {
416  return new ColorBGRA((byte)(color & 255), (byte)((color >> 8) & 255), (byte)((color >> 16) & 255), (byte)((color >> 24) & 255));
417  }
418 
419  /// <summary>
420  /// Converts the color from a packed RGBA integer.
421  /// </summary>
422  /// <param name="color">A packed integer containing all four color components in RGBA order</param>
423  /// <returns>A color.</returns>
424  public static ColorBGRA FromRgba(uint color)
425  {
426  return FromRgba(unchecked((int)color));
427  }
428 
429  /// <summary>
430  /// Adds two colors.
431  /// </summary>
432  /// <param name="left">The first color to add.</param>
433  /// <param name="right">The second color to add.</param>
434  /// <param name="result">When the method completes, completes the sum of the two colors.</param>
435  public static void Add(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
436  {
437  result.A = (byte)(left.A + right.A);
438  result.R = (byte)(left.R + right.R);
439  result.G = (byte)(left.G + right.G);
440  result.B = (byte)(left.B + right.B);
441  }
442 
443  /// <summary>
444  /// Adds two colors.
445  /// </summary>
446  /// <param name="left">The first color to add.</param>
447  /// <param name="right">The second color to add.</param>
448  /// <returns>The sum of the two colors.</returns>
449  public static ColorBGRA Add(ColorBGRA left, ColorBGRA right)
450  {
451  return new ColorBGRA(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A);
452  }
453 
454  /// <summary>
455  /// Subtracts two colors.
456  /// </summary>
457  /// <param name="left">The first color to subtract.</param>
458  /// <param name="right">The second color to subtract.</param>
459  /// <param name="result">WHen the method completes, contains the difference of the two colors.</param>
460  public static void Subtract(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
461  {
462  result.A = (byte)(left.A - right.A);
463  result.R = (byte)(left.R - right.R);
464  result.G = (byte)(left.G - right.G);
465  result.B = (byte)(left.B - right.B);
466  }
467 
468  /// <summary>
469  /// Subtracts two colors.
470  /// </summary>
471  /// <param name="left">The first color to subtract.</param>
472  /// <param name="right">The second color to subtract</param>
473  /// <returns>The difference of the two colors.</returns>
474  public static ColorBGRA Subtract(ColorBGRA left, ColorBGRA right)
475  {
476  return new ColorBGRA(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A);
477  }
478 
479  /// <summary>
480  /// Modulates two colors.
481  /// </summary>
482  /// <param name="left">The first color to modulate.</param>
483  /// <param name="right">The second color to modulate.</param>
484  /// <param name="result">When the method completes, contains the modulated color.</param>
485  public static void Modulate(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
486  {
487  result.A = (byte)(left.A * right.A / 255.0f);
488  result.R = (byte)(left.R * right.R / 255.0f);
489  result.G = (byte)(left.G * right.G / 255.0f);
490  result.B = (byte)(left.B * right.B / 255.0f);
491  }
492 
493  /// <summary>
494  /// Modulates two colors.
495  /// </summary>
496  /// <param name="left">The first color to modulate.</param>
497  /// <param name="right">The second color to modulate.</param>
498  /// <returns>The modulated color.</returns>
499  public static ColorBGRA Modulate(ColorBGRA left, ColorBGRA right)
500  {
501  return new ColorBGRA((left.R * right.R) >> 8, (left.G * right.G) >> 8, (left.B * right.B) >> 8, (left.A * right.A) >> 8);
502  }
503 
504  /// <summary>
505  /// Scales a color.
506  /// </summary>
507  /// <param name="value">The color to scale.</param>
508  /// <param name="scale">The amount by which to scale.</param>
509  /// <param name="result">When the method completes, contains the scaled color.</param>
510  public static void Scale(ref ColorBGRA value, float scale, out ColorBGRA result)
511  {
512  result.A = (byte)(value.A * scale);
513  result.R = (byte)(value.R * scale);
514  result.G = (byte)(value.G * scale);
515  result.B = (byte)(value.B * scale);
516  }
517 
518  /// <summary>
519  /// Scales a color.
520  /// </summary>
521  /// <param name="value">The color to scale.</param>
522  /// <param name="scale">The amount by which to scale.</param>
523  /// <returns>The scaled color.</returns>
524  public static ColorBGRA Scale(ColorBGRA value, float scale)
525  {
526  return new ColorBGRA((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale));
527  }
528 
529  /// <summary>
530  /// Negates a color.
531  /// </summary>
532  /// <param name="value">The color to negate.</param>
533  /// <param name="result">When the method completes, contains the negated color.</param>
534  public static void Negate(ref ColorBGRA value, out ColorBGRA result)
535  {
536  result.A = (byte)(255 - value.A);
537  result.R = (byte)(255 - value.R);
538  result.G = (byte)(255 - value.G);
539  result.B = (byte)(255 - value.B);
540  }
541 
542  /// <summary>
543  /// Negates a color.
544  /// </summary>
545  /// <param name="value">The color to negate.</param>
546  /// <returns>The negated color.</returns>
547  public static ColorBGRA Negate(ColorBGRA value)
548  {
549  return new ColorBGRA(255 - value.R, 255 - value.G, 255 - value.B, 255 - value.A);
550  }
551 
552  /// <summary>
553  /// Restricts a value to be within a specified range.
554  /// </summary>
555  /// <param name="value">The value to clamp.</param>
556  /// <param name="min">The minimum value.</param>
557  /// <param name="max">The maximum value.</param>
558  /// <param name="result">When the method completes, contains the clamped value.</param>
559  public static void Clamp(ref ColorBGRA value, ref ColorBGRA min, ref ColorBGRA max, out ColorBGRA result)
560  {
561  byte alpha = value.A;
562  alpha = (alpha > max.A) ? max.A : alpha;
563  alpha = (alpha < min.A) ? min.A : alpha;
564 
565  byte red = value.R;
566  red = (red > max.R) ? max.R : red;
567  red = (red < min.R) ? min.R : red;
568 
569  byte green = value.G;
570  green = (green > max.G) ? max.G : green;
571  green = (green < min.G) ? min.G : green;
572 
573  byte blue = value.B;
574  blue = (blue > max.B) ? max.B : blue;
575  blue = (blue < min.B) ? min.B : blue;
576 
577  result = new ColorBGRA(red, green, blue, alpha);
578  }
579 
580  /// <summary>
581  /// Restricts a value to be within a specified range.
582  /// </summary>
583  /// <param name="value">The value to clamp.</param>
584  /// <param name="min">The minimum value.</param>
585  /// <param name="max">The maximum value.</param>
586  /// <returns>The clamped value.</returns>
587  public static ColorBGRA Clamp(ColorBGRA value, ColorBGRA min, ColorBGRA max)
588  {
589  ColorBGRA result;
590  Clamp(ref value, ref min, ref max, out result);
591  return result;
592  }
593 
594  /// <summary>
595  /// Performs a linear interpolation between two colors.
596  /// </summary>
597  /// <param name="start">Start color.</param>
598  /// <param name="end">End color.</param>
599  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
600  /// <param name="result">When the method completes, contains the linear interpolation of the two colors.</param>
601  /// <remarks>
602  /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
603  /// </remarks>
604  public static void Lerp(ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result)
605  {
606  result.B = MathUtil.Lerp(start.B, end.B, amount);
607  result.G = MathUtil.Lerp(start.G, end.G, amount);
608  result.R = MathUtil.Lerp(start.R, end.R, amount);
609  result.A = MathUtil.Lerp(start.A, end.A, amount);
610  }
611 
612  /// <summary>
613  /// Performs a linear interpolation between two colors.
614  /// </summary>
615  /// <param name="start">Start color.</param>
616  /// <param name="end">End color.</param>
617  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
618  /// <returns>The linear interpolation of the two colors.</returns>
619  /// <remarks>
620  /// Passing <paramref name="amount"/> a value of 0 will cause <paramref name="start"/> to be returned; a value of 1 will cause <paramref name="end"/> to be returned.
621  /// </remarks>
622  public static ColorBGRA Lerp(ColorBGRA start, ColorBGRA end, float amount)
623  {
624  ColorBGRA result;
625  Lerp(ref start, ref end, amount, out result);
626  return result;
627  }
628 
629  /// <summary>
630  /// Performs a cubic interpolation between two colors.
631  /// </summary>
632  /// <param name="start">Start color.</param>
633  /// <param name="end">End color.</param>
634  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
635  /// <param name="result">When the method completes, contains the cubic interpolation of the two colors.</param>
636  public static void SmoothStep(ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result)
637  {
638  amount = MathUtil.SmoothStep(amount);
639  Lerp(ref start, ref end, amount, out result);
640  }
641 
642  /// <summary>
643  /// Performs a cubic interpolation between two colors.
644  /// </summary>
645  /// <param name="start">Start color.</param>
646  /// <param name="end">End color.</param>
647  /// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end"/>.</param>
648  /// <returns>The cubic interpolation of the two colors.</returns>
649  public static ColorBGRA SmoothStep(ColorBGRA start, ColorBGRA end, float amount)
650  {
651  ColorBGRA result;
652  SmoothStep(ref start, ref end, amount, out result);
653  return result;
654  }
655 
656  /// <summary>
657  /// Returns a color containing the smallest components of the specified colorss.
658  /// </summary>
659  /// <param name="left">The first source color.</param>
660  /// <param name="right">The second source color.</param>
661  /// <param name="result">When the method completes, contains an new color composed of the largest components of the source colorss.</param>
662  public static void Max(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
663  {
664  result.A = (left.A > right.A) ? left.A : right.A;
665  result.R = (left.R > right.R) ? left.R : right.R;
666  result.G = (left.G > right.G) ? left.G : right.G;
667  result.B = (left.B > right.B) ? left.B : right.B;
668  }
669 
670  /// <summary>
671  /// Returns a color containing the largest components of the specified colorss.
672  /// </summary>
673  /// <param name="left">The first source color.</param>
674  /// <param name="right">The second source color.</param>
675  /// <returns>A color containing the largest components of the source colors.</returns>
676  public static ColorBGRA Max(ColorBGRA left, ColorBGRA right)
677  {
678  ColorBGRA result;
679  Max(ref left, ref right, out result);
680  return result;
681  }
682 
683  /// <summary>
684  /// Returns a color containing the smallest components of the specified colors.
685  /// </summary>
686  /// <param name="left">The first source color.</param>
687  /// <param name="right">The second source color.</param>
688  /// <param name="result">When the method completes, contains an new color composed of the smallest components of the source colors.</param>
689  public static void Min(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
690  {
691  result.A = (left.A < right.A) ? left.A : right.A;
692  result.R = (left.R < right.R) ? left.R : right.R;
693  result.G = (left.G < right.G) ? left.G : right.G;
694  result.B = (left.B < right.B) ? left.B : right.B;
695  }
696 
697  /// <summary>
698  /// Returns a color containing the smallest components of the specified colors.
699  /// </summary>
700  /// <param name="left">The first source color.</param>
701  /// <param name="right">The second source color.</param>
702  /// <returns>A color containing the smallest components of the source colors.</returns>
703  public static ColorBGRA Min(ColorBGRA left, ColorBGRA right)
704  {
705  ColorBGRA result;
706  Min(ref left, ref right, out result);
707  return result;
708  }
709 
710  /// <summary>
711  /// Adjusts the contrast of a color.
712  /// </summary>
713  /// <param name="value">The color whose contrast is to be adjusted.</param>
714  /// <param name="contrast">The amount by which to adjust the contrast.</param>
715  /// <param name="result">When the method completes, contains the adjusted color.</param>
716  public static void AdjustContrast(ref ColorBGRA value, float contrast, out ColorBGRA result)
717  {
718  result.A = value.A;
719  result.R = ToByte(0.5f + contrast * (value.R / 255.0f - 0.5f));
720  result.G = ToByte(0.5f + contrast * (value.G / 255.0f - 0.5f));
721  result.B = ToByte(0.5f + contrast * (value.B / 255.0f - 0.5f));
722  }
723 
724  /// <summary>
725  /// Adjusts the contrast of a color.
726  /// </summary>
727  /// <param name="value">The color whose contrast is to be adjusted.</param>
728  /// <param name="contrast">The amount by which to adjust the contrast.</param>
729  /// <returns>The adjusted color.</returns>
730  public static ColorBGRA AdjustContrast(ColorBGRA value, float contrast)
731  {
732  return new ColorBGRA(
733  ToByte(0.5f + contrast * (value.R / 255.0f - 0.5f)),
734  ToByte(0.5f + contrast * (value.G / 255.0f - 0.5f)),
735  ToByte(0.5f + contrast * (value.B / 255.0f - 0.5f)),
736  value.A);
737  }
738 
739  /// <summary>
740  /// Adjusts the saturation of a color.
741  /// </summary>
742  /// <param name="value">The color whose saturation is to be adjusted.</param>
743  /// <param name="saturation">The amount by which to adjust the saturation.</param>
744  /// <param name="result">When the method completes, contains the adjusted color.</param>
745  public static void AdjustSaturation(ref ColorBGRA value, float saturation, out ColorBGRA result)
746  {
747  float grey = value.R / 255.0f * 0.2125f + value.G / 255.0f * 0.7154f + value.B / 255.0f * 0.0721f;
748 
749  result.A = value.A;
750  result.R = ToByte(grey + saturation * (value.R / 255.0f - grey));
751  result.G = ToByte(grey + saturation * (value.G / 255.0f - grey));
752  result.B = ToByte(grey + saturation * (value.B / 255.0f - grey));
753  }
754 
755  /// <summary>
756  /// Adjusts the saturation of a color.
757  /// </summary>
758  /// <param name="value">The color whose saturation is to be adjusted.</param>
759  /// <param name="saturation">The amount by which to adjust the saturation.</param>
760  /// <returns>The adjusted color.</returns>
761  public static ColorBGRA AdjustSaturation(ColorBGRA value, float saturation)
762  {
763  float grey = value.R / 255.0f * 0.2125f + value.G / 255.0f * 0.7154f + value.B / 255.0f * 0.0721f;
764 
765  return new ColorBGRA(
766  ToByte(grey + saturation * (value.R / 255.0f - grey)),
767  ToByte(grey + saturation * (value.G / 255.0f - grey)),
768  ToByte(grey + saturation * (value.B / 255.0f - grey)),
769  value.A);
770  }
771 
772  /// <summary>
773  /// Adds two colors.
774  /// </summary>
775  /// <param name="left">The first color to add.</param>
776  /// <param name="right">The second color to add.</param>
777  /// <returns>The sum of the two colors.</returns>
778  public static ColorBGRA operator +(ColorBGRA left, ColorBGRA right)
779  {
780  return new ColorBGRA(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A);
781  }
782 
783  /// <summary>
784  /// Assert a color (return it unchanged).
785  /// </summary>
786  /// <param name="value">The color to assert (unchange).</param>
787  /// <returns>The asserted (unchanged) color.</returns>
788  public static ColorBGRA operator +(ColorBGRA value)
789  {
790  return value;
791  }
792 
793  /// <summary>
794  /// Subtracts two colors.
795  /// </summary>
796  /// <param name="left">The first color to subtract.</param>
797  /// <param name="right">The second color to subtract.</param>
798  /// <returns>The difference of the two colors.</returns>
799  public static ColorBGRA operator -(ColorBGRA left, ColorBGRA right)
800  {
801  return new ColorBGRA(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A);
802  }
803 
804  /// <summary>
805  /// Negates a color.
806  /// </summary>
807  /// <param name="value">The color to negate.</param>
808  /// <returns>A negated color.</returns>
809  public static ColorBGRA operator -(ColorBGRA value)
810  {
811  return new ColorBGRA(-value.R, -value.G, -value.B, -value.A);
812  }
813 
814  /// <summary>
815  /// Scales a color.
816  /// </summary>
817  /// <param name="scale">The factor by which to scale the color.</param>
818  /// <param name="value">The color to scale.</param>
819  /// <returns>The scaled color.</returns>
820  public static ColorBGRA operator *(float scale, ColorBGRA value)
821  {
822  return new ColorBGRA((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale));
823  }
824 
825  /// <summary>
826  /// Scales a color.
827  /// </summary>
828  /// <param name="value">The factor by which to scale the color.</param>
829  /// <param name="scale">The color to scale.</param>
830  /// <returns>The scaled color.</returns>
831  public static ColorBGRA operator *(ColorBGRA value, float scale)
832  {
833  return new ColorBGRA((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale));
834  }
835 
836  /// <summary>
837  /// Modulates two colors.
838  /// </summary>
839  /// <param name="left">The first color to modulate.</param>
840  /// <param name="right">The second color to modulate.</param>
841  /// <returns>The modulated color.</returns>
842  public static ColorBGRA operator *(ColorBGRA left, ColorBGRA right)
843  {
844  return new ColorBGRA((byte)(left.R * right.R / 255.0f), (byte)(left.G * right.G / 255.0f), (byte)(left.B * right.B / 255.0f), (byte)(left.A * right.A / 255.0f));
845  }
846 
847  /// <summary>
848  /// Tests for equality between two objects.
849  /// </summary>
850  /// <param name="left">The first value to compare.</param>
851  /// <param name="right">The second value to compare.</param>
852  /// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
853  public static bool operator ==(ColorBGRA left, ColorBGRA right)
854  {
855  return left.Equals(right);
856  }
857 
858  /// <summary>
859  /// Tests for inequality between two objects.
860  /// </summary>
861  /// <param name="left">The first value to compare.</param>
862  /// <param name="right">The second value to compare.</param>
863  /// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
864  public static bool operator !=(ColorBGRA left, ColorBGRA right)
865  {
866  return !left.Equals(right);
867  }
868 
869  /// <summary>
870  /// Performs an explicit conversion from <see cref="ColorBGRA"/> to <see cref="Color3"/>.
871  /// </summary>
872  /// <param name="value">The value.</param>
873  /// <returns>The result of the conversion.</returns>
874  public static explicit operator Color3(ColorBGRA value)
875  {
876  return new Color3(value.R, value.G, value.B);
877  }
878 
879  /// <summary>
880  /// Performs an explicit conversion from <see cref="ColorBGRA"/> to <see cref="Vector3"/>.
881  /// </summary>
882  /// <param name="value">The value.</param>
883  /// <returns>The result of the conversion.</returns>
884  public static explicit operator Vector3(ColorBGRA value)
885  {
886  return new Vector3(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f);
887  }
888 
889  /// <summary>
890  /// Performs an explicit conversion from <see cref="ColorBGRA"/> to <see cref="Vector4"/>.
891  /// </summary>
892  /// <param name="value">The value.</param>
893  /// <returns>The result of the conversion.</returns>
894  public static explicit operator Vector4(ColorBGRA value)
895  {
896  return new Vector4(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f);
897  }
898 
899  /// <summary>
900  /// Performs an explicit conversion from <see cref="ColorBGRA"/> to <see cref="Color4"/>.
901  /// </summary>
902  /// <param name="value">The value.</param>
903  /// <returns>The result of the conversion.</returns>
904  public static explicit operator Color4(ColorBGRA value)
905  {
906  return new Color4(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f);
907  }
908 
909  /// <summary>
910  /// Performs an explicit conversion from <see cref="Vector3"/> to <see cref="ColorBGRA"/>.
911  /// </summary>
912  /// <param name="value">The value.</param>
913  /// <returns>The result of the conversion.</returns>
914  public static explicit operator ColorBGRA(Vector3 value)
915  {
916  return new ColorBGRA(value.X / 255.0f, value.Y / 255.0f, value.Z / 255.0f, 1.0f);
917  }
918 
919  /// <summary>
920  /// Performs an explicit conversion from <see cref="Color3"/> to <see cref="ColorBGRA"/>.
921  /// </summary>
922  /// <param name="value">The value.</param>
923  /// <returns>The result of the conversion.</returns>
924  public static explicit operator ColorBGRA(Color3 value)
925  {
926  return new ColorBGRA(value.R, value.G, value.B, 1.0f);
927  }
928 
929  /// <summary>
930  /// Performs an explicit conversion from <see cref="Vector4"/> to <see cref="ColorBGRA"/>.
931  /// </summary>
932  /// <param name="value">The value.</param>
933  /// <returns>The result of the conversion.</returns>
934  public static explicit operator ColorBGRA(Vector4 value)
935  {
936  return new ColorBGRA(value.X, value.Y, value.Z, value.W);
937  }
938 
939  /// <summary>
940  /// Performs an explicit conversion from <see cref="Color4"/> to <see cref="ColorBGRA"/>.
941  /// </summary>
942  /// <param name="value">The value.</param>
943  /// <returns>The result of the conversion.</returns>
944  public static explicit operator ColorBGRA(Color4 value)
945  {
946  return new ColorBGRA(value.R, value.G, value.B, value.A);
947  }
948 
949  /// <summary>
950  /// Performs an implicit conversion from <see cref="Color"/> to <see cref="ColorBGRA"/>.
951  /// </summary>
952  /// <param name="value">The value.</param>
953  /// <returns>The result of the conversion.</returns>
954  public static implicit operator ColorBGRA(Color value)
955  {
956  return new ColorBGRA(value.R, value.G, value.B, value.A);
957  }
958 
959  /// <summary>
960  /// Performs an implicit conversion from <see cref="ColorBGRA"/> to <see cref="Color"/>.
961  /// </summary>
962  /// <param name="value">The value.</param>
963  /// <returns>The result of the conversion.</returns>
964  public static implicit operator Color(ColorBGRA value)
965  {
966  return new Color(value.R, value.G, value.B, value.A);
967  }
968 
969  /// <summary>
970  /// Performs an explicit conversion from <see cref="ColorBGRA"/> to <see cref="System.Int32"/>.
971  /// </summary>
972  /// <param name="value">The value.</param>
973  /// <returns>
974  /// The result of the conversion.
975  /// </returns>
976  public static explicit operator int(ColorBGRA value)
977  {
978  return value.ToBgra();
979  }
980 
981  /// <summary>
982  /// Performs an explicit conversion from <see cref="System.Int32"/> to <see cref="ColorBGRA"/>.
983  /// </summary>
984  /// <param name="value">The value.</param>
985  /// <returns>
986  /// The result of the conversion.
987  /// </returns>
988  public static explicit operator ColorBGRA(int value)
989  {
990  return new ColorBGRA(value);
991  }
992 
993  /// <summary>
994  /// Returns a <see cref="System.String"/> that represents this instance.
995  /// </summary>
996  /// <returns>
997  /// A <see cref="System.String"/> that represents this instance.
998  /// </returns>
999  public override string ToString()
1000  {
1001  return ToString(CultureInfo.CurrentCulture);
1002  }
1003 
1004  /// <summary>
1005  /// Returns a <see cref="System.String"/> that represents this instance.
1006  /// </summary>
1007  /// <param name="format">The format to apply to each channel (byte).</param>
1008  /// <returns>
1009  /// A <see cref="System.String"/> that represents this instance.
1010  /// </returns>
1011  public string ToString(string format)
1012  {
1013  return ToString(format, CultureInfo.CurrentCulture);
1014  }
1015 
1016  /// <summary>
1017  /// Returns a <see cref="System.String"/> that represents this instance.
1018  /// </summary>
1019  /// <param name="formatProvider">The format provider.</param>
1020  /// <returns>
1021  /// A <see cref="System.String"/> that represents this instance.
1022  /// </returns>
1023  public string ToString(IFormatProvider formatProvider)
1024  {
1025  return string.Format(formatProvider, toStringFormat, A, R, G, B);
1026  }
1027 
1028  /// <summary>
1029  /// Returns a <see cref="System.String"/> that represents this instance.
1030  /// </summary>
1031  /// <param name="format">The format to apply to each channel (byte).</param>
1032  /// <param name="formatProvider">The format provider.</param>
1033  /// <returns>
1034  /// A <see cref="System.String"/> that represents this instance.
1035  /// </returns>
1036  public string ToString(string format, IFormatProvider formatProvider)
1037  {
1038  if (format == null)
1039  return ToString(formatProvider);
1040 
1041  return string.Format(formatProvider,
1042  toStringFormat,
1043  A.ToString(format, formatProvider),
1044  R.ToString(format, formatProvider),
1045  G.ToString(format, formatProvider),
1046  B.ToString(format, formatProvider));
1047  }
1048 
1049  /// <summary>
1050  /// Returns a hash code for this instance.
1051  /// </summary>
1052  /// <returns>
1053  /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
1054  /// </returns>
1055  public override int GetHashCode()
1056  {
1057  return A.GetHashCode() + R.GetHashCode() + G.GetHashCode() + B.GetHashCode();
1058  }
1059 
1060  /// <summary>
1061  /// Determines whether the specified <see cref="ColorBGRA"/> is equal to this instance.
1062  /// </summary>
1063  /// <param name="other">The <see cref="ColorBGRA"/> to compare with this instance.</param>
1064  /// <returns>
1065  /// <c>true</c> if the specified <see cref="ColorBGRA"/> is equal to this instance; otherwise, <c>false</c>.
1066  /// </returns>
1067  public bool Equals(ColorBGRA other)
1068  {
1069  return R == other.R && G == other.G && B == other.B && A == other.A;
1070  }
1071 
1072  /// <summary>
1073  /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
1074  /// </summary>
1075  /// <param name="value">The <see cref="System.Object"/> to compare with this instance.</param>
1076  /// <returns>
1077  /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
1078  /// </returns>
1079  public override bool Equals(object value)
1080  {
1081  if (value == null)
1082  return false;
1083 
1084  if (!ReferenceEquals(value.GetType(), typeof(ColorBGRA)))
1085  return false;
1086 
1087  return Equals((ColorBGRA)value);
1088  }
1089 
1090  private static byte ToByte(float component)
1091  {
1092  var value = (int)(component * 255.0f);
1093  return (byte)(value < 0 ? 0 : value > 255 ? 255 : value);
1094  }
1095  }
1096 }
static void Scale(ref ColorBGRA value, float scale, out ColorBGRA result)
Scales a color.
Definition: ColorBGRA.cs:510
byte B
The blue component of the color.
Definition: Color.cs:36
static ColorBGRA FromRgba(int color)
Converts the color from a packed RGBA integer.
Definition: ColorBGRA.cs:414
FbxDouble3 operator*(double factor, FbxDouble3 vector)
float Y
The Y component of the vector.
Definition: Vector3.cs:84
float A
The alpha component of the color.
Definition: Color4.cs:78
static void AdjustContrast(ref ColorBGRA value, float contrast, out ColorBGRA result)
Adjusts the contrast of a color.
Definition: ColorBGRA.cs:716
float W
The W component of the vector.
Definition: Vector4.cs:101
byte G
The green component of the color.
Definition: ColorBGRA.cs:30
static void Min(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
Returns a color containing the smallest components of the specified colors.
Definition: ColorBGRA.cs:689
function b
static void Add(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
Adds two colors.
Definition: ColorBGRA.cs:435
static ColorBGRA Subtract(ColorBGRA left, ColorBGRA right)
Subtracts two colors.
Definition: ColorBGRA.cs:474
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: ColorBGRA.cs:1023
byte B
The blue component of the color.
Definition: ColorBGRA.cs:24
bool Equals(ColorBGRA other)
Determines whether the specified ColorBGRA is equal to this instance.
Definition: ColorBGRA.cs:1067
static ColorBGRA Lerp(ColorBGRA start, ColorBGRA end, float amount)
Performs a linear interpolation between two colors.
Definition: ColorBGRA.cs:622
byte A
The alpha component of the color.
Definition: ColorBGRA.cs:42
Represents a color in the form of rgb.
Definition: Color3.cs:41
ColorBGRA(byte red, byte green, byte blue, byte alpha)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:69
float B
The blue component of the color.
Definition: Color3.cs:59
ColorBGRA(byte[] values)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:166
ColorBGRA(float[] values)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:147
override string ToString()
Returns a System.String that represents this instance.
Definition: ColorBGRA.cs:999
static ColorBGRA FromBgra(uint color)
Converts the color from a packed BGRA integer.
Definition: ColorBGRA.cs:404
ColorBGRA(Vector3 value, float alpha)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:109
float X
The X component of the vector.
Definition: Vector4.cs:83
float R
The red component of the color.
Definition: Color3.cs:47
static ColorBGRA Scale(ColorBGRA value, float scale)
Scales a color.
Definition: ColorBGRA.cs:524
byte R
The red component of the color.
Definition: Color.cs:24
float X
The X component of the vector.
Definition: Vector3.cs:78
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
float B
The blue component of the color.
Definition: Color4.cs:72
Represents a 32-bit color (4 bytes) in the form of BGRA (in byte order: B, G, B, A).
Definition: ColorBGRA.cs:16
static void Lerp(ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result)
Performs a linear interpolation between two colors.
Definition: ColorBGRA.cs:604
float G
The green component of the color.
Definition: Color4.cs:66
override bool Equals(object value)
Determines whether the specified System.Object is equal to this instance.
Definition: ColorBGRA.cs:1079
Represents a color in the form of rgba.
Definition: Color4.cs:42
Vector3 ToVector3()
Converts the color into a three component vector.
Definition: ColorBGRA.cs:246
ColorBGRA(int bgra)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:133
static void Clamp(ref ColorBGRA value, ref ColorBGRA min, ref ColorBGRA max, out ColorBGRA result)
Restricts a value to be within a specified range.
Definition: ColorBGRA.cs:559
Color3 ToColor3()
Converts the color into a three component color.
Definition: ColorBGRA.cs:255
int ToBgra()
Converts the color into a packed integer.
Definition: ColorBGRA.cs:218
float GetSaturation()
Gets the saturation.
Definition: ColorBGRA.cs:353
static void Max(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
Returns a color containing the smallest components of the specified colorss.
Definition: ColorBGRA.cs:662
Represents a four dimensional mathematical vector.
Definition: Vector4.cs:42
byte A
The alpha component of the color.
Definition: Color.cs:42
float R
The red component of the color.
Definition: Color4.cs:60
static void Modulate(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
Modulates two colors.
Definition: ColorBGRA.cs:485
SiliconStudio.Core.Mathematics.Color Color
Definition: ColorPicker.cs:14
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
function s(a)
byte[] ToArray()
Creates an array containing the elements of the color.
Definition: ColorBGRA.cs:273
byte R
The red component of the color.
Definition: ColorBGRA.cs:36
static void Negate(ref ColorBGRA value, out ColorBGRA result)
Negates a color.
Definition: ColorBGRA.cs:534
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: ColorBGRA.cs:1036
Vector4 ToVector4()
Converts the color into a four component vector.
Definition: ColorBGRA.cs:264
static void Subtract(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result)
Subtracts two colors.
Definition: ColorBGRA.cs:460
float Y
The Y component of the vector.
Definition: Vector4.cs:89
ColorBGRA(uint bgra)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:121
static ColorBGRA FromRgba(uint color)
Converts the color from a packed RGBA integer.
Definition: ColorBGRA.cs:424
static ColorBGRA SmoothStep(ColorBGRA start, ColorBGRA end, float amount)
Performs a cubic interpolation between two colors.
Definition: ColorBGRA.cs:649
static ColorBGRA Modulate(ColorBGRA left, ColorBGRA right)
Modulates two colors.
Definition: ColorBGRA.cs:499
int ToRgba()
Converts the color into a packed integer.
Definition: ColorBGRA.cs:232
float G
The green component of the color.
Definition: Color3.cs:53
static ColorBGRA Negate(ColorBGRA value)
Negates a color.
Definition: ColorBGRA.cs:547
SiliconStudio.Core.Mathematics.Vector3 Vector3
string ToString(string format)
Returns a System.String that represents this instance.
Definition: ColorBGRA.cs:1011
static ColorBGRA Min(ColorBGRA left, ColorBGRA right)
Returns a color containing the smallest components of the specified colors.
Definition: ColorBGRA.cs:703
static void AdjustSaturation(ref ColorBGRA value, float saturation, out ColorBGRA result)
Adjusts the saturation of a color.
Definition: ColorBGRA.cs:745
static ColorBGRA Clamp(ColorBGRA value, ColorBGRA min, ColorBGRA max)
Restricts a value to be within a specified range.
Definition: ColorBGRA.cs:587
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
ColorBGRA(byte value)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:48
float Z
The Z component of the vector.
Definition: Vector4.cs:95
override int GetHashCode()
Returns a hash code for this instance.
Definition: ColorBGRA.cs:1055
float GetBrightness()
Gets the brightness.
Definition: ColorBGRA.cs:282
float Z
The Z component of the vector.
Definition: Vector3.cs:90
ColorBGRA(Vector4 value)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:96
static ColorBGRA FromBgra(int color)
Converts the color from a packed BGRA integer.
Definition: ColorBGRA.cs:394
static ColorBGRA Max(ColorBGRA left, ColorBGRA right)
Returns a color containing the largest components of the specified colorss.
Definition: ColorBGRA.cs:676
static ColorBGRA AdjustContrast(ColorBGRA value, float contrast)
Adjusts the contrast of a color.
Definition: ColorBGRA.cs:730
static ColorBGRA AdjustSaturation(ColorBGRA value, float saturation)
Adjusts the saturation of a color.
Definition: ColorBGRA.cs:761
DataStyle
Specifies the style used for textual serialization when an array/list or a dictionary/map must be ser...
Definition: DataStyle.cs:9
ColorBGRA(float value)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:57
byte G
The green component of the color.
Definition: Color.cs:30
static void SmoothStep(ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result)
Performs a cubic interpolation between two colors.
Definition: ColorBGRA.cs:636
static ColorBGRA Add(ColorBGRA left, ColorBGRA right)
Adds two colors.
Definition: ColorBGRA.cs:449
ColorBGRA(float red, float green, float blue, float alpha)
Initializes a new instance of the ColorBGRA struct.
Definition: ColorBGRA.cs:84