19uint32_t getRGB(
int r,
int g,
int b)
21 r = std::clamp(r, 0, 255);
22 g = std::clamp(g, 0, 255);
23 b = std::clamp(b, 0, 255);
24 return (r << 16) | (g << 8) | b;
30uint32_t getRGB(
float r,
float g,
float b)
32 return getRGB((
int)(r * 256.0f),
45 static int constexpr SIZE = 16;
51 static Tables
const instance;
68 auto polish = [x] (
double y) {
69 return (2.0 * y + x / sq(y)) / 3.0;
71 double y = Tables::get().cbrt[(int)(x * Tables::SIZE)];
80 auto polish = [x] (
double y) {
81 return (4.0 * y + x / sq(sq(y))) / 5.0;
83 double y = Tables::get().qn[(int)(x * Tables::SIZE)];
91 return sq(x * qnrt(x));
96 auto entry = [&] (
int i,
float x) {
97 cbrt[i] = std::pow(x /
SIZE, 0.3333f);
98 qn[i] = std::pow(x /
SIZE, 0.2f);
102 for (
int i = 1; i <
SIZE + 1; i++) {
111 uint8_t ir = (
rgb >> 16) & 0xff;
112 uint8_t ig = (
rgb >> 8) & 0xff;
113 uint8_t ib = (
rgb ) & 0xff;
115 float fr = ir / 255.0f;
116 float fg = ig / 255.0f;
117 float fb = ib / 255.0f;
121 auto to_linear = [] (
float &x) {
123 x = pow24((x + 0.055) / 1.055);
134 float x = fr * 0.4124 + fg * 0.3576 + fb * 0.1805;
135 float y = fr * 0.2126 + fg * 0.7152 + fb * 0.0722;
136 float z = fr * 0.0193 + fg * 0.1192 + fb * 0.9505;
138 float vx = x / 0.95047;
140 float vz = z / 1.08883;
144 auto f = [] (
float &x) {
148 x = (7.787 * x) + (16.0 / 116.0);
157 L = 116.0 * vy - 16.0;
158 A = 500.0 * (vx - vy);
159 B = 200.0 * (vy - vz);
164 float vy = (
L + 16.0) / 116.0;
165 float vx =
A / 500.0 + vy;
166 float vz = vy -
B / 200.0;
168 auto finv = [] (
float &x) {
169 float x3 = x * x * x;
173 x = (x - 16.0 / 116.0) / 7.787;
184 float vr = vx * 3.2406 + vy * -1.5372 + vz * -0.4986;
185 float vg = vx * -0.9689 + vy * 1.8758 + vz * 0.0415;
186 float vb = vx * 0.0557 + vy * -0.2040 + vz * 1.0570;
188 auto from_linear = [] (
float &x) {
190 x = 1.055 * std::pow(x, 1.0 / 2.4) - 0.055;
200 return getRGB(vr, vg, vb);
205 return sq(c1.
L - c2.
L)
212 return std::sqrt(
diffSq(c1, c2));
double polish(double t, arc_length_params &alp)
static int constexpr SIZE
uint32_t toRGB() const
Return this CieLab's value converted to an ARGB value.
static float diff(CieLab const &c1, CieLab const &c2)
Computes euclidean distance in CieLab space between two colors.
static float diffSq(CieLab const &c1, CieLab const &c2)
Squared Euclidean distance between two colors in CieLab space.
Helper class to stream background task notifications as a series of messages.