From 191e86530f6ed8347470f8e5e5f6019285802449 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 14 Feb 2020 12:32:45 -0400 Subject: [PATCH] C++ hsluv(): ensure passing color within bounds --- src/utils.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils.cpp b/src/utils.cpp index ceb5aec6..db74827b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -9,6 +9,8 @@ #include "utils.h" #include "../submodules/hsluv-c/src/hsluv.h" +using namespace std; + Utils::Utils() { // Initialization @@ -30,5 +32,11 @@ QString Utils::uuid() { QColor Utils::hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha) { double red, green, blue; hsluv2rgb(hue, saturation, luv, &red, &green, &blue); - return QColor::fromRgbF(red, green, blue, alpha); + + return QColor::fromRgbF( + qMax(0.0, qMin(1.0, red)), + qMax(0.0, qMin(1.0, green)), + qMax(0.0, qMin(1.0, blue)), + qMax(0.0, qMin(1.0, alpha)) + ); }