summaryrefslogtreecommitdiff
path: root/Libraries/LibGfx
diff options
context:
space:
mode:
authorLepkoQQ <lepko.san@gmail.com>2020-08-25 16:28:36 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-26 00:38:23 +0200
commit7a46e0fa3514f7b85d76f10a30b7bf456df1922f (patch)
tree1917dea6d982181d16f974db8be80c5e2870e0d6 /Libraries/LibGfx
parent0604f82a96bf548c9770ffd3b4b46612f949c575 (diff)
downloadserenity-7a46e0fa3514f7b85d76f10a30b7bf456df1922f.zip
LibGfx: Always use 0..360 0..1 0..1 in HSV colors
Diffstat (limited to 'Libraries/LibGfx')
-rw-r--r--Libraries/LibGfx/Color.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/Libraries/LibGfx/Color.h b/Libraries/LibGfx/Color.h
index d58d546584..619be7da05 100644
--- a/Libraries/LibGfx/Color.h
+++ b/Libraries/LibGfx/Color.h
@@ -26,6 +26,7 @@
#pragma once
+#include <AK/Assertions.h>
#include <AK/Forward.h>
#include <AK/StdLibExtras.h>
#include <LibIPC/Forward.h>
@@ -196,14 +197,17 @@ public:
if (hsv.hue >= 360.0)
hsv.hue -= 360.0;
- hsv.hue /= 360.0;
-
if (!max)
hsv.saturation = 0;
else
hsv.saturation = chroma / max;
hsv.value = max;
+
+ ASSERT(hsv.hue >= 0.0 && hsv.hue < 360.0);
+ ASSERT(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
+ ASSERT(hsv.value >= 0.0 && hsv.value <= 1.0);
+
return hsv;
}
@@ -214,9 +218,13 @@ public:
static Color from_hsv(const HSV& hsv)
{
- double hue = hsv.hue * 2.0;
- double saturation = hsv.saturation / 255.0;
- double value = hsv.value / 255.0;
+ ASSERT(hsv.hue >= 0.0 && hsv.hue < 360.0);
+ ASSERT(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
+ ASSERT(hsv.value >= 0.0 && hsv.value <= 1.0);
+
+ double hue = hsv.hue;
+ double saturation = hsv.saturation;
+ double value = hsv.value;
int high = static_cast<int>(hue / 60.0) % 6;
double f = (hue / 60.0) - high;