Added trgb struct

This commit is contained in:
Bob Polis 2023-08-08 12:34:47 +02:00
parent d6d7e3d4cd
commit 969984213d
2 changed files with 36 additions and 6 deletions

View File

@ -1,5 +1,6 @@
#include "iomanip.hpp"
#include <unistd.h>
#include <cmath>
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<int>(floor(_r * 5)),
static_cast<int>(floor(_g * 5)),
static_cast<int>(floor(_b * 5))
};
return result;
}

View File

@ -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};
}
}