diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-06-16 22:29:33 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-06-16 22:29:33 +0000 |
commit | 797149c5a9ee0c7c70947f72cbaece5efd3dd687 (patch) | |
tree | 1c5a8e9dcb09c08e7741c806650c5ef1163387d0 /src/hsv2rgb.c | |
parent | 593e1cbe3470f409c19a7f06f5d10c6f5677361a (diff) | |
download | 2012-violon-leds-797149c5a9ee0c7c70947f72cbaece5efd3dd687.tar.gz 2012-violon-leds-797149c5a9ee0c7c70947f72cbaece5efd3dd687.tar.bz2 2012-violon-leds-797149c5a9ee0c7c70947f72cbaece5efd3dd687.zip |
Création du source tree princpal. Les routines de maths pour calculer le gain déconnent encore je trouve.
Reste à intégrer la partie DMX et a améliorer tout ce qui a été laissé de côté...
git-svn-id: file:///var/svn/2012-violon-leds/trunk@20 6be1fa4d-33ac-4c33-becc-79fcb3794bb6
Diffstat (limited to 'src/hsv2rgb.c')
-rw-r--r-- | src/hsv2rgb.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/hsv2rgb.c b/src/hsv2rgb.c new file mode 100644 index 0000000..9f445e9 --- /dev/null +++ b/src/hsv2rgb.c @@ -0,0 +1,59 @@ +/* hsv2rgb.c + * Convert Hue Saturation Value to Red Green Blue + * + * P.J. 08-Aug-98 + * + * Reference: + * D. F. Rogers + * Procedural Elements for Computer Graphics + * McGraw Hill 1985 + */ + +#include "hsv2rgb.h" + +int hsv2rgb( struct hsv_colour *hsv, struct rgb_colour *rgb ) { + /* + * Purpose: + * Convert HSV values to RGB values + * All values are in the range [0.0 .. 1.0] + */ + float S, H, V, F, M, N, K; + int I; + + S = hsv->s; /* Saturation */ + H = hsv->h; /* Hue */ + V = hsv->v; /* value or brightness */ + + if ( S == 0.0 ) { + /* + * Achromatic case, set level of grey + */ + rgb->r = V; + rgb->g = V; + rgb->b = V; + } else { + /* + * Determine levels of primary colours. + */ + if (H >= 1.0) { + H = 0.0; + } else { + H = H * 6; + } /* end if */ + I = (int) H; /* should be in the range 0..5 */ + F = H - I; /* fractional part */ + + M = V * (1 - S); + N = V * (1 - S * F); + K = V * (1 - S * (1 - F)); + + if (I == 0) { rgb->r = V; rgb->g = K; rgb->b = M; } + if (I == 1) { rgb->r = N; rgb->g = V; rgb->b = M; } + if (I == 2) { rgb->r = M; rgb->g = V; rgb->b = K; } + if (I == 3) { rgb->r = M; rgb->g = N; rgb->b = V; } + if (I == 4) { rgb->r = K; rgb->g = M; rgb->b = V; } + if (I == 5) { rgb->r = V; rgb->g = M; rgb->b = N; } + } /* end if */ + + return 0; +} /* end function hsv2rgb */ |