3 * Copyright (C) 1999 The Free Software Foundation
5 * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
6 * Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
7 * Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 #include "gtkcolorutils.h"
38 #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
40 /* Converts from HSV to RGB */
42 hsv_to_rgb (gdouble *h,
46 gdouble hue, saturation, value;
65 p = value * (1.0 - saturation);
66 q = value * (1.0 - saturation * f);
67 t = value * (1.0 - saturation * (1.0 - f));
108 g_assert_not_reached ();
113 /* Converts from RGB to HSV */
115 rgb_to_hsv (gdouble *r,
119 gdouble red, green, blue;
158 s = (max - min) / max;
169 h = (green - blue) / delta;
170 else if (green == max)
171 h = 2 + (blue - red) / delta;
172 else if (blue == max)
173 h = 4 + (red - green) / delta;
193 * @r: (out): Return value for the red component
194 * @g: (out): Return value for the green component
195 * @b: (out): Return value for the blue component
197 * Converts a color from HSV space to RGB.
199 * Input values must be in the [0.0, 1.0] range;
200 * output values will be in the same range.
205 gtk_hsv_to_rgb (gdouble h, gdouble s, gdouble v,
206 gdouble *r, gdouble *g, gdouble *b)
208 g_return_if_fail (h >= 0.0 && h <= 1.0);
209 g_return_if_fail (s >= 0.0 && s <= 1.0);
210 g_return_if_fail (v >= 0.0 && v <= 1.0);
212 hsv_to_rgb (&h, &s, &v);
229 * @h: (out): Return value for the hue component
230 * @s: (out): Return value for the saturation component
231 * @v: (out): Return value for the value component
233 * Converts a color from RGB space to HSV.
235 * Input values must be in the [0.0, 1.0] range;
236 * output values will be in the same range.
241 gtk_rgb_to_hsv (gdouble r, gdouble g, gdouble b,
242 gdouble *h, gdouble *s, gdouble *v)
244 g_return_if_fail (r >= 0.0 && r <= 1.0);
245 g_return_if_fail (g >= 0.0 && g <= 1.0);
246 g_return_if_fail (b >= 0.0 && b <= 1.0);
248 rgb_to_hsv (&r, &g, &b);