33 lines
785 B
C++
33 lines
785 B
C++
#pragma once
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
|
|
namespace ZShell::services {
|
|
|
|
inline std::array<float, 3> kelvinToGain(int kelvin) {
|
|
const double t = std::clamp(kelvin, 1000, 40000) / 100.0;
|
|
double r, g, b;
|
|
|
|
r = t <= 66.0
|
|
? 1.0
|
|
: std::clamp(
|
|
1.29293618606 * std::pow(t - 60.0, -0.1332047592), 0.0, 1.0);
|
|
g = t <= 66.0
|
|
? std::clamp(0.39008157876 * std::log(t) - 0.63184144378, 0.0, 1.0)
|
|
: std::clamp(
|
|
1.12989086089 * std::pow(t - 60.0, -0.0755148492), 0.0, 1.0);
|
|
b = t >= 66.0
|
|
? 1.0
|
|
: (t <= 19.0
|
|
? 0.0
|
|
: std::clamp(
|
|
0.54320678911 * std::log(t - 10.0) - 1.19625408914,
|
|
0.0,
|
|
1.0));
|
|
|
|
return {static_cast<float>(r), static_cast<float>(g), static_cast<float>(b)};
|
|
}
|
|
|
|
} // namespace ZShell::services
|