Color4

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>

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

Color4()

No initialization by default.

constexpr Color4(T a)

Initialize to (a a a a)

constexpr Color4(T a, T b, T c, T d)

Initialize to (a b c d)

constexpr Color4(const Color4 &v)

Construct from Color4.

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

Construct from Color4.

~Color4()

Destructor.

constexpr const Color4<T> &operator=(const Color4 &v)

Assignment.

T &operator[](int i)

Component-wise value.

const T &operator[](int i) const

Component-wise value.

Arithmetic and Comparison

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

Equality.

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

Inequality.

constexpr const Color4<T> &operator+=(const Color4 &v)

Component-wise addition.

constexpr Color4<T> operator+(const Color4 &v) const

Component-wise addition.

constexpr const Color4<T> &operator-=(const Color4 &v)

Component-wise subtraction.

constexpr Color4<T> operator-(const Color4 &v) const

Component-wise subtraction.

constexpr Color4<T> operator-() const

Component-wise multiplication by -1.

constexpr const Color4<T> &negate()

Component-wise multiplication by -1.

constexpr const Color4<T> &operator*=(const Color4 &v)

Component-wise multiplication.

constexpr const Color4<T> &operator*=(T a)

Component-wise multiplication.

constexpr Color4<T> operator*(const Color4 &v) const

Component-wise multiplication.

constexpr Color4<T> operator*(T a) const

Component-wise multiplication.

constexpr const Color4<T> &operator/=(const Color4 &v)

Component-wise division.

constexpr const Color4<T> &operator/=(T a)

Component-wise division.

constexpr Color4<T> operator/(const Color4 &v) const

Component-wise division.

constexpr Color4<T> operator/(T a) const

Component-wise division.

Numeric Limits

static constexpr unsigned int dimensions()

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

static constexpr T baseTypeLowest()

Largest possible negative value.

static constexpr T baseTypeMax()

Largest possible positive value.

static constexpr T baseTypeSmallest()

Smallest possible positive value.

static constexpr T baseTypeEpsilon()

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

Compatibilty with Sb

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

Set the value.

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

Set the value.

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

Return the value.

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

Return the value.

T *getValue()

Return raw pointer to the value.

const T *getValue() const

Return raw pointer to the value.

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

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream& s, const Color4<T>& v) in doxygen xml output for project “Imath” from directory: doxyxml/. Potential matches:

- std::ostream &operator<<(std::ostream&, Imath::half)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Color4<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Euler<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Interval<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Line3<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Matrix22<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Matrix33<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Matrix44<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Plane3<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Quat<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Shear6<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Vec2<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Vec3<T>&)
- template <class T>
  std::ostream &Imath::operator<<(std::ostream&, const Vec4<T>&)