From 36f062d1a0ac3bfdfbcb9b889fd100281bb290e3 Mon Sep 17 00:00:00 2001 From: William Skaggs Date: Sat, 22 Jan 2005 00:43:31 +0000 Subject: [PATCH] broken pipe on previous commit, finishing --- app/tools/tools-utils.c | 2 +- app/widgets/gimpaction.c | 3 +- libgimpbase/Makefile.am | 3 + libgimpbase/gimpbase.h | 1 + libgimpbase/gimpbaseparams.c | 356 ++++++++++++++++++++++++++++++++ libgimpbase/gimpbaseparams.h | 89 ++++++++ libgimpbase/gimpbasetypes.c | 29 ++- libgimpbase/gimpbasetypes.h | 6 + libgimpcolor/gimpbilinear.c | 2 +- libgimpcolor/gimpcmyk.c | 2 +- libgimpcolor/gimprgb.c | 184 +++++++++++++++++ libgimpcolor/gimprgb.h | 16 ++ libgimpmath/gimpmatrix.c | 179 +++++++++++++++- libgimpmath/gimpmatrix.h | 17 ++ libgimpmath/gimpvector.c | 2 +- plug-ins/gimpressionist/utils.c | 2 +- 16 files changed, 883 insertions(+), 10 deletions(-) create mode 100644 libgimpbase/gimpbaseparams.c create mode 100644 libgimpbase/gimpbaseparams.h diff --git a/app/tools/tools-utils.c b/app/tools/tools-utils.c index 51696860ad..aa116766b0 100644 --- a/app/tools/tools-utils.c +++ b/app/tools/tools-utils.c @@ -18,7 +18,7 @@ #include "config.h" -#include +#include #include "libgimpmath/gimpmath.h" diff --git a/app/widgets/gimpaction.c b/app/widgets/gimpaction.c index 62a2f126e3..93db3c1fd4 100644 --- a/app/widgets/gimpaction.c +++ b/app/widgets/gimpaction.c @@ -25,13 +25,12 @@ #include +#include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" #include "libgimpwidgets/gimpwidgets.h" #include "widgets-types.h" -#include "config/gimpconfig-params.h" - #include "core/gimpmarshal.h" #include "core/gimpimagefile.h" /* eek */ #include "core/gimpviewable.h" diff --git a/libgimpbase/Makefile.am b/libgimpbase/Makefile.am index cf739a7e47..e61be3844c 100644 --- a/libgimpbase/Makefile.am +++ b/libgimpbase/Makefile.am @@ -69,6 +69,8 @@ lib_LTLIBRARIES = libgimpbase-2.0.la libgimpbase_sources = \ gimpbase.h \ gimpbaseenums.h \ + gimpbaseparams.h \ + gimpbaseparams.c \ gimpbasetypes.h \ gimpbasetypes.c \ gimplimits.h \ @@ -109,6 +111,7 @@ libgimpbase_2_0_la_SOURCES = $(libgimpbase_sources) $(libgimpbase_built_sources) libgimpbaseinclude_HEADERS = \ gimpbase.h \ gimpbaseenums.h \ + gimpbaseparams.h \ gimpbasetypes.h \ gimplimits.h \ gimpversion.h \ diff --git a/libgimpbase/gimpbase.h b/libgimpbase/gimpbase.h index 73807b4ed0..d2e0cd9fda 100644 --- a/libgimpbase/gimpbase.h +++ b/libgimpbase/gimpbase.h @@ -23,6 +23,7 @@ #include +#include #include #include #include diff --git a/libgimpbase/gimpbaseparams.c b/libgimpbase/gimpbaseparams.c new file mode 100644 index 0000000000..981f6652d2 --- /dev/null +++ b/libgimpbase/gimpbaseparams.c @@ -0,0 +1,356 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * ParamSpecs for config objects + * Copyright (C) 2001-2003 Sven Neumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include "libgimpbase/gimpbase.h" + +#include "gimpbaseparams.h" +#include "gimpbasetypes.h" + + +/* + * GIMP_TYPE_PARAM_MEMSIZE + */ + +static void gimp_param_memsize_class_init (GParamSpecClass *class); + +/** + * gimp_param_memsize_get_type: + * + * Reveals the object type + * + * Returns: the #GType for a memsize object + * + * Since: GIMP 2.4 + **/ +GType +gimp_param_memsize_get_type (void) +{ + static GType spec_type = 0; + + if (!spec_type) + { + static const GTypeInfo type_info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_memsize_class_init, + NULL, NULL, + sizeof (GParamSpecUInt64), + 0, NULL, NULL + }; + + spec_type = g_type_register_static (G_TYPE_PARAM_UINT64, + "GimpParamMemsize", + &type_info, 0); + } + + return spec_type; +} + +static void +gimp_param_memsize_class_init (GParamSpecClass *class) +{ + class->value_type = GIMP_TYPE_MEMSIZE; +} + +/** + * gimp_param_spec_memsize: + * @name: Canonical name of the param + * @nick: Nickname of the param + * @blurb: Brief desciption of param. + * @minimum: Smallest allowed value of the parameter. + * @maximum: Largest allowed value of the parameter. + * @default_value: Value to use if none is assigned. + * @flags: a combination of #GParamFlags + * + * Creates a param spec to hold a memory size value. + * See g_param_spec_internal() for more information. + * + * Returns: a newly allocated #GParamSpec instance + * + * Since: GIMP 2.4 + **/ +GParamSpec * +gimp_param_spec_memsize (const gchar *name, + const gchar *nick, + const gchar *blurb, + guint64 minimum, + guint64 maximum, + guint64 default_value, + GParamFlags flags) +{ + GParamSpecUInt64 *pspec; + + pspec = g_param_spec_internal (GIMP_TYPE_PARAM_MEMSIZE, + name, nick, blurb, flags); + + pspec->minimum = minimum; + pspec->maximum = maximum; + pspec->default_value = default_value; + + return G_PARAM_SPEC (pspec); +} + + +/* + * GIMP_TYPE_PARAM_PATH + */ + +#define GIMP_PARAM_SPEC_PATH(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PATH, GimpParamSpecPath)) + +typedef struct _GimpParamSpecPath GimpParamSpecPath; + +struct _GimpParamSpecPath +{ + GParamSpecString parent_instance; + + GimpParamPathType type; +}; + +static void gimp_param_path_class_init (GParamSpecClass *class); + +/** + * gimp_param_path_get_type: + * + * Reveals the object type + * + * Returns: the #GType for a directory path object + * + * Since: GIMP 2.4 + **/ +GType +gimp_param_path_get_type (void) +{ + static GType spec_type = 0; + + if (!spec_type) + { + static const GTypeInfo type_info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_path_class_init, + NULL, NULL, + sizeof (GimpParamSpecPath), + 0, NULL, NULL + }; + + spec_type = g_type_register_static (G_TYPE_PARAM_STRING, + "GimpParamPath", + &type_info, 0); + } + + return spec_type; +} + +static void +gimp_param_path_class_init (GParamSpecClass *class) +{ + class->value_type = GIMP_TYPE_PATH; +} + +/** + * gimp_param_spec_path: + * @name: Canonical name of the param + * @nick: Nickname of the param + * @blurb: Brief desciption of param. + * @type: a #GimpParamPathType value. + * @default_value: Value to use if none is assigned. + * @flags: a combination of #GParamFlags + * + * Creates a param spec to hold a filename, dir name, + * or list of file or dir names. + * See g_param_spec_internal() for more information. + * + * Returns: a newly allocated #GParamSpec instance + * + * Since: GIMP 2.4 + **/ +GParamSpec * +gimp_param_spec_path (const gchar *name, + const gchar *nick, + const gchar *blurb, + GimpParamPathType type, + gchar *default_value, + GParamFlags flags) +{ + GParamSpecString *pspec; + + pspec = g_param_spec_internal (GIMP_TYPE_PARAM_PATH, + name, nick, blurb, flags); + + + pspec->default_value = default_value; + + GIMP_PARAM_SPEC_PATH (pspec)->type = type; + + return G_PARAM_SPEC (pspec); +} + +/** + * gimp_param_spec_path_get_path_type: + * @pspec: A #GParamSpec for a path param + * + * Tells whether the path param encodes a filename, + * dir name, or list of file or dir names. + * + * Returns: a #GimpParamPathType value + * + * Since: GIMP 2.4 + **/ +GimpParamPathType +gimp_param_spec_path_type (GParamSpec *pspec) +{ + g_return_val_if_fail (GIMP_IS_PARAM_SPEC_PATH (pspec), 0); + + return GIMP_PARAM_SPEC_PATH (pspec)->type; +} + + +/* + * GIMP_TYPE_PARAM_UNIT + */ + +#define GIMP_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_UNIT, GimpParamSpecUnit)) + +typedef struct _GimpParamSpecUnit GimpParamSpecUnit; + +struct _GimpParamSpecUnit +{ + GParamSpecInt parent_instance; + + gboolean allow_percent; +}; + +static void gimp_param_unit_class_init (GParamSpecClass *class); +static gboolean gimp_param_unit_value_validate (GParamSpec *pspec, + GValue *value); + +/** + * gimp_param_unit_get_type: + * + * Reveals the object type + * + * Returns: the #GType for a unit param object + * + * Since: GIMP 2.4 + **/ +GType +gimp_param_unit_get_type (void) +{ + static GType spec_type = 0; + + if (!spec_type) + { + static const GTypeInfo type_info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_unit_class_init, + NULL, NULL, + sizeof (GimpParamSpecUnit), + 0, NULL, NULL + }; + + spec_type = g_type_register_static (G_TYPE_PARAM_INT, + "GimpParamUnit", + &type_info, 0); + } + + return spec_type; +} + +static void +gimp_param_unit_class_init (GParamSpecClass *class) +{ + class->value_type = GIMP_TYPE_UNIT; + class->value_validate = gimp_param_unit_value_validate; +} + +static gboolean +gimp_param_unit_value_validate (GParamSpec *pspec, + GValue *value) +{ + GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); + GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec); + gint oval = value->data[0].v_int; + + if (uspec->allow_percent && value->data[0].v_int == GIMP_UNIT_PERCENT) + { + value->data[0].v_int = value->data[0].v_int; + } + else + { + value->data[0].v_int = CLAMP (value->data[0].v_int, + ispec->minimum, + gimp_unit_get_number_of_units () - 1); + } + + return value->data[0].v_int != oval; +} + +/** + * gimp_param_spec_unit: + * @name: Canonical name of the param + * @nick: Nickname of the param + * @blurb: Brief desciption of param. + * @allow_pixels: Whether "pixels" is an allowed unit. + * @allow_percent: Whether "perecent" is an allowed unit. + * @default_value: Unit to use if none is assigned. + * @flags: a combination of #GParamFlags + * + * Creates a param spec to hold a units param. + * See g_param_spec_internal() for more information. + * + * Returns: a newly allocated #GParamSpec instance + * + * Since: GIMP 2.4 + **/ +GParamSpec * +gimp_param_spec_unit (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_pixels, + gboolean allow_percent, + GimpUnit default_value, + GParamFlags flags) +{ + GimpParamSpecUnit *pspec; + GParamSpecInt *ispec; + + pspec = g_param_spec_internal (GIMP_TYPE_PARAM_UNIT, + name, nick, blurb, flags); + + ispec = G_PARAM_SPEC_INT (pspec); + + ispec->default_value = default_value; + ispec->minimum = allow_pixels ? GIMP_UNIT_PIXEL : GIMP_UNIT_INCH; + ispec->maximum = GIMP_UNIT_PERCENT - 1; + + pspec->allow_percent = allow_percent; + + return G_PARAM_SPEC (pspec); +} diff --git a/libgimpbase/gimpbaseparams.h b/libgimpbase/gimpbaseparams.h new file mode 100644 index 0000000000..bff221acec --- /dev/null +++ b/libgimpbase/gimpbaseparams.h @@ -0,0 +1,89 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_BASE_PARAMS_H__ +#define __GIMP_BASE_PARAMS_H__ + + +/* For information look into the C source or the html documentation */ + +/* + * GIMP_TYPE_PARAM_MEMSIZE + */ + +#define GIMP_TYPE_PARAM_MEMSIZE (gimp_param_memsize_get_type ()) +#define GIMP_IS_PARAM_SPEC_MEMSIZE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_MEMSIZE)) + +GType gimp_param_memsize_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_memsize (const gchar *name, + const gchar *nick, + const gchar *blurb, + guint64 minimum, + guint64 maximum, + guint64 default_value, + GParamFlags flags); + + +/* + * GIMP_TYPE_PARAM_PATH + */ + +typedef enum +{ + GIMP_PARAM_PATH_FILE, + GIMP_PARAM_PATH_FILE_LIST, + GIMP_PARAM_PATH_DIR, + GIMP_PARAM_PATH_DIR_LIST +} GimpParamPathType; + +#define GIMP_TYPE_PARAM_PATH (gimp_param_path_get_type ()) +#define GIMP_IS_PARAM_SPEC_PATH(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_PATH)) + +GType gimp_param_path_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_path (const gchar *name, + const gchar *nick, + const gchar *blurb, + GimpParamPathType type, + gchar *default_value, + GParamFlags flags); + +GimpParamPathType gimp_param_spec_path_type (GParamSpec *pspec); + + +/* + * GIMP_TYPE_PARAM_UNIT + */ + +#define GIMP_TYPE_PARAM_UNIT (gimp_param_unit_get_type ()) +#define GIMP_IS_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_UNIT)) + +GType gimp_param_unit_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_unit (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_pixels, + gboolean allow_percent, + GimpUnit default_value, + GParamFlags flags); + + +#endif /* __GIMP_BASE_PARAMS_H__ */ diff --git a/libgimpbase/gimpbasetypes.c b/libgimpbase/gimpbasetypes.c index a9f96cfddc..7e5c606eb4 100644 --- a/libgimpbase/gimpbasetypes.c +++ b/libgimpbase/gimpbasetypes.c @@ -27,8 +27,8 @@ #include "gimpbasetypes.h" -static GQuark gimp_translation_domain_quark (void) G_GNUC_CONST; -static GQuark gimp_value_descriptions_quark (void) G_GNUC_CONST; +static GQuark gimp_translation_domain_quark (void) G_GNUC_CONST; +static GQuark gimp_value_descriptions_quark (void) G_GNUC_CONST; /** @@ -157,6 +157,31 @@ gimp_flags_get_value_descriptions (GType flags_type) } +/** + * gimp_path_get_type: + * + * Reveals the object type + * + * Returns: the #GType for GimpPath objects + * + * Since: GIMP 2.4 + **/ +GType +gimp_path_get_type (void) +{ + static GType path_type = 0; + + if (!path_type) + { + static const GTypeInfo type_info = { 0, }; + + path_type = g_type_register_static (G_TYPE_STRING, "GimpPath", + &type_info, 0); + } + + return path_type; +} + /* private functions */ static GQuark diff --git a/libgimpbase/gimpbasetypes.h b/libgimpbase/gimpbasetypes.h index 3fcc636d6a..705887b2f7 100644 --- a/libgimpbase/gimpbasetypes.h +++ b/libgimpbase/gimpbasetypes.h @@ -69,6 +69,12 @@ void gimp_flags_set_value_descriptions (GType fl const GimpFlagsDesc * gimp_flags_get_value_descriptions (GType flags_type); +#define GIMP_TYPE_PATH (gimp_path_get_type ()) +#define GIMP_VALUE_HOLDS_PATH(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_PATH)) + +GType gimp_path_get_type (void) G_GNUC_CONST; + + G_END_DECLS #endif /* __GIMP_BASE_TYPES_H__ */ diff --git a/libgimpcolor/gimpbilinear.c b/libgimpcolor/gimpbilinear.c index 6323e841de..2089009596 100644 --- a/libgimpcolor/gimpbilinear.c +++ b/libgimpcolor/gimpbilinear.c @@ -19,7 +19,7 @@ #include "config.h" -#include +#include #include "libgimpmath/gimpmath.h" diff --git a/libgimpcolor/gimpcmyk.c b/libgimpcolor/gimpcmyk.c index 801bb2fa05..03b671e306 100644 --- a/libgimpcolor/gimpcmyk.c +++ b/libgimpcolor/gimpcmyk.c @@ -19,7 +19,7 @@ #include "config.h" -#include +#include #include "libgimpmath/gimpmath.h" diff --git a/libgimpcolor/gimprgb.c b/libgimpcolor/gimprgb.c index 9c74f669a2..a62c39c01a 100644 --- a/libgimpcolor/gimprgb.c +++ b/libgimpcolor/gimprgb.c @@ -413,3 +413,187 @@ gimp_rgba_distance (const GimpRGB *rgba1, fabs (rgba1->b - rgba2->b) + fabs (rgba1->a - rgba2->a)); } + + +/* + * GIMP_TYPE_PARAM_RGB + */ + +#define GIMP_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RGB, GimpParamSpecRGB)) + +static void gimp_param_rgb_class_init (GParamSpecClass *class); +static void gimp_param_rgb_init (GParamSpec *pspec); +static void gimp_param_rgb_set_default (GParamSpec *pspec, + GValue *value); +static gboolean gimp_param_rgb_validate (GParamSpec *pspec, + GValue *value); +static gint gimp_param_rgb_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2); + +typedef struct _GimpParamSpecRGB GimpParamSpecRGB; + +struct _GimpParamSpecRGB +{ + GParamSpecBoxed parent_instance; + + GimpRGB default_value; +}; + +/** + * gimp_param_rgb_get_type: + * + * Reveals the object type + * + * Returns: the #GType for a GimpParamRGB object + * + * Since: GIMP 2.4 + **/ +GType +gimp_param_rgb_get_type (void) +{ + static GType spec_type = 0; + + if (!spec_type) + { + static const GTypeInfo type_info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_rgb_class_init, + NULL, NULL, + sizeof (GimpParamSpecRGB), + 0, + (GInstanceInitFunc) gimp_param_rgb_init + }; + + spec_type = g_type_register_static (G_TYPE_PARAM_BOXED, + "GimpParamRGB", + &type_info, 0); + } + + return spec_type; +} + +static void +gimp_param_rgb_class_init (GParamSpecClass *class) +{ + class->value_type = GIMP_TYPE_RGB; + class->value_set_default = gimp_param_rgb_set_default; + class->value_validate = gimp_param_rgb_validate; + class->values_cmp = gimp_param_rgb_values_cmp; +} + +static void +gimp_param_rgb_init (GParamSpec *pspec) +{ + GimpParamSpecRGB *cspec = GIMP_PARAM_SPEC_RGB (pspec); + + gimp_rgba_set (&cspec->default_value, 0.0, 0.0, 0.0, 0.0); +} + +static void +gimp_param_rgb_set_default (GParamSpec *pspec, + GValue *value) +{ + GimpParamSpecRGB *cspec = GIMP_PARAM_SPEC_RGB (pspec); + + g_value_set_static_boxed (value, &cspec->default_value); +} + +static gboolean +gimp_param_rgb_validate (GParamSpec *pspec, + GValue *value) +{ + GimpRGB *rgb; + + rgb = value->data[0].v_pointer; + + if (rgb) + { + GimpRGB oval; + + oval = *rgb; + + gimp_rgb_clamp (rgb); + + return (oval.r != rgb->r || + oval.g != rgb->g || + oval.b != rgb->b || + oval.a != rgb->a); + } + + return FALSE; +} + +static gint +gimp_param_rgb_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) +{ + GimpRGB *rgb1; + GimpRGB *rgb2; + + rgb1 = value1->data[0].v_pointer; + rgb2 = value2->data[0].v_pointer; + + /* try to return at least *something*, it's useless anyway... */ + + if (! rgb1) + return rgb2 != NULL ? -1 : 0; + else if (! rgb2) + return rgb1 != NULL; + else + { + guint32 int1, int2; + + gimp_rgba_get_uchar (rgb1, + ((guchar *) &int1) + 0, + ((guchar *) &int1) + 1, + ((guchar *) &int1) + 2, + ((guchar *) &int1) + 3); + gimp_rgba_get_uchar (rgb2, + ((guchar *) &int2) + 0, + ((guchar *) &int2) + 1, + ((guchar *) &int2) + 2, + ((guchar *) &int2) + 3); + + return int1 - int2; + } +} + +/** + * gimp_param_spec_rgb: + * @name: Canonical name of the param + * @nick: Nickname of the param + * @blurb: Brief desciption of param. + * @default_value: Value to use if none is assigned. + * @flags: a combination of #GParamFlags + * + * Creates a param spec to hold an #GimpRGB value. + * See g_param_spec_internal() for more information. + * + * Returns: a newly allocated #GParamSpec instance + * + * Since: GIMP 2.4 + **/ +GParamSpec * +gimp_param_spec_rgb (const gchar *name, + const gchar *nick, + const gchar *blurb, + const GimpRGB *default_value, + GParamFlags flags) +{ + GimpParamSpecRGB *cspec; + + g_return_val_if_fail (default_value != NULL, NULL); + + cspec = g_param_spec_internal (GIMP_TYPE_PARAM_RGB, + name, nick, blurb, flags); + + cspec->default_value = *default_value; + + return G_PARAM_SPEC (cspec); +} + + diff --git a/libgimpcolor/gimprgb.h b/libgimpcolor/gimprgb.h index 199c521284..2976797e54 100644 --- a/libgimpcolor/gimprgb.h +++ b/libgimpcolor/gimprgb.h @@ -31,6 +31,22 @@ G_BEGIN_DECLS GType gimp_rgb_get_type (void) G_GNUC_CONST; +/* + * GIMP_TYPE_PARAM_RGB + */ + +#define GIMP_TYPE_PARAM_RGB (gimp_param_rgb_get_type ()) +#define GIMP_IS_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_RGB)) + +GType gimp_param_rgb_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_rgb (const gchar *name, + const gchar *nick, + const gchar *blurb, + const GimpRGB *default_value, + GParamFlags flags); + + /* RGB and RGBA color types and operations taken from LibGCK */ typedef enum diff --git a/libgimpmath/gimpmatrix.c b/libgimpmath/gimpmatrix.c index 5c15f9bc31..177e3d637e 100644 --- a/libgimpmath/gimpmatrix.c +++ b/libgimpmath/gimpmatrix.c @@ -22,7 +22,7 @@ #include "config.h" -#include +#include #include "gimpmath.h" @@ -30,6 +30,183 @@ #define EPSILON 1e-6 +static GimpMatrix2 * matrix2_copy (const GimpMatrix2 *matrix); + +/** + * gimp_matrix2_get_type: + * + * Reveals the object type + * + * Returns: the #GType for Matrix2 objects + * + * Since: GIMP 2.4 + **/ +GType +gimp_matrix2_get_type (void) +{ + static GType matrix_type = 0; + + if (!matrix_type) + matrix_type = g_boxed_type_register_static ("GimpMatrix2", + (GBoxedCopyFunc) matrix2_copy, + (GBoxedFreeFunc) g_free); + + return matrix_type; +} + + +/* + * GIMP_TYPE_PARAM_MATRIX2 + */ + +#define GIMP_PARAM_SPEC_MATRIX2(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_MATRIX2, GimpParamSpecMatrix2)) + +static void gimp_param_matrix2_class_init (GParamSpecClass *class); +static void gimp_param_matrix2_init (GParamSpec *pspec); +static void gimp_param_matrix2_set_default (GParamSpec *pspec, + GValue *value); +static gint gimp_param_matrix2_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2); + +typedef struct _GimpParamSpecMatrix2 GimpParamSpecMatrix2; + +struct _GimpParamSpecMatrix2 +{ + GParamSpecBoxed parent_instance; + + GimpMatrix2 default_value; +}; + +/** + * gimp_param_matrix2_get_type: + * + * Reveals the object type + * + * Returns: the #GType for a GimpMatrix2 object + * + * Since: GIMP 2.4 + **/ +GType +gimp_param_matrix2_get_type (void) +{ + static GType spec_type = 0; + + if (!spec_type) + { + static const GTypeInfo type_info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_matrix2_class_init, + NULL, NULL, + sizeof (GimpParamSpecMatrix2), + 0, + (GInstanceInitFunc) gimp_param_matrix2_init + }; + + spec_type = g_type_register_static (G_TYPE_PARAM_BOXED, + "GimpParamMatrix2", + &type_info, 0); + } + + return spec_type; +} + +static void +gimp_param_matrix2_class_init (GParamSpecClass *class) +{ + class->value_type = GIMP_TYPE_MATRIX2; + class->value_set_default = gimp_param_matrix2_set_default; + class->values_cmp = gimp_param_matrix2_values_cmp; +} + +static void +gimp_param_matrix2_init (GParamSpec *pspec) +{ + GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec); + + gimp_matrix2_identity (&cspec->default_value); +} + +static void +gimp_param_matrix2_set_default (GParamSpec *pspec, + GValue *value) +{ + GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec); + + g_value_set_static_boxed (value, &cspec->default_value); +} + +static gint +gimp_param_matrix2_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) +{ + GimpMatrix2 *matrix1; + GimpMatrix2 *matrix2; + gint i, j; + + matrix1 = value1->data[0].v_pointer; + matrix2 = value2->data[0].v_pointer; + + /* try to return at least *something*, it's useless anyway... */ + + if (! matrix1) + return matrix2 != NULL ? -1 : 0; + else if (! matrix2) + return matrix1 != NULL; + + for (i = 0; i < 2; i++) + for (j = 0; j < 2; j++) + if (matrix1->coeff[i][j] != matrix2->coeff[i][j]) + return 1; + + return 0; +} + +/** + * gimp_param_spec_matrix2: + * @name: Canonical name of the param + * @nick: Nickname of the param + * @blurb: Brief desciption of param. + * @default_value: Value to use if none is assigned. + * @flags: a combination of #GParamFlags + * + * Creates a param spec to hold a #GimpMatrix2 value. + * See g_param_spec_internal() for more information. + * + * Returns: a newly allocated #GParamSpec instance + * + * Since: GIMP 2.4 + **/ +GParamSpec * +gimp_param_spec_matrix2 (const gchar *name, + const gchar *nick, + const gchar *blurb, + const GimpMatrix2 *default_value, + GParamFlags flags) +{ + GimpParamSpecMatrix2 *cspec; + + g_return_val_if_fail (default_value != NULL, NULL); + + cspec = g_param_spec_internal (GIMP_TYPE_PARAM_MATRIX2, + name, nick, blurb, flags); + + cspec->default_value = *default_value; + + return G_PARAM_SPEC (cspec); +} + + +static GimpMatrix2 * +matrix2_copy (const GimpMatrix2 *matrix) +{ + return (GimpMatrix2 *) g_memdup (matrix, sizeof (GimpMatrix2)); +} + + /** * gimp_matrix2_identity: * @matrix: A matrix. diff --git a/libgimpmath/gimpmatrix.h b/libgimpmath/gimpmatrix.h index 161a6d3ad0..7ac4be95bd 100644 --- a/libgimpmath/gimpmatrix.h +++ b/libgimpmath/gimpmatrix.h @@ -42,6 +42,23 @@ struct _GimpMatrix4 gdouble coeff[4][4]; }; +#define GIMP_TYPE_MATRIX2 (gimp_matrix2_get_type ()) +#define GIMP_VALUE_HOLDS_MATRIX2(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_MATRIX2)) + +GType gimp_matrix2_get_type (void) G_GNUC_CONST; + + +#define GIMP_TYPE_PARAM_MATRIX2 (gimp_param_matrix2_get_type ()) +#define GIMP_IS_PARAM_SPEC_MATRIX2(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_MATRIX2)) + +GType gimp_param_matrix2_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_matrix2 (const gchar *name, + const gchar *nick, + const gchar *blurb, + const GimpMatrix2 *default_value, + GParamFlags flags); + void gimp_matrix2_identity (GimpMatrix2 *matrix); void gimp_matrix2_mult (const GimpMatrix2 *matrix1, diff --git a/libgimpmath/gimpvector.c b/libgimpmath/gimpvector.c index c5b5caec81..31c46b8196 100644 --- a/libgimpmath/gimpvector.c +++ b/libgimpmath/gimpvector.c @@ -29,7 +29,7 @@ #include "config.h" -#include +#include #include "gimpmath.h" diff --git a/plug-ins/gimpressionist/utils.c b/plug-ins/gimpressionist/utils.c index 3167f66e01..9665acd5f2 100644 --- a/plug-ins/gimpressionist/utils.c +++ b/plug-ins/gimpressionist/utils.c @@ -6,7 +6,7 @@ #include -#include +#include #include