diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-06 09:55:27 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-06 09:55:27 +0100 |
commit | 4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a (patch) | |
tree | 6c137a20f95f0be71d11940c6acb77e11aee6377 /src/colorramp.c | |
parent | Fix warning (diff) | |
download | redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.gz redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.bz2 redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.xz |
Style
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/colorramp.c')
-rw-r--r-- | src/colorramp.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/colorramp.c b/src/colorramp.c index 80f11fd..295bf41 100644 --- a/src/colorramp.c +++ b/src/colorramp.c @@ -20,22 +20,52 @@ */ #include "common.h" -/* Helper macro used in the fill functions */ -#define F(Y, WP, C) pow((Y) * setting->brightness * (WP), 1.0/setting->gamma[C]) + +#if defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wfloat-equal" +#endif #define X(SUFFIX, TYPE, MAX, TRUE_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;\ + if (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\ colorramp_fill_##SUFFIX(TYPE *gamma_r, TYPE *gamma_g, TYPE *gamma_b,\ size_t size_r, size_t size_g, size_t size_b,\ const struct color_setting *setting)\ {\ double r = 1, g = 1, b = 1;\ - size_t i;\ libred_get_colour(setting->temperature, &r, &g, &b);\ - for (i = 0; i < size_r; i++) gamma_r[i] = F((double)i / size_r, r, 0) * (MAX);\ - for (i = 0; i < size_g; i++) gamma_g[i] = F((double)i / size_g, g, 1) * (MAX);\ - for (i = 0; i < size_b; i++) gamma_b[i] = F((double)i / size_b, b, 2) * (MAX);\ + 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,) |