From 090009a8e107888fb9f1ab5a2997d65c8c121398 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 16 Sep 2021 18:13:08 +0200 Subject: Improve makefile + minor fixes and improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- blackbody.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'blackbody.c') 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 -#include -#include +# include "libred.h" +# include +# include +# include /** * 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; -- cgit v1.2.3-70-g09d2