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>, ISpanFormattable, IFormattable
- Implements
Constructors
ColorBGRA(Vector3, float)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(Vector3 value, float alpha)
Parameters
valueVector3The red, green, and blue components of the color.
alphafloatThe alpha component of the color.
ColorBGRA(Vector4)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(Vector4 value)
Parameters
valueVector4The red, green, blue, and alpha components of the color.
ColorBGRA(byte)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(byte value)
Parameters
valuebyteThe 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
redbyteThe red component of the color.
greenbyteThe green component of the color.
bluebyteThe blue component of the color.
alphabyteThe alpha component of the color.
ColorBGRA(byte[])
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(byte[] values)
Parameters
valuesbyte[]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
valuesisnull.- ArgumentOutOfRangeException
Thrown when
valuescontains more or less than four elements.
ColorBGRA(int)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(int bgra)
Parameters
bgraintA packed integer containing all four color components in BGRA.
ColorBGRA(float)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(float value)
Parameters
valuefloatThe 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
redfloatThe red component of the color.
greenfloatThe green component of the color.
bluefloatThe blue component of the color.
alphafloatThe alpha component of the color.
ColorBGRA(float[])
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(float[] values)
Parameters
valuesfloat[]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
valuesisnull.- ArgumentOutOfRangeException
Thrown when
valuescontains more or less than four elements.
ColorBGRA(uint)
Initializes a new instance of the ColorBGRA struct.
public ColorBGRA(uint bgra)
Parameters
bgrauintA 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] { readonly get; set; }
Parameters
indexintThe 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
indexis 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
leftColorBGRAThe first color to add.
rightColorBGRAThe second color to add.
resultColorBGRAWhen 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
valueColorBGRAThe color whose contrast is to be adjusted.
contrastfloatThe 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
valueColorBGRAThe color whose contrast is to be adjusted.
contrastfloatThe amount by which to adjust the contrast.
resultColorBGRAWhen 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
valueColorBGRAThe color whose saturation is to be adjusted.
saturationfloatThe 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
valueColorBGRAThe color whose saturation is to be adjusted.
saturationfloatThe amount by which to adjust the saturation.
resultColorBGRAWhen 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
valueColorBGRAThe value to clamp.
minColorBGRAThe minimum value.
maxColorBGRAThe 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
valueColorBGRAThe value to clamp.
minColorBGRAThe minimum value.
maxColorBGRAThe maximum value.
resultColorBGRAWhen 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 readonly 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 readonly bool Equals(ColorBGRA other)
Parameters
Returns
Equals(object?)
Determines whether the specified object is equal to this instance.
public override readonly bool Equals(object? value)
Parameters
valueobjectThe object to compare with this instance.
Returns
- bool
trueif the specified object is equal to this instance; otherwise,false.
FromBgra(int)
Converts the color from a packed BGRA integer.
public static ColorBGRA FromBgra(int color)
Parameters
colorintA 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
coloruintA 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
colorintA 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
coloruintA packed integer containing all four color components in RGBA order
Returns
- ColorBGRA
A color.
GetBrightness()
Gets the brightness.
public readonly float GetBrightness()
Returns
GetHashCode()
Returns a hash code for this instance.
public override readonly 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 readonly float GetHue()
Returns
GetSaturation()
Gets the saturation.
public readonly 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
startColorBGRAStart color.
endColorBGRAEnd color.
amountfloatValue 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
startColorBGRAStart color.
endColorBGRAEnd color.
amountfloatValue between 0 and 1 indicating the weight of
end.resultColorBGRAWhen 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
leftColorBGRAThe first source color.
rightColorBGRAThe second source color.
resultColorBGRAWhen 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
leftColorBGRAThe first source color.
rightColorBGRAThe second source color.
resultColorBGRAWhen 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
leftColorBGRAThe first color to modulate.
rightColorBGRAThe second color to modulate.
resultColorBGRAWhen the method completes, contains the modulated color.
Negate(ColorBGRA)
Negates a color.
public static ColorBGRA Negate(ColorBGRA value)
Parameters
valueColorBGRAThe 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
valueColorBGRAThe color to negate.
resultColorBGRAWhen 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
valueColorBGRAThe color to scale.
scalefloatThe amount by which to scale.
resultColorBGRAWhen 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
startColorBGRAStart color.
endColorBGRAEnd color.
amountfloatValue 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
startColorBGRAStart color.
endColorBGRAEnd color.
amountfloatValue between 0 and 1 indicating the weight of
end.resultColorBGRAWhen 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
leftColorBGRAThe first color to subtract.
rightColorBGRAThe second color to subtract.
resultColorBGRAWHen the method completes, contains the difference of the two colors.
ToArray()
Creates an array containing the elements of the color.
public readonly 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 readonly int ToBgra()
Returns
- int
A packed integer containing all four color components.
ToColor3()
Converts the color into a three component color.
public readonly 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 readonly int ToRgba()
Returns
- int
A packed integer containing all four color components.
ToString()
Returns a string that represents this instance.
public override readonly string ToString()
Returns
ToString(string?, IFormatProvider?)
Returns a string that represents this instance.
public readonly string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format.
formatProviderIFormatProviderThe format provider.
Returns
ToVector3()
Converts the color into a three component vector.
public readonly 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 readonly 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
trueiflefthas the same value asright; otherwise,false.
explicit operator ColorBGRA(Color3)
public static explicit operator ColorBGRA(Color3 value)
Parameters
valueColor3The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator ColorBGRA(Color4)
public static explicit operator ColorBGRA(Color4 value)
Parameters
valueColor4The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator Color3(ColorBGRA)
public static explicit operator Color3(ColorBGRA value)
Parameters
valueColorBGRAThe value.
Returns
- Color3
The result of the conversion.
explicit operator Color4(ColorBGRA)
public static explicit operator Color4(ColorBGRA value)
Parameters
valueColorBGRAThe value.
Returns
- Color4
The result of the conversion.
explicit operator Vector3(ColorBGRA)
public static explicit operator Vector3(ColorBGRA value)
Parameters
valueColorBGRAThe value.
Returns
- Vector3
The result of the conversion.
explicit operator Vector4(ColorBGRA)
public static explicit operator Vector4(ColorBGRA value)
Parameters
valueColorBGRAThe value.
Returns
- Vector4
The result of the conversion.
explicit operator int(ColorBGRA)
public static explicit operator int(ColorBGRA value)
Parameters
valueColorBGRAThe value.
Returns
- int
The result of the conversion.
explicit operator ColorBGRA(Vector3)
public static explicit operator ColorBGRA(Vector3 value)
Parameters
valueVector3The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator ColorBGRA(Vector4)
public static explicit operator ColorBGRA(Vector4 value)
Parameters
valueVector4The value.
Returns
- ColorBGRA
The result of the conversion.
explicit operator ColorBGRA(int)
public static explicit operator ColorBGRA(int value)
Parameters
valueintThe value.
Returns
- ColorBGRA
The result of the conversion.
implicit operator ColorBGRA(Color)
public static implicit operator ColorBGRA(Color value)
Parameters
valueColorThe value.
Returns
- ColorBGRA
The result of the conversion.
implicit operator Color(ColorBGRA)
public static implicit operator Color(ColorBGRA value)
Parameters
valueColorBGRAThe 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
trueiflefthas 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
valueColorBGRAThe color to negate.
Returns
- ColorBGRA
A negated color.
operator +(ColorBGRA)
Assert a color (return it unchanged).
public static ColorBGRA operator +(ColorBGRA value)
Parameters
valueColorBGRAThe color to assert (unchange).
Returns
- ColorBGRA
The asserted (unchanged) color.