diff --git a/libgimpmath/gimpmath.def b/libgimpmath/gimpmath.def index 1aeea16edc..1a489403ac 100644 --- a/libgimpmath/gimpmath.def +++ b/libgimpmath/gimpmath.def @@ -4,6 +4,7 @@ EXPORTS gimp_matrix2_mult gimp_matrix3_affine gimp_matrix3_determinant + gimp_matrix3_get_type gimp_matrix3_identity gimp_matrix3_invert gimp_matrix3_is_affine @@ -20,7 +21,9 @@ EXPORTS gimp_matrix4_to_deg gimp_md5_get_digest gimp_param_matrix2_get_type + gimp_param_matrix3_get_type gimp_param_spec_matrix2 + gimp_param_spec_matrix3 gimp_vector2_add gimp_vector2_add_val gimp_vector2_cross_product diff --git a/libgimpmath/gimpmatrix.c b/libgimpmath/gimpmatrix.c index 9b8224a590..594cdd38fe 100644 --- a/libgimpmath/gimpmatrix.c +++ b/libgimpmath/gimpmatrix.c @@ -264,6 +264,183 @@ gimp_matrix2_mult (const GimpMatrix2 *matrix1, *matrix2 = tmp; } + +static GimpMatrix3 * matrix3_copy (const GimpMatrix3 *matrix); + +/** + * gimp_matrix3_get_type: + * + * Reveals the object type + * + * Returns: the #GType for Matrix3 objects + * + * Since: GIMP 2.8 + **/ +GType +gimp_matrix3_get_type (void) +{ + static GType matrix_type = 0; + + if (!matrix_type) + matrix_type = g_boxed_type_register_static ("GimpMatrix3", + (GBoxedCopyFunc) matrix3_copy, + (GBoxedFreeFunc) g_free); + + return matrix_type; +} + + +/* + * GIMP_TYPE_PARAM_MATRIX3 + */ + +#define GIMP_PARAM_SPEC_MATRIX3(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_MATRIX3, GimpParamSpecMatrix3)) + +static void gimp_param_matrix3_class_init (GParamSpecClass *class); +static void gimp_param_matrix3_init (GParamSpec *pspec); +static void gimp_param_matrix3_set_default (GParamSpec *pspec, + GValue *value); +static gint gimp_param_matrix3_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2); + +typedef struct _GimpParamSpecMatrix3 GimpParamSpecMatrix3; + +struct _GimpParamSpecMatrix3 +{ + GParamSpecBoxed parent_instance; + + GimpMatrix3 default_value; +}; + +/** + * gimp_param_matrix3_get_type: + * + * Reveals the object type + * + * Returns: the #GType for a GimpMatrix3 object + * + * Since: GIMP 2.8 + **/ +GType +gimp_param_matrix3_get_type (void) +{ + static GType spec_type = 0; + + if (!spec_type) + { + static const GTypeInfo type_info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_matrix3_class_init, + NULL, NULL, + sizeof (GimpParamSpecMatrix3), + 0, + (GInstanceInitFunc) gimp_param_matrix3_init + }; + + spec_type = g_type_register_static (G_TYPE_PARAM_BOXED, + "GimpParamMatrix3", + &type_info, 0); + } + + return spec_type; +} + +static void +gimp_param_matrix3_class_init (GParamSpecClass *class) +{ + class->value_type = GIMP_TYPE_MATRIX3; + class->value_set_default = gimp_param_matrix3_set_default; + class->values_cmp = gimp_param_matrix3_values_cmp; +} + +static void +gimp_param_matrix3_init (GParamSpec *pspec) +{ + GimpParamSpecMatrix3 *cspec = GIMP_PARAM_SPEC_MATRIX3 (pspec); + + gimp_matrix3_identity (&cspec->default_value); +} + +static void +gimp_param_matrix3_set_default (GParamSpec *pspec, + GValue *value) +{ + GimpParamSpecMatrix3 *cspec = GIMP_PARAM_SPEC_MATRIX3 (pspec); + + g_value_set_static_boxed (value, &cspec->default_value); +} + +static gint +gimp_param_matrix3_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) +{ + GimpMatrix3 *matrix1; + GimpMatrix3 *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 < 3; i++) + for (j = 0; j < 3; j++) + if (matrix1->coeff[i][j] != matrix2->coeff[i][j]) + return 1; + + return 0; +} + +/** + * gimp_param_spec_matrix3: + * @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 #GimpMatrix3 value. + * See g_param_spec_internal() for more information. + * + * Returns: a newly allocated #GParamSpec instance + * + * Since: GIMP 2.8 + **/ +GParamSpec * +gimp_param_spec_matrix3 (const gchar *name, + const gchar *nick, + const gchar *blurb, + const GimpMatrix3 *default_value, + GParamFlags flags) +{ + GimpParamSpecMatrix3 *cspec; + + cspec = g_param_spec_internal (GIMP_TYPE_PARAM_MATRIX3, + name, nick, blurb, flags); + + if (default_value) + cspec->default_value = *default_value; + + return G_PARAM_SPEC (cspec); +} + + +static GimpMatrix3 * +matrix3_copy (const GimpMatrix3 *matrix) +{ + return (GimpMatrix3 *) g_memdup (matrix, sizeof (GimpMatrix3)); +} + + /** * gimp_matrix3_identity: * @matrix: A matrix. diff --git a/libgimpmath/gimpmatrix.h b/libgimpmath/gimpmatrix.h index c55646ccc6..2b36bc27b6 100644 --- a/libgimpmath/gimpmatrix.h +++ b/libgimpmath/gimpmatrix.h @@ -59,6 +59,11 @@ struct _GimpMatrix4 gdouble coeff[4][4]; }; + +/*****************/ +/* GimpMatrix2 */ +/*****************/ + #define GIMP_TYPE_MATRIX2 (gimp_matrix2_get_type ()) #define GIMP_VALUE_HOLDS_MATRIX2(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_MATRIX2)) @@ -81,6 +86,29 @@ void gimp_matrix2_identity (GimpMatrix2 *matrix); void gimp_matrix2_mult (const GimpMatrix2 *matrix1, GimpMatrix2 *matrix2); + +/*****************/ +/* GimpMatrix3 */ +/*****************/ + +#define GIMP_TYPE_MATRIX3 (gimp_matrix3_get_type ()) +#define GIMP_VALUE_HOLDS_MATRIX3(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_MATRIX3)) + +GType gimp_matrix3_get_type (void) G_GNUC_CONST; + + +#define GIMP_TYPE_PARAM_MATRIX3 (gimp_param_matrix3_get_type ()) +#define GIMP_IS_PARAM_SPEC_MATRIX3(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_MATRIX3)) + +GType gimp_param_matrix3_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_matrix3 (const gchar *name, + const gchar *nick, + const gchar *blurb, + const GimpMatrix3 *default_value, + GParamFlags flags); + + void gimp_matrix3_identity (GimpMatrix3 *matrix); void gimp_matrix3_mult (const GimpMatrix3 *matrix1, GimpMatrix3 *matrix2); @@ -118,6 +146,11 @@ void gimp_matrix3_transform_point (const GimpMatrix3 *matrix, gdouble *newx, gdouble *newy); + +/*****************/ +/* GimpMatrix4 */ + +/*****************/ void gimp_matrix4_to_deg (const GimpMatrix4 *matrix, gdouble *a, gdouble *b,