1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickcolordialogutils_p.h"
5
6std::pair<qreal, qreal> getSaturationAndValue(qreal saturation, qreal lightness)
7{
8 const qreal v = lightness + saturation * qMin(a: lightness, b: 1 - lightness);
9 if (v == .0)
10 return { .0, .0 };
11 const qreal s = 2 * (1 - lightness / v);
12 return { s, v };
13}
14
15std::pair<qreal, qreal> getSaturationAndLightness(qreal saturation, qreal value)
16{
17 const qreal l = value * (1 - saturation / 2);
18 if (l == .0)
19 return { .0, .0 };
20 if (l == 1 && value == 1)
21 return { saturation, l };
22 const qreal s = (value - l) / qMin(a: l, b: 1 - l);
23 return { s, l };
24}
25

source code of qtdeclarative/src/quickdialogs/quickdialogsquickimpl/qquickcolordialogutils.cpp