]> git.imager.perl.org - imager.git/blobdiff - color.c
re-work the context macros
[imager.git] / color.c
diff --git a/color.c b/color.c
index ab33bfc194c7c3b297171a27d4aaa33e2fd4ca9e..9c9d195b9dee255111c8d9e68e999ce3a3d37549 100644 (file)
--- a/color.c
+++ b/color.c
@@ -1,4 +1,4 @@
-#include "image.h"
+#include "imager.h"
 #include <math.h>
 
 /*
@@ -33,7 +33,7 @@ Each value is scaled into the range 0 to 1.0.
 =cut
 */
 void i_rgb_to_hsvf(i_fcolor *color) {
-  double h, s, v;
+  double h = 0, s, v;
   double temp;
   double Cr, Cg, Cb;
 
@@ -74,7 +74,7 @@ Each value is scaled into the range 0 to 255.
 =cut
 */
 void i_rgb_to_hsv(i_color *color) {
-  double h, s, v;
+  double h = 0, s, v;
   double temp;
   double Cr, Cg, Cb;
 
@@ -173,13 +173,14 @@ void i_hsv_to_rgb(i_color *color) {
   }
   else {
     int i;
-    double f, m, n, k;
+    double f;
+    int m, n, k;
     h = h / 255.0 * 6;
     i = h;
     f = h - i;
-    m = v * (255 - s) / 255;
-    n = v * (255 - s * f) / 255;
-    k = v * (255 - s * (1 - f)) / 255;
+    m = 0.5 + v * (255 - s) / 255;
+    n = 0.5 + v * (255 - s * f) / 255;
+    k = 0.5 + v * (255 - s * (1 - f)) / 255;
     switch (i) {
     case 0:
       color->rgb.r = v; color->rgb.g = k; color->rgb.b = m;