include <libgimpmath/gimpmathtypes.h>.

2003-07-07  Sven Neumann  <sven@gimp.org>

	* libgimpbase/gimpbasetypes.h: include <libgimpmath/gimpmathtypes.h>.

	* 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".
This commit is contained in:
Sven Neumann 2003-07-07 16:22:45 +00:00 committed by Sven Neumann
parent 11c42a09a9
commit 6f83a52571
24 changed files with 583 additions and 67 deletions

View File

@ -1,3 +1,20 @@
2003-07-07 Sven Neumann <sven@gimp.org>
* libgimpbase/gimpbasetypes.h: include <libgimpmath/gimpmathtypes.h>.
* 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 <sven@gimp.org>
* libgimpmath/gimpvector.[ch]: added const qualifiers.

View File

@ -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,

View File

@ -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
*/

View File

@ -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,\

View File

@ -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;

View File

@ -29,22 +29,28 @@
#include <glib-object.h>
#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)

View File

@ -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))

View File

@ -25,7 +25,7 @@
#include <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpbase/gimpbase.h"
#include "config-types.h"

View File

@ -37,7 +37,9 @@
#include <io.h>
#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 */

View File

@ -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__ */

View File

@ -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;

View File

@ -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;
};

View File

@ -19,11 +19,13 @@ gimp_md5_get_digest
<SECTION>
<FILE>gimpmatrix</FILE>
<TITLE>GimpMatrix</TITLE>
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

View File

@ -24,6 +24,13 @@ basic matrix manipulations and tests.
#GimpVector4
</para>
<!-- ##### STRUCT GimpMatrix2 ##### -->
<para>
</para>
@coeff:
<!-- ##### STRUCT GimpMatrix3 ##### -->
<para>
@ -38,6 +45,22 @@ basic matrix manipulations and tests.
@coeff:
<!-- ##### FUNCTION gimp_matrix2_identity ##### -->
<para>
</para>
@matrix:
<!-- ##### FUNCTION gimp_matrix3_identity ##### -->
<para>
</para>
@matrix:
<!-- ##### FUNCTION gimp_matrix3_transform_point ##### -->
<para>
@ -59,14 +82,6 @@ basic matrix manipulations and tests.
@matrix2:
<!-- ##### FUNCTION gimp_matrix3_identity ##### -->
<para>
</para>
@matrix:
<!-- ##### FUNCTION gimp_matrix3_translate ##### -->
<para>

View File

@ -22,6 +22,7 @@
#include <libgimpcolor/gimpcolortypes.h>
#include <libgimpmath/gimpmathtypes.h>
G_BEGIN_DECLS

View File

@ -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,

View File

@ -25,7 +25,7 @@
#include <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpbase/gimpbase.h"
#include "config-types.h"

View File

@ -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,\

View File

@ -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;

View File

@ -37,7 +37,9 @@
#include <io.h>
#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 */

View File

@ -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__ */

View File

@ -24,6 +24,7 @@
G_BEGIN_DECLS
typedef struct _GimpMatrix2 GimpMatrix2;
typedef struct _GimpMatrix3 GimpMatrix3;
typedef struct _GimpMatrix4 GimpMatrix4;

View File

@ -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:

View File

@ -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,