Arty
color.h
1 #ifndef COLOR_H
2 #define COLOR_H
3 
4 #include "float3.h"
5 #include "float4.h"
6 
7 struct rgba;
8 
9 struct rgb : public float3 {
10  rgb() {}
11  rgb(const float3& rgb) : float3(rgb) {}
12  rgb(float r, float g, float b) : float3(r, g, b) {}
13  explicit rgb(float x) : float3(x) {}
14  explicit rgb(const rgba& rgba);
15 
16  rgb& operator += (const rgb& p) {
17  *this = *this + p;
18  return *this;
19  }
20 
21  rgb& operator += (const Atom<rgb>& atom) {
22  #pragma omp atomic
23  x += atom.value.x;
24  #pragma omp atomic
25  y += atom.value.y;
26  #pragma omp atomic
27  z += atom.value.z;
28  return *this;
29  }
30 };
31 
32 struct rgba : public float4 {
33  rgba() {}
34  rgba(const float4& rgba) : float4(rgba) {}
35  rgba(float r, float g, float b, float a) : float4(r, g, b, a) {}
36  explicit rgba(float x) : float4(x) {}
37  explicit rgba(const rgb& rgb, float a) : float4(rgb, a) {}
38 
39  rgba& operator += (const rgba& p) {
40  *this = *this + p;
41  return *this;
42  }
43 
44  rgba& operator += (const Atom<rgba>& atom) {
45  #pragma omp atomic
46  x += atom.value.x;
47  #pragma omp atomic
48  y += atom.value.y;
49  #pragma omp atomic
50  z += atom.value.z;
51  #pragma omp atomic
52  w += atom.value.w;
53  return *this;
54  }
55 };
56 
57 inline rgb::rgb(const rgba& rgba) : float3(rgba) {}
58 
59 static const rgb luminance(0.2126f, 0.7152f, 0.0722f);
60 
61 inline rgb gamma(const rgb& c, float g = 0.5f) {
62  return rgb(std::pow(c.x, g), std::pow(c.y, g), std::pow(c.z, g));
63 }
64 
65 inline rgba gamma(const rgba& c, float g = 0.5f) {
66  return rgba(std::pow(c.x, g), std::pow(c.y, g), std::pow(c.z, g), c.w);
67 }
68 
69 inline rgb clamp(const rgb& val, const rgb& min, const rgb& max) {
70  return rgb(clamp(val.x, min.x, max.x),
71  clamp(val.y, min.y, max.y),
72  clamp(val.z, min.z, max.z));
73 }
74 
75 inline rgba clamp(const rgba& val, const rgba& min, const rgba& max) {
76  return rgba(clamp(val.x, min.x, max.x),
77  clamp(val.y, min.y, max.y),
78  clamp(val.z, min.z, max.z),
79  clamp(val.w, min.w, max.w));
80 }
81 
82 #endif // COLOR_H
Definition: float3.h:10
Definition: color.h:32
Definition: float4.h:9
Class that represents a value that has to be treated atomically.
Definition: common.h:143
Definition: color.h:9