applied a patch from S. Mukund that fixes the gimp_hsv_to_rgb_int() and

2003-08-31  Sven Neumann  <sven@gimp.org>

	* libgimpcolor/gimpcolorspace.c: applied a patch from S. Mukund
	that fixes the gimp_hsv_to_rgb_int() and gimp_rgb_to_hsv_int()
	functions (bug #115626).
This commit is contained in:
Sven Neumann
2003-08-31 16:20:12 +00:00
committed by Sven Neumann
parent dbc4b46e20
commit d93c2f61c8
2 changed files with 42 additions and 33 deletions

View File

@ -1,3 +1,9 @@
2003-08-31 Sven Neumann <sven@gimp.org>
* libgimpcolor/gimpcolorspace.c: applied a patch from S. Mukund
that fixes the gimp_hsv_to_rgb_int() and gimp_rgb_to_hsv_int()
functions (bug #115626).
2003-08-31 Sven Neumann <sven@gimp.org> 2003-08-31 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/color.pdb: applied a patch from Shawn Willden * tools/pdbgen/pdb/color.pdb: applied a patch from Shawn Willden

View File

@ -441,12 +441,10 @@ gimp_rgb_to_hsv_int (gint *red,
gint *green, gint *green,
gint *blue) gint *blue)
{ {
gint r, g, b; gdouble r, g, b;
gdouble h, s, v; gdouble h, s, v;
gint min, max; gint min;
gint delta; gdouble delta;
h = 0.0;
r = *red; r = *red;
g = *green; g = *green;
@ -454,43 +452,41 @@ gimp_rgb_to_hsv_int (gint *red,
if (r > g) if (r > g)
{ {
max = MAX (r, b); v = MAX (r, b);
min = MIN (g, b); min = MIN (g, b);
} }
else else
{ {
max = MAX (g, b); v = MAX (g, b);
min = MIN (r, b); min = MIN (r, b);
} }
delta = v - min;
v = max; if (v == 0.0)
s = 0.0;
if (max != 0)
s = ((max - min) * 255) / (gdouble) max;
else else
s = 0; s = delta / v;
if (s == 0) if (s == 0.0)
h = 0; h = 0.0;
else else
{ {
delta = max - min; if (r == v)
if (r == max) h = 60.0 * (g - b) / delta;
h = (g - b) / (gdouble) delta; else if (g == v)
else if (g == max) h = 120 + 60.0 * (b - r) / delta;
h = 2 + (b - r) / (gdouble) delta; else
else if (b == max) h = 240 + 60.0 * (r - g) / delta;
h = 4 + (r - g) / (gdouble) delta;
h *= 42.5;
if (h < 0) if (h < 0.0)
h += 255; h += 360.0;
if (h > 255) if (h > 360.0)
h -= 255; h -= 360.0;
} }
*red = ROUND (h); *red = ROUND (h);
*green = ROUND (s); *green = ROUND (s * 255.0);
*blue = ROUND (v); *blue = ROUND (v);
} }
@ -499,8 +495,9 @@ gimp_hsv_to_rgb_int (gint *hue,
gint *saturation, gint *saturation,
gint *value) gint *value)
{ {
gdouble h, s, v; gdouble h, s, v, h_temp;
gdouble f, p, q, t; gdouble f, p, q, t;
gint i;
if (*saturation == 0) if (*saturation == 0)
{ {
@ -510,16 +507,23 @@ gimp_hsv_to_rgb_int (gint *hue,
} }
else else
{ {
h = *hue * 6.0 / 255.0; h = *hue;
s = *saturation / 255.0; s = *saturation / 255.0;
v = *value / 255.0; v = *value / 255.0;
if (h == 360)
h_temp = 0;
else
h_temp = h;
f = h - (gint) h; h_temp = h_temp / 60.0;
i = floor (h_temp);
f = h_temp - i;
p = v * (1.0 - s); p = v * (1.0 - s);
q = v * (1.0 - (s * f)); q = v * (1.0 - (s * f));
t = v * (1.0 - (s * (1.0 - f))); t = v * (1.0 - (s * (1.0 - f)));
switch ((gint) h) switch (i)
{ {
case 0: case 0:
*hue = ROUND (v * 255.0); *hue = ROUND (v * 255.0);
@ -552,7 +556,6 @@ gimp_hsv_to_rgb_int (gint *hue,
break; break;
case 5: case 5:
case 6:
*hue = ROUND (v * 255.0); *hue = ROUND (v * 255.0);
*saturation = ROUND (p * 255.0); *saturation = ROUND (p * 255.0);
*value = ROUND (q * 255.0); *value = ROUND (q * 255.0);