#include <Magnum/Math/Color.h>
template<class T = Float>
Color4 class
Color in linear RGBA color space.
Contents
See Color3 for more information.
Base classes
-
template<class T>class Vector4<Float>
- Four-component vector.
Public types
- using FloatingPointType = Color3<T>::FloatingPointType
- Corresponding floating-point type.
-
using Hsv = std::
tuple<Deg<FloatingPointType>, FloatingPointType, FloatingPointType> deprecated in 2019.10 - HSV float color.
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 ColorHsv<FloatingPointType>& 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> deprecated in 2019.10
- Create RGB color from HSV representation.
- 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 fromSrgbAlpha(UnsignedInt srgbAlpha) -> Color4<T>
- Create linear RGBA color from 32-bit sRGB + alpha representation.
- static auto fromSrgb(UnsignedInt srgb, T a = Implementation::fullChannel<T>()) -> Color4<T>
- Create linear RGBA color from 32-bit sRGB + alpha 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
- Construct a zero color.
-
Color4(Magnum::
NoInitT) explicit noexcept - Construct a 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 a vector from another of different type.
-
template<class U, class V = decltype(Implementation::VectorConverter<4, T, U>::from(std::Color4(const U& other) explicit constexpr
declval<U>()))> - Construct color from external representation.
- Color4(const Vector<4, T>& other) constexpr noexcept
- Copy constructor.
Public functions
- auto toHsv() const -> ColorHsv<FloatingPointType>
- 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 toSrgbAlphaInt() const -> UnsignedInt
- Convert to 32-bit integral sRGB + linear 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 std:: tuple<Deg<FloatingPointType>, FloatingPointType, FloatingPointType> Magnum:: Math:: Color4<T>:: Hsv
HSV float color.
Function documentation
template<class T>
static Color4<T> Magnum:: Math:: Color4<T>:: fromHsv(const ColorHsv<FloatingPointType>& 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 .
template<class T>
static Color4<T> Magnum:: Math:: Color4<T>:: fromHsv(Deg<FloatingPointType> hue,
FloatingPointType saturation,
FloatingPointType value,
T alpha = Implementation::fullChannel<T>())
Create RGB color from HSV representation.
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::
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::
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:
Vector4ub srgbAlpha; auto rgba = Color4::fromSrgbAlpha(srgbAlpha);
For conversion from a linear 32-bit representation (i.e, without applying the sRGB curve), use unpack():
Color4ub a{0xff, 0x33, 0x66, 0x99}; auto bFromSrgb = Color4::fromSrgbAlpha(a); // {1.0f, 0.03311f, 0.1329f, 0.6f} auto bFromLinear = Math::unpack<Color4>(a); // {1.0f, 0.2f, 0.4f, 0.6f}
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 | Linear 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. Same as above, but with alpha as a separate parameter.
template<class T>
static Color4<T> Magnum:: Math:: Color4<T>:: fromSrgbAlpha(UnsignedInt srgbAlpha)
Create linear RGBA color from 32-bit sRGB + alpha representation.
Parameters | |
---|---|
srgbAlpha | 32-bit sRGB color 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.
See Color3::
Color4 a = Color4::fromSrgbAlpha(0xff336680); Color4 b = 0xff336680_srgbaf;
Note that the integral value is endian-dependent (the red channel being in the last byte on little-endian platforms), for conversion from an endian-independent sRGB / linear representation use fromSrgbAlpha(const Vector4<Integral>&) / unpack().
template<class T>
static Color4<T> Magnum:: Math:: Color4<T>:: fromSrgb(UnsignedInt srgb,
T a = Implementation::fullChannel<T>())
Create linear RGBA color from 32-bit sRGB + alpha representation.
Parameters | |
---|---|
srgb | 24-bit sRGB color |
a | Linear 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. Same as above, but with alpha as a separate parameter.
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::
template<class T>
Magnum:: Math:: Color4<T>:: Color4() constexpr noexcept
Default constructor.
Equivalent to Color4(ZeroInitT).
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>
template<class U>
Magnum:: Math:: Color4<T>:: Color4(const Vector<4, U>& other) explicit constexpr noexcept
Construct a vector from another of different type.
Performs only default casting on the values, no rounding or anything else. Example usage:
Vector4 floatingPoint{1.3f, 2.7f, -15.0f, 7.0f}; Vector4i integral{floatingPoint}; // {1, 2, -15, 7}
template<class T>
ColorHsv<FloatingPointType> Magnum:: Math:: Color4<T>:: toHsv() const
Convert to HSV representation.
The alpha channel is not subject to any conversion, so it is ignored.
template<class T>
Deg<FloatingPointType> Magnum:: Math:: Color4<T>:: hue() const
Hue.
Returns | Hue in range . |
---|
template<class T>
FloatingPointType Magnum:: Math:: Color4<T>:: saturation() const
Saturation.
Returns | Saturation in range . |
---|
template<class T>
FloatingPointType Magnum:: Math:: Color4<T>:: value() const
Value.
Returns | Value in range . |
---|
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::
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; Vector4ub srgbAlpha = color.toSrgbAlpha<UnsignedByte>();
For conversion to a linear 32-bit representation (i.e, without applying the sRGB curve), use pack():
Color4 a{1.0f, 0.2f, 0.4f, 0.6f}; auto bSrgb = a.toSrgbAlpha<UnsignedByte>(); // {0xff, 0x7c, 0xaa, 0x99} auto bLinear = Math::pack<Color4ub>(a); // {0xff, 0x33, 0x66, 0x99}
template<class T>
UnsignedInt Magnum:: Math:: Color4<T>:: toSrgbAlphaInt() const
Convert to 32-bit integral sRGB + linear alpha representation.
See Color3::
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::
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:
using namespace Math::Literals; 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""_
using namespace Math::Literals; Vector4ub 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:
using namespace Math::Literals; 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.
Calls Color4::
using namespace Math::Literals; 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.
If Corrade::░▒▓█
shades. The square shade is calculated as a product of Color4::
If Corrade::
If Corrade::#ff33aaff
). Other underlying types are handled by operator<<(Corrade::
For example, the following snippet:
Debug{Debug::Flag::Color} << 0x3bd26700_rgba << 0x3bd26733_rgba << 0x3bd26766_rgba << 0x3bd26799_rgba << 0x3bd267cc_rgba << 0x3bd267ff_rgba;
prints the following on terminals that support it:
░░ ▒▒ ▓▓ ██