gegl r2183 - in trunk: . gegl/operation operations/common



Author: ok
Date: Thu Apr 17 22:24:42 2008
New Revision: 2183
URL: http://svn.gnome.org/viewvc/gegl?rev=2183&view=rev

Log:
Added infrastructure to support multiple process implementations in
GEGL operations. Optimized versions can be added with either
gegl_operation_class_add_processor (class, process_fast, "fast");
by setting the environment variable GEGL_QUALITY to fast this
alternate code path will be chosen.
* gegl/operation/gegl-operation-processors.c:
(gegl_operation_class_add_processor): added infrastructure.
* gegl/operation/gegl-operation.h: added function prototype.
* gegl/operation/Makefile.am: added new file.
* operations/common/invert.c: (process_fast): added implementation
with vertical artifacts.
(gegl_chant_class_init): register the fast version.


Added:
   trunk/gegl/operation/gegl-operation-processors.c
Modified:
   trunk/ChangeLog
   trunk/gegl/operation/Makefile.am
   trunk/gegl/operation/gegl-operation.h
   trunk/operations/common/invert.c

Modified: trunk/gegl/operation/Makefile.am
==============================================================================
--- trunk/gegl/operation/Makefile.am	(original)
+++ trunk/gegl/operation/Makefile.am	Thu Apr 17 22:24:42 2008
@@ -11,6 +11,7 @@
 	gegl-operation-point-filter.c   \
 	gegl-operation-sink.c       	\
 	gegl-operation-source.c		\
+	gegl-operation-processors.c     \
 	gegl-operations.c
 
 

Added: trunk/gegl/operation/gegl-operation-processors.c
==============================================================================
--- (empty file)
+++ trunk/gegl/operation/gegl-operation-processors.c	Thu Apr 17 22:24:42 2008
@@ -0,0 +1,148 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2003      Calvin Williamson
+ *           2005-2008 Ãyvind KolÃs
+ */
+
+#define GEGL_INTERNAL
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <string.h>
+
+#include "gegl-types.h"
+#include "gegl-operation.h"
+#include "gegl-utils.h"
+#include "graph/gegl-node.h"
+#include "graph/gegl-connection.h"
+#include "graph/gegl-pad.h"
+#include "buffer/gegl-region.h"
+#include "buffer/gegl-buffer.h"
+#include "gegl-operations.h"
+
+#include  "gegl-operation-area-filter.h"
+#include  "gegl-operation-composer.h"
+#include  "gegl-operation-filter.h"
+#include  "gegl-operation-meta.h"
+#include  "gegl-operation-point-composer.h"
+#include  "gegl-operation-point-filter.h"
+#include  "gegl-operation-sink.h"
+#include  "gegl-operation-source.h"
+
+void
+gegl_operation_class_add_processor (GeglOperationClass *cclass,
+                                    GCallback           process,
+                                    const gchar        *string)
+{
+  gint i;
+  GType    type        = G_TYPE_FROM_CLASS (cclass);
+  GType    parent_type = g_type_parent (type);
+  gint     vfunc_offset;
+  gpointer process_vfunc_ptr;
+
+#define ELSE_IF(type) else if(parent_type==type)
+if(parent_type == GEGL_TYPE_OPERATION)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationClass, process);
+ELSE_IF( GEGL_TYPE_OPERATION_SOURCE)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationSourceClass, process);
+ELSE_IF( GEGL_TYPE_OPERATION_SINK)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationSinkClass, process);
+ELSE_IF( GEGL_TYPE_OPERATION_FILTER)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationFilterClass, process);
+ELSE_IF( GEGL_TYPE_OPERATION_AREA_FILTER)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationFilterClass, process);
+ELSE_IF( GEGL_TYPE_OPERATION_POINT_FILTER)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointFilterClass, process);
+ELSE_IF( GEGL_TYPE_OPERATION_COMPOSER)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationComposerClass, process);
+ELSE_IF( GEGL_TYPE_OPERATION_POINT_COMPOSER)
+  vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointComposerClass, process);
+#undef ELSE_IF
+else
+  {
+     g_error ("%s unable to use %s as parent_type for %s",
+              G_STRFUNC, g_type_name (parent_type), g_type_name(G_TYPE_FROM_CLASS (cclass)));
+  }
+  process_vfunc_ptr = G_STRUCT_MEMBER_P(cclass, vfunc_offset);
+#define PROCESS_VFUNC (*(GCallback*) G_STRUCT_MEMBER_P ((cclass), (vfunc_offset)))
+
+
+  /* Store the default implementation */
+  if (cclass->processor[0]==NULL)
+    {
+      if (cclass->process == NULL)
+        g_error ("No process() vfunc defined for %s",
+                 g_type_name (G_TYPE_FROM_CLASS (cclass)));
+      cclass->processor[0]=process;
+      cclass->processor_string[0]=g_strdup ("reference");
+    }
+
+  /* Find a free slot for this one */
+  for (i=1; i<MAX_PROCESSOR; i++)
+    {
+      if (cclass->processor[i]==NULL)
+        {
+          cclass->processor[i]=process;
+          cclass->processor_string[i]=g_strdup (string);
+          break;
+        }
+    }
+  if (i>=MAX_PROCESSOR)
+    {
+      g_warning ("Too many processors added to %s",
+                 g_type_name (G_TYPE_FROM_CLASS (cclass)));
+    }
+
+  if (g_getenv ("GEGL_QUALITY"))
+    {
+      const gchar *quality = g_getenv ("GEGL_QUALITY");
+      GCallback fast      = NULL;
+      GCallback good      = NULL;
+      GCallback reference = NULL;
+
+      for (i=0;i<MAX_PROCESSOR;i++)
+        {
+          const gchar *string = cclass->processor_string[i];
+          GCallback    cb     = cclass->processor[i];
+
+          if (string && cb!=NULL)
+            {
+              if (g_str_equal (string, "fast"))
+                fast = cb;
+              else if (g_str_equal (string, "good"))
+                good = cb;
+              else if (g_str_equal (string, "reference"))
+                reference = cb;
+            }
+        }
+
+      g_assert (reference);
+      if (g_str_equal (quality, "fast"))
+        {
+          g_print ("Setting %s processor for %s\n", fast?"fast":good?"good":"reference",
+           g_type_name (G_TYPE_FROM_CLASS (cclass)));
+          PROCESS_VFUNC = fast?fast:good?good:reference;
+        }
+      else if (g_str_equal (quality, "good"))
+        {
+          g_print ("Setting %s processor for %s\n", good?"good":"reference",
+           g_type_name (G_TYPE_FROM_CLASS (cclass)));
+          PROCESS_VFUNC = good?good:reference;
+        }
+        /* best */
+    }
+}

Modified: trunk/gegl/operation/gegl-operation.h
==============================================================================
--- trunk/gegl/operation/gegl-operation.h	(original)
+++ trunk/gegl/operation/gegl-operation.h	Thu Apr 17 22:24:42 2008
@@ -62,6 +62,12 @@
  * See <a href='gegl-plugin.h.html'>gegl-plugin.h</a> for details.
  */
 
+#define MAX_PROCESSOR 4
+
+void gegl_operation_class_add_processor (GeglOperationClass *cclass,
+                                         GCallback           process,
+                                         const gchar        *string);
+
 struct _GeglOperationClass
 {
   GObjectClass    parent_class;
@@ -132,6 +138,10 @@
   GeglNode*     (*detect)                    (GeglOperation       *operation,
                                               gint                 x,
                                               gint                 y);
+
+
+  GCallback      processor[MAX_PROCESSOR];
+  gchar          *processor_string[MAX_PROCESSOR];
 };
 
 

Modified: trunk/operations/common/invert.c
==============================================================================
--- trunk/operations/common/invert.c	(original)
+++ trunk/operations/common/invert.c	Thu Apr 17 22:24:42 2008
@@ -53,6 +53,39 @@
   return TRUE;
 }
 
+
+static gboolean
+process_fast (GeglOperation *op,
+              void          *in_buf,
+              void          *out_buf,
+              glong          samples)
+{
+  glong   i;
+  gfloat *in  = in_buf;
+  gfloat *out = out_buf;
+
+  for (i=0; i<samples; i++)
+    {
+      int  j;
+      for (j=0; j<3; j++)
+        {
+          gfloat c;
+          c = in[j];
+          c = 1.0 - c;
+          if (i%2)
+            out[j] = c;
+          else
+            out[j] = (c - 0.5) * 2.0 + 0.5;
+        }
+      out[3]=in[3];
+      in += 4;
+      out+= 4;
+    }
+  return TRUE;
+}
+
+
+
 static void
 gegl_chant_class_init (GeglChantClass *klass)
 {
@@ -69,6 +102,10 @@
   operation_class->description =
      "Inverts the components (except alpha), the result is the"
      " corresponding \"negative\" image.";
+
+  g_print ("hi\n");
+  gegl_operation_class_add_processor (operation_class,
+                                      G_CALLBACK (process_fast), "fast");
 }
 
 #endif



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