2003-07-15 04:15:43 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2001-01-24 02:49:44 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2001-01-24 02:49:44 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2003-07-15 04:15:43 +08:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-01-24 02:49:44 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2001-01-24 02:49:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2006-07-20 05:23:10 +08:00
|
|
|
#include <glib-object.h>
|
2001-01-24 02:49:44 +08:00
|
|
|
|
|
|
|
#include "gimpcolortypes.h"
|
|
|
|
|
|
|
|
#include "gimphsv.h"
|
|
|
|
|
|
|
|
|
2010-06-30 01:46:37 +08:00
|
|
|
/**
|
2010-06-30 02:08:39 +08:00
|
|
|
* SECTION: gimphsv
|
2010-06-30 01:46:37 +08:00
|
|
|
* @title: GimpHSV
|
|
|
|
* @short_description: Definitions and Functions relating to HSV colors.
|
|
|
|
*
|
|
|
|
* Definitions and Functions relating to HSV colors.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2006-07-20 05:23:10 +08:00
|
|
|
/*
|
|
|
|
* GIMP_TYPE_HSV
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GimpHSV * gimp_hsv_copy (const GimpHSV *hsv);
|
|
|
|
|
|
|
|
|
2019-07-17 12:35:00 +08:00
|
|
|
G_DEFINE_BOXED_TYPE (GimpHSV, gimp_hsv, gimp_hsv_copy, g_free)
|
2006-07-20 05:23:10 +08:00
|
|
|
|
|
|
|
static GimpHSV *
|
|
|
|
gimp_hsv_copy (const GimpHSV *hsv)
|
|
|
|
{
|
|
|
|
return g_memdup (hsv, sizeof (GimpHSV));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-24 02:49:44 +08:00
|
|
|
/* HSV functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_hsv_set (GimpHSV *hsv,
|
2006-04-12 18:53:28 +08:00
|
|
|
gdouble h,
|
|
|
|
gdouble s,
|
|
|
|
gdouble v)
|
2001-01-24 02:49:44 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (hsv != NULL);
|
|
|
|
|
|
|
|
hsv->h = h;
|
|
|
|
hsv->s = s;
|
|
|
|
hsv->v = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_hsv_clamp (GimpHSV *hsv)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hsv != NULL);
|
|
|
|
|
|
|
|
hsv->h -= (gint) hsv->h;
|
|
|
|
|
|
|
|
if (hsv->h < 0)
|
|
|
|
hsv->h += 1.0;
|
|
|
|
|
|
|
|
hsv->s = CLAMP (hsv->s, 0.0, 1.0);
|
|
|
|
hsv->v = CLAMP (hsv->v, 0.0, 1.0);
|
|
|
|
hsv->a = CLAMP (hsv->a, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_hsva_set (GimpHSV *hsva,
|
2006-04-12 18:53:28 +08:00
|
|
|
gdouble h,
|
|
|
|
gdouble s,
|
|
|
|
gdouble v,
|
|
|
|
gdouble a)
|
2001-01-24 02:49:44 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (hsva != NULL);
|
|
|
|
|
|
|
|
hsva->h = h;
|
|
|
|
hsva->s = s;
|
|
|
|
hsva->v = v;
|
|
|
|
hsva->a = a;
|
|
|
|
}
|