Color4#

#include <Imath/ImathColor.h>

The Color4 class template represents a 4-component color (red, green, blue, and alpha), with pre-defined typedefs of unsigned char, half, and float.

The Color4 class is not derived from Vec4. Its fields are named r, g, b, and a. The class itself implies no specific interpretation of the values.

There are also various utility functions that operate on colors defined in ImathColorAlgo.h and described in Color Functions.

Example:

#include <Imath/ImathColor.h>
#include <cassert>

void
color4_example ()
{
    Imath::C4f r (1.0f, 0.0f, 0.0f, 1.0f);
    Imath::C4f g (0.0f, 1.0f, 0.0f, 1.0f);
    Imath::C4f b (0.0f, 0.0f, 1.0f, 1.0f);

    Imath::C4f w = r + g + b;

    assert (w.r == 1.0f);
    assert (w.g == 1.0f);
    assert (w.b == 1.0f);
    assert (w.a == 3.0f);
}
typedef Color4<unsigned char> Imath::Color4c#

4 8-bit integer channels

typedef Color4<half> Imath::Color4h#

4 half channels

typedef Color4<float> Imath::Color4f#

4 float channels

typedef Color4<unsigned char> Imath::C4c#

4 8-bit integer channels

typedef Color4<half> Imath::C4h#

4 half channels

typedef Color4<float> Imath::C4f#

4 float channels

template<class T>
class Color4#

A 4-channel color class: 3 channels plus alpha.

For convenience, the fields are named r, g, and b, although this class does not impose interpretation on the channels, which can represent either rgb or hsv color values.

Direct access to elements

T r#
T g#
T b#
T a#

Constructors and Assignment

inline Color4() noexcept#

No initialization by default.

inline explicit constexpr Color4(T a) noexcept#

Initialize to (a a a a)

inline constexpr Color4(T a, T b, T c, T d) noexcept#

Initialize to (a b c d)

inline constexpr Color4(const Color4 &v) noexcept#

Construct from Color4.

template<class S>
inline constexpr Color4(const Color4<S> &v) noexcept#

Construct from Color4.

~Color4() = default#

Destructor.

inline constexpr const Color4 &operator=(const Color4 &v) noexcept#

Assignment.

inline T &operator[](int i) noexcept#

Component-wise value.

inline const T &operator[](int i) const noexcept#

Component-wise value.

Arithmetic and Comparison

template<class S>
inline constexpr bool operator==(const Color4<S> &v) const noexcept#

Equality.

template<class S>
inline constexpr bool operator!=(const Color4<S> &v) const noexcept#

Inequality.

inline constexpr const Color4 &operator+=(const Color4 &v) noexcept#

Component-wise addition.

inline constexpr Color4 operator+(const Color4 &v) const noexcept#

Component-wise addition.

inline constexpr const Color4 &operator-=(const Color4 &v) noexcept#

Component-wise subtraction.

inline constexpr Color4 operator-(const Color4 &v) const noexcept#

Component-wise subtraction.

inline constexpr Color4 operator-() const noexcept#

Component-wise multiplication by -1.

inline constexpr const Color4 &negate() noexcept#

Component-wise multiplication by -1.

inline constexpr const Color4 &operator*=(const Color4 &v) noexcept#

Component-wise multiplication.

inline constexpr const Color4 &operator*=(T a) noexcept#

Component-wise multiplication.

inline constexpr Color4 operator*(const Color4 &v) const noexcept#

Component-wise multiplication.

inline constexpr Color4 operator*(T a) const noexcept#

Component-wise multiplication.

inline constexpr const Color4 &operator/=(const Color4 &v) noexcept#

Component-wise division.

inline constexpr const Color4 &operator/=(T a) noexcept#

Component-wise division.

inline constexpr Color4 operator/(const Color4 &v) const noexcept#

Component-wise division.

inline constexpr Color4 operator/(T a) const noexcept#

Component-wise division.

Compatibilty with Sb

template<class S>
inline void setValue(S a, S b, S c, S d) noexcept#

Set the value.

template<class S>
inline void setValue(const Color4<S> &v) noexcept#

Set the value.

template<class S>
inline void getValue(S &a, S &b, S &c, S &d) const noexcept#

Return the value.

template<class S>
inline void getValue(Color4<S> &v) const noexcept#

Return the value.

inline T *getValue() noexcept#

Return raw pointer to the value.

inline const T *getValue() const noexcept#

Return raw pointer to the value.

Numeric Limits

static inline constexpr unsigned int dimensions() noexcept#

Number of dimensions (channels), i.e. 4 for a Color4.

static inline constexpr T baseTypeLowest() noexcept#

Largest possible negative value.

static inline constexpr T baseTypeMax() noexcept#

Largest possible positive value.

static inline constexpr T baseTypeSmallest() noexcept#

Smallest possible positive value.

static inline constexpr T baseTypeEpsilon() noexcept#

Smallest possible e for which 1+e != 1.

Public Types

typedef T BaseType#

The base type: In templates that accept a parameter V (could be a Color4), you can refer to T as V::BaseType

template<class T>
std::ostream &Imath::operator<<(std::ostream &s, const Color4<T> &v)#

Stream output, as “(r g b a)”.