le3d - LightEngine 3D
A straightforward C++ 3D software engine for real-time graphics
color.h
Go to the documentation of this file.
1 
33 #ifndef LE_COLOR_H
34 #define LE_COLOR_H
35 
36 #include <stdint.h>
37 
42 class LeColor {
43 public:
44  LeColor& operator=(LeColor const& color) {
45  r = color.r;
46  g = color.g;
47  b = color.b;
48  a = color.a;
49  return *this;
50  }
51 
52 #ifdef AMIGA
53  LeColor(): a(0), r(0), g(0), b(0) {}
54  LeColor(uint8_t const& _r, uint8_t const& _g, uint8_t const& _b, uint8_t const& _a): a(_a), r(_r), g(_g), b(_b) {}
55  explicit LeColor(int const& color): a(color >> 24), r(color >> 16), g(color >> 8), b(color) {};
56  LeColor& operator=(int const& color) {
57  a = color >> 24;
58  r = color >> 16;
59  g = color >> 8;
60  b = color;
61 
62  return *this;
63  }
64  operator int() {
65  return (a << 24) | (r << 16) | (g << 8) | b;
66  }
67 
68 public:
69  static LeColor rgba(uint32_t const& rgba) {
70  return LeColor(rgba >> 16, rgba >> 8, rgba >> 0, rgba >> 24);
71  }
72 
73  static LeColor rgb(uint32_t const& rgb) {
74  return LeColor(rgb >> 16, rgb >> 8, rgb, 1);
75  }
76 
77 public:
78  uint8_t a;
79  uint8_t r;
80  uint8_t g;
81  uint8_t b;
82 
83 #else
84  LeColor(): b(0), g(0), r(0), a(0) {}
85  LeColor(uint8_t const& _r, uint8_t const& _g, uint8_t const& _b, uint8_t const& _a): b(_b), g(_g), r(_r), a(_a) {}
86  explicit LeColor(int const& color): b(color), g(color >> 8), r(color >> 16), a(color >> 24) {};
87  LeColor& operator=(int const& color) {
88  r = color >> 16;
89  g = color >> 8;
90  b = color;
91  a = color >> 24;
92 
93  return *this;
94  }
95  operator int() {
96  return (r << 16) | (g << 8) | b | (a << 24);
97  }
98 
99 public:
100  static LeColor rgba(uint32_t const& rgba) {
101  return LeColor(rgba >> 16, rgba >> 8, rgba, rgba >> 24);
102  }
103 
104  static LeColor rgb(uint32_t const& rgb) {
105  return LeColor(rgb >> 16, rgb >> 8, rgb, 1);
106  }
107 
108 public:
109  uint8_t b;
110  uint8_t g;
111  uint8_t r;
112  uint8_t a;
113 #endif
114 };
115 
116 
117 #endif
LeColor()
Definition: color.h:84
uint8_t b
Definition: color.h:109
LeColor & operator=(LeColor const &color)
Definition: color.h:44
LeColor(uint8_t const &_r, uint8_t const &_g, uint8_t const &_b, uint8_t const &_a)
Definition: color.h:85
uint8_t g
Definition: color.h:110
Represent an RGBA color.
Definition: color.h:42
static LeColor rgba(uint32_t const &rgba)
Definition: color.h:100
LeColor(int const &color)
Definition: color.h:86
uint8_t r
Definition: color.h:111
static LeColor rgb(uint32_t const &rgb)
Definition: color.h:104
LeColor & operator=(int const &color)
Definition: color.h:87
uint8_t a
Definition: color.h:112