TinyGPU
Loading...
Searching...
No Matches
RGB888.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 24-bit RGB888 format.
9 *
10 * The class provides conversion between 8-bit per channel RGB values and the
11 * packed 24-bit representation (3 bytes) commonly used in graphics.
12 */
13class RGB888 {
14 public:
15 /// Creates a black RGB888 color.
16 RGB888() = default;
17
18 /// Creates a color from 8-bit red, green, and blue components.
19 RGB888(uint8_t r, uint8_t g, uint8_t b) { setValue(r, g, b); }
20
21 /// Creates a grayscale color from a single 8-bit value (all channels set to v).
22 explicit RGB888(uint8_t v) { setValue(v, v, v); }
23
24 /// Sets the color from 8-bit red, green, and blue components.
25 void setValue(uint8_t r, uint8_t g, uint8_t b) {
26 value[0] = r;
27 value[1] = g;
28 value[2] = b;
29 }
30
31 /// Returns the red component.
32 uint8_t getRed() const { return value[0]; }
33 /// Returns the green component.
34 uint8_t getGreen() const { return value[1]; }
35 /// Returns the blue component.
36 uint8_t getBlue() const { return value[2]; }
37
38 /// Returns the packed RGB888 value as a pointer to 3 bytes.
39 const uint8_t* getValue() const { return value; }
40
41 /// Returns size in bits
42 static uint8_t size() { return 24; }
43
44 protected:
45 uint8_t value[3] = {0, 0, 0};
46};
47
48inline bool operator!=(const tinygpu::RGB888& lhs, const tinygpu::RGB888& rhs) {
49 return lhs.getRed() != rhs.getRed() || lhs.getGreen() != rhs.getGreen() || lhs.getBlue() != rhs.getBlue();
50}
51} // namespace tinygpu
RGB color stored in 24-bit RGB888 format.
Definition: RGB888.h:13
uint8_t value[3]
Definition: RGB888.h:45
RGB888(uint8_t v)
Creates a grayscale color from a single 8-bit value (all channels set to v).
Definition: RGB888.h:22
uint8_t getBlue() const
Returns the blue component.
Definition: RGB888.h:36
static uint8_t size()
Returns size in bits.
Definition: RGB888.h:42
uint8_t getGreen() const
Returns the green component.
Definition: RGB888.h:34
uint8_t getRed() const
Returns the red component.
Definition: RGB888.h:32
const uint8_t * getValue() const
Returns the packed RGB888 value as a pointer to 3 bytes.
Definition: RGB888.h:39
RGB888(uint8_t r, uint8_t g, uint8_t b)
Creates a color from 8-bit red, green, and blue components.
Definition: RGB888.h:19
void setValue(uint8_t r, uint8_t g, uint8_t b)
Sets the color from 8-bit red, green, and blue components.
Definition: RGB888.h:25
RGB888()=default
Creates a black RGB888 color.
Definition: AVIWriter.h:9
bool operator!=(const tinygpu::RGB888 &lhs, const tinygpu::RGB888 &rhs)
Definition: RGB888.h:48