Beatmup
Beatmup::Color::Matrix Class Reference

RGBA color mapping. More...

#include <matrix.h>

Inheritance diagram for Beatmup::Color::Matrix:
Beatmup::Object

Public Member Functions

color4f r () const
 
color4f g () const
 
color4f b () const
 
color4f a () const
 
color4fr ()
 
color4fg ()
 
color4fb ()
 
color4fa ()
 
 Matrix ()
 Initializes the color matrix to identity. More...
 
 Matrix (const color4f &r, const color4f &g, const color4f &b, const color4f &a)
 Constructs a matrix from four RGBA color values setting them as matrix rows. More...
 
 Matrix (float hDegrees, float saturationFactor=1.0f, float valueFactor=1.0f)
 Constructs a color matrix representing an HSV correction transformation. More...
 
 Matrix (const color3f &preservedColor, float saturationFactor=1.0f, float valueFactor=1.0f)
 Constructs a color matrix representing continuous color inversion with a fixed hue point. More...
 
color4foperator[] (int)
 Retrieves matrix rows by index in 0..3 range. More...
 
color4f operator[] (int) const
 
Matrix operator* (const Matrix &) const
 Computes the right-multiplication of the current Matrix and another Matrix. More...
 
void operator= (const Matrix &)
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Public Attributes

union {
   float   elem [4][4]
 
   struct {
      color4f   rows [4]
 
   } 
 
}; 
 Matrix elements. More...
 

Detailed Description

RGBA color mapping.

A color value is mapped onto another color value by multiplying the 4x4 matrix by an RGBA input column.

Definition at line 29 of file matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/4]

Matrix::Matrix ( )

Initializes the color matrix to identity.

Definition at line 28 of file matrix.cpp.

28  {
29  r() = color4f{ 1, 0, 0, 0 };
30  g() = color4f{ 0, 1, 0, 0 };
31  b() = color4f{ 0, 0, 1, 0 };
32  a() = color4f{ 0, 0, 0, 1 };
33 }
color4f r() const
Definition: matrix.h:60
color4f g() const
Definition: matrix.h:61
color4f b() const
Definition: matrix.h:62
color4f a() const
Definition: matrix.h:63

◆ Matrix() [2/4]

Matrix::Matrix ( const color4f r,
const color4f g,
const color4f b,
const color4f a 
)

Constructs a matrix from four RGBA color values setting them as matrix rows.

Parameters
rFirst row of the color matrix.
gSecond row of the color matrix.
bThird row of the color matrix.
aFourth row of the color matrix.

Definition at line 35 of file matrix.cpp.

35  {
36  this->r() = r;
37  this->g() = g;
38  this->b() = b;
39  this->a() = a;
40 }

◆ Matrix() [3/4]

Matrix::Matrix ( float  hDegrees,
float  saturationFactor = 1.0f,
float  valueFactor = 1.0f 
)

Constructs a color matrix representing an HSV correction transformation.

Parameters
hDegreeshue offset in degrees (additive)
saturationFactorsaturation scaling factor
valueFactorvalue scaling factor

Definition at line 69 of file matrix.cpp.

69  {
70  /*
71  R = [1 0 0; 0 cos(H) -sin(H); 0 sin(H) cos(H)];
72  A = [1 1 1; 1 / sqrt(2) - 1 / sqrt(2) 0; 1 / sqrt(6) 1 / sqrt(6) - 2 / sqrt(6)]';
73  M = simplify(A *[V 0 0; 0 V*S 0; 0 0 V*S] * R * inv(A))
74  */
75  const float H = hDegrees * (float)pi / 180,
76  S = saturationFactor, V = valueFactor;
77  r() = { (V*(12 * S*cos(H) + 6)) / 18, -(V*(6 * S*cos(H) + 6 * sqrtf(3)*S*sin(H) - 6)) / 18, (V*(6 * sqrtf(3)*S*sin(H) - 6 * S*cos(H) + 6)) / 18, 0 };
78  g() = { (V*(6 * sqrtf(3)*S*sin(H) - 6 * S*cos(H) + 6)) / 18, (V*(12 * S*cos(H) + 6)) / 18, -(V*(S*cos(H) + sqrtf(3)*S*sin(H) - 1)) / 3, 0 };
79  b() = {-(V*(6 * S*cos(H) + 6 * sqrtf(3)*S*sin(H) - 6)) / 18, (V*(6 * sqrtf(3)*S*sin(H) - 6 * S*cos(H) + 6)) / 18, (V*(4 * S*cos(H) + 2)) / 6, 0 };
80  a() = color4f{ 0, 0, 0, 1 };
81 }
const float pi
Definition: basic_types.h:29

◆ Matrix() [4/4]

Matrix::Matrix ( const color3f preservedColor,
float  saturationFactor = 1.0f,
float  valueFactor = 1.0f 
)

Constructs a color matrix representing continuous color inversion with a fixed hue point.

Parameters
preservedColorcolor giving a hue value that remains unchanged by the transform.
saturationFactorsaturation scaling factor
valueFactorvalue scaling factor

Definition at line 84 of file matrix.cpp.

84  {
85  /*
86  R = [1 0 0; 0 cos(H) -sin(H); 0 sin(H) cos(H)];
87  A = [1 1 1; 1 / sqrt(2) - 1 / sqrt(2) 0; 1 / sqrt(6) 1 / sqrt(6) - 2 / sqrt(6)]';
88  M = simplify(A * inv(R) * [V 0 0; 0 V*S 0; 0 0 -V*S] * R * inv(A))
89  */
90  const Color::hsva_t hsva(preservedColor);
91  const float _2H = 2 * (-hsva.h * 2 * pi - pi / 6),
92  S = saturationFactor, V = valueFactor;
93  r() = { (V*(S*cos(_2H) - sqrtf(3)*S*sin(_2H) + 1)) / 3, -(V*(2 * S*cos(_2H) - 1)) / 3, (V*(S*cos(_2H) + sqrtf(3)*S*sin(_2H) + 1)) / 3, 0 };
94  g() = {-(V*(2 * S*cos(_2H) - 1)) / 3, (V*(S*cos(_2H) + sqrtf(3)*S*sin(_2H) + 1)) / 3, (V*(S*cos(_2H) - sqrtf(3)*S*sin(_2H) + 1)) / 3, 0 };
95  b() = { (V*(S*cos(_2H) + sqrtf(3)*S*sin(_2H) + 1)) / 3, (V*(S*cos(_2H) - sqrtf(3)*S*sin(_2H) + 1)) / 3, -(V*(4 * S*cos(_2H) - 2)) / 6, 0 };
96  a() = color4f{ 0, 0, 0, 1 };
97 }
HSVA quad (for hue, saturation, value and alpha)
Definition: color_spaces.h:34
Beatmup::color3f preservedColor

Member Function Documentation

◆ r() [1/2]

color4f Beatmup::Color::Matrix::r ( ) const
inline

Definition at line 60 of file matrix.h.

60 { return rows[0]; }
color4f rows[4]
Definition: matrix.h:38

◆ g() [1/2]

color4f Beatmup::Color::Matrix::g ( ) const
inline

Definition at line 61 of file matrix.h.

61 { return rows[1]; }

◆ b() [1/2]

color4f Beatmup::Color::Matrix::b ( ) const
inline

Definition at line 62 of file matrix.h.

62 { return rows[2]; }

◆ a() [1/2]

color4f Beatmup::Color::Matrix::a ( ) const
inline

Definition at line 63 of file matrix.h.

63 { return rows[3]; }

◆ r() [2/2]

color4f& Beatmup::Color::Matrix::r ( )
inline

Definition at line 64 of file matrix.h.

64 { return rows[0]; }

◆ g() [2/2]

color4f& Beatmup::Color::Matrix::g ( )
inline

Definition at line 65 of file matrix.h.

65 { return rows[1]; }

◆ b() [2/2]

color4f& Beatmup::Color::Matrix::b ( )
inline

Definition at line 66 of file matrix.h.

66 { return rows[2]; }

◆ a() [2/2]

color4f& Beatmup::Color::Matrix::a ( )
inline

Definition at line 67 of file matrix.h.

67 { return rows[3]; }

◆ operator[]() [1/2]

color4f & Matrix::operator[] ( int  row)

Retrieves matrix rows by index in 0..3 range.

Definition at line 42 of file matrix.cpp.

42  {
43  return rows[row];
44 }

◆ operator[]() [2/2]

color4f Matrix::operator[] ( int  row) const

Definition at line 47 of file matrix.cpp.

47  {
48  return rows[row];
49 }

◆ operator*()

Matrix Matrix::operator* ( const Matrix another) const

Computes the right-multiplication of the current Matrix and another Matrix.

Definition at line 52 of file matrix.cpp.

52  {
53  Matrix _;
54  for (int i = 0; i < 4; i++) {
55  _.elem[i][0] = MUL(elem, another.elem, i, 0);
56  _.elem[i][1] = MUL(elem, another.elem, i, 1);
57  _.elem[i][2] = MUL(elem, another.elem, i, 2);
58  _.elem[i][3] = MUL(elem, another.elem, i, 3);
59  }
60  return _;
61 }
RGBA color mapping.
Definition: matrix.h:29
float elem[4][4]
Definition: matrix.h:36
#define MUL(a, b, i, j)
Definition: matrix.cpp:26

◆ operator=()

void Matrix::operator= ( const Matrix source)

Definition at line 64 of file matrix.cpp.

64  {
65  memcpy(elem, source.elem, sizeof(elem));
66 }

Member Data Documentation

◆ elem

float Beatmup::Color::Matrix::elem[4][4]

Definition at line 36 of file matrix.h.

◆ rows

color4f Beatmup::Color::Matrix::rows[4]

Definition at line 38 of file matrix.h.

◆ 

union { ... }

Matrix elements.


The documentation for this class was generated from the following files: