aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickdialogs/quickdialogsquickimpl/qquickcolordialogutils.cpp
blob: 9bb7a413e492bb4446a8fe2b97781f015ad0d24a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

#include "qquickcolordialogutils_p.h"

QT_BEGIN_NAMESPACE

std::pair<qreal, qreal> getSaturationAndValue(qreal saturation, qreal lightness)
{
    const qreal v = lightness + saturation * qMin(lightness, 1 - lightness);
    if (v == .0)
        return { .0, .0 };
    const qreal s = 2 * (1 - lightness / v);
    return { s, v };
}

std::pair<qreal, qreal> getSaturationAndLightness(qreal saturation, qreal value)
{
    const qreal l = value * (1 - saturation / 2);
    if (l == .0)
        return { .0, .0 };
    if (l == 1 && value == 1)
        return { saturation, l };
    const qreal s = (value - l) / qMin(l, 1 - l);
    return { s, l };
}

QT_END_NAMESPACE