From: Matthew Fernandez Date: Sun, 2 May 2021 03:24:25 +0000 (-0700) Subject: more explicit float computation in hsv2rgb X-Git-Tag: 2.47.2~7^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=adbe7d908162a3d724d2d00ed900a2ddebe7c379;p=graphviz more explicit float computation in hsv2rgb Instead of being vague with ints, doubles, and floats, this commit standardizes on float literals in hsv2rgb. This squashes a number of -Wfloat-conversion compiler warnings. --- diff --git a/cmd/lefty/gfxview.c b/cmd/lefty/gfxview.c index 9d2d2d201..2803b9a5d 100644 --- a/cmd/lefty/gfxview.c +++ b/cmd/lefty/gfxview.c @@ -19,6 +19,7 @@ #include "parse.h" #include "exec.h" #include "gfxview.h" +#include #define max(a, b) (((a) >= (b)) ? (a) : (b)) #define min(a, b) (((a) >= (b)) ? (b) : (a)) @@ -1754,22 +1755,22 @@ static void hsv2rgb (float h, float s, float v, Gcolor_t *cp) { int i; /* clip to reasonable values */ - h = max (min (h, 1.0), 0.0); - s = max (min (s, 1.0), 0.0); - v = max (min (v, 1.0), 0.0); - r = g = b = 0.0; + h = fmaxf (fminf (h, 1.0f), 0.0f); + s = fmaxf (fminf (s, 1.0f), 0.0f); + v = fmaxf (fminf (v, 1.0f), 0.0f); + r = g = b = 0.0f; - if (s == 0.0) + if (s == 0.0f) r = g = b = v; else { - if (h == 1.0) - h = 0.0; - h = h * 6.0; + if (h == 1.0f) + h = 0.0f; + h = h * 6.0f; i = (int) h; f = h - (float) i; - p = v * (1 - s); - q = v * (1 - (s * f)); - t = v * (1 - (s * (1 - f))); + p = v * (1.0f - s); + q = v * (1.0f - (s * f)); + t = v * (1.0f - (s * (1.0f - f))); switch (i) { case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; @@ -1779,7 +1780,7 @@ static void hsv2rgb (float h, float s, float v, Gcolor_t *cp) { case 5: r = v; g = p; b = q; break; } } - cp->r = (int) (255.0 * r); - cp->g = (int) (255.0 * g); - cp->b = (int) (255.0 * b); + cp->r = (int) (255.0f * r); + cp->g = (int) (255.0f * g); + cp->b = (int) (255.0f * b); }