summaryrefslogtreecommitdiffstats
path: root/Smoke/colormap.c
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2007-12-18 18:24:04 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2007-12-18 18:24:04 (GMT)
commitc287b3f591fe3e10dceedfd90a5ce71b2c703988 (patch)
tree98a1fe82d85e97199b099a720e9784064f8430b9 /Smoke/colormap.c
parent9363bc6887a7ffb9ea6c0f6a63a93c215e227502 (diff)
download2iv35-c287b3f591fe3e10dceedfd90a5ce71b2c703988.zip
2iv35-c287b3f591fe3e10dceedfd90a5ce71b2c703988.tar.gz
2iv35-c287b3f591fe3e10dceedfd90a5ce71b2c703988.tar.bz2
More cleaning up, seperating modules etc
Diffstat (limited to 'Smoke/colormap.c')
-rw-r--r--Smoke/colormap.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/Smoke/colormap.c b/Smoke/colormap.c
index 6cacb1b..ffb9afe 100644
--- a/Smoke/colormap.c
+++ b/Smoke/colormap.c
@@ -3,6 +3,8 @@
#include <windows.h>
#endif
+#include <math.h>
+
#include "palette.h"
#include "colormap.h"
#include "funcs.h"
@@ -120,6 +122,94 @@ static float clamp(float value)
return value;
}
+void HSVtoRGB(float *r, float *g, float *b, float h, float s, float v)
+{
+ int i;
+ float f, p, q, t;
+
+ if( s == 0 ) {
+ // achromatic (grey)
+ *r = *g = *b = v;
+ return;
+ }
+
+ h /= 60; // sector 0 to 5
+ i = floor(h);
+ f = h - i; // factorial part of h
+ p = v * (1 - s);
+ q = v * (1 - s * f);
+ t = v * (1 - s * (1 - f));
+
+ switch(i) {
+ case 0:
+ *r = v;
+ *g = t;
+ *b = p;
+ break;
+ case 1:
+ *r = q;
+ *g = v;
+ *b = p;
+ break;
+ case 2:
+ *r = p;
+ *g = v;
+ *b = t;
+ break;
+ case 3:
+ *r = p;
+ *g = q;
+ *b = v;
+ break;
+ case 4:
+ *r = t;
+ *g = p;
+ *b = v;
+ break;
+ default: // case 5:
+ *r = v;
+ *g = p;
+ *b = q;
+ break;
+ }
+
+}
+
+// r,g,b values are from 0 to 1
+// h = [0,360], s = [0,1], v = [0,1]
+// if s == 0, then h = -1 (undefined)
+void RGBtoHSV( float r, float g, float b, float *h, float *s, float *v )
+{
+ float min, max, delta;
+
+ min = MIN3(r, g, b);
+ max = MAX3(r, g, b);
+ *v = max; // v
+
+ delta = max - min;
+
+ if(max != 0) {
+ *s = delta / max; // s
+ } else {
+ // r = g = b = 0 // s = 0, v is undefined
+ *s = 0;
+ *h = -1;
+ return;
+ }
+
+ if(r == max) {
+ *h = ( g - b ) / delta; // between yellow & magenta
+ } else if(g == max) {
+ *h = 2 + (b - r) / delta; // between cyan & yellow
+ } else {
+ *h = 4 + (r - g) / delta; // between magenta & cyan
+ }
+ *h *= 60; // degrees
+ if(*h < 0) {
+ *h += 360;
+ }
+}
+
struct color4f colormap_get_color(float value)
{
struct color4f return_value;