Re: [AD] 4.0.2 release

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Eric Botcazou wrote:
Except that treating a negative hue was precisely the bug :-)

OK, I read a bit of that thread on [AL]. I think the best solution would be to add `case 6' right in front of `case 0'; that should allow any hue. (Allowing any hue is a Good Thing IMHO because it's usually depicted as a circle (in particular, the range 0...360 suggests degrees), and it's continuous that way. Plus, if even Allegro's examples assume negative hue is ok, chances are that other people do it too.)

I attach an updated patch which adds the same check for negative values as my previous patch, adds 'case 6' in front of 'case 0', and makes float-->int conversion be rounded (now hsv_to_rgb() is always the exact inverse of rgb_to_hsv()).

--
Sven Sandberg   svsa1977@xxxxxxxxxx   home.student.uu.se/svsa1977
Index: src/color.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/color.c,v
retrieving revision 1.13
diff -u -r1.13 color.c
--- src/color.c	17 May 2002 17:20:45 -0000	1.13
+++ src/color.c	11 Jun 2002 23:07:19 -0000
@@ -355,13 +355,17 @@
    }
    else {
       h = fmod(h, 360.0) / 60.0;
+      if (h < 0)
+	 h += 6.0f;
+
       i = (int)h;
       f = h - i;
-      x = v * (1.0f - s);
-      y = v * (1.0f - (s * f));
-      z = v * (1.0f - (s * (1.0f - f)));
+      x = v * (1.0f - s) + 0.5f;
+      y = v * (1.0f - (s * f)) + 0.5f;
+      z = v * (1.0f - (s * (1.0f - f))) + 0.5f;
 
       switch (i) {
+	 case 6:
 	 case 0: *r = v; *g = z; *b = x; break;
 	 case 1: *r = y; *g = v; *b = x; break;
 	 case 2: *r = x; *g = v; *b = z; break;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/