From 6f83a525712a4e0e8e60ed91e03f71e37fca4e05 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 7 Jul 2003 16:22:45 +0000 Subject: [PATCH] include . 2003-07-07 Sven Neumann * libgimpbase/gimpbasetypes.h: include . * libgimpmath/gimpmathtypes.h * libgimpmath/gimpmatrix.[ch]: added GimpMatrix2 struct definition and new function gimp_matrix2_identity(). * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-params.[ch] * app/config/gimpconfig-serialize.c * app/config/gimpconfig-types.[ch] * app/config/gimpconfig.c * app/config/gimpscanner.[ch]: added a boxed type around GimpMatrix2. * app/text/gimptext.[ch]: added new property "transformation". --- ChangeLog | 17 +++ app/config/gimpconfig-deserialize.c | 23 ++++ app/config/gimpconfig-params.c | 124 ++++++++++++++++++ app/config/gimpconfig-params.h | 62 ++++++--- app/config/gimpconfig-serialize.c | 21 ++- app/config/gimpconfig-types.c | 52 ++++++-- app/config/gimpconfig-types.h | 6 + app/config/gimpconfig.c | 2 +- app/config/gimpscanner.c | 76 ++++++++++- app/config/gimpscanner.h | 2 + app/text/gimptext.c | 19 ++- app/text/gimptext.h | 1 + .../libgimpmath/libgimpmath-sections.txt | 4 +- devel-docs/libgimpmath/tmpl/gimpmatrix.sgml | 31 +++-- libgimpbase/gimpbasetypes.h | 1 + libgimpconfig/gimpconfig-deserialize.c | 23 ++++ libgimpconfig/gimpconfig-iface.c | 2 +- libgimpconfig/gimpconfig-params.h | 62 ++++++--- libgimpconfig/gimpconfig-serialize.c | 21 ++- libgimpconfig/gimpscanner.c | 76 ++++++++++- libgimpconfig/gimpscanner.h | 2 + libgimpmath/gimpmathtypes.h | 1 + libgimpmath/gimpmatrix.c | 15 +++ libgimpmath/gimpmatrix.h | 7 + 24 files changed, 583 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index c36359e535..af27f1cdd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2003-07-07 Sven Neumann + + * libgimpbase/gimpbasetypes.h: include . + + * libgimpmath/gimpmathtypes.h + * libgimpmath/gimpmatrix.[ch]: added GimpMatrix2 struct definition + and new function gimp_matrix2_identity(). + + * app/config/gimpconfig-deserialize.c + * app/config/gimpconfig-params.[ch] + * app/config/gimpconfig-serialize.c + * app/config/gimpconfig-types.[ch] + * app/config/gimpconfig.c + * app/config/gimpscanner.[ch]: added a boxed type around GimpMatrix2. + + * app/text/gimptext.[ch]: added new property "transformation". + 2003-07-07 Sven Neumann * libgimpmath/gimpvector.[ch]: added const qualifiers. diff --git a/app/config/gimpconfig-deserialize.c b/app/config/gimpconfig-deserialize.c index 87e92416b1..2d54440205 100644 --- a/app/config/gimpconfig-deserialize.c +++ b/app/config/gimpconfig-deserialize.c @@ -33,6 +33,7 @@ #include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" +#include "libgimpmath/gimpmath.h" #include "config-types.h" @@ -77,6 +78,9 @@ static GTokenType gimp_config_deserialize_path (GValue *value, static GTokenType gimp_config_deserialize_color (GValue *value, GParamSpec *prop_spec, GScanner *scanner); +static GTokenType gimp_config_deserialize_matrix2 (GValue *value, + GParamSpec *prop_spec, + GScanner *scanner); static GTokenType gimp_config_deserialize_object (GValue *value, GObject *object, GParamSpec *prop_spec, @@ -346,6 +350,10 @@ gimp_config_deserialize_value (GValue *value, { return gimp_config_deserialize_color (value, prop_spec, scanner); } + else if (prop_spec->value_type == GIMP_TYPE_MATRIX2) + { + return gimp_config_deserialize_matrix2 (value, prop_spec, scanner); + } else if (prop_spec->value_type == G_TYPE_VALUE_ARRAY) { return gimp_config_deserialize_value_array (value, @@ -600,6 +608,21 @@ gimp_config_deserialize_color (GValue *value, return G_TOKEN_RIGHT_PAREN; } +static GTokenType +gimp_config_deserialize_matrix2 (GValue *value, + GParamSpec *prop_spec, + GScanner *scanner) +{ + GimpMatrix2 matrix; + + if (! gimp_scanner_parse_matrix2 (scanner, &matrix)) + return G_TOKEN_NONE; + + g_value_set_boxed (value, &matrix); + + return G_TOKEN_RIGHT_PAREN; +} + static GTokenType gimp_config_deserialize_object (GValue *value, GObject *object, diff --git a/app/config/gimpconfig-params.c b/app/config/gimpconfig-params.c index 002faf7707..8158bf6507 100644 --- a/app/config/gimpconfig-params.c +++ b/app/config/gimpconfig-params.c @@ -25,6 +25,9 @@ #include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" +#include "libgimpmath/gimpmath.h" + +#include "config-types.h" #include "gimpconfig-params.h" #include "gimpconfig-types.h" @@ -188,6 +191,127 @@ gimp_param_spec_color (const gchar *name, } +/* + * 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; +}; + +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; +} + +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); +} + + /* * GIMP_TYPE_PARAM_MEMSIZE */ diff --git a/app/config/gimpconfig-params.h b/app/config/gimpconfig-params.h index e602605e14..759ae36dc3 100644 --- a/app/config/gimpconfig-params.h +++ b/app/config/gimpconfig-params.h @@ -50,6 +50,22 @@ GParamSpec * gimp_param_spec_color (const gchar *name, GParamFlags flags); +/* + * GIMP_TYPE_PARAM_MATRIX2 + */ + +#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); + + /* * GIMP_TYPE_PARAM_MEMSIZE */ @@ -59,13 +75,13 @@ GParamSpec * gimp_param_spec_color (const gchar *name, GType gimp_param_memsize_get_type (void) G_GNUC_CONST; -GParamSpec * gimp_param_spec_memsize (const gchar *name, - const gchar *nick, - const gchar *blurb, - gulong minimum, - gulong maximum, - gulong default_value, - GParamFlags flags); +GParamSpec * gimp_param_spec_memsize (const gchar *name, + const gchar *nick, + const gchar *blurb, + gulong minimum, + gulong maximum, + gulong default_value, + GParamFlags flags); /* @@ -85,14 +101,14 @@ typedef enum 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); +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); +GimpParamPathType gimp_param_spec_path_type (GParamSpec *pspec); /* @@ -104,12 +120,12 @@ GimpParamPathType gimp_param_spec_path_type (GParamSpec *pspec); 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, - GimpUnit default_value, - GParamFlags flags); +GParamSpec * gimp_param_spec_unit (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_pixels, + GimpUnit default_value, + GParamFlags flags); /* some convenience macros to install object properties */ @@ -144,6 +160,12 @@ GParamSpec * gimp_param_spec_unit (const gchar *name, g_param_spec_int (name, NULL, blurb,\ min, max, default,\ flags | GIMP_CONFIG_PARAM_FLAGS)) +#define GIMP_CONFIG_INSTALL_PROP_MATRIX2(class, id,\ + name, blurb, default, flags)\ + g_object_class_install_property (class, id,\ + gimp_param_spec_matrix2 (name, NULL, blurb,\ + default,\ + flags | GIMP_CONFIG_PARAM_FLAGS)) #define GIMP_CONFIG_INSTALL_PROP_MEMSIZE(class, id,\ name, blurb, min, max, default, flags)\ g_object_class_install_property (class, id,\ diff --git a/app/config/gimpconfig-serialize.c b/app/config/gimpconfig-serialize.c index 920578472d..69f5333384 100644 --- a/app/config/gimpconfig-serialize.c +++ b/app/config/gimpconfig-serialize.c @@ -34,6 +34,7 @@ #endif #include "libgimpbase/gimpbase.h" +#include "libgimpmath/gimpmath.h" #include "libgimpcolor/gimpcolor.h" #include "config-types.h" @@ -338,7 +339,7 @@ gimp_config_serialize_value (const GValue *value, g_string_append (str, bool ? "yes" : "no"); return TRUE; } - + if (G_VALUE_HOLDS_ENUM (value)) { GEnumClass *enum_class; @@ -408,6 +409,24 @@ gimp_config_serialize_value (const GValue *value, return TRUE; } + if (GIMP_VALUE_HOLDS_MATRIX2 (value)) + { + GimpMatrix2 *trafo; + gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE]; + gint i, j, k; + + trafo = g_value_get_boxed (value); + + for (i = 0, k = 0; i < 2; i++) + for (j = 0; j < 2; j++, k++) + g_ascii_formatd (buf[k], + G_ASCII_DTOSTR_BUF_SIZE, "%f", trafo->coeff[i][j]); + + g_string_append_printf (str, "(matrix %s %s %s %s)", + buf[0], buf[1], buf[2], buf[3]); + return TRUE; + } + if (G_VALUE_TYPE (value) == G_TYPE_VALUE_ARRAY) { GValueArray *array; diff --git a/app/config/gimpconfig-types.c b/app/config/gimpconfig-types.c index 7028df5fb8..e6ab568759 100644 --- a/app/config/gimpconfig-types.c +++ b/app/config/gimpconfig-types.c @@ -29,22 +29,28 @@ #include #include "libgimpbase/gimpbase.h" +#include "libgimpmath/gimpmath.h" + +#include "config-types.h" #include "gimpconfig-types.h" -static GimpRGB * color_copy (const GimpRGB *color); -static void color_free (GimpRGB *color); +static GimpRGB * color_copy (const GimpRGB *color); +static void color_free (GimpRGB *color); -static void memsize_to_string (const GValue *src_value, - GValue *dest_value); -static void string_to_memsize (const GValue *src_value, - GValue *dest_value); +static GimpMatrix2 * matrix2_copy (const GimpMatrix2 *matrix); +static void matrix2_free (GimpMatrix2 *matrix); -static void unit_to_string (const GValue *src_value, - GValue *dest_value); -static void string_to_unit (const GValue *src_value, - GValue *dest_value); +static void memsize_to_string (const GValue *src_value, + GValue *dest_value); +static void string_to_memsize (const GValue *src_value, + GValue *dest_value); + +static void unit_to_string (const GValue *src_value, + GValue *dest_value); +static void string_to_unit (const GValue *src_value, + GValue *dest_value); GType @@ -60,6 +66,19 @@ gimp_color_get_type (void) return color_type; } +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) matrix2_free); + + return matrix_type; +} + GType gimp_memsize_get_type (void) { @@ -218,6 +237,19 @@ string_to_memsize (const GValue *src_value, } +static GimpMatrix2 * +matrix2_copy (const GimpMatrix2 *matrix) +{ + return (GimpMatrix2 *) g_memdup (matrix, sizeof (GimpMatrix2)); +} + +static void +matrix2_free (GimpMatrix2 *matrix) +{ + g_free (matrix); +} + + static void unit_to_string (const GValue *src_value, GValue *dest_value) diff --git a/app/config/gimpconfig-types.h b/app/config/gimpconfig-types.h index ef9dfd3a1a..cc16bdc351 100644 --- a/app/config/gimpconfig-types.h +++ b/app/config/gimpconfig-types.h @@ -29,6 +29,12 @@ GType gimp_color_get_type (void) G_GNUC_CONST; +#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_MEMSIZE (gimp_memsize_get_type ()) #define GIMP_VALUE_HOLDS_MEMSIZE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_MEMSIZE)) diff --git a/app/config/gimpconfig.c b/app/config/gimpconfig.c index ea76c1fae9..e87df5e64d 100644 --- a/app/config/gimpconfig.c +++ b/app/config/gimpconfig.c @@ -25,7 +25,7 @@ #include -#include "libgimpcolor/gimpcolor.h" +#include "libgimpbase/gimpbase.h" #include "config-types.h" diff --git a/app/config/gimpscanner.c b/app/config/gimpscanner.c index 286892b904..ef9e687877 100644 --- a/app/config/gimpscanner.c +++ b/app/config/gimpscanner.c @@ -37,7 +37,9 @@ #include #endif +#include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" +#include "libgimpmath/gimpmath.h" #include "config-types.h" @@ -366,8 +368,9 @@ gimp_scanner_parse_color (GScanner *scanner, gimp_rgba_set (&color, col[0], col[1], col[2], col[3]); gimp_rgb_clamp (&color); } + + token = G_TOKEN_RIGHT_PAREN; } - token = G_TOKEN_RIGHT_PAREN; break; case G_TOKEN_RIGHT_PAREN: @@ -397,6 +400,77 @@ gimp_scanner_parse_color (GScanner *scanner, return (token == G_TOKEN_NONE); } +gboolean +gimp_scanner_parse_matrix2 (GScanner *scanner, + GimpMatrix2 *dest) +{ + guint scope_id; + guint old_scope_id; + GTokenType token; + GimpMatrix2 matrix; + + scope_id = g_quark_from_static_string ("gimp_scanner_parse_matrix"); + old_scope_id = g_scanner_set_scope (scanner, scope_id); + + if (! g_scanner_scope_lookup_symbol (scanner, scope_id, "matrix")) + g_scanner_scope_add_symbol (scanner, scope_id, "matrix", 0); + + token = G_TOKEN_LEFT_PAREN; + + while (g_scanner_peek_next_token (scanner) == token) + { + token = g_scanner_get_next_token (scanner); + + switch (token) + { + case G_TOKEN_LEFT_PAREN: + token = G_TOKEN_SYMBOL; + break; + + case G_TOKEN_SYMBOL: + { + token = G_TOKEN_FLOAT; + + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][0])) + goto finish; + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][1])) + goto finish; + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][0])) + goto finish; + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][1])) + goto finish; + + token = G_TOKEN_RIGHT_PAREN; + } + break; + + case G_TOKEN_RIGHT_PAREN: + token = G_TOKEN_NONE; /* indicates success */ + goto finish; + + default: /* do nothing */ + break; + } + } + + finish: + + if (token != G_TOKEN_NONE) + { + g_scanner_get_next_token (scanner); + g_scanner_unexp_token (scanner, token, NULL, NULL, NULL, + _("fatal parse error"), TRUE); + } + else + { + *dest = matrix; + } + + g_scanner_set_scope (scanner, old_scope_id); + + return (token == G_TOKEN_NONE); +} + /* private functions */ diff --git a/app/config/gimpscanner.h b/app/config/gimpscanner.h index 59697750bc..498d53a674 100644 --- a/app/config/gimpscanner.h +++ b/app/config/gimpscanner.h @@ -45,6 +45,8 @@ gboolean gimp_scanner_parse_float (GScanner *scanner, gdouble *dest); gboolean gimp_scanner_parse_color (GScanner *scanner, GimpRGB *dest); +gboolean gimp_scanner_parse_matrix2 (GScanner *scanner, + GimpMatrix2 *dest); #endif /* __GIMP_SCANNER_H__ */ diff --git a/app/text/gimptext.c b/app/text/gimptext.c index 8477eba456..5ba4853596 100644 --- a/app/text/gimptext.c +++ b/app/text/gimptext.c @@ -62,6 +62,7 @@ enum PROP_BOX_WIDTH, PROP_BOX_HEIGHT, PROP_BOX_UNIT, + PROP_TRANSFORMATION, PROP_BORDER }; @@ -124,6 +125,7 @@ gimp_text_class_init (GimpTextClass *klass) GObjectClass *object_class; GParamSpec *param_spec; GimpRGB black; + GimpMatrix2 identity; gchar *language; object_class = G_OBJECT_CLASS (klass); @@ -135,6 +137,7 @@ gimp_text_class_init (GimpTextClass *klass) object_class->set_property = gimp_text_set_property; gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); + gimp_matrix2_identity (&identity); language = gimp_text_get_default_language (); @@ -221,6 +224,10 @@ gimp_text_class_init (GimpTextClass *klass) "box-unit", NULL, TRUE, GIMP_UNIT_PIXEL, 0); + GIMP_CONFIG_INSTALL_PROP_MATRIX2 (object_class, PROP_TRANSFORMATION, + "transformation", NULL, + &identity, + 0); /* border does only exist to implement the old text API */ param_spec = g_param_spec_int ("border", NULL, NULL, @@ -316,6 +323,9 @@ gimp_text_get_property (GObject *object, case PROP_BOX_UNIT: g_value_set_int (value, text->box_unit); break; + case PROP_TRANSFORMATION: + g_value_set_boxed (value, &text->transformation); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -328,8 +338,9 @@ gimp_text_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - GimpText *text = GIMP_TEXT (object); - GimpRGB *color; + GimpText *text = GIMP_TEXT (object); + GimpRGB *color; + GimpMatrix2 *matrix; switch (property_id) { @@ -388,6 +399,10 @@ gimp_text_set_property (GObject *object, case PROP_BOX_UNIT: text->box_unit = g_value_get_int (value); break; + case PROP_TRANSFORMATION: + matrix = g_value_get_boxed (value); + text->transformation = *matrix; + break; case PROP_BORDER: text->border = g_value_get_int (value); break; diff --git a/app/text/gimptext.h b/app/text/gimptext.h index 62dcb7b951..ac51a6723a 100644 --- a/app/text/gimptext.h +++ b/app/text/gimptext.h @@ -53,6 +53,7 @@ struct _GimpText gdouble box_width; gdouble box_height; GimpUnit box_unit; + GimpMatrix2 transformation; /* for historical reasons, don't use */ gint border; }; diff --git a/devel-docs/libgimpmath/libgimpmath-sections.txt b/devel-docs/libgimpmath/libgimpmath-sections.txt index 1a1e302479..f1e2695e61 100644 --- a/devel-docs/libgimpmath/libgimpmath-sections.txt +++ b/devel-docs/libgimpmath/libgimpmath-sections.txt @@ -19,11 +19,13 @@ gimp_md5_get_digest
gimpmatrix GimpMatrix +GimpMatrix2 GimpMatrix3 GimpMatrix4 +gimp_matrix2_identity +gimp_matrix3_identity gimp_matrix3_transform_point gimp_matrix3_mult -gimp_matrix3_identity gimp_matrix3_translate gimp_matrix3_scale gimp_matrix3_rotate diff --git a/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml b/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml index 211d5fd10e..438a06b373 100644 --- a/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml +++ b/devel-docs/libgimpmath/tmpl/gimpmatrix.sgml @@ -24,6 +24,13 @@ basic matrix manipulations and tests. #GimpVector4 + + + + + +@coeff: + @@ -38,6 +45,22 @@ basic matrix manipulations and tests. @coeff: + + + + + +@matrix: + + + + + + + +@matrix: + + @@ -59,14 +82,6 @@ basic matrix manipulations and tests. @matrix2: - - - - - -@matrix: - - diff --git a/libgimpbase/gimpbasetypes.h b/libgimpbase/gimpbasetypes.h index daf390ae20..cf77f01233 100644 --- a/libgimpbase/gimpbasetypes.h +++ b/libgimpbase/gimpbasetypes.h @@ -22,6 +22,7 @@ #include +#include G_BEGIN_DECLS diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c index 87e92416b1..2d54440205 100644 --- a/libgimpconfig/gimpconfig-deserialize.c +++ b/libgimpconfig/gimpconfig-deserialize.c @@ -33,6 +33,7 @@ #include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" +#include "libgimpmath/gimpmath.h" #include "config-types.h" @@ -77,6 +78,9 @@ static GTokenType gimp_config_deserialize_path (GValue *value, static GTokenType gimp_config_deserialize_color (GValue *value, GParamSpec *prop_spec, GScanner *scanner); +static GTokenType gimp_config_deserialize_matrix2 (GValue *value, + GParamSpec *prop_spec, + GScanner *scanner); static GTokenType gimp_config_deserialize_object (GValue *value, GObject *object, GParamSpec *prop_spec, @@ -346,6 +350,10 @@ gimp_config_deserialize_value (GValue *value, { return gimp_config_deserialize_color (value, prop_spec, scanner); } + else if (prop_spec->value_type == GIMP_TYPE_MATRIX2) + { + return gimp_config_deserialize_matrix2 (value, prop_spec, scanner); + } else if (prop_spec->value_type == G_TYPE_VALUE_ARRAY) { return gimp_config_deserialize_value_array (value, @@ -600,6 +608,21 @@ gimp_config_deserialize_color (GValue *value, return G_TOKEN_RIGHT_PAREN; } +static GTokenType +gimp_config_deserialize_matrix2 (GValue *value, + GParamSpec *prop_spec, + GScanner *scanner) +{ + GimpMatrix2 matrix; + + if (! gimp_scanner_parse_matrix2 (scanner, &matrix)) + return G_TOKEN_NONE; + + g_value_set_boxed (value, &matrix); + + return G_TOKEN_RIGHT_PAREN; +} + static GTokenType gimp_config_deserialize_object (GValue *value, GObject *object, diff --git a/libgimpconfig/gimpconfig-iface.c b/libgimpconfig/gimpconfig-iface.c index ea76c1fae9..e87df5e64d 100644 --- a/libgimpconfig/gimpconfig-iface.c +++ b/libgimpconfig/gimpconfig-iface.c @@ -25,7 +25,7 @@ #include -#include "libgimpcolor/gimpcolor.h" +#include "libgimpbase/gimpbase.h" #include "config-types.h" diff --git a/libgimpconfig/gimpconfig-params.h b/libgimpconfig/gimpconfig-params.h index e602605e14..759ae36dc3 100644 --- a/libgimpconfig/gimpconfig-params.h +++ b/libgimpconfig/gimpconfig-params.h @@ -50,6 +50,22 @@ GParamSpec * gimp_param_spec_color (const gchar *name, GParamFlags flags); +/* + * GIMP_TYPE_PARAM_MATRIX2 + */ + +#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); + + /* * GIMP_TYPE_PARAM_MEMSIZE */ @@ -59,13 +75,13 @@ GParamSpec * gimp_param_spec_color (const gchar *name, GType gimp_param_memsize_get_type (void) G_GNUC_CONST; -GParamSpec * gimp_param_spec_memsize (const gchar *name, - const gchar *nick, - const gchar *blurb, - gulong minimum, - gulong maximum, - gulong default_value, - GParamFlags flags); +GParamSpec * gimp_param_spec_memsize (const gchar *name, + const gchar *nick, + const gchar *blurb, + gulong minimum, + gulong maximum, + gulong default_value, + GParamFlags flags); /* @@ -85,14 +101,14 @@ typedef enum 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); +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); +GimpParamPathType gimp_param_spec_path_type (GParamSpec *pspec); /* @@ -104,12 +120,12 @@ GimpParamPathType gimp_param_spec_path_type (GParamSpec *pspec); 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, - GimpUnit default_value, - GParamFlags flags); +GParamSpec * gimp_param_spec_unit (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_pixels, + GimpUnit default_value, + GParamFlags flags); /* some convenience macros to install object properties */ @@ -144,6 +160,12 @@ GParamSpec * gimp_param_spec_unit (const gchar *name, g_param_spec_int (name, NULL, blurb,\ min, max, default,\ flags | GIMP_CONFIG_PARAM_FLAGS)) +#define GIMP_CONFIG_INSTALL_PROP_MATRIX2(class, id,\ + name, blurb, default, flags)\ + g_object_class_install_property (class, id,\ + gimp_param_spec_matrix2 (name, NULL, blurb,\ + default,\ + flags | GIMP_CONFIG_PARAM_FLAGS)) #define GIMP_CONFIG_INSTALL_PROP_MEMSIZE(class, id,\ name, blurb, min, max, default, flags)\ g_object_class_install_property (class, id,\ diff --git a/libgimpconfig/gimpconfig-serialize.c b/libgimpconfig/gimpconfig-serialize.c index 920578472d..69f5333384 100644 --- a/libgimpconfig/gimpconfig-serialize.c +++ b/libgimpconfig/gimpconfig-serialize.c @@ -34,6 +34,7 @@ #endif #include "libgimpbase/gimpbase.h" +#include "libgimpmath/gimpmath.h" #include "libgimpcolor/gimpcolor.h" #include "config-types.h" @@ -338,7 +339,7 @@ gimp_config_serialize_value (const GValue *value, g_string_append (str, bool ? "yes" : "no"); return TRUE; } - + if (G_VALUE_HOLDS_ENUM (value)) { GEnumClass *enum_class; @@ -408,6 +409,24 @@ gimp_config_serialize_value (const GValue *value, return TRUE; } + if (GIMP_VALUE_HOLDS_MATRIX2 (value)) + { + GimpMatrix2 *trafo; + gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE]; + gint i, j, k; + + trafo = g_value_get_boxed (value); + + for (i = 0, k = 0; i < 2; i++) + for (j = 0; j < 2; j++, k++) + g_ascii_formatd (buf[k], + G_ASCII_DTOSTR_BUF_SIZE, "%f", trafo->coeff[i][j]); + + g_string_append_printf (str, "(matrix %s %s %s %s)", + buf[0], buf[1], buf[2], buf[3]); + return TRUE; + } + if (G_VALUE_TYPE (value) == G_TYPE_VALUE_ARRAY) { GValueArray *array; diff --git a/libgimpconfig/gimpscanner.c b/libgimpconfig/gimpscanner.c index 286892b904..ef9e687877 100644 --- a/libgimpconfig/gimpscanner.c +++ b/libgimpconfig/gimpscanner.c @@ -37,7 +37,9 @@ #include #endif +#include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" +#include "libgimpmath/gimpmath.h" #include "config-types.h" @@ -366,8 +368,9 @@ gimp_scanner_parse_color (GScanner *scanner, gimp_rgba_set (&color, col[0], col[1], col[2], col[3]); gimp_rgb_clamp (&color); } + + token = G_TOKEN_RIGHT_PAREN; } - token = G_TOKEN_RIGHT_PAREN; break; case G_TOKEN_RIGHT_PAREN: @@ -397,6 +400,77 @@ gimp_scanner_parse_color (GScanner *scanner, return (token == G_TOKEN_NONE); } +gboolean +gimp_scanner_parse_matrix2 (GScanner *scanner, + GimpMatrix2 *dest) +{ + guint scope_id; + guint old_scope_id; + GTokenType token; + GimpMatrix2 matrix; + + scope_id = g_quark_from_static_string ("gimp_scanner_parse_matrix"); + old_scope_id = g_scanner_set_scope (scanner, scope_id); + + if (! g_scanner_scope_lookup_symbol (scanner, scope_id, "matrix")) + g_scanner_scope_add_symbol (scanner, scope_id, "matrix", 0); + + token = G_TOKEN_LEFT_PAREN; + + while (g_scanner_peek_next_token (scanner) == token) + { + token = g_scanner_get_next_token (scanner); + + switch (token) + { + case G_TOKEN_LEFT_PAREN: + token = G_TOKEN_SYMBOL; + break; + + case G_TOKEN_SYMBOL: + { + token = G_TOKEN_FLOAT; + + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][0])) + goto finish; + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][1])) + goto finish; + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][0])) + goto finish; + if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][1])) + goto finish; + + token = G_TOKEN_RIGHT_PAREN; + } + break; + + case G_TOKEN_RIGHT_PAREN: + token = G_TOKEN_NONE; /* indicates success */ + goto finish; + + default: /* do nothing */ + break; + } + } + + finish: + + if (token != G_TOKEN_NONE) + { + g_scanner_get_next_token (scanner); + g_scanner_unexp_token (scanner, token, NULL, NULL, NULL, + _("fatal parse error"), TRUE); + } + else + { + *dest = matrix; + } + + g_scanner_set_scope (scanner, old_scope_id); + + return (token == G_TOKEN_NONE); +} + /* private functions */ diff --git a/libgimpconfig/gimpscanner.h b/libgimpconfig/gimpscanner.h index 59697750bc..498d53a674 100644 --- a/libgimpconfig/gimpscanner.h +++ b/libgimpconfig/gimpscanner.h @@ -45,6 +45,8 @@ gboolean gimp_scanner_parse_float (GScanner *scanner, gdouble *dest); gboolean gimp_scanner_parse_color (GScanner *scanner, GimpRGB *dest); +gboolean gimp_scanner_parse_matrix2 (GScanner *scanner, + GimpMatrix2 *dest); #endif /* __GIMP_SCANNER_H__ */ diff --git a/libgimpmath/gimpmathtypes.h b/libgimpmath/gimpmathtypes.h index ef6f705ac9..87fc3b1124 100644 --- a/libgimpmath/gimpmathtypes.h +++ b/libgimpmath/gimpmathtypes.h @@ -24,6 +24,7 @@ G_BEGIN_DECLS +typedef struct _GimpMatrix2 GimpMatrix2; typedef struct _GimpMatrix3 GimpMatrix3; typedef struct _GimpMatrix4 GimpMatrix4; diff --git a/libgimpmath/gimpmatrix.c b/libgimpmath/gimpmatrix.c index 405c9f6696..a4668fec8f 100644 --- a/libgimpmath/gimpmatrix.c +++ b/libgimpmath/gimpmatrix.c @@ -29,6 +29,21 @@ #define EPSILON 1e-6 +/** + * gimp_matrix2_identity: + * @matrix: A matrix. + * + * Sets the matrix to the identity matrix. + */ +void +gimp_matrix2_identity (GimpMatrix2 *matrix) +{ + static const GimpMatrix2 identity = { { { 1.0, 0.0 }, + { 0.0, 1.0 } } }; + + *matrix = identity; +} + /** * gimp_matrix3_transform_point: diff --git a/libgimpmath/gimpmatrix.h b/libgimpmath/gimpmatrix.h index c9a6988ada..9f83b5dd08 100644 --- a/libgimpmath/gimpmatrix.h +++ b/libgimpmath/gimpmatrix.h @@ -27,6 +27,11 @@ G_BEGIN_DECLS /* For information look into the C source or the html documentation */ +struct _GimpMatrix2 +{ + gdouble coeff[2][2]; +}; + struct _GimpMatrix3 { gdouble coeff[3][3]; @@ -38,6 +43,8 @@ struct _GimpMatrix4 }; +void gimp_matrix2_identity (GimpMatrix2 *matrix); + void gimp_matrix3_transform_point (const GimpMatrix3 *matrix, gdouble x, gdouble y,