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
6QT_BEGIN_NAMESPACE
7
8std::pair<qreal, qreal> getSaturationAndValue(qreal saturation, qreal lightness)
9{
10 const qreal v = lightness + saturation * qMin(a: lightness, b: 1 - lightness);
11 if (v == .0)
12 return { .0, .0 };
13 const qreal s = 2 * (1 - lightness / v);
14 return { s, v };
15}
16
17std::pair<qreal, qreal> getSaturationAndLightness(qreal saturation, qreal value)
18{
19 const qreal l = value * (1 - saturation / 2);
20 if (l == .0)
21 return { .0, .0 };
22 if (l == 1 && value == 1)
23 return { saturation, l };
24 const qreal s = (value - l) / qMin(a: l, b: 1 - l);
25 return { s, l };
26}
27
28QT_END_NAMESPACE
29

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