gKit2 light
color.cpp
1 
2 #include <cmath>
3 #include <algorithm>
4 
5 #include "color.h"
6 
7 
8 float Color::power( ) const
9 {
10  return (r+g+b) / 3;
11 }
12 
13 float Color::max( ) const
14 {
15  return std::max(r, std::max(g, std::max(b, float(0))));
16 }
17 
18 Color linear( const Color& color )
19 {
20  const float g= float(1 / 2.2);
21  return Color(std::pow(color.r, g), std::pow(color.g, g), std::pow(color.b, g), color.a);
22 }
23 
24 Color gamma( const Color& color )
25 {
26  const float invg= float(2.2);
27  return Color(std::pow(color.r, invg), std::pow(color.g, invg), std::pow(color.b, invg), color.a);
28 }
29 
30 
32 {
33  return Color(0, 0, 0);
34 }
35 
37 {
38  return Color(1, 1, 1);
39 }
40 
42 {
43  return Color(1, 0, 0);
44 }
45 
47 {
48  return Color(0, 1, 0);
49 }
50 
52 {
53  return Color(0, 0, 1);
54 }
55 
57 {
58  return Color(1, 1, 0);
59 }
60 
61 
62 Color operator+ ( const Color& a, const Color& b )
63 {
64  return Color(a.r + b.r, a.g + b.g, a.b + b.b, a.a + b.a);
65 }
66 
67 Color operator- ( const Color& c )
68 {
69  return Color(-c.r, -c.g, -c.b, -c.a);
70 }
71 
72 Color operator- ( const Color& a, const Color& b )
73 {
74  return a + (-b);
75 }
76 
77 Color operator* ( const Color& a, const Color& b )
78 {
79  return Color(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);
80 }
81 
82 Color operator* ( const float k, const Color& c )
83 {
84  return Color(c.r * k, c.g * k, c.b * k, c.a * k);
85 }
86 
87 Color operator* ( const Color& c, const float k )
88 {
89  return k * c;
90 }
91 
92 Color operator/ ( const Color& a, const Color& b )
93 {
94  return Color(a.r / b.r, a.g / b.g, a.b / b.b, a.a / b.a);
95 }
96 
97 Color operator/ ( const float k, const Color& c )
98 {
99  return Color(k / c.r, k / c.g, k / c.b, k / c.a);
100 }
101 
102 Color operator/ ( const Color& c, const float k )
103 {
104  float kk= 1 / k;
105  return kk * c;
106 }
Color Red()
utilitaire. renvoie une couleur rouge.
Definition: color.cpp:41
Color Yellow()
utilitaire. renvoie une couleur jaune.
Definition: color.cpp:56
Color Blue()
utilitaire. renvoie une couleur bleue.
Definition: color.cpp:51
Color Black()
utilitaire. renvoie une couleur noire.
Definition: color.cpp:31
Color Green()
utilitaire. renvoie une couleur verte.
Definition: color.cpp:46
Color linear(const Color &color)
correction gamma : srgb vers rgb
Definition: color.cpp:18
Color gamma(const Color &color)
correction gamma : rgb vers srgb
Definition: color.cpp:24
Color White()
utilitaire. renvoie une couleur blanche.
Definition: color.cpp:36
Point max(const Point &a, const Point &b)
renvoie la plus grande composante de chaque point. x, y, z= max(a.x, b.x), max(a.y,...
Definition: vec.cpp:35
representation d'une couleur (rgba) transparente ou opaque.
Definition: color.h:14