Numworks Epsilon  1.4.1
Graphing Calculator Operating System
color.h
Go to the documentation of this file.
1 #ifndef KANDINSKY_COLOR_H
2 #define KANDINSKY_COLOR_H
3 
4 #include <stdint.h>
5 
6 class KDColor {
7 public:
8  constexpr KDColor() : m_value(0) {}
9  // FIXME: This should not be needed, and is probably wasting CPU cycles
10  static constexpr KDColor RGB16(uint16_t rgb) {
11  return KDColor(rgb);
12  }
13  static constexpr KDColor RGB24(uint32_t rgb) {
14  return KDColor(((rgb&0xF80000)>>8)|((rgb&0x00FC00)>>5)|((rgb&0x0000F8)>>3));
15  }
16  static constexpr KDColor RGB888(uint8_t r, uint8_t g, uint8_t b) {
17  return KDColor((r>>3)<<11 | (g>>2) << 5 | (b>>3));
18  }
19  uint8_t red() const {
20  uint8_t r5 = (m_value>>11)&0x1F;
21  return r5 << 3;
22  }
23 
24  uint8_t green() const {
25  uint8_t g6 = (m_value>>5)&0x3F;
26  return g6 << 2;
27  }
28 
29  uint8_t blue() const {
30  uint8_t b5 = m_value&0x1F;
31  return b5 << 3;
32  }
33 
34  static KDColor blend(KDColor first, KDColor second, uint8_t alpha);
35  operator uint16_t() const { return m_value; }
36 private:
37  constexpr KDColor(uint16_t value) : m_value(value) {}
38  uint16_t m_value;
39 };
40 
41 constexpr KDColor KDColorBlack = KDColor::RGB24(0x000000);
42 constexpr KDColor KDColorWhite = KDColor::RGB24(0xFFFFFF);
43 constexpr KDColor KDColorRed = KDColor::RGB24(0xFF0000);
44 constexpr KDColor KDColorGreen = KDColor::RGB24(0x00FF00);
45 constexpr KDColor KDColorBlue = KDColor::RGB24(0x0000FF);
46 constexpr KDColor KDColorYellow = KDColor::RGB24(0xFFFF00);
47 
48 #endif
constexpr KDColor KDColorBlue
Definition: color.h:45
static constexpr KDColor RGB888(uint8_t r, uint8_t g, uint8_t b)
Definition: color.h:16
unsigned short uint16_t
Definition: stdint.h:5
unsigned char uint8_t
Definition: stdint.h:4
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDColor RGB16(uint16_t rgb)
Definition: color.h:10
unsigned int uint32_t
Definition: stdint.h:6
uint8_t green() const
Definition: color.h:24
uint8_t red() const
Definition: color.h:19
constexpr KDColor()
Definition: color.h:8
constexpr KDColor KDColorBlack
Definition: color.h:41
constexpr KDColor KDColorYellow
Definition: color.h:46
Definition: color.h:6
uint8_t blue() const
Definition: color.h:29
constexpr KDColor KDColorRed
Definition: color.h:43
constexpr KDColor KDColorGreen
Definition: color.h:44
static constexpr KDColor RGB24(uint32_t rgb)
Definition: color.h:13
static KDColor blend(KDColor first, KDColor second, uint8_t alpha)
Definition: color.cpp:3