From 969984213d74aa2a34ba201b8d56b5bb5074377b Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Tue, 8 Aug 2023 12:34:47 +0200 Subject: [PATCH] Added trgb struct --- src/iomanip.cpp | 12 ++++++++++++ src/iomanip.hpp | 30 ++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/iomanip.cpp b/src/iomanip.cpp index 40ef023..185ff17 100644 --- a/src/iomanip.cpp +++ b/src/iomanip.cpp @@ -1,5 +1,6 @@ #include "iomanip.hpp" #include +#include using namespace sc::io; @@ -225,3 +226,14 @@ sc::io::rgbb::rgbb(int r, int g, int b) : std::ostream& sc::io::operator<<(std::ostream &out, const rgbb& obj) { return rgb(out, obj._r, obj._g, obj._b, 48); } + +sc::io::trgb::trgb(double r, double g, double b) : _r {r}, _g {g}, _b {b} {} + +sc::io::trgb::operator rgbf() { + rgbf result { + static_cast(floor(_r * 5)), + static_cast(floor(_g * 5)), + static_cast(floor(_b * 5)) + }; + return result; +} diff --git a/src/iomanip.hpp b/src/iomanip.hpp index 47293de..0404b16 100644 --- a/src/iomanip.hpp +++ b/src/iomanip.hpp @@ -54,17 +54,17 @@ namespace sc { }; struct rgbf { - int _r; - int _g; - int _b; + int _r; // 0 .. 5 + int _g; // 0 .. 5 + int _b; // 0 .. 5 rgbf(int r, int g, int b); }; struct rgbb { - int _r; - int _g; - int _b; + int _r; // 0 .. 5 + int _g; // 0 .. 5 + int _b; // 0 .. 5 rgbb(int r, int g, int b); }; @@ -73,6 +73,24 @@ namespace sc { std::ostream& operator<<(std::ostream& out, const grayb& obj); std::ostream& operator<<(std::ostream& out, const rgbf& obj); std::ostream& operator<<(std::ostream& out, const rgbb& obj); + + struct trgb { + double _r; // 0.0 .. 1.0 + double _g; // 0.0 .. 1.0 + double _b; // 0.0 .. 1.0 + + trgb(double r, double g, double b); + operator rgbf(); + }; + + const trgb black {0.0, 0.0, 0.0}; + const trgb red {1.0, 0.0, 0.0}; + const trgb green {0.0, 1.0, 0.0}; + const trgb yellow {1.0, 1.0, 0.0}; + const trgb blue {0.0, 0.0, 1.0}; + const trgb magenta {1.0, 0.0, 1.0}; + const trgb cyan {0.0, 1.0, 1.0}; + const trgb white {1.0, 1.0, 1.0}; } }