Table of Contents

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

color Color

Color used to initialize the color.

Color4(Color3)

Initializes a new instance of the Color4 struct.

public Color4(Color3 color)

Parameters

color Color3

Color3 used to initialize the color.

Color4(Color3, float)

Initializes a new instance of the Color4 struct.

public Color4(Color3 color, float alpha = 1)

Parameters

color Color3

Color3 used to initialize the color.

alpha float

The alpha component of the color.

Color4(ColorBGRA)

Initializes a new instance of the Color4 struct.

public Color4(ColorBGRA color)

Parameters

color ColorBGRA

Color used to initialize the color.

Color4(Vector3, float)

Initializes a new instance of the Color4 struct.

public Color4(Vector3 value, float alpha = 1)

Parameters

value Vector3

The red, green, and blue components of the color.

alpha float

The alpha component of the color.

Color4(Vector4)

Initializes a new instance of the Color4 struct.

public Color4(Vector4 value)

Parameters

value Vector4

The 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 int

A 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 float

The 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 float

The red component of the color.

green float

The green component of the color.

blue float

The blue component of the color.

alpha float

The 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 is null.

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 uint

A 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

float

B

The blue component of the color.

[DataMember(2)]
public float B

Field Value

float

Black

The Black color (0, 0, 0, 1).

public static readonly Color4 Black

Field Value

Color4

G

The green component of the color.

[DataMember(1)]
public float G

Field Value

float

R

The red component of the color.

[DataMember(0)]
public float R

Field Value

float

White

The White color (1, 1, 1, 1).

public static readonly Color4 White

Field Value

Color4

Properties

this[int]

Gets or sets the component at the specified index.

public float this[int index] { get; set; }

Parameters

index int

The 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

left Color4

The first color to add.

right Color4

The second color to add.

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 Color4

The first color to add.

right Color4

The second color to add.

result Color4

When 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 Color4

The color whose contrast is to be adjusted.

contrast float

The 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 Color4

The color whose contrast is to be adjusted.

contrast float

The amount by which to adjust the contrast.

result Color4

When 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 Color4

The color whose saturation is to be adjusted.

saturation float

The 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 Color4

The color whose saturation is to be adjusted.

saturation float

The amount by which to adjust the saturation.

result Color4

When 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

value Color4

The value to clamp.

min Color4

The minimum value.

max Color4

The maximum value.

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 Color4

The value to clamp.

min Color4

The minimum value.

max Color4

The maximum value.

result Color4

When 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

r float

The R component

g float

The G component

b float

The B component

a float

The A component

Equals(Color4)

Determines whether the specified Color4 is equal to this instance.

public bool Equals(Color4 other)

Parameters

other Color4

The Color4 to compare with this instance.

Returns

bool

true if the specified Color4 is equal to this instance; otherwise, false.

Equals(object)

Determines whether the specified object is equal to this instance.

public override bool Equals(object value)

Parameters

value object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

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 Color4

Start color.

end Color4

End color.

amount float

Value 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 Color4

Start color.

end Color4

End color.

amount float

Value between 0 and 1 indicating the weight of end.

result Color4

When 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

left Color4

The first source color.

right Color4

The second source color.

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 Color4

The first source color.

right Color4

The second source color.

result Color4

When 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

left Color4

The first source color.

right Color4

The second source color.

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 Color4

The first source color.

right Color4

The second source color.

result Color4

When 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

left Color4

The first color to modulate.

right Color4

The second color to modulate.

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 Color4

The first color to modulate.

right Color4

The second color to modulate.

result Color4

When the method completes, contains the modulated color.

Negate(Color4)

Negates a color.

public static Color4 Negate(Color4 value)

Parameters

value Color4

The 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 Color4

The color to negate.

result Color4

When 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 Color4

The 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

value Color4

The color to scale.

scale float

The amount by which to scale.

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 Color4

The color to scale.

scale float

The amount by which to scale.

result Color4

When 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 Color4

Start color.

end Color4

End color.

amount float

Value 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 Color4

Start color.

end Color4

End color.

amount float

Value between 0 and 1 indicating the weight of end.

result Color4

When 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

left Color4

The first color to subtract.

right Color4

The second color to subtract

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 Color4

The first color to subtract.

right Color4

The second color to subtract.

result Color4

WHen 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

r byte
g byte
b byte
a byte

ToColor3()

Converts this color to an equivalent Color3, discarding the alpha channel.

public Color3 ToColor3()

Returns

Color3

An equivalent Color3, discarding the alpha channel.

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

string

A string that represents this instance.

ToString(IFormatProvider)

Returns a string that represents this instance.

public string ToString(IFormatProvider formatProvider)

Parameters

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToString(string)

Returns a string that represents this instance.

public string ToString(string format)

Parameters

format string

The format to apply to each channel (float).

Returns

string

A string that represents this instance.

ToString(string, IFormatProvider)

Returns a string that represents this instance.

public string ToString(string format, IFormatProvider formatProvider)

Parameters

format string

The format to apply to each channel (float).

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

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

left Color4

The first color to add.

right Color4

The second color to add.

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

left Color4

The first value to compare.

right Color4

The second value to compare.

Returns

bool

true if left has the same value as right; otherwise, false.

explicit operator Color3(Color4)

Performs an explicit conversion from Color4 to Color3.

public static explicit operator Color3(Color4 value)

Parameters

value Color4

The value.

Returns

Color3

The result of the conversion.

explicit operator ColorBGRA(Color4)

Performs an explicit conversion from Vector4 to Color4.

public static explicit operator ColorBGRA(Color4 value)

Parameters

value Color4

The value.

Returns

ColorBGRA

The result of the conversion.

explicit operator Vector3(Color4)

Performs an explicit conversion from Color4 to Vector3.

public static explicit operator Vector3(Color4 value)

Parameters

value Color4

The value.

Returns

Vector3

The result of the conversion.

explicit operator int(Color4)

Performs an explicit conversion from Color4 to int.

public static explicit operator int(Color4 value)

Parameters

value Color4

The value.

Returns

int

The result of the conversion.

explicit operator Color4(ColorBGRA)

Performs an explicit conversion from Vector3 to Color4.

public static explicit operator Color4(ColorBGRA value)

Parameters

value ColorBGRA

The value.

Returns

Color4

The result of the conversion.

explicit operator Color4(Vector3)

Performs an explicit conversion from Vector3 to Color4.

public static explicit operator Color4(Vector3 value)

Parameters

value Vector3

The value.

Returns

Color4

The result of the conversion.

explicit operator Color4(Vector4)

Performs an explicit conversion from Vector4 to Color4.

public static explicit operator Color4(Vector4 value)

Parameters

value Vector4

The value.

Returns

Color4

The result of the conversion.

explicit operator Color4(int)

Performs an explicit conversion from int to Color4.

public static explicit operator Color4(int value)

Parameters

value int

The value.

Returns

Color4

The result of the conversion.

implicit operator Vector4(Color4)

Performs an implicit conversion from Color4 to Vector4.

public static implicit operator Vector4(Color4 value)

Parameters

value Color4

The 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

left Color4

The first value to compare.

right Color4

The second value to compare.

Returns

bool

true if left has a different value than right; otherwise, false.

operator *(Color4, Color4)

Modulates two colors.

public static Color4 operator *(Color4 left, Color4 right)

Parameters

left Color4

The first color to modulate.

right Color4

The second color to modulate.

Returns

Color4

The modulated color.

operator *(Color4, float)

Scales a color.

public static Color4 operator *(Color4 value, float scale)

Parameters

value Color4

The factor by which to scale the color.

scale float

The color to scale.

Returns

Color4

The scaled color.

operator *(float, Color4)

Scales a color.

public static Color4 operator *(float scale, Color4 value)

Parameters

scale float

The factor by which to scale the color.

value Color4

The color to scale.

Returns

Color4

The scaled color.

operator -(Color4, Color4)

Subtracts two colors.

public static Color4 operator -(Color4 left, Color4 right)

Parameters

left Color4

The first color to subtract.

right Color4

The second color to subtract.

Returns

Color4

The difference of the two colors.

operator -(Color4)

Negates a color.

public static Color4 operator -(Color4 value)

Parameters

value Color4

The color to negate.

Returns

Color4

A negated color.

operator +(Color4)

Assert a color (return it unchanged).

public static Color4 operator +(Color4 value)

Parameters

value Color4

The color to assert (unchanged).

Returns

Color4

The asserted (unchanged) color.