summaryrefslogtreecommitdiff
path: root/src/helpers/Color.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-12-03 18:58:24 +0000
committerGitHub <noreply@github.com>2024-12-03 18:58:24 +0000
commit320144ae7288fe23686935ebb235d9fe0c900862 (patch)
tree351b04e228926f98c12c340284c25450bb1fed4f /src/helpers/Color.cpp
parent92186898c0ca1b3f72922b72c4af1723f0d9b888 (diff)
core: move colorspace handling to oklab (#8635)
* Meson: add hyprgraphics * Nix: add hyprgraphics * CI/setup_base: get hyprgraphics-git --------- Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
Diffstat (limited to 'src/helpers/Color.cpp')
-rw-r--r--src/helpers/Color.cpp56
1 files changed, 43 insertions, 13 deletions
diff --git a/src/helpers/Color.cpp b/src/helpers/Color.cpp
index f9a207bb..fe217c0f 100644
--- a/src/helpers/Color.cpp
+++ b/src/helpers/Color.cpp
@@ -5,22 +5,52 @@
#define GREEN(c) ((double)(((c) >> 8) & 0xff) / 255.0)
#define BLUE(c) ((double)(((c)) & 0xff) / 255.0)
-CColor::CColor() {}
+CHyprColor::CHyprColor() {}
-CColor::CColor(float r, float g, float b, float a) {
- this->r = r;
- this->g = g;
- this->b = b;
- this->a = a;
+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();
}
-CColor::CColor(uint64_t hex) {
- this->r = RED(hex);
- this->g = GREEN(hex);
- this->b = BLUE(hex);
- this->a = ALPHA(hex);
+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();
}
-uint32_t CColor::getAsHex() const {
+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 {
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;
-} \ No newline at end of file
+}
+
+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};
+}