diff options
author | Mattias Andrée <maandree@kth.se> | 2021-09-16 18:13:08 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-09-16 18:13:08 +0200 |
commit | 090009a8e107888fb9f1ab5a2997d65c8c121398 (patch) | |
tree | ebb909ccbc6f6d29af5469964953aac987b86960 /blackbody.c | |
parent | whitespace (diff) | |
download | libred-1.0.2.tar.gz libred-1.0.2.tar.bz2 libred-1.0.2.tar.xz |
Improve makefile + minor fixes and improvements1.0.2
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'blackbody.c')
-rw-r--r-- | blackbody.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/blackbody.c b/blackbody.c index e654c9d..6edc85a 100644 --- a/blackbody.c +++ b/blackbody.c @@ -1,28 +1,28 @@ /* See LICENSE file for copyright and license details. */ -#if __GNUC__ +#if defined(__GNUC__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" #endif #ifndef LIBRED_COMPILING_PARSER -#include "libred.h" -#include <errno.h> -#include <math.h> -#include <stddef.h> +# include "libred.h" +# include <errno.h> +# include <math.h> +# include <stddef.h> /** * Colour temperatures in CIE xy (xyY without Y) */ static struct xy {double x, y;} xy_table[] = { -#include "10deg-xy.i" +# include "10deg-xy.i" }; /** * Colour temperatures in sRGB */ static struct rgb {double r, g, b;} rgb_table[] = { -#include "10deg-rgb.i" +# include "10deg-rgb.i" }; @@ -145,6 +145,7 @@ libred_get_colour(long int temp, double *r, double *g, double *b) { double x1, y1, x2, y2; size_t i; + long int tmp; if (temp > LIBRED_HIGHEST_TEMPERATURE) temp = LIBRED_HIGHEST_TEMPERATURE; @@ -154,15 +155,16 @@ libred_get_colour(long int temp, double *r, double *g, double *b) return -1; } - if (temp % LIBRED_DELTA_TEMPERATURE) { - i = (temp - LIBRED_LOWEST_TEMPERATURE) / LIBRED_DELTA_TEMPERATURE; + tmp = temp - LIBRED_LOWEST_TEMPERATURE; + + i = (size_t)(tmp / LIBRED_DELTA_TEMPERATURE); + if (tmp % LIBRED_DELTA_TEMPERATURE) { x1 = xy_table[i].x; y1 = xy_table[i].y; x2 = xy_table[i + 1].x; y2 = xy_table[i + 1].y; interpolate(x1, y1, x2, y2, (double)temp, r, g, b); } else { - i = (temp - LIBRED_LOWEST_TEMPERATURE) / LIBRED_DELTA_TEMPERATURE; *r = rgb_table[i].r; *g = rgb_table[i].g; *b = rgb_table[i].b; |