TinyGPU
Loading...
Searching...
No Matches
RGB666.h
Go to the documentation of this file.
1#pragma once
2#include <stddef.h>
3#include <stdint.h>
4
5namespace tinygpu {
6
7/**
8 * @brief RGB color stored in 18-bit RGB666 format.
9 *
10 * The class provides conversion between 8-bit per channel RGB values and the
11 * packed 18-bit representation (3 bytes, 6 bits per channel, upper bits used) commonly used in displays.
12 */
13class RGB666 {
14 public:
15 /// Creates a black RGB666 color.
16 RGB666() = default;
17
18 /// Creates a color from 8-bit red, green, and blue components.
19 RGB666(uint8_t r, uint8_t g, uint8_t b) { setValue(r, g, b); }
20
21 /// Sets the color from 8-bit red, green, and blue components.
22 void setValue(uint8_t r, uint8_t g, uint8_t b) {
23 value[0] = r & 0xFC; // upper 6 bits
24 value[1] = g & 0xFC;
25 value[2] = b & 0xFC;
26 }
27
28 /// Returns the red component (expanded to 8 bits).
29 uint8_t getRed() const { return value[0]; }
30 /// Returns the green component (expanded to 8 bits).
31 uint8_t getGreen() const { return value[1]; }
32 /// Returns the blue component (expanded to 8 bits).
33 uint8_t getBlue() const { return value[2]; }
34
35 /// Returns the packed RGB666 value as a pointer to 3 bytes (upper 6 bits used).
36 const uint8_t* getValue() const { return value; }
37
38 /// Returns size in bits
39 static uint8_t size() { return 18; }
40
41 protected:
42 uint8_t value[3] = {0, 0, 0};
43};
44
45} // namespace tinygpu
RGB color stored in 18-bit RGB666 format.
Definition: RGB666.h:13
uint8_t value[3]
Definition: RGB666.h:42
RGB666(uint8_t r, uint8_t g, uint8_t b)
Creates a color from 8-bit red, green, and blue components.
Definition: RGB666.h:19
uint8_t getBlue() const
Returns the blue component (expanded to 8 bits).
Definition: RGB666.h:33
static uint8_t size()
Returns size in bits.
Definition: RGB666.h:39
uint8_t getGreen() const
Returns the green component (expanded to 8 bits).
Definition: RGB666.h:31
uint8_t getRed() const
Returns the red component (expanded to 8 bits).
Definition: RGB666.h:29
const uint8_t * getValue() const
Returns the packed RGB666 value as a pointer to 3 bytes (upper 6 bits used).
Definition: RGB666.h:36
RGB666()=default
Creates a black RGB666 color.
void setValue(uint8_t r, uint8_t g, uint8_t b)
Sets the color from 8-bit red, green, and blue components.
Definition: RGB666.h:22
Definition: AVIWriter.h:9