gegl r1900 - in trunk: . gegl operations/blur operations/color



Author: ok
Date: Wed Jan 23 01:54:42 2008
New Revision: 1900
URL: http://svn.gnome.org/viewvc/gegl?rev=1900&view=rev

Log:
* gegl/gegl-chant.h: allocate and free the properties structure
manually, tweak the define type macro to generate the class name
taking the GEGL_CHANT_C_FILE into account.
* operations/blur/box-blur.c: ported to new chanting API.
* operations/color/invert.c: ported to new chanting API.


Modified:
   trunk/ChangeLog
   trunk/gegl/gegl-chant.h
   trunk/operations/blur/box-blur.c
   trunk/operations/color/invert.c

Modified: trunk/gegl/gegl-chant.h
==============================================================================
--- trunk/gegl/gegl-chant.h	(original)
+++ trunk/gegl/gegl-chant.h	Wed Jan 23 01:54:42 2008
@@ -26,12 +26,65 @@
 #error "GEGL_CHANT_C_FILE not defined"
 #endif
 
+#include <gegl-plugin.h>
+
+#undef G_DEFINE_DYNAMIC_TYPE
+#undef G_DEFINE_DYNAMIC_TYPE_EXTENDED
+
+#define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P)          G_DEFINE_DYNAMIC_TYPE_EXTENDED (GEGL_CHANT_C_FILE, TN, t_n, T_P, 0, {})
+#define G_DEFINE_DYNAMIC_TYPE_EXTENDED(C_FILE, TypeName, type_name, TYPE_PARENT, flags, CODE) \
+  static void     type_name##_init              (TypeName        *self); \
+static void     type_name##_class_init        (TypeName##Class *klass); \
+static void     type_name##_class_finalize    (TypeName##Class *klass); \
+static gpointer type_name##_parent_class = NULL; \
+static GType    type_name##_type_id = 0; \
+static void     type_name##_class_intern_init (gpointer klass) \
+  { \
+    type_name##_parent_class = g_type_class_peek_parent (klass); \
+    type_name##_class_init ((TypeName##Class*) klass); \
+  } \
+GType \
+type_name##_get_type (void) \
+  { \
+    return type_name##_type_id; \
+  } \
+static void \
+type_name##_register_type (GTypeModule *type_module) \
+  { \
+    gchar tempname[256];    \
+    gchar *p;               \
+    GType g_define_type_id; \
+    const GTypeInfo g_define_type_info = { \
+          sizeof (TypeName##Class), \
+          (GBaseInitFunc) NULL, \
+          (GBaseFinalizeFunc) NULL, \
+          (GClassInitFunc) type_name##_class_intern_init, \
+          (GClassFinalizeFunc) type_name##_class_finalize, \
+          NULL,   /* class_data */ \
+          sizeof (TypeName), \
+          0,      /* n_preallocs */ \
+          (GInstanceInitFunc) type_name##_init, \
+          NULL    /* value_table */ \
+        }; \
+    g_snprintf (tempname, 256, "%s", #TypeName GEGL_CHANT_C_FILE);\
+    for (p = &tempname[0]; *p; p++) {\
+      if (*p=='.') *p='_';\
+    }\
+    type_name##_type_id = g_type_module_register_type (type_module, \
+                                                       TYPE_PARENT, \
+                                                       tempname,    \
+                                                       &g_define_type_info, \
+                                                       (GTypeFlags) flags); \
+    g_define_type_id = type_name##_type_id; \
+    { CODE ; } \
+  }
+
+
 
 #define GEGL_CHANT_PROPERTIES(op) \
     ((GeglChantProperties*)(((GeglChantOperation*)(op))->properties))
 /****************************************************************************/
 
-#include <gegl-plugin.h>
 
 #ifdef GEGL_CHANT_TYPE_OPERATION
 #include <operation/gegl-operation.h>
@@ -45,6 +98,8 @@
 {
   GeglOperationClass parent_class;
 } GeglChantOperationClass;
+
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_OPERATION);
 #endif
 
 #ifdef GEGL_CHANT_TYPE_META
@@ -59,6 +114,8 @@
 {
   GeglOperationMetaClass parent_class;
 } GeglChantOperationClass;
+
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_META);
 #endif
 
 #ifdef GEGL_CHANT_TYPE_SOURCE
@@ -73,6 +130,8 @@
 {
   GeglOperationSourceClass parent_class;
 } GeglChantOperationClass;
+
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_SOURCE);
 #endif
 
 #ifdef GEGL_CHANT_TYPE_SINK
@@ -87,6 +146,8 @@
 {
   GeglOperationSinkClass parent_class;
 } GeglChantOperationClass;
+
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_SINK);
 #endif
 
 #ifdef GEGL_CHANT_TYPE_FILTER
@@ -101,6 +162,8 @@
 {
   GeglOperationFilterClass parent_class;
 } GeglChantOperationClass;
+
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_FILTER);
 #endif
 
 #ifdef GEGL_CHANT_TYPE_COMPOSER
@@ -115,6 +178,9 @@
 {
   GeglOperationComposerClass parent_class;
 } GeglChantOperationClass;
+
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_COMPOSER);
+
 #endif
 
 #ifdef GEGL_CHANT_TYPE_POINT_FILTER
@@ -129,6 +195,10 @@
 {
   GeglOperationPointFilterClass parent_class;
 } GeglChantOperationClass;
+
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_POINT_FILTER);
+
+
 #endif
 
 #ifdef GEGL_CHANT_TYPE_AREA_FILTER
@@ -143,6 +213,7 @@
 {
   GeglOperationAreaFilterClass parent_class;
 } GeglChantOperationClass;
+G_DEFINE_DYNAMIC_TYPE (GeglChantOperation, operation, GEGL_TYPE_OPERATION_AREA_FILTER);
 #endif
 
 
@@ -163,15 +234,11 @@
 
 
 typedef struct _GeglChantProperties GeglChantProperties;
-static GType operation_get_type      ();
+GType operation_get_type ();
 static void  operation_register_type (GTypeModule *module);
 
 static void
-gegl_chant_init (GeglChantOperation *self)
-{
-  self->properties = G_TYPE_INSTANCE_GET_PRIVATE ((self),
-      operation_get_type (), GeglChantProperties);
-}
+gegl_chant_init (GeglChantOperation *self);
 
 /* if GEGL_CHANT_CUSTOM is defined you have to provide the following
  * code or your own implementation of it
@@ -211,6 +278,8 @@
 
 struct _GeglChantProperties
 {
+  gpointer dummy_filler; /* to avoid empty struct, can be done a bit more cleverly to
+                            avoid adding it when there is actual properties*/
 #define gegl_chant_int(name, min, max, def, blurb)     gint        name;
 #define gegl_chant_double(name, min, max, def, blurb)  gdouble     name;
 #define gegl_chant_boolean(name, def, blurb)           gboolean    name;
@@ -510,6 +579,7 @@
 #undef gegl_chant_color
 #undef gegl_chant_curve
 #undef gegl_chant_vector
+  g_free (properties);
 }
 
 static GObject *
@@ -537,7 +607,7 @@
   object_class->get_property = get_property;
   object_class->constructor  = gegl_chant_constructor;
 
-  g_type_class_add_private (klass, sizeof (GeglChantProperties));
+/*  g_type_class_add_private (klass, sizeof (GeglChantProperties));*/
 
 #define gegl_chant_int(name, min, max, def, blurb)                          \
   g_object_class_install_property (object_class, PROP_##name,               \
@@ -643,4 +713,10 @@
 }
 
 
+static void
+gegl_chant_init (GeglChantOperation *self)
+{
+  self->properties = g_new0 (GeglChantProperties, 1);
+}
+
 /****************************************************************************/

Modified: trunk/operations/blur/box-blur.c
==============================================================================
--- trunk/operations/blur/box-blur.c	(original)
+++ trunk/operations/blur/box-blur.c	Wed Jan 23 01:54:42 2008
@@ -15,21 +15,17 @@
  *
  * Copyright 2006 Ãyvind KolÃs <pippin gimp org>
  */
-#if GEGL_CHANT_PROPERTIES
+#ifdef GEGL_CHANT_PROPERTIES
 
-gegl_chant_double (radius, 0.0, 200.0, 4.0,
-  "Radius of square pixel region, (width and height will be radius*2+1.")
+gegl_chant_double (radius, 0.0, 200.0, 4.0, "Radius of square pixel region, (width and height will be radius*2+1.")
 
 #else
 
-#define GEGL_CHANT_NAME            box_blur
-#define GEGL_CHANT_SELF            "box-blur.c"
-#define GEGL_CHANT_DESCRIPTION     "Performs an averaging of a square box of pixels."
-#define GEGL_CHANT_CATEGORIES      "blur"
+#define GEGL_CHANT_TYPE_AREA_FILTER
+#define GEGL_CHANT_C_FILE          "box-blur.c"
 
-#define GEGL_CHANT_AREA_FILTER
 
-#include "gegl-old-chant.h"
+#include "gegl-chant.h"
 
 static void hor_blur (GeglBuffer *src,
                       GeglBuffer *dst,
@@ -47,17 +43,14 @@
          GeglBuffer          *output,
          const GeglRectangle *result)
 {
-  GeglChantOperation  *self;
-
-  GeglBuffer *temp;
-
-  self  = GEGL_CHANT_OPERATION (operation);
+  GeglChantProperties *properties = GEGL_CHANT_PROPERTIES (operation);
+  GeglBuffer          *temp;
 
   temp  = gegl_buffer_new (gegl_buffer_get_extent (input),
                            babl_format ("RaGaBaA float"));
 
-  hor_blur (input, temp,  self->radius);
-  ver_blur (temp, output, self->radius);
+  hor_blur (input, temp,  properties->radius);
+  ver_blur (temp, output, properties->radius);
 
   g_object_unref (temp);
   return  TRUE;
@@ -236,9 +229,28 @@
 static void tickle (GeglOperation *operation)
 {
   GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
-  GeglChantOperation      *blur = GEGL_CHANT_OPERATION (operation);
+  GeglChantProperties     *properties = GEGL_CHANT_PROPERTIES (operation);
   area->left = area->right = area->top = area->bottom =
-      ceil (blur->radius);
+      ceil (properties->radius);
+}
+
+
+static void
+operation_class_init (GeglChantOperationClass *klass)
+{
+  GeglOperationClass       *operation_class;
+  GeglOperationFilterClass *filter_class;
+
+  operation_class  = GEGL_OPERATION_CLASS (klass);
+  filter_class     = GEGL_OPERATION_FILTER_CLASS (klass);
+
+  operation_class->description = "Performs an averaging of a square box of pixels.";
+  operation_class->categories = "blur";
+  operation_class->tickle = tickle;
+  filter_class->process = process;
+
+  gegl_operation_class_set_name (operation_class, "box-blur");
+  gegl_chant_class_init (klass);
 }
 
 

Modified: trunk/operations/color/invert.c
==============================================================================
--- trunk/operations/color/invert.c	(original)
+++ trunk/operations/color/invert.c	Wed Jan 23 01:54:42 2008
@@ -15,16 +15,15 @@
  *
  * Copyright 2006 Ãyvind KolÃs <pippin gimp org>
  */
-#if GEGL_CHANT_PROPERTIES
+#ifdef GEGL_CHANT_PROPERTIES
    /* no properties */
 #else
 
-#define GEGL_CHANT_POINT_FILTER
-#define GEGL_CHANT_NAME          invert
-#define GEGL_CHANT_DESCRIPTION   "Inverts the components (except alpha), the result is the corresponding \"negative\" image."
-#define GEGL_CHANT_SELF          "invert.c"
-#define GEGL_CHANT_CATEGORIES    "color"
-#include "gegl-old-chant.h"
+#define GEGL_CHANT_TYPE_POINT_FILTER
+#define GEGL_CHANT_C_FILE        "invert.c"
+
+
+#include "gegl-chant.h"
 
 static gboolean
 process (GeglOperation *op,
@@ -53,4 +52,21 @@
   return TRUE;
 }
 
+static void
+operation_class_init (GeglChantOperationClass *klass)
+{
+  GeglOperationClass            *operation_class;
+  GeglOperationPointFilterClass *point_filter_class;
+
+  operation_class    = GEGL_OPERATION_CLASS (klass);
+  point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
+
+  operation_class->description = "Inverts the components (except alpha), the result is the corresponding \"negative\" image.";
+  operation_class->categories = "color";
+  point_filter_class->process = process;
+
+  gegl_operation_class_set_name (operation_class, "invert");
+  gegl_chant_class_init (klass);
+}
+
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]