30
30
#define EPSILON 1e-6
33
static GimpMatrix2 * matrix2_copy (const GimpMatrix2 *matrix);
36
* gimp_matrix2_get_type:
38
* Reveals the object type
40
* Returns: the #GType for Matrix2 objects
45
gimp_matrix2_get_type (void)
47
static GType matrix_type = 0;
50
matrix_type = g_boxed_type_register_static ("GimpMatrix2",
51
(GBoxedCopyFunc) matrix2_copy,
52
(GBoxedFreeFunc) g_free);
59
* GIMP_TYPE_PARAM_MATRIX2
62
#define GIMP_PARAM_SPEC_MATRIX2(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_MATRIX2, GimpParamSpecMatrix2))
64
static void gimp_param_matrix2_class_init (GParamSpecClass *class);
65
static void gimp_param_matrix2_init (GParamSpec *pspec);
66
static void gimp_param_matrix2_set_default (GParamSpec *pspec,
68
static gint gimp_param_matrix2_values_cmp (GParamSpec *pspec,
70
const GValue *value2);
72
typedef struct _GimpParamSpecMatrix2 GimpParamSpecMatrix2;
74
struct _GimpParamSpecMatrix2
76
GParamSpecBoxed parent_instance;
78
GimpMatrix2 default_value;
82
* gimp_param_matrix2_get_type:
84
* Reveals the object type
86
* Returns: the #GType for a GimpMatrix2 object
91
gimp_param_matrix2_get_type (void)
93
static GType spec_type = 0;
97
static const GTypeInfo type_info =
99
sizeof (GParamSpecClass),
101
(GClassInitFunc) gimp_param_matrix2_class_init,
103
sizeof (GimpParamSpecMatrix2),
105
(GInstanceInitFunc) gimp_param_matrix2_init
108
spec_type = g_type_register_static (G_TYPE_PARAM_BOXED,
117
gimp_param_matrix2_class_init (GParamSpecClass *class)
119
class->value_type = GIMP_TYPE_MATRIX2;
120
class->value_set_default = gimp_param_matrix2_set_default;
121
class->values_cmp = gimp_param_matrix2_values_cmp;
125
gimp_param_matrix2_init (GParamSpec *pspec)
127
GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
129
gimp_matrix2_identity (&cspec->default_value);
133
gimp_param_matrix2_set_default (GParamSpec *pspec,
136
GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
138
g_value_set_static_boxed (value, &cspec->default_value);
142
gimp_param_matrix2_values_cmp (GParamSpec *pspec,
143
const GValue *value1,
144
const GValue *value2)
146
GimpMatrix2 *matrix1;
147
GimpMatrix2 *matrix2;
150
matrix1 = value1->data[0].v_pointer;
151
matrix2 = value2->data[0].v_pointer;
153
/* try to return at least *something*, it's useless anyway... */
156
return matrix2 != NULL ? -1 : 0;
158
return matrix1 != NULL;
160
for (i = 0; i < 2; i++)
161
for (j = 0; j < 2; j++)
162
if (matrix1->coeff[i][j] != matrix2->coeff[i][j])
169
* gimp_param_spec_matrix2:
170
* @name: Canonical name of the param
171
* @nick: Nickname of the param
172
* @blurb: Brief desciption of param.
173
* @default_value: Value to use if none is assigned.
174
* @flags: a combination of #GParamFlags
176
* Creates a param spec to hold a #GimpMatrix2 value.
177
* See g_param_spec_internal() for more information.
179
* Returns: a newly allocated #GParamSpec instance
184
gimp_param_spec_matrix2 (const gchar *name,
187
const GimpMatrix2 *default_value,
190
GimpParamSpecMatrix2 *cspec;
192
g_return_val_if_fail (default_value != NULL, NULL);
194
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_MATRIX2,
195
name, nick, blurb, flags);
197
cspec->default_value = *default_value;
199
return G_PARAM_SPEC (cspec);
204
matrix2_copy (const GimpMatrix2 *matrix)
206
return (GimpMatrix2 *) g_memdup (matrix, sizeof (GimpMatrix2));
34
211
* gimp_matrix2_identity:
35
212
* @matrix: A matrix.
391
566
/* functions to test for matrix properties */
395
* gimp_matrix3_is_diagonal:
396
* @matrix: The matrix that is to be tested.
398
* Checks if the given matrix is diagonal.
400
* Returns: TRUE if the matrix is diagonal.
403
gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix)
407
for (i = 0; i < 3; i++)
409
for (j = 0; j < 3; j++)
411
if (i != j && fabs (matrix->coeff[i][j]) > EPSILON)
420
569
* gimp_matrix3_is_identity:
421
570
* @matrix: The matrix that is to be tested.
423
572
* Checks if the given matrix is the identity matrix.
425
* Returns: TRUE if the matrix is the identity matrix.
574
* Returns: %TRUE if the matrix is the identity matrix, %FALSE otherwise
428
577
gimp_matrix3_is_identity (const GimpMatrix3 *matrix)
452
/* Check if we'll need to interpolate when applying this matrix.
453
This function returns TRUE if all entries of the upper left
454
2x2 matrix are either 0 or 1
602
* gimp_matrix3_is_diagonal:
603
* @matrix: The matrix that is to be tested.
605
* Checks if the given matrix is diagonal.
607
* Returns: %TRUE if the matrix is diagonal, %FALSE otherwise
610
gimp_matrix3_is_diagonal (const GimpMatrix3 *matrix)
614
for (i = 0; i < 3; i++)
616
for (j = 0; j < 3; j++)
618
if (i != j && fabs (matrix->coeff[i][j]) > EPSILON)
627
* gimp_matrix3_is_affine:
628
* @matrix: The matrix that is to be tested.
630
* Checks if the given matrix defines an affine transformation.
632
* Returns: %TRUE if the matrix defines an affine transformation,
638
gimp_matrix3_is_affine (const GimpMatrix3 *matrix)
640
return (fabs (matrix->coeff[2][0]) < EPSILON &&
641
fabs (matrix->coeff[2][1]) < EPSILON &&
642
fabs (matrix->coeff[2][2] - 1.0) < EPSILON);
459
646
* gimp_matrix3_is_simple: