LMMS
Loading...
Searching...
No Matches
ColorHelper.h
Go to the documentation of this file.
1/* ColorHelper.h - Helper methods for color related algorithms, etc.
2 *
3 * Copyright (c) 2024- Michael Gregorius
4 *
5 * This file is part of LMMS - https://lmms.io
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public
18 * License along with this program (see COPYING); if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA.
21 *
22 */
23
24#ifndef LMMS_GUI_COLOR_HELPER_H
25#define LMMS_GUI_COLOR_HELPER_H
26
27#include <cmath>
28#include <QColor>
29
30namespace lmms::gui
31{
32
34{
35public:
36 static QColor interpolateInRgb(const QColor& a, const QColor& b, float t)
37 {
38#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
39 using ColorType = float;
40#else
41 using ColorType = qreal;
42#endif
43
44 ColorType ar, ag, ab, aa;
45 a.getRgbF(&ar, &ag, &ab, &aa);
46
47 ColorType br, bg, bb, ba;
48 b.getRgbF(&br, &bg, &bb, &ba);
49
50 const auto t2 = static_cast<ColorType>(t);
51 const auto interH = std::lerp(ar, br, t2);
52 const auto interS = std::lerp(ag, bg, t2);
53 const auto interV = std::lerp(ab, bb, t2);
54 const auto interA = std::lerp(aa, ba, t2);
55
56 return QColor::fromRgbF(interH, interS, interV, interA);
57 }
58};
59
60} // namespace lmms::gui
61
62#endif // LMMS_GUI_COLOR_HELPER_H
uint8_t a
Definition Spc_Cpu.h:141
Definition ColorHelper.h:34
static QColor interpolateInRgb(const QColor &a, const QColor &b, float t)
Definition ColorHelper.h:36
G bb
Definition inflate.c:1057
struct huft * t
Definition inflate.c:943
Definition AudioPortAudio.cpp:223
b
Definition crypt.c:628