summaryrefslogtreecommitdiffstats
path: root/Smoke/palette.c
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2007-12-19 20:59:56 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2007-12-19 20:59:56 (GMT)
commit5f1fc7b0711f51dd05077303f854c658ccd9dcba (patch)
tree7d519f704a04a8f25d3e5f14ce809a7d985c4581 /Smoke/palette.c
parenta60088999da4f44bf5885f431fe78eb87d643ae7 (diff)
download2iv35-5f1fc7b0711f51dd05077303f854c658ccd9dcba.zip
2iv35-5f1fc7b0711f51dd05077303f854c658ccd9dcba.tar.gz
2iv35-5f1fc7b0711f51dd05077303f854c658ccd9dcba.tar.bz2
Loads of splitting, gui templates added for other elements
Diffstat (limited to 'Smoke/palette.c')
-rw-r--r--Smoke/palette.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/Smoke/palette.c b/Smoke/palette.c
index e5727c9..fbf4c25 100644
--- a/Smoke/palette.c
+++ b/Smoke/palette.c
@@ -6,10 +6,101 @@
#include <math.h>
+
#include "funcs.h"
+
#include "palette.h"
+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;
+ }
+}
+
+
//rainbow: Implements a color palette, mapping the scalar 'value' to a rainbow color RGB
void rainbow(float value, float *R, float *G, float *B)
{