app: s/sprintf/g_snprintf/ in xcf_save_image()
[gimp.git] / libgimpcolor / gimphsv.c
blob56bfbd7ed18e2f74a35bc7b2cce37ed7747eccc3
1 /* LIBGIMP - The GIMP Library
2 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
4 * This library is free software: you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <https://www.gnu.org/licenses/>.
19 #include "config.h"
21 #include <glib-object.h>
23 #include "gimpcolortypes.h"
25 #include "gimphsv.h"
28 /**
29 * SECTION: gimphsv
30 * @title: GimpHSV
31 * @short_description: Definitions and Functions relating to HSV colors.
33 * Definitions and Functions relating to HSV colors.
34 **/
38 * GIMP_TYPE_HSV
41 static GimpHSV * gimp_hsv_copy (const GimpHSV *hsv);
44 GType
45 gimp_hsv_get_type (void)
47 static GType hsv_type = 0;
49 if (!hsv_type)
50 hsv_type = g_boxed_type_register_static ("GimpHSV",
51 (GBoxedCopyFunc) gimp_hsv_copy,
52 (GBoxedFreeFunc) g_free);
54 return hsv_type;
57 static GimpHSV *
58 gimp_hsv_copy (const GimpHSV *hsv)
60 return g_memdup (hsv, sizeof (GimpHSV));
64 /* HSV functions */
66 void
67 gimp_hsv_set (GimpHSV *hsv,
68 gdouble h,
69 gdouble s,
70 gdouble v)
72 g_return_if_fail (hsv != NULL);
74 hsv->h = h;
75 hsv->s = s;
76 hsv->v = v;
79 void
80 gimp_hsv_clamp (GimpHSV *hsv)
82 g_return_if_fail (hsv != NULL);
84 hsv->h -= (gint) hsv->h;
86 if (hsv->h < 0)
87 hsv->h += 1.0;
89 hsv->s = CLAMP (hsv->s, 0.0, 1.0);
90 hsv->v = CLAMP (hsv->v, 0.0, 1.0);
91 hsv->a = CLAMP (hsv->a, 0.0, 1.0);
94 void
95 gimp_hsva_set (GimpHSV *hsva,
96 gdouble h,
97 gdouble s,
98 gdouble v,
99 gdouble a)
101 g_return_if_fail (hsva != NULL);
103 hsva->h = h;
104 hsva->s = s;
105 hsva->v = v;
106 hsva->a = a;