mirror of
https://github.com/LMMS/lmms.git
synced 2026-01-22 05:18:12 -05:00
* use c++20 concepts and numbers for lmms_constants.h * replace lmms::numbers::sqrt2 with std::numbers::sqrt2 * replace lmms::numbers::e with std::numbers::e Also replace the only use of lmms::numbers::inv_e with a local constexpr instead * remove lmms::numbers::pi_half and lmms::numbers::pi_sqr They were only used in one or two places each * replace lmms::numbers::pi with std::numbers::pi * add #include <numbers> to every file touched so far This is probably not needed for some of these files. I'll remove those later * Remove lmms::numbers Rest in peace lmms::numbers::tau, my beloved * Add missing #include <numbers> * replace stray use of F_EPSILON with approximatelyEqual() * make many constants inline constexpr A lot of the remaining constants in lmms_constants.h are specific to SaProcessor. If they are only used there, shouldn't they be in SaProcessor.h? * ok then, it's allowed to be signed * remove #include "lmms_constants.h" for files that don't need it - And also move F_EPSILON into lmms_math.h - And also add an overload for fast_rand() to specify a higher and lower bound - And a bunch of other nonsense * ok then, it's allowed to be inferred * ok then, it can accept an integral * fix typo * appease msvc * appease msvc again * Replace linearInterpolate with std::lerp() As well as time travel to undo several foolish decisions and squash tiny commits together * Fix msvc constexpr warnings * Fix msvc float to double truncation warning * Apply two suggestions from code review Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * Apply suggestions from code review Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * fix silly mistake * Remove SlicerT's dependence on lmms_math.h * Allow more type inference on fastRand() and fastPow10f() * Apply suggestions from code review Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * Clean up fastRand() a little bit more --------- Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
/* ColorHelper.h - Helper methods for color related algorithms, etc.
|
|
*
|
|
* Copyright (c) 2024- Michael Gregorius
|
|
*
|
|
* This file is part of LMMS - https://lmms.io
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program (see COPYING); if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
*/
|
|
|
|
#ifndef LMMS_GUI_COLOR_HELPER_H
|
|
#define LMMS_GUI_COLOR_HELPER_H
|
|
|
|
#include <cmath>
|
|
#include <QColor>
|
|
|
|
namespace lmms::gui
|
|
{
|
|
|
|
class ColorHelper
|
|
{
|
|
public:
|
|
static QColor interpolateInRgb(const QColor& a, const QColor& b, float t)
|
|
{
|
|
qreal ar, ag, ab, aa;
|
|
a.getRgbF(&ar, &ag, &ab, &aa);
|
|
|
|
qreal br, bg, bb, ba;
|
|
b.getRgbF(&br, &bg, &bb, &ba);
|
|
|
|
const auto t2 = static_cast<qreal>(t);
|
|
const float interH = std::lerp(ar, br, t2);
|
|
const float interS = std::lerp(ag, bg, t2);
|
|
const float interV = std::lerp(ab, bb, t2);
|
|
const float interA = std::lerp(aa, ba, t2);
|
|
|
|
return QColor::fromRgbF(interH, interS, interV, interA);
|
|
}
|
|
};
|
|
|
|
} // namespace lmms::gui
|
|
|
|
#endif // LMMS_GUI_COLOR_HELPER_H
|