2022-03-31 17:50:00 +02:00
|
|
|
#include "Color.hpp"
|
2023-08-07 13:35:19 +02:00
|
|
|
|
|
|
|
#define ALPHA(c) ((double)(((c) >> 24) & 0xff) / 255.0)
|
|
|
|
#define RED(c) ((double)(((c) >> 16) & 0xff) / 255.0)
|
|
|
|
#define GREEN(c) ((double)(((c) >> 8) & 0xff) / 255.0)
|
|
|
|
#define BLUE(c) ((double)(((c)) & 0xff) / 255.0)
|
2022-03-31 17:50:00 +02:00
|
|
|
|
2024-12-03 19:58:24 +01:00
|
|
|
CHyprColor::CHyprColor() {}
|
2022-03-31 17:50:00 +02:00
|
|
|
|
2024-12-03 19:58:24 +01:00
|
|
|
CHyprColor::CHyprColor(float r_, float g_, float b_, float a_) {
|
|
|
|
r = r_;
|
|
|
|
g = g_;
|
|
|
|
b = b_;
|
|
|
|
a = a_;
|
|
|
|
|
|
|
|
okLab = Hyprgraphics::CColor(Hyprgraphics::CColor::SSRGB{r, g, b}).asOkLab();
|
2022-03-31 17:50:00 +02:00
|
|
|
}
|
|
|
|
|
2024-12-03 19:58:24 +01:00
|
|
|
CHyprColor::CHyprColor(uint64_t hex) {
|
|
|
|
r = RED(hex);
|
|
|
|
g = GREEN(hex);
|
|
|
|
b = BLUE(hex);
|
|
|
|
a = ALPHA(hex);
|
|
|
|
|
|
|
|
okLab = Hyprgraphics::CColor(Hyprgraphics::CColor::SSRGB{r, g, b}).asOkLab();
|
2022-03-31 17:50:00 +02:00
|
|
|
}
|
|
|
|
|
2024-12-03 19:58:24 +01:00
|
|
|
CHyprColor::CHyprColor(const Hyprgraphics::CColor& color, float a_) {
|
|
|
|
const auto SRGB = color.asRgb();
|
|
|
|
r = SRGB.r;
|
|
|
|
g = SRGB.g;
|
|
|
|
b = SRGB.b;
|
|
|
|
a = a_;
|
|
|
|
|
|
|
|
okLab = color.asOkLab();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CHyprColor::getAsHex() const {
|
2024-04-05 22:23:06 +02:00
|
|
|
return (uint32_t)(a * 255.f) * 0x1000000 + (uint32_t)(r * 255.f) * 0x10000 + (uint32_t)(g * 255.f) * 0x100 + (uint32_t)(b * 255.f) * 0x1;
|
2024-12-03 19:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Hyprgraphics::CColor::SSRGB CHyprColor::asRGB() const {
|
|
|
|
return {r, g, b};
|
|
|
|
}
|
|
|
|
|
|
|
|
Hyprgraphics::CColor::SOkLab CHyprColor::asOkLab() const {
|
|
|
|
return okLab;
|
|
|
|
}
|
|
|
|
|
|
|
|
Hyprgraphics::CColor::SHSL CHyprColor::asHSL() const {
|
|
|
|
return Hyprgraphics::CColor(okLab).asHSL();
|
|
|
|
}
|
|
|
|
|
|
|
|
CHyprColor CHyprColor::stripA() const {
|
|
|
|
return {r, g, b, 1.F};
|
|
|
|
}
|