/*- * redshift-ng - Automatically adjust display colour temperature according the Sun * * Copyright (c) 2009-2018 Jon Lund Steffensen * Copyright (c) 2014-2016, 2025 Mattias Andrée * * redshift-ng 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 3 of the License, or * (at your option) any later version. * * redshift-ng 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 redshift-ng. If not, see . */ #include "common.h" void interpolate_colour_settings(const struct colour_setting *a, const struct colour_setting *b, double t, struct colour_setting *result) { int i; t = CLAMP(0.0, t, 1.0); result->temperature = (1.0 - t) * a->temperature + t * b->temperature; result->brightness = (1.0 - t) * a->brightness + t * b->brightness; for (i = 0; i < 3; i++) result->gamma[i] = (1.0 - t) * a->gamma[i] + t * b->gamma[i]; } int colour_setting_diff_is_major(const struct colour_setting *a, const struct colour_setting *b) { return MAX(a->temperature, b->temperature) - MIN(a->temperature, b->temperature) > 25UL || fabs(a->brightness - b->brightness) > 0.1 || fabs(a->gamma[0] - b->gamma[0]) > 0.1 || fabs(a->gamma[1] - b->gamma[1]) > 0.1 || fabs(a->gamma[2] - b->gamma[2]) > 0.1; } #define X(SUFFIX, RAMPS, TYPE, MAX, DEPTH)\ /** * Fill a gamma ramp * * @param ramp The gamma ramp * @param size The gamma ramp size (number of stops) * @param brightness The brightness (between 0 and 1) of the channel, which is * the overall applied brightness multiplied but the effect * on the channel from the colour temperature * @param gamma The gamma to apply to the channel */\ static void\ fill_ramp_##SUFFIX(TYPE *ramp, size_t size, double brightness, double gamma)\ {\ size_t i;\ double v;\ brightness /= (size - 1U);\ if (exact_eq(gamma, 1.0)) {\ brightness *= (MAX);\ for (i = 0; i < size; i++)\ ramp[i] = (TYPE)(i * brightness);\ } else {\ gamma = 1.0 / gamma;\ for (i = 0; i < size; i++) {\ v = pow(i * brightness, gamma) * (MAX);\ ramp[i] = (TYPE)v;\ }\ }\ }\ \ void\ fill_ramps_##SUFFIX(TYPE *gamma_r, TYPE *gamma_g, TYPE *gamma_b,\ size_t size_r, size_t size_g, size_t size_b,\ const struct colour_setting *setting)\ {\ double r = 1, g = 1, b = 1;\ libred_get_colour(setting->temperature, &r, &g, &b);\ fill_ramp_##SUFFIX(gamma_r, size_r, setting->brightness * r, setting->gamma[0]);\ fill_ramp_##SUFFIX(gamma_g, size_g, setting->brightness * g, setting->gamma[1]);\ fill_ramp_##SUFFIX(gamma_b, size_b, setting->brightness * b, setting->gamma[2]);\ } LIST_RAMPS_STOP_VALUE_TYPES(X,)