template<class T>
Color3 class
Color in linear RGB color space.
Contents
The class can store either floating-point (normalized) or integral (denormalized) representation of linear RGB color. Colors in sRGB color space should not be used directly in calculations — they should be converted to linear RGB using fromSrgb(), calculation done on the linear representation and then converted back to sRGB using toSrgb().
Note that constructor conversion between different types (like in Vector classes) doesn't do any (de)normalization, you should use pack) and unpack() instead, for example:
Color3 a{1.0f, 0.5f, 0.75f}; auto b = pack<Color3ub>(a); // b == {255, 127, 191}
Conversion from and to HSV is done always using floating-point types, so hue is always in range in range , saturation and value in range .
Base classes
-
template<class T>class Vector3
- Three-component vector.
Public types
- using FloatingPointType = TypeTraits<T>::FloatingPointType
- Corresponding floating-point type.
-
using Hsv = std::
tuple<Deg<FloatingPointType>, FloatingPointType, FloatingPointType> - Type for storing HSV color space values.
- using HSV = Hsv deprecated
- Type for storing HSV color space values.
Public static functions
- static auto red(T red = Implementation::fullChannel<T>()) -> Color3<T> constexpr
- Red color.
- static auto green(T green = Implementation::fullChannel<T>()) -> Color3<T> constexpr
- Green color.
- static auto blue(T blue = Implementation::fullChannel<T>()) -> Color3<T> constexpr
- Blue color.
- static auto cyan(T red = T(0)) -> Color3<T> constexpr
- Cyan color.
- static auto magenta(T green = T(0)) -> Color3<T> constexpr
- Magenta color.
- static auto yellow(T blue = T(0)) -> Color3<T> constexpr
- Yellow color.
- static auto fromHsv(const Hsv& hsv) -> Color3<T>
- Create RGB color from HSV representation.
- static auto fromHsv(Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value) -> Color3<T>
- static auto fromHSV(const Hsv& hsv) -> Color3<T> deprecated
- Create RGB color from HSV representation.
- static auto fromHSV(Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value) -> Color3<T> deprecated
- static auto fromSrgb(const Vector3<FloatingPointType>& srgb) -> Color3<T>
- Create linear RGB color from sRGB representation.
-
template<class Integral>static auto fromSrgb(const Vector3<Integral>& srgb) -> Color3<T>
- Create linear RGB color from integral sRGB representation.
- static auto fromXyz(const Vector3<FloatingPointType>& xyz) -> Color3<T>
- Create RGB color from CIE XYZ representation.
Constructors, destructors, conversion operators
- Color3(ZeroInitT = ZeroInit) constexpr noexcept
- Default constructor.
- Color3(NoInitT) explicit noexcept
- Construct vector without initializing the contents.
- Color3(T rgb) explicit constexpr noexcept
- Gray constructor.
- Color3(T r, T g, T b) constexpr noexcept
- Constructor.
-
template<class U>Color3(const Vector<3, U>& other) explicit constexpr noexcept
- Construct vector from another of different type.
-
template<class U, class V = decltype(Implementation::VectorConverter<3, T, U>::from(std::Color3(const U& other) explicit constexpr
declval<U>()))> - Construct color from external representation.
- Color3(const Vector<3, T>& other) constexpr noexcept
- Copy constructor.
Public functions
- auto toHsv() const -> Hsv
- Convert to HSV representation.
- auto toHSV() const -> Hsv deprecated
- Convert to HSV representation.
- auto hue() const -> Deg<FloatingPointType>
- Hue.
- auto saturation() const -> FloatingPointType
- Saturation.
- auto value() const -> FloatingPointType
- Value.
- auto toSrgb() const -> Vector3<FloatingPointType>
- Convert to sRGB representation.
-
template<class Integral>auto toSrgb() const -> Vector3<Integral>
- Convert to integral sRGB representation.
- auto toXyz() const -> Vector3<FloatingPointType>
- Convert to CIE XYZ representation.
Typedef documentation
template<class T>
typedef TypeTraits<T>::FloatingPointType Magnum:: Math:: Color3<T>:: FloatingPointType
Corresponding floating-point type.
For HSV and other color spaces.
template<class T>
typedef std:: tuple<Deg<FloatingPointType>, FloatingPointType, FloatingPointType> Magnum:: Math:: Color3<T>:: Hsv
Type for storing HSV color space values.
Hue in range , saturation and value in range .
Function documentation
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: red(T red = Implementation::fullChannel<T>()) constexpr
Red color.
Convenience alternative to e.g. Color3{red, 0.0f, 0.0f}
. With floating-point underlying type equivalent to Vector3::
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: green(T green = Implementation::fullChannel<T>()) constexpr
Green color.
Convenience alternative to e.g. Color3(0.0f, green, 0.0f)
. With floating-point underlying type equivalent to Vector3::
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: blue(T blue = Implementation::fullChannel<T>()) constexpr
Blue color.
Convenience alternative to e.g. Color3{0.0f, 0.0f, blue}
. With floating-point underlying type equivalent to Vector3::
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: cyan(T red = T(0)) constexpr
Cyan color.
Convenience alternative to e.g. Color3{red, 1.0f, 1.0f}
. With floating-point underlying type equivalent to Vector3::
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: magenta(T green = T(0)) constexpr
Magenta color.
Convenience alternative to e.g. Color3{1.0f, green, 1.0f}
. With floating-point underlying type equivalent to Vector3::
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: yellow(T blue = T(0)) constexpr
Yellow color.
Convenience alternative to e.g. Color3{1.0f, 1.0f, yellow}
. With floating-point underlying type equivalent to Vector3::
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: fromHsv(Deg<FloatingPointType> hue,
FloatingPointType saturation,
FloatingPointType value)
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 Color3<T> Magnum:: Math:: Color3<T>:: fromHSV(Deg<FloatingPointType> hue,
FloatingPointType saturation,
FloatingPointType value)
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: fromSrgb(const Vector3<FloatingPointType>& srgb)
Create linear RGB color from sRGB representation.
Parameters | |
---|---|
srgb | Color in sRGB color space |
Applies inverse sRGB curve onto input, returning the input in linear RGB color space with D65 illuminant and 2° standard colorimetric observer.
template<class T>
template<class Integral>
static Color3<T> Magnum:: Math:: Color3<T>:: fromSrgb(const Vector3<Integral>& srgb)
Create linear RGB color from integral sRGB representation.
Parameters | |
---|---|
srgb | Color in sRGB color space |
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 RGB color out of it:
Math::Vector3<UnsignedByte> srgb; auto rgb = Color3::fromSrgb(srgb);
template<class T>
static Color3<T> Magnum:: Math:: Color3<T>:: fromXyz(const Vector3<FloatingPointType>& xyz)
Create RGB color from CIE XYZ representation.
Parameters | |
---|---|
xyz | Color in CIE XYZ color space |
Applies transformation matrix, returning the input in linear RGB color space with D65 illuminant and 2° standard colorimetric observer.
template<class T>
Magnum:: Math:: Color3<T>:: Color3(T rgb) explicit constexpr noexcept
Gray constructor.
Parameters | |
---|---|
rgb | RGB value |
template<class T>
Magnum:: Math:: Color3<T>:: Color3(T r,
T g,
T b) constexpr noexcept
Constructor.
Parameters | |
---|---|
r | R value |
g | G value |
b | B value |
template<class T>
template<class U>
Magnum:: Math:: Color3<T>:: Color3(const Vector<3, 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>
Deg<FloatingPointType> Magnum:: Math:: Color3<T>:: hue() const
Hue.
Returns | Hue in range . |
---|
template<class T>
FloatingPointType Magnum:: Math:: Color3<T>:: saturation() const
Saturation.
Returns | Saturation in range . |
---|
template<class T>
FloatingPointType Magnum:: Math:: Color3<T>:: value() const
Value.
Returns | Value in range . |
---|
template<class T>
Vector3<FloatingPointType> Magnum:: Math:: Color3<T>:: toSrgb() const
Convert to sRGB representation.
Assuming the color is in linear RGB with D65 illuminant and 2° standard colorimetric observer, applies sRGB curve onto it, returning the color represented in sRGB color space:
template<class T>
template<class Integral>
Vector3<Integral> Magnum:: Math:: Color3<T>:: toSrgb() const
Convert to integral sRGB 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 RGB color and want to create for example an 8-bit sRGB representation out of it:
Color3 color; Math::Vector3<UnsignedByte> srgb = color.toSrgb<UnsignedByte>();
template<class T>
Vector3<FloatingPointType> Magnum:: Math:: Color3<T>:: toXyz() const
Convert to CIE XYZ representation.
Assuming the color is in linear RGB with D65 illuminant and 2° standard colorimetric observer, applies transformation matrix, returning the color in CIE XYZ color space.
Please note that x(), y() and z() do not correspond to primaries in CIE XYZ color space, but are rather aliases to r(), g() and b().
template<class T>
Color3<UnsignedByte> operator"" _rgb(unsigned long long value) constexpr
8bit-per-channel linear RGB literal
Unpacks the literal into three 8-bit values. Example usage:
Color3ub a = 0x33b27f_rgb; // {0x33, 0xb2, 0x7f}
template<class T>
Vector3<UnsignedByte> operator"" _srgb(unsigned long long value) constexpr
8bit-per-channel sRGB literal
Unpacks the literal into three 8-bit values without any colorspace conversion. Behaves identically to operator""_
Math::Vector3<UnsignedByte> a = 0x33b27f_srgb; // {0x33, 0xb2, 0x7f}
template<class T>
Color3<Float> operator"" _rgbf(unsigned long long value)
Float linear RGB literal.
Unpacks the 8-bit values into three floats. Example usage:
Color3 a = 0x33b27f_rgbf; // {0.2f, 0.698039f, 0.498039f}
template<class T>
Color3<Float> operator"" _srgbf(unsigned long long value)
Float sRGB literal.
Unpacks the 8-bit values into three floats and converts the color space from sRGB to linear RGB. See Color3::
Color3 a = 0x33b27f_srgbf; // {0.0331048f, 0.445201f, 0.212231f}
template<class T>
Corrade:: Utility:: Debug& operator<<(Corrade:: Utility:: Debug& debug,
const Color3<UnsignedByte>& value)
Debug output operator.
Prints the value as hex color (e.g. #ff33aa
). Other underlying types are handled by operator<<(Corrade::