Struct Color4
- Namespace
- Stride.Core.Mathematics
- Assembly
- Stride.Core.Mathematics.dll
Represents a color in the form of rgba.
[DataContract("Color4")]
[DataStyle(DataStyle.Compact)]
public struct Color4 : IEquatable<Color4>, IFormattable
- Implements
Constructors
Color4(Color)
Initializes a new instance of the Color4 struct.
public Color4(Color color)
Parameters
Color4(Color3)
Initializes a new instance of the Color4 struct.
public Color4(Color3 color)
Parameters
Color4(Color3, float)
Initializes a new instance of the Color4 struct.
public Color4(Color3 color, float alpha = 1)
Parameters
Color4(ColorBGRA)
Initializes a new instance of the Color4 struct.
public Color4(ColorBGRA color)
Parameters
Color4(Vector3, float)
Initializes a new instance of the Color4 struct.
public Color4(Vector3 value, float alpha = 1)
Parameters
value
Vector3The red, green, and blue components of the color.
alpha
floatThe alpha component of the color.
Color4(Vector4)
Initializes a new instance of the Color4 struct.
public Color4(Vector4 value)
Parameters
value
Vector4The red, green, blue, and alpha components of the color.
Color4(int)
Initializes a new instance of the Color4 struct.
public Color4(int rgba)
Parameters
rgba
intA packed integer containing all four color components in RGBA order.
Color4(float)
Initializes a new instance of the Color4 struct.
public Color4(float value)
Parameters
value
floatThe value that will be assigned to all components.
Color4(float, float, float, float)
Initializes a new instance of the Color4 struct.
public Color4(float red, float green, float blue, float alpha = 1)
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.
Color4(float[])
Initializes a new instance of the Color4 struct.
public Color4(float[] values)
Parameters
values
float[]The values to assign to the red, green, blue, and 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.
Color4(uint)
Initializes a new instance of the Color4 struct.
public Color4(uint rgba)
Parameters
rgba
uintA packed integer containing all four color components in RGBA order.
Fields
A
The alpha component of the color.
[DataMember(3)]
public float A
Field Value
B
The blue component of the color.
[DataMember(2)]
public float B
Field Value
Black
The Black color (0, 0, 0, 1).
public static readonly Color4 Black
Field Value
G
The green component of the color.
[DataMember(1)]
public float G
Field Value
R
The red component of the color.
[DataMember(0)]
public float R
Field Value
White
The White color (1, 1, 1, 1).
public static readonly Color4 White
Field Value
Properties
this[int]
Gets or sets the component at the specified index.
public float 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
- float
The value of the red, green, blue, and alpha components, depending on the index.
Exceptions
- ArgumentOutOfRangeException
Thrown when the
index
is out of the range [0, 3].
Methods
Add(Color4, Color4)
Adds two colors.
public static Color4 Add(Color4 left, Color4 right)
Parameters
Returns
- Color4
The sum of the two colors.
Add(ref readonly Color4, ref readonly Color4, out Color4)
Adds two colors.
public static void Add(ref readonly Color4 left, ref readonly Color4 right, out Color4 result)
Parameters
left
Color4The first color to add.
right
Color4The second color to add.
result
Color4When the method completes, completes the sum of the two colors.
AdjustContrast(Color4, float)
Adjusts the contrast of a color.
public static Color4 AdjustContrast(Color4 value, float contrast)
Parameters
value
Color4The color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
Returns
- Color4
The adjusted color.
AdjustContrast(ref readonly Color4, float, out Color4)
Adjusts the contrast of a color.
public static void AdjustContrast(ref readonly Color4 value, float contrast, out Color4 result)
Parameters
value
Color4The color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
result
Color4When the method completes, contains the adjusted color.
AdjustSaturation(Color4, float)
Adjusts the saturation of a color.
public static Color4 AdjustSaturation(Color4 value, float saturation)
Parameters
value
Color4The color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
Returns
- Color4
The adjusted color.
AdjustSaturation(ref readonly Color4, float, out Color4)
Adjusts the saturation of a color.
public static void AdjustSaturation(ref readonly Color4 value, float saturation, out Color4 result)
Parameters
value
Color4The color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
result
Color4When the method completes, contains the adjusted color.
Clamp(Color4, Color4, Color4)
Restricts a value to be within a specified range.
public static Color4 Clamp(Color4 value, Color4 min, Color4 max)
Parameters
Returns
- Color4
The clamped value.
Clamp(ref readonly Color4, ref readonly Color4, ref readonly Color4, out Color4)
Restricts a value to be within a specified range.
public static void Clamp(ref readonly Color4 value, ref readonly Color4 min, ref readonly Color4 max, out Color4 result)
Parameters
value
Color4The value to clamp.
min
Color4The minimum value.
max
Color4The maximum value.
result
Color4When the method completes, contains the clamped value.
Deconstruct(out float, out float, out float, out float)
Deconstructs the vector's components into named variables.
public void Deconstruct(out float r, out float g, out float b, out float a)
Parameters
Equals(Color4)
Determines whether the specified Color4 is equal to this instance.
public bool Equals(Color4 other)
Parameters
Returns
Equals(object)
Determines whether the specified object is equal to this instance.
public override bool Equals(object value)
Parameters
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.
Lerp(Color4, Color4, float)
Performs a linear interpolation between two colors.
public static Color4 Lerp(Color4 start, Color4 end, float amount)
Parameters
start
Color4Start color.
end
Color4End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- Color4
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 Color4, ref readonly Color4, float, out Color4)
Performs a linear interpolation between two colors.
public static void Lerp(ref readonly Color4 start, ref readonly Color4 end, float amount, out Color4 result)
Parameters
start
Color4Start color.
end
Color4End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
Color4When 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(Color4, Color4)
Returns a color containing the largest components of the specified colors.
public static Color4 Max(Color4 left, Color4 right)
Parameters
Returns
- Color4
A color containing the largest components of the source colors.
Max(ref readonly Color4, ref readonly Color4, out Color4)
Returns a color containing the smallest components of the specified colors.
public static void Max(ref readonly Color4 left, ref readonly Color4 right, out Color4 result)
Parameters
left
Color4The first source color.
right
Color4The second source color.
result
Color4When the method completes, contains an new color composed of the largest components of the source colors.
Min(Color4, Color4)
Returns a color containing the smallest components of the specified colors.
public static Color4 Min(Color4 left, Color4 right)
Parameters
Returns
- Color4
A color containing the smallest components of the source colors.
Min(ref readonly Color4, ref readonly Color4, out Color4)
Returns a color containing the smallest components of the specified colors.
public static void Min(ref readonly Color4 left, ref readonly Color4 right, out Color4 result)
Parameters
left
Color4The first source color.
right
Color4The second source color.
result
Color4When the method completes, contains an new color composed of the smallest components of the source colors.
Modulate(Color4, Color4)
Modulates two colors.
public static Color4 Modulate(Color4 left, Color4 right)
Parameters
Returns
- Color4
The modulated color.
Modulate(ref readonly Color4, ref readonly Color4, out Color4)
Modulates two colors.
public static void Modulate(ref readonly Color4 left, ref readonly Color4 right, out Color4 result)
Parameters
left
Color4The first color to modulate.
right
Color4The second color to modulate.
result
Color4When the method completes, contains the modulated color.
Negate(Color4)
Negates a color.
public static Color4 Negate(Color4 value)
Parameters
value
Color4The color to negate.
Returns
- Color4
The negated color.
Negate(ref readonly Color4, out Color4)
Negates a color.
public static void Negate(ref readonly Color4 value, out Color4 result)
Parameters
value
Color4The color to negate.
result
Color4When the method completes, contains the negated color.
PremultiplyAlpha(Color4)
Premultiplies the color components by the alpha value.
public static Color4 PremultiplyAlpha(Color4 value)
Parameters
value
Color4The color to premultiply.
Returns
- Color4
A color with premultiplied alpha.
Scale(Color4, float)
Scales a color.
public static Color4 Scale(Color4 value, float scale)
Parameters
Returns
- Color4
The scaled color.
Scale(ref readonly Color4, float, out Color4)
Scales a color.
public static void Scale(ref readonly Color4 value, float scale, out Color4 result)
Parameters
value
Color4The color to scale.
scale
floatThe amount by which to scale.
result
Color4When the method completes, contains the scaled color.
SmoothStep(Color4, Color4, float)
Performs a cubic interpolation between two colors.
public static Color4 SmoothStep(Color4 start, Color4 end, float amount)
Parameters
start
Color4Start color.
end
Color4End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- Color4
The cubic interpolation of the two colors.
SmoothStep(ref readonly Color4, ref readonly Color4, float, out Color4)
Performs a cubic interpolation between two colors.
public static void SmoothStep(ref readonly Color4 start, ref readonly Color4 end, float amount, out Color4 result)
Parameters
start
Color4Start color.
end
Color4End color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
Color4When the method completes, contains the cubic interpolation of the two colors.
Subtract(Color4, Color4)
Subtracts two colors.
public static Color4 Subtract(Color4 left, Color4 right)
Parameters
Returns
- Color4
The difference of the two colors.
Subtract(ref readonly Color4, ref readonly Color4, out Color4)
Subtracts two colors.
public static void Subtract(ref readonly Color4 left, ref readonly Color4 right, out Color4 result)
Parameters
left
Color4The first color to subtract.
right
Color4The second color to subtract.
result
Color4WHen the method completes, contains the difference of the two colors.
ToArray()
Creates an array containing the elements of the color.
public float[] ToArray()
Returns
- float[]
A four-element array containing the components of the color.
ToBgra()
Converts the color into a packed integer.
public int ToBgra()
Returns
- int
A packed integer containing all four color components.
ToBgra(out byte, out byte, out byte, out byte)
Converts the color into a packed integer.
public void ToBgra(out byte r, out byte g, out byte b, out byte a)
Parameters
ToColor3()
Converts this color to an equivalent Color3, discarding the alpha channel.
public Color3 ToColor3()
Returns
ToLinear()
Converts this color from sRGB space to linear space.
public Color4 ToLinear()
Returns
- Color4
A color4 in linear space.
ToRgba()
Converts the color into a packed integer.
public int ToRgba()
Returns
- int
A packed integer containing all four color components.
ToSRgb()
Converts this color from linear space to sRGB space.
public Color4 ToSRgb()
Returns
- Color4
A color3 in sRGB space.
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 (float).
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 (float).
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 +(Color4, Color4)
Adds two colors.
public static Color4 operator +(Color4 left, Color4 right)
Parameters
Returns
- Color4
The sum of the two colors.
operator ==(Color4, Color4)
Tests for equality between two objects.
public static bool operator ==(Color4 left, Color4 right)
Parameters
Returns
- bool
true
ifleft
has the same value asright
; otherwise,false
.
explicit operator Color3(Color4)
public static explicit operator Color3(Color4 value)
Parameters
value
Color4The value.
Returns
- Color3
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 Vector3(Color4)
public static explicit operator Vector3(Color4 value)
Parameters
value
Color4The value.
Returns
- Vector3
The result of the conversion.
explicit operator int(Color4)
public static explicit operator int(Color4 value)
Parameters
value
Color4The value.
Returns
- int
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 Color4(Vector3)
public static explicit operator Color4(Vector3 value)
Parameters
value
Vector3The value.
Returns
- Color4
The result of the conversion.
explicit operator Color4(Vector4)
public static explicit operator Color4(Vector4 value)
Parameters
value
Vector4The value.
Returns
- Color4
The result of the conversion.
explicit operator Color4(int)
public static explicit operator Color4(int value)
Parameters
value
intThe value.
Returns
- Color4
The result of the conversion.
implicit operator Vector4(Color4)
public static implicit operator Vector4(Color4 value)
Parameters
value
Color4The value.
Returns
- Vector4
The result of the conversion.
operator !=(Color4, Color4)
Tests for inequality between two objects.
public static bool operator !=(Color4 left, Color4 right)
Parameters
Returns
- bool
true
ifleft
has a different value thanright
; otherwise,false
.
operator *(Color4, Color4)
Modulates two colors.
public static Color4 operator *(Color4 left, Color4 right)
Parameters
Returns
- Color4
The modulated color.
operator *(Color4, float)
Scales a color.
public static Color4 operator *(Color4 value, float scale)
Parameters
Returns
- Color4
The scaled color.
operator *(float, Color4)
Scales a color.
public static Color4 operator *(float scale, Color4 value)
Parameters
Returns
- Color4
The scaled color.
operator -(Color4, Color4)
Subtracts two colors.
public static Color4 operator -(Color4 left, Color4 right)
Parameters
Returns
- Color4
The difference of the two colors.
operator -(Color4)
Negates a color.
public static Color4 operator -(Color4 value)
Parameters
value
Color4The color to negate.
Returns
- Color4
A negated color.
operator +(Color4)
Assert a color (return it unchanged).
public static Color4 operator +(Color4 value)
Parameters
value
Color4The color to assert (unchanged).
Returns
- Color4
The asserted (unchanged) color.