Struct ColorBGRA
- Namespace
- Stride.Core.Mathematics
- Assembly
- Stride.Core.Mathematics.dll
Represents a 32-bit color (4 bytes) in the form of BGRA (in byte order: B, G, R, A).
[DataContract("ColorBGRA")]
[DataStyle(DataStyle.Compact)]
public struct ColorBGRA : IEquatable<ColorBGRA>, IFormattable
- Implements
Constructors
ColorBGRA(Vector3, float)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(Vector3 value, float alpha)
Parameters
value
Vector3The red, green, and blue components of the color.
alpha
floatThe alpha component of the color.
ColorBGRA(Vector4)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(Vector4 value)
Parameters
value
Vector4The red, green, blue, and alpha components of the color.
ColorBGRA(byte)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(byte value)
Parameters
value
byteThe value that will be assigned to all components.
ColorBGRA(byte, byte, byte, byte)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(byte red, byte green, byte blue, byte alpha)
Parameters
red
byteThe red component of the color.
green
byteThe green component of the color.
blue
byteThe blue component of the color.
alpha
byteThe alpha component of the color.
ColorBGRA(byte[])
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(byte[] values)
Parameters
values
byte[]The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements.
Exceptions
- ArgumentNullException
Thrown when
values
isnull
.- ArgumentOutOfRangeException
Thrown when
values
contains more or less than four elements.
ColorBGRA(int)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(int bgra)
Parameters
bgra
intA packed integer containing all four color components in BGRA.
ColorBGRA(float)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(float value)
Parameters
value
floatThe value that will be assigned to all components.
ColorBGRA(float, float, float, float)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(float red, float green, float blue, float alpha)
Parameters
red
floatThe red component of the color.
green
floatThe green component of the color.
blue
floatThe blue component of the color.
alpha
floatThe alpha component of the color.
ColorBGRA(float[])
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(float[] values)
Parameters
values
float[]The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements.
Exceptions
- ArgumentNullException
Thrown when
values
isnull
.- ArgumentOutOfRangeException
Thrown when
values
contains more or less than four elements.
ColorBGRA(uint)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(uint bgra)
Parameters
bgra
uintA packed integer containing all four color components in BGRA order.
Fields
A
The alpha component of the color.
[DataMember(3)]
public byte A
Field Value
B
The blue component of the color.
[DataMember(0)]
public byte B
Field Value
G
The green component of the color.
[DataMember(1)]
public byte G
Field Value
R
The red component of the color.
[DataMember(2)]
public byte R
Field Value
Properties
this[int]
Gets or sets the component at the specified index.
public byte this[int index] { get; set; }
Parameters
index
intThe 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.
Property Value
- byte
The value of the alpha, red, green, or blue component, depending on the index.
Exceptions
- ArgumentOutOfRangeException
Thrown when the
index
is out of the range [0, 3].
Methods
Add(ColorBGRA, ColorBGRA)
Adds two colors.
public static ColorBGRA Add(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
The sum of the two colors.
Add(ref readonly ColorBGRA, ref readonly ColorBGRA, out ColorBGRA)
Adds two colors.
public static void Add(ref readonly ColorBGRA left, ref readonly ColorBGRA right, out ColorBGRA result)
Parameters
left
ColorBGRAThe first color to add.
right
ColorBGRAThe second color to add.
result
ColorBGRAWhen the method completes, completes the sum of the two colors.
AdjustContrast(ColorBGRA, float)
Adjusts the contrast of a color.
public static ColorBGRA AdjustContrast(ColorBGRA value, float contrast)
Parameters
value
ColorBGRAThe color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
Returns
- ColorBGRA
The adjusted color.
AdjustContrast(ref readonly ColorBGRA, float, out ColorBGRA)
Adjusts the contrast of a color.
public static void AdjustContrast(ref readonly ColorBGRA value, float contrast, out ColorBGRA result)
Parameters
value
ColorBGRAThe color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
result
ColorBGRAWhen the method completes, contains the adjusted color.
AdjustSaturation(ColorBGRA, float)
Adjusts the saturation of a color.
public static ColorBGRA AdjustSaturation(ColorBGRA value, float saturation)
Parameters
value
ColorBGRAThe color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
Returns
- ColorBGRA
The adjusted color.
AdjustSaturation(ref readonly ColorBGRA, float, out ColorBGRA)
Adjusts the saturation of a color.
public static void AdjustSaturation(ref readonly ColorBGRA value, float saturation, out ColorBGRA result)
Parameters
value
ColorBGRAThe color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
result
ColorBGRAWhen the method completes, contains the adjusted color.
Clamp(ColorBGRA, ColorBGRA, ColorBGRA)
Restricts a value to be within a specified range.
public static ColorBGRA Clamp(ColorBGRA value, ColorBGRA min, ColorBGRA max)
Parameters
value
ColorBGRAThe value to clamp.
min
ColorBGRAThe minimum value.
max
ColorBGRAThe maximum value.
Returns
- ColorBGRA
The clamped value.
Clamp(ref readonly ColorBGRA, ref readonly ColorBGRA, ref readonly ColorBGRA, out ColorBGRA)
Restricts a value to be within a specified range.
public static void Clamp(ref readonly ColorBGRA value, ref readonly ColorBGRA min, ref readonly ColorBGRA max, out ColorBGRA result)
Parameters
value
ColorBGRAThe value to clamp.
min
ColorBGRAThe minimum value.
max
ColorBGRAThe maximum value.
result
ColorBGRAWhen the method completes, contains the clamped value.
Deconstruct(out byte, out byte, out byte, out byte)
Deconstructs the vector's components into named variables.
public void Deconstruct(out byte r, out byte g, out byte b, out byte a)
Parameters
Equals(ColorBGRA)
Determines whether the specified ColorBGRA is equal to this instance.
public bool Equals(ColorBGRA other)
Parameters
Returns
Equals(object)
Determines whether the specified object is equal to this instance.
public override bool Equals(object value)
Parameters
Returns
FromBgra(int)
Converts the color from a packed BGRA integer.
public static ColorBGRA FromBgra(int color)
Parameters
color
intA packed integer containing all four color components in BGRA order
Returns
- ColorBGRA
A color.
FromBgra(uint)
Converts the color from a packed BGRA integer.
public static ColorBGRA FromBgra(uint color)
Parameters
color
uintA packed integer containing all four color components in BGRA order
Returns
- ColorBGRA
A color.
FromRgba(int)
Converts the color from a packed RGBA integer.
public static ColorBGRA FromRgba(int color)
Parameters
color
intA packed integer containing all four color components in RGBA order
Returns
- ColorBGRA
A color.
FromRgba(uint)
Converts the color from a packed RGBA integer.
public static ColorBGRA FromRgba(uint color)
Parameters
color
uintA packed integer containing all four color components in RGBA order
Returns
- ColorBGRA
A color.
GetBrightness()
Gets the brightness.
public float GetBrightness()
Returns
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
GetHue()
Gets the hue.
public float GetHue()
Returns
GetSaturation()
Gets the saturation.
public float GetSaturation()
Returns
Lerp(ColorBGRA, ColorBGRA, float)
Performs a linear interpolation between two colors.
public static ColorBGRA Lerp(ColorBGRA start, ColorBGRA end, float amount)
Parameters
start
ColorBGRAStart color.
end
ColorBGRAEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- ColorBGRA
The linear interpolation of the two colors.
Remarks
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Lerp(ref readonly ColorBGRA, ref readonly ColorBGRA, float, out ColorBGRA)
Performs a linear interpolation between two colors.
public static void Lerp(ref readonly ColorBGRA start, ref readonly ColorBGRA end, float amount, out ColorBGRA result)
Parameters
start
ColorBGRAStart color.
end
ColorBGRAEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
ColorBGRAWhen the method completes, contains the linear interpolation of the two colors.
Remarks
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Max(ColorBGRA, ColorBGRA)
Returns a color containing the largest components of the specified colorss.
public static ColorBGRA Max(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
A color containing the largest components of the source colors.
Max(ref readonly ColorBGRA, ref readonly ColorBGRA, out ColorBGRA)
Returns a color containing the smallest components of the specified colorss.
public static void Max(ref readonly ColorBGRA left, ref readonly ColorBGRA right, out ColorBGRA result)
Parameters
left
ColorBGRAThe first source color.
right
ColorBGRAThe second source color.
result
ColorBGRAWhen the method completes, contains an new color composed of the largest components of the source colorss.
Min(ColorBGRA, ColorBGRA)
Returns a color containing the smallest components of the specified colors.
public static ColorBGRA Min(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
A color containing the smallest components of the source colors.
Min(ref readonly ColorBGRA, ref readonly ColorBGRA, out ColorBGRA)
Returns a color containing the smallest components of the specified colors.
public static void Min(ref readonly ColorBGRA left, ref readonly ColorBGRA right, out ColorBGRA result)
Parameters
left
ColorBGRAThe first source color.
right
ColorBGRAThe second source color.
result
ColorBGRAWhen the method completes, contains an new color composed of the smallest components of the source colors.
Modulate(ColorBGRA, ColorBGRA)
Modulates two colors.
public static ColorBGRA Modulate(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
The modulated color.
Modulate(ref readonly ColorBGRA, ref readonly ColorBGRA, out ColorBGRA)
Modulates two colors.
public static void Modulate(ref readonly ColorBGRA left, ref readonly ColorBGRA right, out ColorBGRA result)
Parameters
left
ColorBGRAThe first color to modulate.
right
ColorBGRAThe second color to modulate.
result
ColorBGRAWhen the method completes, contains the modulated color.
Negate(ColorBGRA)
Negates a color.
public static ColorBGRA Negate(ColorBGRA value)
Parameters
value
ColorBGRAThe color to negate.
Returns
- ColorBGRA
The negated color.
Negate(ref readonly ColorBGRA, out ColorBGRA)
Negates a color.
public static void Negate(ref readonly ColorBGRA value, out ColorBGRA result)
Parameters
value
ColorBGRAThe color to negate.
result
ColorBGRAWhen the method completes, contains the negated color.
Scale(ColorBGRA, float)
Scales a color.
public static ColorBGRA Scale(ColorBGRA value, float scale)
Parameters
Returns
- ColorBGRA
The scaled color.
Scale(ref readonly ColorBGRA, float, out ColorBGRA)
Scales a color.
public static void Scale(ref readonly ColorBGRA value, float scale, out ColorBGRA result)
Parameters
value
ColorBGRAThe color to scale.
scale
floatThe amount by which to scale.
result
ColorBGRAWhen the method completes, contains the scaled color.
SmoothStep(ColorBGRA, ColorBGRA, float)
Performs a cubic interpolation between two colors.
public static ColorBGRA SmoothStep(ColorBGRA start, ColorBGRA end, float amount)
Parameters
start
ColorBGRAStart color.
end
ColorBGRAEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- ColorBGRA
The cubic interpolation of the two colors.
SmoothStep(ref readonly ColorBGRA, ref readonly ColorBGRA, float, out ColorBGRA)
Performs a cubic interpolation between two colors.
public static void SmoothStep(ref readonly ColorBGRA start, ref readonly ColorBGRA end, float amount, out ColorBGRA result)
Parameters
start
ColorBGRAStart color.
end
ColorBGRAEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
ColorBGRAWhen the method completes, contains the cubic interpolation of the two colors.
Subtract(ColorBGRA, ColorBGRA)
Subtracts two colors.
public static ColorBGRA Subtract(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
The difference of the two colors.
Subtract(ref readonly ColorBGRA, ref readonly ColorBGRA, out ColorBGRA)
Subtracts two colors.
public static void Subtract(ref readonly ColorBGRA left, ref readonly ColorBGRA right, out ColorBGRA result)
Parameters
left
ColorBGRAThe first color to subtract.
right
ColorBGRAThe second color to subtract.
result
ColorBGRAWHen the method completes, contains the difference of the two colors.
ToArray()
Creates an array containing the elements of the color.
public byte[] ToArray()
Returns
- byte[]
A four-element array containing the components of the color in BGRA order.
ToBgra()
Converts the color into a packed integer.
public int ToBgra()
Returns
- int
A packed integer containing all four color components.
ToColor3()
Converts the color into a three component color.
public Color3 ToColor3()
Returns
- Color3
A three component color containing the red, green, and blue components of the color.
ToRgba()
Converts the color into a packed integer.
public int ToRgba()
Returns
- int
A packed integer containing all four color components.
ToString()
Returns a string that represents this instance.
public override string ToString()
Returns
ToString(IFormatProvider)
Returns a string that represents this instance.
public string ToString(IFormatProvider formatProvider)
Parameters
formatProvider
IFormatProviderThe format provider.
Returns
ToString(string)
Returns a string that represents this instance.
public string ToString(string format)
Parameters
format
stringThe format to apply to each channel (byte).
Returns
ToString(string, IFormatProvider)
Returns a string that represents this instance.
public string ToString(string format, IFormatProvider formatProvider)
Parameters
format
stringThe format to apply to each channel (byte).
formatProvider
IFormatProviderThe format provider.
Returns
ToVector3()
Converts the color into a three component vector.
public Vector3 ToVector3()
Returns
- Vector3
A three component vector containing the red, green, and blue components of the color.
ToVector4()
Converts the color into a four component vector.
public Vector4 ToVector4()
Returns
- Vector4
A four component vector containing all four color components.
Operators
operator +(ColorBGRA, ColorBGRA)
Adds two colors.
public static ColorBGRA operator +(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
The sum of the two colors.
operator ==(ColorBGRA, ColorBGRA)
Tests for equality between two objects.
public static bool operator ==(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- bool
true
ifleft
has the same value asright
; otherwise,false
.
explicit operator ColorBGRA(Color3)
public static explicit operator ColorBGRA(Color3 value)
Parameters
value
Color3The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator ColorBGRA(Color4)
public static explicit operator ColorBGRA(Color4 value)
Parameters
value
Color4The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator Color3(ColorBGRA)
public static explicit operator Color3(ColorBGRA value)
Parameters
value
ColorBGRAThe value.
Returns
- Color3
The result of the conversion.
explicit operator Color4(ColorBGRA)
public static explicit operator Color4(ColorBGRA value)
Parameters
value
ColorBGRAThe value.
Returns
- Color4
The result of the conversion.
explicit operator Vector3(ColorBGRA)
public static explicit operator Vector3(ColorBGRA value)
Parameters
value
ColorBGRAThe value.
Returns
- Vector3
The result of the conversion.
explicit operator Vector4(ColorBGRA)
public static explicit operator Vector4(ColorBGRA value)
Parameters
value
ColorBGRAThe value.
Returns
- Vector4
The result of the conversion.
explicit operator int(ColorBGRA)
public static explicit operator int(ColorBGRA value)
Parameters
value
ColorBGRAThe value.
Returns
- int
The result of the conversion.
explicit operator ColorBGRA(Vector3)
public static explicit operator ColorBGRA(Vector3 value)
Parameters
value
Vector3The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator ColorBGRA(Vector4)
public static explicit operator ColorBGRA(Vector4 value)
Parameters
value
Vector4The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator ColorBGRA(int)
public static explicit operator ColorBGRA(int value)
Parameters
value
intThe value.
Returns
- ColorBGRA
The result of the conversion.
implicit operator ColorBGRA(Color)
public static implicit operator ColorBGRA(Color value)
Parameters
value
ColorThe value.
Returns
- ColorBGRA
The result of the conversion.
implicit operator Color(ColorBGRA)
public static implicit operator Color(ColorBGRA value)
Parameters
value
ColorBGRAThe value.
Returns
- Color
The result of the conversion.
operator !=(ColorBGRA, ColorBGRA)
Tests for inequality between two objects.
public static bool operator !=(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- bool
true
ifleft
has a different value thanright
; otherwise,false
.
operator *(ColorBGRA, ColorBGRA)
Modulates two colors.
public static ColorBGRA operator *(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
The modulated color.
operator *(ColorBGRA, float)
Scales a color.
public static ColorBGRA operator *(ColorBGRA value, float scale)
Parameters
Returns
- ColorBGRA
The scaled color.
operator *(float, ColorBGRA)
Scales a color.
public static ColorBGRA operator *(float scale, ColorBGRA value)
Parameters
Returns
- ColorBGRA
The scaled color.
operator -(ColorBGRA, ColorBGRA)
Subtracts two colors.
public static ColorBGRA operator -(ColorBGRA left, ColorBGRA right)
Parameters
Returns
- ColorBGRA
The difference of the two colors.
operator -(ColorBGRA)
Negates a color.
public static ColorBGRA operator -(ColorBGRA value)
Parameters
value
ColorBGRAThe color to negate.
Returns
- ColorBGRA
A negated color.
operator +(ColorBGRA)
Assert a color (return it unchanged).
public static ColorBGRA operator +(ColorBGRA value)
Parameters
value
ColorBGRAThe color to assert (unchange).
Returns
- ColorBGRA
The asserted (unchanged) color.