VectSharp  2.2.1
A light library for C# vector graphics
Colour.cs
1 /*
2  VectSharp - A light library for C# vector graphics.
3  Copyright (C) 2020-2022 Giorgio Bianchini
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, version 3.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 using System;
19 
20 namespace VectSharp
21 {
22  /// <summary>
23  /// Represents an RGB colour.
24  /// </summary>
25  public partial struct Colour : IEquatable<Colour>
26  {
27  /// <summary>
28  /// Red component of the colour. Range: [0, 1].
29  /// </summary>
30  public double R;
31 
32  /// <summary>
33  /// Green component of the colour. Range: [0, 1].
34  /// </summary>
35  public double G;
36 
37  /// <summary>
38  /// Blue component of the colour. Range: [0, 1].
39  /// </summary>
40  public double B;
41 
42  /// <summary>
43  /// Alpha component of the colour. Range: [0, 1].
44  /// </summary>
45  public double A;
46 
47  private Colour(double r, double g, double b, double a)
48  {
49  R = r;
50  G = g;
51  B = b;
52  A = a;
53  }
54 
55  /// <summary>
56  /// Create a new colour from RGB (red, green and blue) values.
57  /// </summary>
58  /// <param name="r">The red component of the colour. Range: [0, 1].</param>
59  /// <param name="g">The green component of the colour. Range: [0, 1].</param>
60  /// <param name="b">The blue component of the colour. Range: [0, 1].</param>
61  /// <returns>A <see cref="Colour"/> struct with the specified components and an alpha component of 1.</returns>
62  public static Colour FromRgb(double r, double g, double b)
63  {
64  return new Colour(r, g, b, 1);
65  }
66 
67  /// <summary>
68  /// Create a new colour from RGB (red, green and blue) values.
69  /// </summary>
70  /// <param name="r">The red component of the colour. Range: [0, 255].</param>
71  /// <param name="g">The green component of the colour. Range: [0, 255].</param>
72  /// <param name="b">The blue component of the colour. Range: [0, 255].</param>
73  /// <returns>A <see cref="Colour"/> struct with the specified components and an alpha component of 1.</returns>
74  public static Colour FromRgb(byte r, byte g, byte b)
75  {
76  return new Colour(r / 255.0, g / 255.0, b / 255.0, 1);
77  }
78 
79  /// <summary>
80  /// Create a new colour from RGB (red, green and blue) values.
81  /// </summary>
82  /// <param name="r">The red component of the colour. Range: [0, 255].</param>
83  /// <param name="g">The green component of the colour. Range: [0, 255].</param>
84  /// <param name="b">The blue component of the colour. Range: [0, 255].</param>
85  /// <returns>A <see cref="Colour"/> struct with the specified components and an alpha component of 1.</returns>
86  public static Colour FromRgb(int r, int g, int b)
87  {
88  return new Colour(r / 255.0, g / 255.0, b / 255.0, 1);
89  }
90 
91  /// <summary>
92  /// Create a new colour from RGBA (red, green, blue and alpha) values.
93  /// </summary>
94  /// <param name="r">The red component of the colour. Range: [0, 1].</param>
95  /// <param name="g">The green component of the colour. Range: [0, 1].</param>
96  /// <param name="b">The blue component of the colour. Range: [0, 1].</param>
97  /// <param name="a">The alpha component of the colour. Range: [0, 1].</param>
98  /// <returns>A <see cref="Colour"/> struct with the specified components.</returns>
99  public static Colour FromRgba(double r, double g, double b, double a)
100  {
101  return new Colour(r, g, b, a);
102  }
103 
104  /// <summary>
105  /// Create a new colour from RGBA (red, green, blue and alpha) values.
106  /// </summary>
107  /// <param name="r">The red component of the colour. Range: [0, 255].</param>
108  /// <param name="g">The green component of the colour. Range: [0, 255].</param>
109  /// <param name="b">The blue component of the colour. Range: [0, 255].</param>
110  /// <param name="a">The alpha component of the colour. Range: [0, 255].</param>
111  /// <returns>A <see cref="Colour"/><see cref="Colour"/> struct with the specified components.</returns>
112  public static Colour FromRgba(byte r, byte g, byte b, byte a)
113  {
114  return new Colour(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
115  }
116 
117  /// <summary>
118  /// Create a new colour from RGBA (red, green, blue and alpha) values.
119  /// </summary>
120  /// <param name="r">The red component of the colour. Range: [0, 255].</param>
121  /// <param name="g">The green component of the colour. Range: [0, 255].</param>
122  /// <param name="b">The blue component of the colour. Range: [0, 255].</param>
123  /// <param name="a">The alpha component of the colour. Range: [0, 1].</param>
124  /// <returns>A <see cref="Colour"/> struct with the specified components.</returns>
125  public static Colour FromRgba(byte r, byte g, byte b, double a)
126  {
127  return new Colour(r / 255.0, g / 255.0, b / 255.0, a);
128  }
129  /// <summary>
130  /// Create a new colour from RGBA (red, green, blue and alpha) values.
131  /// </summary>
132  /// <param name="r">The red component of the colour. Range: [0, 255].</param>
133  /// <param name="g">The green component of the colour. Range: [0, 255].</param>
134  /// <param name="b">The blue component of the colour. Range: [0, 255].</param>
135  /// <param name="a">The alpha component of the colour. Range: [0, 255].</param>
136  /// <returns>A <see cref="Colour"/> struct with the specified components.</returns>
137  public static Colour FromRgba(int r, int g, int b, int a)
138  {
139  return new Colour(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
140  }
141 
142  /// <summary>
143  /// Create a new colour from RGBA (red, green, blue and alpha) values.
144  /// </summary>
145  /// <param name="r">The red component of the colour. Range: [0, 255].</param>
146  /// <param name="g">The green component of the colour. Range: [0, 255].</param>
147  /// <param name="b">The blue component of the colour. Range: [0, 255].</param>
148  /// <param name="a">The alpha component of the colour. Range: [0, 1].</param>
149  /// <returns>A <see cref="Colour"/> struct with the specified components.</returns>
150  public static Colour FromRgba(int r, int g, int b, double a)
151  {
152  return new Colour(r / 255.0, g / 255.0, b / 255.0, a);
153  }
154 
155  /// <summary>
156  /// Create a new colour from RGBA (red, green, blue and alpha) values.
157  /// </summary>
158  /// <param name="colour">A <see cref="ValueTuple{Int32, Int32, Int32, Double}"/> containing component information for the colour. For r, g, and b, range: [0, 255]; for a, range: [0, 1].</param>
159  /// <returns>A <see cref="Colour"/> struct with the specified components.</returns>
160  public static Colour FromRgba((int r, int g, int b, double a) colour)
161  {
162  return new Colour(colour.r / 255.0, colour.g / 255.0, colour.b / 255.0, colour.a);
163  }
164 
165  /// <inheritdoc/>
166  public override bool Equals(object obj)
167  {
168  if (!(obj is Colour))
169  {
170  return false;
171  }
172  else
173  {
174  return this.Equals((Colour)obj);
175  }
176  }
177 
178  /// <inheritdoc/>
179  public bool Equals(Colour col)
180  {
181  return col.R == this.R && col.G == this.G && col.B == this.B && col.A == this.A;
182  }
183 
184  /// <inheritdoc/>
185  public static bool operator ==(Colour col1, Colour col2)
186  {
187  return col1.R == col2.R && col1.G == col2.G && col1.B == col2.B && col1.A == col2.A;
188  }
189 
190  /// <inheritdoc/>
191  public static bool operator !=(Colour col1, Colour col2)
192  {
193  return col1.R != col2.R || col1.G != col2.G || col1.B != col2.B || col1.A != col2.A;
194  }
195 
196  /// <inheritdoc/>
197  public override int GetHashCode()
198  {
199  return (int)(this.R * 255 + this.G * 255 * 255 + this.B * 255 * 255 * 255 + this.A * 255 * 255 * 255 * 255);
200  }
201 
202  /// <summary>
203  /// Convert the <see cref="Colour"/> object into a hex string that is constituted by a "#" followed by two-digit hexadecimal representations of the red, green and blue components of the colour (in the range 0x00 - 0xFF).
204  /// Optionally also includes opacity (alpha channel) data.
205  /// </summary>
206  /// <param name="includeAlpha">Whether two additional hex digits representing the colour's opacity (alpha channel) should be included in the string.</param>
207  /// <returns>A hex colour string.</returns>
208  public string ToCSSString(bool includeAlpha)
209  {
210  if (includeAlpha)
211  {
212  return "#" + ((int)Math.Round(this.R * 255)).ToString("X2") + ((int)Math.Round(this.G * 255)).ToString("X2") + ((int)Math.Round(this.B * 255)).ToString("X2") + ((int)Math.Round(this.A * 255)).ToString("X2");
213  }
214  else
215  {
216  return "#" + ((int)Math.Round(this.R * 255)).ToString("X2") + ((int)Math.Round(this.G * 255)).ToString("X2") + ((int)Math.Round(this.B * 255)).ToString("X2");
217  }
218  }
219 
220  /// <summary>
221  /// Convert a CSS colour string into a <see cref="Colour"/> object.
222  /// </summary>
223  /// <param name="cssString">The CSS colour string. In addition to 148 standard colour names (case-insensitive), #RGB, #RGBA, #RRGGBB and #RRGGBBAA hex strings and rgb(r, g, b) and rgba(r, g, b, a) functional colour notations are supported.</param>
224  /// <returns></returns>
225  public static Colour? FromCSSString(string cssString)
226  {
227  if (cssString.StartsWith("#"))
228  {
229  cssString = cssString.Substring(1);
230 
231  if (cssString.Length == 3)
232  {
233  byte r = byte.Parse(cssString.Substring(0, 1) + cssString.Substring(0, 1), System.Globalization.NumberStyles.HexNumber);
234  byte g = byte.Parse(cssString.Substring(1, 1) + cssString.Substring(1, 1), System.Globalization.NumberStyles.HexNumber);
235  byte b = byte.Parse(cssString.Substring(2, 1) + cssString.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
236 
237  return Colour.FromRgb(r, g, b);
238  }
239  else if (cssString.Length == 4)
240  {
241  byte r = byte.Parse(cssString.Substring(0, 1) + cssString.Substring(0, 1), System.Globalization.NumberStyles.HexNumber);
242  byte g = byte.Parse(cssString.Substring(1, 1) + cssString.Substring(1, 1), System.Globalization.NumberStyles.HexNumber);
243  byte b = byte.Parse(cssString.Substring(2, 1) + cssString.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
244  byte a = byte.Parse(cssString.Substring(3, 1) + cssString.Substring(3, 1), System.Globalization.NumberStyles.HexNumber);
245 
246  return Colour.FromRgba(r, g, b, a);
247  }
248  else if (cssString.Length == 6)
249  {
250  byte r = byte.Parse(cssString.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
251  byte g = byte.Parse(cssString.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
252  byte b = byte.Parse(cssString.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
253 
254  return Colour.FromRgb(r, g, b);
255  }
256  else if (cssString.Length == 8)
257  {
258  byte r = byte.Parse(cssString.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
259  byte g = byte.Parse(cssString.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
260  byte b = byte.Parse(cssString.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
261  byte a = byte.Parse(cssString.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
262 
263  return Colour.FromRgba(r, g, b, a);
264  }
265  else
266  {
267  return null;
268  }
269  }
270  else if (cssString.StartsWith("rgb(") || cssString.StartsWith("rgba("))
271  {
272  try
273  {
274  cssString = cssString.Substring(cssString.IndexOf("(") + 1).Replace(")", "").Replace(" ", "");
275  string[] splitCssString = cssString.Split(',');
276 
277  double R = ParseColourValueOrPercentage(splitCssString[0]);
278  double G = ParseColourValueOrPercentage(splitCssString[1]);
279  double B = ParseColourValueOrPercentage(splitCssString[2]);
280 
281  double A = 1;
282 
283  if (splitCssString.Length == 4)
284  {
285  A = double.Parse(splitCssString[3], System.Globalization.CultureInfo.InvariantCulture);
286  }
287 
288  return Colour.FromRgba(R, G, B, A);
289  }
290  catch
291  {
292  return null;
293  }
294  }
295  else
296  {
297  if (StandardColours.TryGetValue(cssString, out Colour tbr))
298  {
299  return tbr;
300  }
301  else
302  {
303  return null;
304  }
305  }
306  }
307 
308  private static double ParseColourValueOrPercentage(string value)
309  {
310  if (int.TryParse(value, out int tbr))
311  {
312  return tbr / 255.0;
313  }
314  else if (value.Contains("%"))
315  {
316  return double.Parse(value.Replace("%", ""), System.Globalization.CultureInfo.InvariantCulture) / 100.0;
317  }
318  else
319  {
320  return double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
321  }
322  }
323 
324  /// <summary>
325  /// Create a new <see cref="Colour"/> with the same RGB components as the <paramref name="original"/> <see cref="Colour"/>, but with the specified <paramref name="alpha"/>.
326  /// </summary>
327  /// <param name="original">The original <see cref="Colour"/> from which the RGB components will be taken.</param>
328  /// <param name="alpha">The alpha component of the new <see cref="Colour"/>.</param>
329  /// <returns>A <see cref="Colour"/> struct with the same RGB components as the <paramref name="original"/> <see cref="Colour"/> and the specified <paramref name="alpha"/>.</returns>
330  public static Colour WithAlpha(Colour original, double alpha)
331  {
332  return Colour.FromRgba(original.R, original.G, original.B, alpha);
333  }
334 
335  /// <summary>
336  /// Create a new <see cref="Colour"/> with the same RGB components as the <paramref name="original"/> <see cref="Colour"/>, but with the specified <paramref name="alpha"/>.
337  /// </summary>
338  /// <param name="original">The original <see cref="Colour"/> from which the RGB components will be taken.</param>
339  /// <param name="alpha">The alpha component of the new <see cref="Colour"/>.</param>
340  /// <returns>A <see cref="Colour"/> struct with the same RGB components as the <paramref name="original"/> <see cref="Colour"/> and the specified <paramref name="alpha"/>.</returns>
341  public static Colour WithAlpha(Colour original, byte alpha)
342  {
343  return Colour.FromRgba(original.R, original.G, original.B, (double)alpha / 255.0);
344  }
345 
346  /// <summary>
347  /// Create a new <see cref="Colour"/> with the same RGB components as the current <see cref="Colour"/>, but with the specified <paramref name="alpha"/>.
348  /// </summary>
349  /// <param name="alpha">The alpha component of the new <see cref="Colour"/>.</param>
350  /// <returns>A <see cref="Colour"/> struct with the same RGB components as the current <see cref="Colour"/> and the specified <paramref name="alpha"/>.</returns>
351  public Colour WithAlpha(double alpha)
352  {
353  return Colour.FromRgba(this.R, this.G, this.B, alpha);
354  }
355 
356  /// <summary>
357  /// Create a new <see cref="Colour"/> with the same RGB components as the current <see cref="Colour"/>, but with the specified <paramref name="alpha"/>.
358  /// </summary>
359  /// <param name="alpha">The alpha component of the new <see cref="Colour"/>.</param>
360  /// <returns>A <see cref="Colour"/> struct with the same RGB components as the current <see cref="Colour"/> and the specified <paramref name="alpha"/>.</returns>
361  public Colour WithAlpha(byte alpha)
362  {
363  return Colour.FromRgba(this.R, this.G, this.B, (double)alpha / 255.0);
364  }
365 
366  /// <summary>
367  /// Converts a <see cref="Colour"/> to the CIE XYZ colour space.
368  /// </summary>
369  /// <returns>A <see cref="ValueTuple"/> containing the X, Y and Z components of the <see cref="Colour"/>.</returns>
370  public (double X, double Y, double Z) ToXYZ()
371  {
372  double r, g, b;
373 
374  if (R <= 0.04045)
375  {
376  r = 25 * R / 323;
377  }
378  else
379  {
380  r = Math.Pow((200 * R + 11) / 211, 2.4);
381  }
382 
383  if (G <= 0.04045)
384  {
385  g = 25 * G / 323;
386  }
387  else
388  {
389  g = Math.Pow((200 * G + 11) / 211, 2.4);
390  }
391 
392  if (B <= 0.04045)
393  {
394  b = 25 * B / 323;
395  }
396  else
397  {
398  b = Math.Pow((200 * B + 11) / 211, 2.4);
399  }
400 
401  double x = 0.41239080 * r + 0.35758434 * g + 0.18048079 * b;
402  double y = 0.21263901 * r + 0.71516868 * g + 0.07219232 * b;
403  double z = 0.01933082 * r + 0.11919478 * g + 0.95053215 * b;
404 
405  return (x, y, z);
406  }
407 
408  /// <summary>
409  /// Creates a <see cref="Colour"/> from CIE XYZ coordinates.
410  /// </summary>
411  /// <param name="x">The X coordinate.</param>
412  /// <param name="y">The Y coordinate.</param>
413  /// <param name="z">The Z coordinate.</param>
414  /// <returns>An sRGB <see cref="Colour"/> created from the specified components.</returns>
415  public static Colour FromXYZ(double x, double y, double z)
416  {
417  double r = +3.24096994 * x - 1.53738318 * y - 0.49861076 * z;
418  double g = -0.96924364 * x + 1.8759675 * y + 0.04155506 * z;
419  double b = 0.05563008 * x - 0.20397696 * y + 1.05697151 * z;
420 
421  if (r <= 0.0031308)
422  {
423  r = 323 * r / 25;
424  }
425  else
426  {
427  r = (211 * Math.Pow(r, 1 / 2.4) - 11) / 200;
428  }
429 
430  if (g <= 0.0031308)
431  {
432  g = 323 * g / 25;
433  }
434  else
435  {
436  g = (211 * Math.Pow(g, 1 / 2.4) - 11) / 200;
437  }
438 
439  if (b <= 0.0031308)
440  {
441  b = 323 * b / 25;
442  }
443  else
444  {
445  b = (211 * Math.Pow(b, 1 / 2.4) - 11) / 200;
446  }
447 
448  r = Math.Min(Math.Max(0, r), 1);
449  g = Math.Min(Math.Max(0, g), 1);
450  b = Math.Min(Math.Max(0, b), 1);
451 
452  return Colour.FromRgb(r, g, b);
453  }
454 
455  /// <summary>
456  /// Converts a <see cref="Colour"/> to the CIE Lab colour space (under Illuminant D65).
457  /// </summary>
458  /// <returns>A <see cref="ValueType"/> containing the L*, a* and b* components of the <see cref="Colour"/>.</returns>
459  public (double L, double a, double b) ToLab()
460  {
461  double f(double t)
462  {
463  const double d = 6.0 / 29;
464 
465  if (t > d * d * d)
466  {
467  return Math.Pow(t, 1.0 / 3);
468  }
469  else
470  {
471  return t / (3 * d * d) + 4.0 / 29;
472  }
473  }
474 
475  const double xN = 0.950489;
476  const double yN = 1;
477  const double zN = 1.088840;
478 
479  (double x, double y, double z) = this.ToXYZ();
480 
481  double fY = f(y / yN);
482 
483  double l = 1.16 * fY - 0.16;
484  double a = 5 * (f(x / xN) - fY);
485  double b = 2 * (fY - f(z / zN));
486 
487  return (l, a, b);
488  }
489 
490  /// <summary>
491  /// Creates a <see cref="Colour"/> from CIE Lab coordinates (under Illuminant D65).
492  /// </summary>
493  /// <param name="L">The L* component.</param>
494  /// <param name="a">The a* component.</param>
495  /// <param name="b">The b* component.</param>
496  /// <returns>An sRGB <see cref="Colour"/> created from the specified components.</returns>
497  public static Colour FromLab(double L, double a, double b)
498  {
499  double f(double t)
500  {
501  const double d = 6.0 / 29;
502 
503  if (t > d)
504  {
505  return t * t * t;
506  }
507  else
508  {
509  return 3 * d * d * (t - 4.0 / 29);
510  }
511  }
512 
513  const double xN = 0.950489;
514  const double yN = 1;
515  const double zN = 1.088840;
516 
517  double x = xN * f((L + 0.16) / 1.16 + a / 5);
518  double y = yN * f((L + 0.16) / 1.16);
519  double z = zN * f((L + 0.16) / 1.16 - b / 2);
520 
521  return Colour.FromXYZ(x, y, z);
522  }
523 
524  /// <summary>
525  /// Converts a <see cref="Colour"/> to the HSL colour space.
526  /// </summary>
527  /// <returns>A <see cref="ValueType"/> containing the H, S and L components of the <see cref="Colour"/>. Each component has range [0, 1].</returns>
528  public (double H, double S, double L) ToHSL()
529  {
530  double xMax = Math.Max(Math.Max(R, G), B);
531  double xMin = Math.Min(Math.Min(R, G), B);
532 
533  double l = (xMax + xMin) * 0.5;
534 
535  double h;
536 
537  if (xMax == xMin)
538  {
539  h = 0;
540  }
541  else if (xMax == R)
542  {
543  h = (G - B) / (xMax - xMin) / 6;
544  }
545  else if (xMax == G)
546  {
547  h = (2 + (B - R) / (xMax - xMin)) / 6;
548  }
549  else
550  {
551  h = (4 + (R - G) / (xMax - xMin)) / 6;
552  }
553 
554  double s;
555 
556  if (l == 0 || l == 1)
557  {
558  s = 0;
559  }
560  else
561  {
562  s = (xMax - l) / Math.Min(l, 1 - l);
563  }
564 
565  return (h, s, l);
566  }
567 
568  /// <summary>
569  /// Creates a <see cref="Colour"/> from HSL coordinates.
570  /// </summary>
571  /// <param name="h">The H component. Should be in range [0, 1].</param>
572  /// <param name="s">The S component. Should be in range [0, 1].</param>
573  /// <param name="l">The L component. Should be in range [0, 1].</param>
574  /// <returns>A <see cref="Colour"/> created from the specified components.</returns>
575  public static Colour FromHSL(double h, double s, double l)
576  {
577  double c = (1 - Math.Abs(2 * l - 1)) * s;
578 
579  double hp = h * 6;
580 
581  double x = c * (1 - Math.Abs((hp % 2) - 1));
582 
583  double r1, g1, b1;
584 
585  if (hp <= 1)
586  {
587  r1 = c;
588  g1 = x;
589  b1 = 0;
590  }
591  else if (hp <= 2)
592  {
593  r1 = x;
594  g1 = c;
595  b1 = 0;
596  }
597  else if (hp <= 3)
598  {
599  r1 = 0;
600  g1 = c;
601  b1 = x;
602  }
603  else if (hp <= 4)
604  {
605  r1 = 0;
606  g1 = x;
607  b1 = c;
608  }
609  else if (hp <= 5)
610  {
611  r1 = x;
612  g1 = 0;
613  b1 = c;
614  }
615  else if (hp <= 6)
616  {
617  r1 = c;
618  g1 = 0;
619  b1 = x;
620  }
621  else
622  {
623  r1 = 0;
624  g1 = 0;
625  b1 = 0;
626  }
627 
628  double m = l - c / 2;
629 
630  return Colour.FromRgb(r1 + m, g1 + m, b1 + m);
631  }
632 
633  }
634 }
VectSharp.Colour.L
double L
Converts a Colour to the CIE Lab colour space (under Illuminant D65).
Definition: Colour.cs:459
VectSharp.Colour
Represents an RGB colour.
Definition: Colour.cs:26
VectSharp.Colour.FromRgba
static Colour FromRgba(byte r, byte g, byte b, byte a)
Create a new colour from RGBA (red, green, blue and alpha) values.
Definition: Colour.cs:112
VectSharp.Colour.FromXYZ
static Colour FromXYZ(double x, double y, double z)
Creates a Colour from CIE XYZ coordinates.
Definition: Colour.cs:415
VectSharp.Colour.WithAlpha
Colour WithAlpha(byte alpha)
Create a new Colour with the same RGB components as the current Colour, but with the specified alpha ...
Definition: Colour.cs:361
VectSharp.Colour.R
double R
Red component of the colour. Range: [0, 1].
Definition: Colour.cs:30
VectSharp
Definition: Brush.cs:26
VectSharp.Colour.GetHashCode
override int GetHashCode()
Definition: Colour.cs:197
VectSharp.Colour.operator==
static bool operator==(Colour col1, Colour col2)
Definition: Colour.cs:185
VectSharp.Colour.A
double A
Alpha component of the colour. Range: [0, 1].
Definition: Colour.cs:45
VectSharp.Colour.FromCSSString
static ? Colour FromCSSString(string cssString)
Convert a CSS colour string into a Colour object.
Definition: Colour.cs:225
VectSharp.Colour.FromRgba
static Colour FromRgba(int r, int g, int b, double a)
Create a new colour from RGBA (red, green, blue and alpha) values.
Definition: Colour.cs:150
VectSharp.Colour.FromRgb
static Colour FromRgb(int r, int g, int b)
Create a new colour from RGB (red, green and blue) values.
Definition: Colour.cs:86
VectSharp.Colour.FromRgb
static Colour FromRgb(byte r, byte g, byte b)
Create a new colour from RGB (red, green and blue) values.
Definition: Colour.cs:74
VectSharp.Colour.WithAlpha
static Colour WithAlpha(Colour original, byte alpha)
Create a new Colour with the same RGB components as the original Colour, but with the specified alph...
Definition: Colour.cs:341
VectSharp.Colour.WithAlpha
static Colour WithAlpha(Colour original, double alpha)
Create a new Colour with the same RGB components as the original Colour, but with the specified alph...
Definition: Colour.cs:330
VectSharp.Colour.FromRgba
static Colour FromRgba(int r, int g, int b, int a)
Create a new colour from RGBA (red, green, blue and alpha) values.
Definition: Colour.cs:137
VectSharp.Colour.H
double H
Converts a Colour to the HSL colour space.
Definition: Colour.cs:528
VectSharp.Colour.FromRgba
static Colour FromRgba(byte r, byte g, byte b, double a)
Create a new colour from RGBA (red, green, blue and alpha) values.
Definition: Colour.cs:125
VectSharp.Colour.Equals
bool Equals(Colour col)
Definition: Colour.cs:179
VectSharp.Colour.ToCSSString
string ToCSSString(bool includeAlpha)
Convert the Colour object into a hex string that is constituted by a "#" followed by two-digit hexade...
Definition: Colour.cs:208
VectSharp.Colour.WithAlpha
Colour WithAlpha(double alpha)
Create a new Colour with the same RGB components as the current Colour, but with the specified alpha ...
Definition: Colour.cs:351
VectSharp.Colour.Equals
override bool Equals(object obj)
Definition: Colour.cs:166
VectSharp.Colour.X
double X
Converts a Colour to the CIE XYZ colour space.
Definition: Colour.cs:370
VectSharp.Colour.B
double B
Blue component of the colour. Range: [0, 1].
Definition: Colour.cs:40
VectSharp.Colour.FromRgba
static Colour FromRgba((int r, int g, int b, double a) colour)
Create a new colour from RGBA (red, green, blue and alpha) values.
Definition: Colour.cs:160
VectSharp.Colour.FromHSL
static Colour FromHSL(double h, double s, double l)
Creates a Colour from HSL coordinates.
Definition: Colour.cs:575
VectSharp.Colour.FromRgb
static Colour FromRgb(double r, double g, double b)
Create a new colour from RGB (red, green and blue) values.
Definition: Colour.cs:62
VectSharp.Colour.G
double G
Green component of the colour. Range: [0, 1].
Definition: Colour.cs:35
VectSharp.Colour.FromLab
static Colour FromLab(double L, double a, double b)
Creates a Colour from CIE Lab coordinates (under Illuminant D65).
Definition: Colour.cs:497
VectSharp.Colour.operator!=
static bool operator!=(Colour col1, Colour col2)
Definition: Colour.cs:191
VectSharp.Colour.FromRgba
static Colour FromRgba(double r, double g, double b, double a)
Create a new colour from RGBA (red, green, blue and alpha) values.
Definition: Colour.cs:99