44
55#include " Color.hpp"
66
7+ #include < cmath>
8+ #include < iostream>
9+
710namespace jngl {
811
912Rgb::Rgb (float red, float green, float blue) : red(red), green(green), blue(blue) {
@@ -44,6 +47,18 @@ void Rgb::setBlue(const float blue) {
4447 this ->blue = blue;
4548}
4649
50+ uint8_t Rgb::getRed_u8 () const {
51+ return static_cast <uint8_t >(std::lround (red * 255 .f ));
52+ }
53+
54+ uint8_t Rgb::getGreen_u8 () const {
55+ return static_cast <uint8_t >(std::lround (green * 255 .f ));
56+ }
57+
58+ uint8_t Rgb::getBlue_u8 () const {
59+ return static_cast <uint8_t >(std::lround (blue * 255 .f ));
60+ }
61+
4762Rgb::operator Color () const {
4863 return Color{ static_cast <unsigned char >(red * 255 ), static_cast <unsigned char >(green * 255 ),
4964 static_cast <unsigned char >(blue * 255 ) };
@@ -54,6 +69,16 @@ Rgb interpolate(Rgb a, Rgb b, float t) {
5469 a.getBlue () * (1 .f - t) + b.getBlue () * t };
5570}
5671
72+ bool operator ==(Rgb a, Rgb b) {
73+ return a.getRed_u8 () == b.getRed_u8 () && a.getGreen_u8 () == b.getGreen_u8 () &&
74+ a.getBlue_u8 () == b.getBlue_u8 ();
75+ }
76+
77+ std::ostream& operator <<(std::ostream& os, Rgb color) {
78+ os << " jngl::Rgb{ " << color.getRed () << " , " << color.getGreen () << " , " << color.getBlue () << " }" ;
79+ return os;
80+ }
81+
5782} // namespace jngl
5883
5984jngl::Rgb operator " " _rgb(const unsigned long long hex) {
0 commit comments