]> git.sesse.net Git - movit/commitdiff
Split off hsv2rgb() in a separate file.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 Oct 2012 13:10:48 +0000 (15:10 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 Oct 2012 13:10:48 +0000 (15:10 +0200)
Makefile
test.cpp
util.cpp [new file with mode: 0644]
util.h [new file with mode: 0644]

index af7ca8e8ee5f862f6e419edd0c9a61a7e4e96d5e..b8b0f37a41b754099ad1c99327127bd048b84a13 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,13 +3,13 @@ CXX=g++
 CXXFLAGS=-Wall
 LDFLAGS=-lSDL -lSDL_image -lGL
 
-test: test.o
-       $(CXX) -o test test.o $(LDFLAGS)
+test: test.o util.o
+       $(CXX) -o test test.o util.o $(LDFLAGS)
 
 .o: .cpp
        $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
 
 clean:
-       $(RM) test test.o
+       $(RM) test test.o util.o
 
 .PHONY: clean
index 634a0ea249d2c4155c27e5380533509ad12700d3..6de5452a7270601cf12d1c5d8f3390da6cdf2057 100644 (file)
--- a/test.cpp
+++ b/test.cpp
@@ -20,6 +20,8 @@
 #include <GL/gl.h>
 #include <GL/glext.h>
 
+#include "util.h"
+
 #ifdef NDEBUG
 #define check_error()
 #else
@@ -92,48 +94,6 @@ enum textures {
        HSV_WHEEL = 4,
 };
 
-// assumes h in [0, 2pi> or [-pi, pi>
-void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
-{
-       if (h < 0.0f) {
-               h += 2.0f * M_PI;
-       }
-       float c = v * s;
-       float hp = (h * 180.0 / M_PI) / 60.0;
-       float x = c * (1 - fabs(fmod(hp, 2.0f) - 1.0f));
-
-       if (hp >= 0 && hp < 1) {
-               *r = c;
-               *g = x;
-               *b = 0.0f;
-       } else if (hp >= 1 && hp < 2) {
-               *r = x;
-               *g = c;
-               *b = 0.0f;
-       } else if (hp >= 2 && hp < 3) {
-               *r = 0.0f;
-               *g = c;
-               *b = x;
-       } else if (hp >= 3 && hp < 4) {
-               *r = 0.0f;
-               *g = x;
-               *b = c;
-       } else if (hp >= 4 && hp < 5) {
-               *r = x;
-               *g = 0.0f;
-               *b = c;
-       } else {
-               *r = c;
-               *g = 0.0f;
-               *b = x;
-       }
-
-       float m = v - c;
-       *r += m;
-       *g += m;
-       *b += m;
-}
-
 GLhandleARB read_shader(const char* filename, GLenum type)
 {
        static char buf[131072];
diff --git a/util.cpp b/util.cpp
new file mode 100644 (file)
index 0000000..592e4d5
--- /dev/null
+++ b/util.cpp
@@ -0,0 +1,44 @@
+#include <math.h>
+
+#include "util.h"
+
+void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
+{
+       if (h < 0.0f) {
+               h += 2.0f * M_PI;
+       }
+       float c = v * s;
+       float hp = (h * 180.0 / M_PI) / 60.0;
+       float x = c * (1 - fabs(fmod(hp, 2.0f) - 1.0f));
+
+       if (hp >= 0 && hp < 1) {
+               *r = c;
+               *g = x;
+               *b = 0.0f;
+       } else if (hp >= 1 && hp < 2) {
+               *r = x;
+               *g = c;
+               *b = 0.0f;
+       } else if (hp >= 2 && hp < 3) {
+               *r = 0.0f;
+               *g = c;
+               *b = x;
+       } else if (hp >= 3 && hp < 4) {
+               *r = 0.0f;
+               *g = x;
+               *b = c;
+       } else if (hp >= 4 && hp < 5) {
+               *r = x;
+               *g = 0.0f;
+               *b = c;
+       } else {
+               *r = c;
+               *g = 0.0f;
+               *b = x;
+       }
+
+       float m = v - c;
+       *r += m;
+       *g += m;
+       *b += m;
+}
diff --git a/util.h b/util.h
new file mode 100644 (file)
index 0000000..0d49945
--- /dev/null
+++ b/util.h
@@ -0,0 +1,7 @@
+#ifndef _UTIL_H
+#define _UTIL_H 1
+
+// assumes h in [0, 2pi> or [-pi, pi>
+void hsv2rgb(float h, float s, float v, float *r, float *g, float *b);
+
+#endif // !defined(_UTIL_H)