Table of Contents

Struct Color<T>

Namespace
Sdl3Sharp.Video.Coloring
Assembly
Sdl3Sharp.dll

Represents a color with red, green, blue and alpha components

public readonly struct Color<T> : IEquatable<Color<T>>, ISpanFormattable, IFormattable, IEqualityOperators<Color<T>, Color<T>, bool> where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>

Type Parameters

T

The type of the color components

Implements
Inherited Members

Remarks

Most often the type T is either byte for 32-bit pixel values with unsigned integer ranges from 0 to 255 for each component, or float for 128-bit pixel values with floating-point ranges from 0 to 1 for each component.

Color<byte> values can be directly reinterpreted as an integer-packed color which uses the Rgba32 format (Abgr8888 on little-endian systems and Rgba8888 on big-endian systems).

Color<float> values can be directly reinterpreted as a float-packed color which uses the Rgba128Float format.

Constructors

Color(in T, in T, in T, in T)

Represents a color with red, green, blue and alpha components

[SetsRequiredMembers]
public Color(in T r, in T g, in T b, in T a)

Parameters

r T

The value of the red component

g T

The value of the green component

b T

The value of the blue component

a T

The value of the alpha component

Remarks

Most often the type T is either byte for 32-bit pixel values with unsigned integer ranges from 0 to 255 for each component, or float for 128-bit pixel values with floating-point ranges from 0 to 1 for each component.

Color<byte> values can be directly reinterpreted as an integer-packed color which uses the Rgba32 format (Abgr8888 on little-endian systems and Rgba8888 on big-endian systems).

Color<float> values can be directly reinterpreted as a float-packed color which uses the Rgba128Float format.

Properties

A

Gets or initializes the alpha component value of the color

public required T A { get; init; }

Property Value

T

The alpha component value of the color

B

Gets or initializes the blue component value of the color

public required T B { get; init; }

Property Value

T

The blue component value of the color

G

Gets or initializes the green component value of the color

public required T G { get; init; }

Property Value

T

The green component value of the color

R

Gets or initializes the red component value of the color

public required T R { get; init; }

Property Value

T

The red component value of the color

Methods

Deconstruct(out T, out T, out T, out T)

Deconstructs the color into its red, green, blue and alpha component values

public void Deconstruct(out T r, out T g, out T b, out T a)

Parameters

r T

The red component value of the color

g T

The green component value of the color

b T

The blue component value of the color

a T

The alpha component value of the color

Equals(in Color<T>)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(in Color<T> other)

Parameters

other Color<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

ToString(IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(IFormatProvider? formatProvider)

Parameters

formatProvider IFormatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

ToString(string?)

Formats the value of the current instance using the specified format.

public string ToString(string? format)

Parameters

format string

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

Returns

string

The value of the current instance in the specified format.

ToString(string?, IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

formatProvider IFormatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Tries to format the value of the current instance into the provided span of characters.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)

Parameters

destination Span<char>

The span in which to write this instance's value formatted as a span of characters.

charsWritten int

When this method returns, contains the number of characters that were written in destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.

provider IFormatProvider

An optional object that supplies culture-specific formatting information for destination.

Returns

bool

true if the formatting was successful; otherwise, false.

Operators

operator ==(in Color<T>, in Color<T>)

Compares two values to determine equality.

public static bool operator ==(in Color<T> left, in Color<T> right)

Parameters

left Color<T>

The value to compare with right.

right Color<T>

The value to compare with left.

Returns

bool

true if left is equal to right; otherwise, false.

implicit operator (T R, T G, T B, T A)(in Color<T>)

Converts a color to a tuple of its red, green, blue and alpha component values

public static implicit operator (T R, T G, T B, T A)(in Color<T> color)

Parameters

color Color<T>

The color to convert

Returns

(T R, T G, T B, T A)

A tuple containing the red, green, blue and alpha component values of the color

implicit operator Color<T>(in (T R, T G, T B, T A))

Converts a tuple of red, green, blue and alpha component values to a color

public static implicit operator Color<T>(in (T R, T G, T B, T A) rgba)

Parameters

rgba (T R, T G, T B, T A)

The tuple to convert

Returns

Color<T>

A color with the specified red, green, blue and alpha component values

operator !=(in Color<T>, in Color<T>)

Compares two values to determine inequality.

public static bool operator !=(in Color<T> left, in Color<T> right)

Parameters

left Color<T>

The value to compare with right.

right Color<T>

The value to compare with left.

Returns

bool

true if left is not equal to right; otherwise, false.