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, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
37 #include "gtkcolorutils.h"
40 #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
42 /* Converts from HSV to RGB */
44 hsv_to_rgb (gdouble *h,
48 gdouble hue, saturation, value;
67 p = value * (1.0 - saturation);
68 q = value * (1.0 - saturation * f);
69 t = value * (1.0 - saturation * (1.0 - f));
110 g_assert_not_reached ();
115 /* Converts from RGB to HSV */
117 rgb_to_hsv (gdouble *r,
121 gdouble red, green, blue;
160 s = (max - min) / max;
171 h = (green - blue) / delta;
172 else if (green == max)
173 h = 2 + (blue - red) / delta;
174 else if (blue == max)
175 h = 4 + (red - green) / delta;
195 * @r: (out): Return value for the red component
196 * @g: (out): Return value for the green component
197 * @b: (out): Return value for the blue component
199 * Converts a color from HSV space to RGB.
201 * Input values must be in the [0.0, 1.0] range;
202 * output values will be in the same range.
207 gtk_hsv_to_rgb (gdouble h, gdouble s, gdouble v,
208 gdouble *r, gdouble *g, gdouble *b)
210 g_return_if_fail (h >= 0.0 && h <= 1.0);
211 g_return_if_fail (s >= 0.0 && s <= 1.0);
212 g_return_if_fail (v >= 0.0 && v <= 1.0);
214 hsv_to_rgb (&h, &s, &v);
231 * @h: (out): Return value for the hue component
232 * @s: (out): Return value for the saturation component
233 * @v: (out): Return value for the value component
235 * Converts a color from RGB space to HSV.
237 * Input values must be in the [0.0, 1.0] range;
238 * output values will be in the same range.
243 gtk_rgb_to_hsv (gdouble r, gdouble g, gdouble b,
244 gdouble *h, gdouble *s, gdouble *v)
246 g_return_if_fail (r >= 0.0 && r <= 1.0);
247 g_return_if_fail (g >= 0.0 && g <= 1.0);
248 g_return_if_fail (b >= 0.0 && b <= 1.0);
250 rgb_to_hsv (&r, &g, &b);