Patch:
diff -u -p -r imlib2-1.4.1.000.old/src/lib/color_helpers.c
imlib2-1.4.1.000.new/src/lib/color_helpers.c
--- imlib2-1.4.1.000.old/src/lib/color_helpers.c 2007-05-21
00:58:01.000000000 +0200
+++ imlib2-1.4.1.000.new/src/lib/color_helpers.c 2008-04-15
09:34:36.000000000 +0200
@@ -5,117 +5,89 @@
*/
void
-__imlib_rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v)
+__imlib_rgb_to_hsv( int r, int g, int b, float *h, float *s, float *v )
{
- int min, max;
- int delta;
+ register float min, max, delta;
- max = (r + g + abs(r - g)) / 2;
- max = (max + b + abs(max - b)) / 2;
- min = (r + g - abs(r - g)) / 2;
- min = (min + b - abs(min - b)) / 2;
+ min = ((( r < g ) ? r : g) < b ) ? (( r < g ) ? r : g) : b;
+ max = ((( r > g ) ? r : g) > b ) ? (( r > g ) ? r : g) : b;
- delta = max - min;
- *v = (float)(100 * max) / 255.0;
-
- if (max != 0)
- *s = (float)(100 * delta) / (float)max;
- else
- {
- *s = 0.0;
+ *v = max / 255.0;
+ delta = ( max - min );
+ if( delta == 0 )
+ {
*h = 0.0;
- *v = 0.0;
- }
- if (r == max)
- {
- *h = (float)(100 * (g - b)) / (float)(6.0 * delta);
- }
- else
- {
- if (g == max)
- {
- *h = (float)(100 * (2 * delta + b - r)) / (float)(6.0 * delta);
- }
- else
- {
- *h = (float)(100 * (4 * delta + r - g)) / (float)(6.0 * delta);
- }
- }
- if (*h < 0.0)
- *h += 100.0;
- if (*h > 100.0)
- *h -= 100.0;
+ *s = 0.0;
+ return;
+ }
+ *s = delta / max;
+ if( r == max )
+ *h = ( g - b ) / delta;
+ else if( g == max )
+ *h = 2.0 + ( b - r ) / delta;
+ else
+ *h = 4.0 + ( r - g ) / delta;
+ *h *= 60.0;
+ if( *h < 0 )
+ *h += 360.0;
}
void
__imlib_hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b)
{
- float hh, f;
- float p, q, t;
- int i;
+ register float f, vf;
+ register int i, p, q, t, vv;
- if (s == 0.0)
- {
- *r = round((v * 255.0) / 100.0);
- *g = round((v * 255.0) / 100.0);
- *b = round((v * 255.0) / 100.0);
+ vf = 255.0 * v;
+ vv = (int)round( vf );
+ if( s == 0.0 )
+ {
+ *r = *g = *b = vv;
return;
- }
-
- hh = (h * 6.0) / 100.0;
- i = floor(hh);
- f = hh - (float)i;
-
- p = v * (1.0 - s / 100.0) / 100.0;
- q = v * (1.0 - (s * f) / 100.0) / 100.0;
- t = v * (1.0 - s * (1.0 - f) / 100.0) / 100.0;
+ }
- switch (i)
- {
- case 0:
- {
- *r = round(v * 255.0 / 100.0);
- *g = round(t * 255.0);
- *b = round(p * 255.0);
- break;
- }
- case 1:
- {
- *r = round(q * 255.0);
- *g = round(v * 255.0 / 100.0);
- *b = round(p * 255.0);
- break;
- }
- case 2:
- {
- *r = round(p * 255.0);
- *g = round(v * 255.0 / 100.0);
- *b = round(t * 255.0);
- break;
- }
- case 3:
- {
- *r = round(p * 255.0);
- *g = round(q * 255.0);
- *b = round(v * 255.0 / 100.0);
- break;
- }
- case 4:
- {
- *r = round(t * 255.0);
- *g = round(p * 255.0);
- *b = round(v * 255.0 / 100.0);
- break;
- }
- case 5:
- {
- *r = round(v * 255.0 / 100.0);
- *g = round(p * 255.0);
- *b = round(q * 255.0);
- break;
- }
- }
+ h /= 60.0;
+ i = floor(h);
+ f = h - (float)i;
+ p = (int)round( vf * (1.0 - s ));
+ q = (int)round( vf * (1.0 - (s * f)));
+ t = (int)round( vf * (1.0 - s * (1.0 - f)));
+
+ switch( i % 6 )
+ {
+ case 0:
+ *r = vv;
+ *g = t;
+ *b = p;
+ break;
+ case 1:
+ *r = q;
+ *g = vv;
+ *b = p;
+ break;
+ case 2:
+ *r = p;
+ *g = vv;
+ *b = t;
+ break;
+ case 3:
+ *r = p;
+ *g = q;
+ *b = vv;
+ break;
+ case 4:
+ *r = t;
+ *g = p;
+ *b = vv;
+ break;
+ case 5:
+ default:
+ *r = vv;
+ *g = p;
+ *b = q;
+ break;
+ }
}
void
diff -u -p -r imlib2-1.4.1.000.old/src/lib/grad.c
imlib2-1.4.1.000.new/src/lib/grad.c
--- imlib2-1.4.1.000.old/src/lib/grad.c 2007-05-21 00:58:01.000000000 +0200
+++ imlib2-1.4.1.000.new/src/lib/grad.c 2008-04-15 09:29:32.000000000 +0200
@@ -112,7 +112,7 @@ __imlib_MapRange(ImlibRange * rg, int le
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
}
}
- inc = ((ll - 1) << 16) / (len);
+ inc = ((ll - 1) << 16) / (len-1);
l = 0;
for (i = 0; i < len; i++)
{
@@ -194,7 +194,7 @@ __imlib_MapHsvaRange(ImlibRange * rg, in
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
}
}
- inc = ((ll - 1) << 16) / (len);
+ inc = ((ll - 1) << 16) / (len-1);
l = 0;
for (i = 0; i < len; i++)
{
--
Dariusz Knociński
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel