Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Helpers.Data.Rgba Struct Reference

Class the represents a floating-point color of red, green, blue, and alpha More...

Public Member Functions

 Rgba (Rgba c)
 Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct. More...
 
 Rgba (float r, float g, float b)
 Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct. More...
 
 Rgba (Rgba rgb, float a)
 Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct. More...
 
 Rgba (float r, float g, float b, float a)
 Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct. More...
 
string ToHex ()
 Convert the Rgba instance to a 8-digit hex string More...
 
override string ToString ()
 Show the Rgba in a human-readable string format More...
 
byte[] ToBytes ()
 Convert Rgba instance to array of 4 bytes More...
 
void Clamp (float min, float max)
 Clamp each component of Rgba to between min and max More...
 
void Clamp ()
 Clamp each component between 0 and 1 More...
 
void ClampScale (float max)
 Clamp the Rgba instance, but in a way that scales down the rest of the colors eg, if you have 2.0,1.0,0.5,1.0, and ClampScale(1). You will get 1.0, 0.5, 0.25, 1.0 The alpha component does not follow the scaling More...
 
void ClampScale ()
 Clamp the Rgba instance, but in a way that scales down the rest of the colors eg, if you have 2.0,1.0,0.5,1.0, and ClampScale(1). You will get 1.0, 0.5, 0.25, 1.0 The alpha component does not follow the scaling More...
 
Rgba Mix (Rgba with, float amt)
 Mix current color with an amount of a second color More...
 

Static Public Member Functions

static Rgba FromBytes (byte[] bytes)
 Gets the Rgba instance of a 3 or 4-tuple byte array More...
 
static Rgba FromBytes (byte r, byte g, byte b, byte a)
 Gets the Rgba from the byte-version of rgba More...
 
static Rgba FromBytes (byte r, byte g, byte b)
 Gets the Rgba instaince from bytes RGB More...
 
static Rgba FromBytes (int r, int g, int b, int a)
 Gets the Rgba instance from 0-255 range integers More...
 
static Rgba FromBytes (int r, int g, int b)
 Gets the Rgba instance from 0-255 range integers More...
 
static Rgba FromHexString (string hexString)
 Gets an Rgba instance from a 3,4,6,8 length hex string, including starting '#' eg #123, #1234, #11223344, #112233 More...
 
static implicit operator Vector4 (Rgba color)
 Cast to a vector4 for easy conversion More...
 
static implicit operator Rgba (Vector4 vec)
 Get a rgba instance from a vector More...
 
static operator Rgba (float[] colors)
 Convert a 4-tuple float array to an Rgba instance More...
 
static Rgba operator+ (Rgba v, Rgba w)
 Add instances More...
 
static Rgba operator- (Rgba v, Rgba w)
 Subtract components More...
 
static Rgba operator* (Rgba v, Rgba w)
 Multiply each component by its counterpart More...
 
static Rgba operator* (Rgba v, float c)
 Multiply each component by a constant More...
 
static Rgba operator* (float c, Rgba v)
 Multiply each component by a constant More...
 
static Rgba operator/ (Rgba v, float c)
 Divide each component by a constant More...
 

Public Attributes

float R
 Red component More...
 
float G
 Green component More...
 
float B
 Blue component More...
 
float A
 Alpha component More...
 

Static Public Attributes

static readonly Rgba Zero = new Rgba(0f, 0f, 0f, 0f)
 All-zeros (0,0,0,0) More...
 
static readonly Rgba Black = new Rgba(0f, 0f, 0f, 1f)
 Black (0,0,0,1) More...
 
static readonly Rgba White = new Rgba(1f, 1f, 1f, 1f)
 White (1,1,1,1) More...
 
static readonly Rgba Gray = new Rgba(0.5f, 0.5f, 0.5f, 1f)
 Gray (0.5, 0.5, 0.5, 1) More...
 
static readonly Rgba Transparent = new Rgba(0f, 0f, 0f, 0f)
 Transparent (0,0,0,0) More...
 
static readonly Rgba Red = new Rgba(1f, 0f, 0f, 1f)
 Red (1,0,0,1) More...
 
static readonly Rgba Green = new Rgba(0f, 1f, 0f, 1f)
 Green (0,1,0,1) More...
 
static readonly Rgba Blue = new Rgba(0f, 0f, 1f, 1f)
 Blue (0,0,1,1) More...
 

Properties

Rgba Grayscale [get]
 Get the average grayscale version of this color Alpha remains the same More...
 
float Luminosity [get]
 Get the average luminosity, multiplied by alpha More...
 
float LuminosityRgb [get]
 Get the luminosity of just the RGB components More...
 
float LuminosityWeighted [get]
 Gets the human-eye corrected luminosity weights More...
 
float LuminosityWeightedRgb [get]
 Gets the human-eye corrected RGB components, luminosity More...
 

Detailed Description

Class the represents a floating-point color of red, green, blue, and alpha

Attribute: StructLayout(LayoutKind.Sequential, Pack = 1)

Constructor & Destructor Documentation

pluginbase.Helpers.Data.Rgba.Rgba ( Rgba  c)

Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.

Parameters
cC.
40  {
41  R = c.R;
42  G = c.G;
43  B = c.B;
44  A = c.A;
45  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28
pluginbase.Helpers.Data.Rgba.Rgba ( float  r,
float  g,
float  b 
)

Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.

Parameters
rThe red component.
gThe green component.
bThe blue component.
54  {
55  R = r;
56  G = g;
57  B = b;
58  A = 1f;
59  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28
pluginbase.Helpers.Data.Rgba.Rgba ( Rgba  rgb,
float  a 
)

Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.

Parameters
rgbRgb.
aThe alpha component.
67  {
68  R = rgb.R;
69  G = rgb.G;
70  B = rgb.B;
71  A = a;
72  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28
pluginbase.Helpers.Data.Rgba.Rgba ( float  r,
float  g,
float  b,
float  a 
)

Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.

Parameters
rThe red component.
gThe green component.
bThe blue component.
aThe alpha component.
82  {
83  R = r;
84  G = g;
85  B = b;
86  A = a;
87  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28

Member Function Documentation

void pluginbase.Helpers.Data.Rgba.Clamp ( float  min,
float  max 
)

Clamp each component of Rgba to between min and max

Parameters
minMinimum.
maxMax.
267  {
268  R = R < min ? min : (R > max ? max : R);
269  G = G < min ? min : (G > max ? max : G);
270  B = B < min ? min : (B > max ? max : B);
271  A = A < min ? min : (A > max ? max : A);
272  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28
void pluginbase.Helpers.Data.Rgba.Clamp ( )

Clamp each component between 0 and 1

278  {
279  Clamp(0f, 1f);
280  }
void Clamp()
Clamp each component between 0 and 1
Definition: Rgba.cs:277
void pluginbase.Helpers.Data.Rgba.ClampScale ( float  max)

Clamp the Rgba instance, but in a way that scales down the rest of the colors eg, if you have 2.0,1.0,0.5,1.0, and ClampScale(1). You will get 1.0, 0.5, 0.25, 1.0 The alpha component does not follow the scaling

Parameters
maxMax.
289  {
290  float mval = R > G && R > B ? R : (G > B ? G : B);
291  if (mval > max)
292  {
293  float ratio = 1f / (mval / max);
294  R *= ratio;
295  G *= ratio;
296  B *= ratio;
297  }
298  A = A > max ? max : A;
299  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28
void pluginbase.Helpers.Data.Rgba.ClampScale ( )

Clamp the Rgba instance, but in a way that scales down the rest of the colors eg, if you have 2.0,1.0,0.5,1.0, and ClampScale(1). You will get 1.0, 0.5, 0.25, 1.0 The alpha component does not follow the scaling

307  {
308  ClampScale(1f);
309  }
void ClampScale()
Clamp the Rgba instance, but in a way that scales down the rest of the colors eg, if you have 2...
Definition: Rgba.cs:306
static Rgba pluginbase.Helpers.Data.Rgba.FromBytes ( byte[]  bytes)
static

Gets the Rgba instance of a 3 or 4-tuple byte array

Returns
The bytes.
Parameters
bytesBytes.

Attribute: 0] / 255f, bytes[1] / 255f, bytes[2

/ 255f);

Attribute: 0] / 255f, bytes[1] / 255f, bytes[2] / 255f, bytes[3

/ 255f);

95  {
96  if (bytes.Length == 3)
97  {
98  return new Rgba(bytes[0] / 255f, bytes[1] / 255f, bytes[2] / 255f);
99  }
100  if (bytes.Length == 4)
101  {
102  return new Rgba(bytes[0] / 255f, bytes[1] / 255f, bytes[2] / 255f, bytes[3] / 255f);
103  }
104  throw new ArgumentOutOfRangeException("Expected 3 or 4 bytes");
105  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static Rgba pluginbase.Helpers.Data.Rgba.FromBytes ( byte  r,
byte  g,
byte  b,
byte  a 
)
static

Gets the Rgba from the byte-version of rgba

Returns
The bytes.
Parameters
rThe red component.
gThe green component.
bThe blue component.
aThe alpha component.
116  {
117  return new Rgba(r/255f, g/255f, b/255f, a/255f);
118  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static Rgba pluginbase.Helpers.Data.Rgba.FromBytes ( byte  r,
byte  g,
byte  b 
)
static

Gets the Rgba instaince from bytes RGB

Returns
The bytes.
Parameters
rThe red component.
gThe green component.
bThe blue component.
128  {
129  return FromBytes(r, g, b, byte.MaxValue);
130  }
static Rgba FromBytes(byte[] bytes)
Gets the Rgba instance of a 3 or 4-tuple byte array
Definition: Rgba.cs:94
static Rgba pluginbase.Helpers.Data.Rgba.FromBytes ( int  r,
int  g,
int  b,
int  a 
)
static

Gets the Rgba instance from 0-255 range integers

Returns
The bytes.
Parameters
rThe red component.
gThe green component.
bThe blue component.
aThe alpha component.
141  {
142  return FromBytes((byte)r, (byte)g, (byte)b, (byte)a);
143  }
static Rgba FromBytes(byte[] bytes)
Gets the Rgba instance of a 3 or 4-tuple byte array
Definition: Rgba.cs:94
static Rgba pluginbase.Helpers.Data.Rgba.FromBytes ( int  r,
int  g,
int  b 
)
static

Gets the Rgba instance from 0-255 range integers

Returns
The bytes.
Parameters
rThe red component.
gThe green component.
bThe blue component.
153  {
154  return FromBytes((byte)r, (byte)g, (byte)b);
155  }
static Rgba FromBytes(byte[] bytes)
Gets the Rgba instance of a 3 or 4-tuple byte array
Definition: Rgba.cs:94
static Rgba pluginbase.Helpers.Data.Rgba.FromHexString ( string  hexString)
static

Gets an Rgba instance from a 3,4,6,8 length hex string, including starting '#' eg #123, #1234, #11223344, #112233

Returns
The hex string.
Parameters
hexStringHex string.

Attribute: 0

!= '#')

Attribute: 1

),

Attribute: 2

),

Attribute: 3

),

Attribute: 4

) : byte.MaxValue);

Attribute: 1], hexString[2

),

Attribute: 3], hexString[4

),

Attribute: 5], hexString[6

),

Attribute: 7], hexString[8

) : byte.MaxValue);

164  {
165  if (hexString[0] != '#')
166  {
167  throw new FormatException("Invalid hex string");
168  }
169 
170  if (hexString.Length == 4 || hexString.Length == 5) //eg #AAA or #AAAF (RGB/RGBA)
171  {
172  return Rgba.FromBytes(
173  Hex.CharValExpanded(hexString[1]),
174  Hex.CharValExpanded(hexString[2]),
175  Hex.CharValExpanded(hexString[3]),
176  hexString.Length == 5 ? Hex.CharValExpanded(hexString[4]) : byte.MaxValue);
177  }
178  if (hexString.Length == 7 || hexString.Length == 9) //eg #AAAAAA or #AABBCCFF
179  {
180  return Rgba.FromBytes(
181  Hex.CharVal(hexString[1], hexString[2]),
182  Hex.CharVal(hexString[3], hexString[4]),
183  Hex.CharVal(hexString[5], hexString[6]),
184  hexString.Length == 9 ? Hex.CharVal(hexString[7], hexString[8]) : byte.MaxValue);
185  }
186 
187  throw new ArgumentOutOfRangeException("Invalid hex string");
188  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
Rgba pluginbase.Helpers.Data.Rgba.Mix ( Rgba  with,
float  amt 
)

Mix current color with an amount of a second color

Parameters
withWith.
amtAmt.
317  {
318  return this * (1f - amt) + with * amt;
319  }
static implicit pluginbase.Helpers.Data.Rgba.operator Rgba ( Vector4  vec)
static

Get a rgba instance from a vector

226  {
227  return new Rgba(vec.X, vec.Y, vec.Z, vec.W);
228  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static pluginbase.Helpers.Data.Rgba.operator Rgba ( float[]  colors)
explicitstatic

Convert a 4-tuple float array to an Rgba instance

Attribute: 0], colors[1], colors[2], colors[3

);

234  {
235  if (colors.Length != 4)
236  {
237  throw new IndexOutOfRangeException("Unable to convert array to RGBA, incorrect size");
238  }
239  return new Rgba(colors[0], colors[1], colors[2], colors[3]);
240  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static implicit pluginbase.Helpers.Data.Rgba.operator Vector4 ( Rgba  color)
static

Cast to a vector4 for easy conversion

218  {
219  return new Vector4(color.R, color.G, color.B, color.A);
220  }
static Rgba pluginbase.Helpers.Data.Rgba.operator* ( Rgba  v,
Rgba  w 
)
static

Multiply each component by its counterpart

407  {
408  return new Rgba(v.R * w.R, v.G * w.G, v.B * w.B, v.A * w.A);
409  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static Rgba pluginbase.Helpers.Data.Rgba.operator* ( Rgba  v,
float  c 
)
static

Multiply each component by a constant

415  {
416  return new Rgba(v.R * c, v.G * c, v.B * c, v.A * c);
417  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static Rgba pluginbase.Helpers.Data.Rgba.operator* ( float  c,
Rgba  v 
)
static

Multiply each component by a constant

423  {
424  return new Rgba(v.R * c, v.G * c, v.B * c, v.A * c);
425  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static Rgba pluginbase.Helpers.Data.Rgba.operator+ ( Rgba  v,
Rgba  w 
)
static

Add instances

391  {
392  return new Rgba(v.R + w.R, v.G + w.G, v.B + w.B, v.A + w.A);
393  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static Rgba pluginbase.Helpers.Data.Rgba.operator- ( Rgba  v,
Rgba  w 
)
static

Subtract components

399  {
400  return new Rgba(v.R - w.R, v.G - w.G, v.B - w.B, v.A - w.A);
401  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
static Rgba pluginbase.Helpers.Data.Rgba.operator/ ( Rgba  v,
float  c 
)
static

Divide each component by a constant

431  {
432  return new Rgba(v.R / c, v.G / c, v.B / c, v.A / c);
433  }
Rgba(Rgba c)
Initializes a new instance of the pluginbase.Helpers.Data.Rgba struct.
Definition: Rgba.cs:39
byte [] pluginbase.Helpers.Data.Rgba.ToBytes ( )

Convert Rgba instance to array of 4 bytes

Returns
The bytes.
247  {
248  return new byte[]
249  {
250  (byte)(R * 255f),
251  (byte)(G * 255f),
252  (byte)(B * 255f),
253  (byte)(A * 255f)
254  };
255  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28
string pluginbase.Helpers.Data.Rgba.ToHex ( )

Convert the Rgba instance to a 8-digit hex string

Returns
The hex.
195  {
196  byte r = (byte)(this.R * byte.MaxValue);
197  byte g = (byte)(this.G * byte.MaxValue);
198  byte b = (byte)(this.B * byte.MaxValue);
199  byte a = (byte)(this.A * byte.MaxValue);
200  return string.Format("#{0}{1}{2}{3}", Hex.ToHex(r, 2), Hex.ToHex(g, 2), Hex.ToHex(b, 2), Hex.ToHex(a, 2));
201  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28
override string pluginbase.Helpers.Data.Rgba.ToString ( )

Show the Rgba in a human-readable string format

Returns
A System.String that represents the current pluginbase.Helpers.Data.Rgba.
208  {
209  return string.Format("[{0},{1},{2},{3}]", R, G, B, A);
210  }
float A
Alpha component
Definition: Rgba.cs:33
float R
Red component
Definition: Rgba.cs:18
float G
Green component
Definition: Rgba.cs:23
float B
Blue component
Definition: Rgba.cs:28

Member Data Documentation

float pluginbase.Helpers.Data.Rgba.A

Alpha component

float pluginbase.Helpers.Data.Rgba.B

Blue component

readonly Rgba pluginbase.Helpers.Data.Rgba.Black = new Rgba(0f, 0f, 0f, 1f)
static

Black (0,0,0,1)

readonly Rgba pluginbase.Helpers.Data.Rgba.Blue = new Rgba(0f, 0f, 1f, 1f)
static

Blue (0,0,1,1)

float pluginbase.Helpers.Data.Rgba.G

Green component

readonly Rgba pluginbase.Helpers.Data.Rgba.Gray = new Rgba(0.5f, 0.5f, 0.5f, 1f)
static

Gray (0.5, 0.5, 0.5, 1)

readonly Rgba pluginbase.Helpers.Data.Rgba.Green = new Rgba(0f, 1f, 0f, 1f)
static

Green (0,1,0,1)

float pluginbase.Helpers.Data.Rgba.R

Red component

readonly Rgba pluginbase.Helpers.Data.Rgba.Red = new Rgba(1f, 0f, 0f, 1f)
static

Red (1,0,0,1)

readonly Rgba pluginbase.Helpers.Data.Rgba.Transparent = new Rgba(0f, 0f, 0f, 0f)
static

Transparent (0,0,0,0)

readonly Rgba pluginbase.Helpers.Data.Rgba.White = new Rgba(1f, 1f, 1f, 1f)
static

White (1,1,1,1)

readonly Rgba pluginbase.Helpers.Data.Rgba.Zero = new Rgba(0f, 0f, 0f, 0f)
static

All-zeros (0,0,0,0)

Property Documentation

Rgba pluginbase.Helpers.Data.Rgba.Grayscale
get

Get the average grayscale version of this color Alpha remains the same

The grayscale.

float pluginbase.Helpers.Data.Rgba.Luminosity
get

Get the average luminosity, multiplied by alpha

The luminosity.

float pluginbase.Helpers.Data.Rgba.LuminosityRgb
get

Get the luminosity of just the RGB components

The luminosity rgb.

float pluginbase.Helpers.Data.Rgba.LuminosityWeighted
get

Gets the human-eye corrected luminosity weights

The luminosity weighted.

float pluginbase.Helpers.Data.Rgba.LuminosityWeightedRgb
get

Gets the human-eye corrected RGB components, luminosity

The luminosity weighted rgb.


The documentation for this struct was generated from the following file: