Lumiverse  2.5
A framework for creating lighting control applications
Pixel.h
1 #ifndef Lumiverse_PIXEL_H
2 #define Lumiverse_PIXEL_H
3 
4 #ifdef USE_ARNOLD_CACHING
5 
6 #include <iostream>
7 
8 namespace Lumiverse {
9 
16 class Pixel {
17 public:
21  virtual inline float illum() = 0;
22 };
23 
28 class Pixel3 : public Pixel {
29 public:
30  Pixel3() {
31  r = 1;
32  g = 1;
33  b = 1;
34  }
35 
36  Pixel3(float x, float y, float z) {
37  r = x;
38  g = y;
39  b = z;
40  }
41 
42  float r, g, b;
43 
44  Pixel3 operator *(float scalar) {
45  return Pixel3(r * scalar, g * scalar, b * scalar);
46  }
47 
48  void operator *=(int scalar) {
49  r *= scalar;
50  g *= scalar;
51  b *= scalar;
52  }
53 
54  inline float illum() {
55  return (float) (0.2126*r + 0.7152*g + 0.0722*b);
56  }
57 };
58 
63 class Pixel4 : public Pixel {
64 public:
65  Pixel4() {
66  r = 1;
67  g = 1;
68  b = 1;
69  a = 1;
70  }
71 
72  Pixel4(float x, float y, float z, float w) {
73  r = x;
74  g = y;
75  b = z;
76  a = w;
77  }
78 
79  float r, g, b, a;
80 
81  inline float illum() {
82  return (float) (0.2126*r + 0.7152*g + 0.0722*b);
83  }
84 
85  Pixel4 operator *(float scalar) {
86  return Pixel4(r * scalar, g * scalar, b * scalar, a);
87  }
88 
89  void operator *=(int scalar) {
90  r *= scalar;
91  g *= scalar;
92  b *= scalar;
93  }
94 
95 };
96 
100 inline int clamp(float x) { return x < 0 ? 0 : x > 1 ? 255 : int(x * 255); }
101 inline float clamp(float x, float min, float max) { return x < min ? min : (x > max) ? max : x; }
102 
103 }; // namespace Lumiverse
104 
105 #endif // USE_ARNOLD_CACHING
106 
107 #endif // Lumiverse_PIXEL_H
double clamp(double val, double min, double max)
Clamps a value between a min and a max.
Definition: LumiverseColorLib.cpp:242
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2