This is a snapshot of a work-in-progress documentation theme. If you feel lost, miss something, or want to see the original Doxygen docs instead, head over to the archived version of this documentation page.

template<class T = Float>
Magnum::Math::Color4 class

Color in linear RGBA color space.

See Color3 for more information.

Base classes

template<class T>
class Vector4
Four-component vector.

Public types

using FloatingPointType = Color3<T>::FloatingPointType
Corresponding floating-point type.
using Hsv = Color3<T>::Hsv
Type for storing HSV color space values.
using HSV = Hsv
Type for storing HSV color space values.

Public static functions

static auto red(T red = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) -> Color4<T> constexpr
Red color.
static auto green(T green = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) -> Color4<T> constexpr
Green color.
static auto blue(T blue = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) -> Color4<T> constexpr
Blue color.
static auto cyan(T red = T(0), T alpha = Implementation::fullChannel<T>()) -> Color4<T> constexpr
Cyan color.
static auto magenta(T green = T(0), T alpha = Implementation::fullChannel<T>()) -> Color4<T> constexpr
Magenta color.
static auto yellow(T blue = T(0), T alpha = Implementation::fullChannel<T>()) -> Color4<T> constexpr
Yellow color.
static auto fromHsv(const Hsv& hsv, T a = Implementation::fullChannel<T>()) -> Color4<T>
Create RGB color from HSV representation.
static auto fromHsv(Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value, T alpha = Implementation::fullChannel<T>()) -> Color4<T>
static auto fromHSV(const Hsv& hsv, T a = Implementation::fullChannel<T>()) -> Color4<T>
Create RGB color from HSV representation.
static auto fromHSV(Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value, T a = Implementation::fullChannel<T>()) -> Color4<T>
static auto fromSrgbAlpha(const Vector4<FloatingPointType>& srgbAlpha) -> Color4<T>
Create linear RGBA color from sRGB + alpha representation.
static auto fromSrgb(const Vector3<FloatingPointType>& srgb, T a = Implementation::fullChannel<T>()) -> Color4<T>
Create linear RGBA color from sRGB representation.
template<class Integral>
static auto fromSrgbAlpha(const Vector4<Integral>& srgbAlpha) -> Color4<T>
Create linear RGB color from integral sRGB + alpha representation.
template<class Integral>
static auto fromSrgb(const Vector3<Integral>& srgb, T a = Implementation::fullChannel<T>()) -> Color4<T>
Create linear RGB color from integral sRGB representation.
static auto fromXyz(const Vector3<FloatingPointType> xyz, T a = Implementation::fullChannel<T>()) -> Color4<T>
Create RGBA color from CIE XYZ representation.

Constructors, destructors, conversion operators

Color4() constexpr noexcept
Default constructor.
Color4(ZeroInitT) explicit constexpr noexcept
Default constructor.

Color4(NoInitT) explicit noexcept
Construct vector without initializing the contents.

Color4(T rgb, T alpha = Implementation::fullChannel<T>()) explicit constexpr noexcept
Gray constructor.
Color4(T r, T g, T b, T a = Implementation::fullChannel<T>()) constexpr noexcept
Constructor.
Color4(const Vector3<T>& rgb, T a = Implementation::fullChannel<T>()) constexpr noexcept
Constructor.
template<class U>
Color4(const Vector<4, U>& other) explicit constexpr noexcept
Construct vector from another of different type.
template<class U, class V = decltype(Implementation::VectorConverter<4, T, U>::from(std::declval<U>()))>
Color4(const U& other) explicit constexpr
Construct color from external representation.
Color4(const Vector<4, T>& other) constexpr noexcept
Copy constructor.

Public functions

auto toHsv() const -> Hsv
Convert to HSV representation.
auto toHSV() const -> Hsv
Convert to HSV representation.
auto hue() const -> Deg<FloatingPointType>
Hue.
auto saturation() const -> FloatingPointType
Saturation.
auto value() const -> FloatingPointType
Value.
auto toSrgbAlpha() const -> Vector4<FloatingPointType>
Convert to sRGB + alpha representation.
template<class Integral>
auto toSrgbAlpha() const -> Vector4<Integral>
Convert to integral sRGB + alpha representation.
auto toXyz() const -> Vector3<FloatingPointType>
Convert to CIE XYZ representation.

Typedef documentation

template<class T>
typedef Color3<T>::FloatingPointType Magnum::Math::Color4<T>::FloatingPointType

Corresponding floating-point type.

For HSV and other color spaces.

template<class T>
typedef Color3<T>::Hsv Magnum::Math::Color4<T>::Hsv

Type for storing HSV color space values.

Hue in range LaTeX Math $ [0.0, 360.0] $ , saturation and value in range LaTeX Math $ [0.0, 1.0] $ .

template<class T>
typedef Hsv Magnum::Math::Color4<T>::HSV

Type for storing HSV color space values.

Function documentation

template<class T>
static Color4<T> Magnum::Math::Color4<T>::red(T red = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) constexpr

Red color.

Convenience alternative to e.g. Color4{red, 0.0f, 0.0f, alpha}.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::green(T green = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) constexpr

Green color.

Convenience alternative to e.g. Color4{0.0f, green, 0.0f, alpha}.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::blue(T blue = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) constexpr

Blue color.

Convenience alternative to e.g. Color4{0.0f, 0.0f, blue, alpha}.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::cyan(T red = T(0), T alpha = Implementation::fullChannel<T>()) constexpr

Cyan color.

Convenience alternative to e.g. Color4{red, 1.0f, 1.0f, alpha}.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::magenta(T green = T(0), T alpha = Implementation::fullChannel<T>()) constexpr

Magenta color.

Convenience alternative to e.g. Color4{1.0f, green, 1.0f, alpha}.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::yellow(T blue = T(0), T alpha = Implementation::fullChannel<T>()) constexpr

Yellow color.

Convenience alternative to e.g. Color4{1.0f, 1.0f, blue, alpha}.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::fromHsv(const Hsv& hsv, T a = Implementation::fullChannel<T>())

Create RGB color from HSV representation.

Parameters
hsv Color in HSV color space
a Alpha value, defaults to 1.0 for floating-point types and maximum positive value for integral types

Hue can overflow the range LaTeX Math $ [0.0, 360.0] $ .

template<class T>
static Color4<T> Magnum::Math::Color4<T>::fromHsv(Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value, T alpha = Implementation::fullChannel<T>())

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::fromHSV(const Hsv& hsv, T a = Implementation::fullChannel<T>())

Create RGB color from HSV representation.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::fromHSV(Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value, T a = Implementation::fullChannel<T>())

template<class T>
static Color4<T> Magnum::Math::Color4<T>::fromSrgbAlpha(const Vector4<FloatingPointType>& srgbAlpha)

Create linear RGBA color from sRGB + alpha representation.

Parameters
srgbAlpha Color in sRGB color space with linear alpha

Applies inverse sRGB curve onto RGB channels of the input, alpha channel is assumed to be linear. See Color3::fromSrgb() for more information.

template<class T>
static Color4<T> Magnum::Math::Color4<T>::fromSrgb(const Vector3<FloatingPointType>& srgb, T a = Implementation::fullChannel<T>())

Create linear RGBA color from sRGB representation.

Parameters
srgb Color in sRGB color space
a Alpha value, defaults to 1.0 for floating-point types and maximum positive value for integral types

Applies inverse sRGB curve onto RGB channels of the input. Alpha value is taken as-is. See Color3::fromSrgb() for more information.

template<class T> template<class Integral>
static Color4<T> Magnum::Math::Color4<T>::fromSrgbAlpha(const Vector4<Integral>& srgbAlpha)

Create linear RGB color from integral sRGB + alpha representation.

Parameters
srgbAlpha Color in sRGB color space with linear alpha

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Useful in cases where you have for example an 8-bit sRGB + alpha representation and want to create a floating-point linear RGBA color out of it:

Math::Vector4<UnsignedByte> srgbAlpha;
auto rgba = Color4::fromSrgbAlpha(srgbAlpha);

template<class T> template<class Integral>
static Color4<T> Magnum::Math::Color4<T>::fromSrgb(const Vector3<Integral>& srgb, T a = Implementation::fullChannel<T>())

Create linear RGB color from integral sRGB representation.

Parameters
srgb Color in sRGB color space
a Alpha value, defaults to 1.0 for floating-point types and maximum positive value for integral types

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Useful in cases where you have for example an 8-bit sRGB representation and want to create a floating-point linear RGBA color out of it:

Math::Vector3<UnsignedByte> srgb;
auto rgba = Color4::fromSrgb(srgb);

template<class T>
static Color4<T> Magnum::Math::Color4<T>::fromXyz(const Vector3<FloatingPointType> xyz, T a = Implementation::fullChannel<T>())

Create RGBA color from CIE XYZ representation.

Parameters
xyz Color in CIE XYZ color space
a Alpha value, defaults to 1.0 for floating-point types and maximum positive value for integral types

Applies transformation matrix, returning the input in linear RGB color space. See Color3::fromXyz() for more information.

template<class T>
Magnum::Math::Color4<T>::Color4() constexpr noexcept

Default constructor.

All components are set to zero.

template<class T>
Magnum::Math::Color4<T>::Color4(ZeroInitT) explicit constexpr noexcept

Default constructor.

LaTeX Math \[ \boldsymbol v = \boldsymbol 0 \]

template<class T>
Magnum::Math::Color4<T>::Color4(T rgb, T alpha = Implementation::fullChannel<T>()) explicit constexpr noexcept

Gray constructor.

Parameters
rgb RGB value
alpha Alpha value, defaults to 1.0 for floating-point types and maximum positive value for integral types

template<class T>
Magnum::Math::Color4<T>::Color4(T r, T g, T b, T a = Implementation::fullChannel<T>()) constexpr noexcept

Constructor.

Parameters
r R value
g G value
b B value
a A value, defaults to 1.0 for floating-point types and maximum positive value for integral types.

template<class T>
Magnum::Math::Color4<T>::Color4(const Vector3<T>& rgb, T a = Implementation::fullChannel<T>()) constexpr noexcept

Constructor.

Parameters
rgb Three-component color
a A value

template<class T> template<class U>
Magnum::Math::Color4<T>::Color4(const Vector<4, U>& other) explicit constexpr noexcept

Construct vector from another of different type.

Performs only default casting on the values, no rounding or anything else. Example usage:

Vector<4, Float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f);
Vector<4, Byte> integral(floatingPoint);
// integral == {1, 2, -15, 7}

template<class T>
Hsv Magnum::Math::Color4<T>::toHsv() const

Convert to HSV representation.

The alpha channel is not subject to any conversion, so it is ignored. Example usage:

Deg hue;
Float saturation, value;
std::tie(hue, saturation, value) = color.toHsv();

template<class T>
Hsv Magnum::Math::Color4<T>::toHSV() const

Convert to HSV representation.

template<class T>
Deg<FloatingPointType> Magnum::Math::Color4<T>::hue() const

Hue.

Returns Hue in range LaTeX Math $ [0.0, 360.0] $ .

template<class T>
FloatingPointType Magnum::Math::Color4<T>::saturation() const

Saturation.

Returns Saturation in range LaTeX Math $ [0.0, 1.0] $ .

template<class T>
FloatingPointType Magnum::Math::Color4<T>::value() const

Value.

Returns Value in range LaTeX Math $ [0.0, 1.0] $ .

template<class T>
Vector4<FloatingPointType> Magnum::Math::Color4<T>::toSrgbAlpha() const

Convert to sRGB + alpha representation.

Assuming the color is in linear RGB, applies sRGB curve onto the RGB channels, returning the color represented in sRGB color space. Alpha channel is kept linear. See Color3::toSrgb() for more information.

template<class T> template<class Integral>
Vector4<Integral> Magnum::Math::Color4<T>::toSrgbAlpha() const

Convert to integral sRGB + alpha representation.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Useful in cases where you have a floating-point linear RGBA color and want to create for example an 8-bit sRGB + alpha representation out of it:

Color4 color;
Math::Vector4<UnsignedByte> srgbAlpha = color.toSrgbAlpha<UnsignedByte>();

template<class T>
Vector3<FloatingPointType> Magnum::Math::Color4<T>::toXyz() const

Convert to CIE XYZ representation.

Assuming the color is in linear RGB, applies transformation matrix, returning the color in CIE XYZ color space. The alpha channel is not subject to any conversion, so it is ignored. See Color3::toXyz() for more information.

Please note that xyz(), x(), y() and z() do not correspond to primaries in CIE XYZ color space, but are rather aliases to rgb(), r(), g() and b().

template<class T>
Color4<UnsignedByte> operator""_rgba(unsigned long long value) constexpr

8bit-per-channel linear RGBA literal

Unpacks the literal into four 8-bit values. Example usage:

Color4ub a = 0x33b27fcc_rgba;   // {0x33, 0xb2, 0x7f, 0xcc}

template<class T>
Vector4<UnsignedByte> operator""_srgba(unsigned long long value) constexpr

8bit-per-channel sRGB + alpha literal

Unpacks the literal into four 8-bit values without any colorspace conversion. Behaves identically to operator""_rgba() though it doesn't return a Color4 type to indicate that the resulting value is not linear RGBA. Use this literal to document that given value is in sRGB + alpha. Example usage:

Math::Vector4<UnsignedByte> a = 0x33b27fcc_srgba;   // {0x33, 0xb2, 0x7f, 0xcc}

template<class T>
Color4<Float> operator""_rgbaf(unsigned long long value)

Float linear RGBA literal.

Unpacks the 8-bit values into four floats. Example usage:

Color4 a = 0x33b27fcc_rgbaf;    // {0.2f, 0.698039f, 0.498039f, 0.8f}

template<class T>
Color4<Float> operator""_srgbaf(unsigned long long value)

Float sRGB + alpha literal.

Unpacks the 8-bit values into four floats and converts the color space from sRGB + alpha to linear RGBA. See Color4::fromSrgbAlpha() for more information. Example usage:

Color4 a = 0x33b27fcc_srgbaf;  // {0.0331048f, 0.445201f, 0.212231f, 0.8f}

template<class T>
Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, const Color4<UnsignedByte>& value)

Debug output operator.


Prints the value as hex color (e.g. #9933aaff). Other underlying types are handled by operator<<(Corrade::Utility::Debug&, const Vector<size, T>&).