summaryrefslogtreecommitdiff
path: root/src/nes/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/nes/util')
-rw-r--r--src/nes/util/CMakeLists.txt4
-rw-r--r--src/nes/util/rgb.hh33
2 files changed, 37 insertions, 0 deletions
diff --git a/src/nes/util/CMakeLists.txt b/src/nes/util/CMakeLists.txt
new file mode 100644
index 0000000..c2255dd
--- /dev/null
+++ b/src/nes/util/CMakeLists.txt
@@ -0,0 +1,4 @@
+target_sources(
+ nes
+ PRIVATE
+ rgb.hh) \ No newline at end of file
diff --git a/src/nes/util/rgb.hh b/src/nes/util/rgb.hh
new file mode 100644
index 0000000..d62c70c
--- /dev/null
+++ b/src/nes/util/rgb.hh
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <cstdint>
+
+namespace nes
+{
+ /// An RGB value.
+ class rgb
+ {
+ public:
+ explicit rgb() = default;
+
+ explicit rgb(std::uint8_t const r, std::uint8_t const g, std::uint8_t const b)
+ : r{ r }
+ , g{ g }
+ , b{ b }
+ {
+ }
+
+ static auto from_hex(std::uint32_t const hex) -> rgb
+ {
+ auto res = rgb{};
+ res.r = (hex & 0x00FF0000) >> 16;
+ res.g = (hex & 0x0000FF00) >> 8;
+ res.b = (hex & 0x000000FF) >> 0;
+ return res;
+ }
+
+ std::uint8_t r{ 0 };
+ std::uint8_t g{ 0 };
+ std::uint8_t b{ 0 };
+ };
+} // namespace nes \ No newline at end of file