[gegl] operations: Add "gegl:gegl-buffer-save/load" ops



commit 4143031b2c1eac276cffe3fe999cf287578b2677
Author: Martin Nordholts <martinn src gnome org>
Date:   Fri May 14 18:57:09 2010 +0200

    operations: Add "gegl:gegl-buffer-save/load" ops
    
    Add "gegl:gegl-buffer-save" and "gegl:gegl-buffer-load". Register
    these as both save and load handlers, so that you can do
    
      $ gegl clones.xml -o clones.gegl
    
    to create a GeglBuffer output, and then
    
      $ gegl clones.gegl
    
    to display the GeglBuffer.

 operations/common/gegl-buffer-load-op.c |   91 +++++++++++++++++++++++++++++++
 operations/common/gegl-buffer-save-op.c |   65 ++++++++++++++++++++++
 2 files changed, 156 insertions(+), 0 deletions(-)
---
diff --git a/operations/common/gegl-buffer-load-op.c b/operations/common/gegl-buffer-load-op.c
new file mode 100644
index 0000000..afffdca
--- /dev/null
+++ b/operations/common/gegl-buffer-load-op.c
@@ -0,0 +1,91 @@
+/* This file is an image processing operation for 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 2010 Martin Nordholts <martinn src gnome org>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+gegl_chant_file_path (path, _("File"), "/tmp/gegl-buffer.gegl", _("Path of GeglBuffer file to load."))
+
+#else
+
+#define GEGL_CHANT_TYPE_SOURCE
+#define GEGL_CHANT_C_FILE       "gegl-buffer-load-op.c"
+
+#include "gegl-chant.h"
+
+
+static void
+gegl_buffer_load_op_ensure_buffer (GeglChantO *o)
+{
+  if (!o->chant_data)
+    o->chant_data = gegl_buffer_load (o->path);
+}
+
+static GeglRectangle
+gegl_buffer_load_op_get_bounding_box (GeglOperation *operation)
+{
+  GeglRectangle  result = { 0, 0, 0, 0 };
+  GeglChantO    *o      = GEGL_CHANT_PROPERTIES (operation);
+
+  gegl_buffer_load_op_ensure_buffer (o);
+
+  if (o->chant_data)
+    {
+      result.width  = gegl_buffer_get_width  (GEGL_BUFFER (o->chant_data));
+      result.height = gegl_buffer_get_height (GEGL_BUFFER (o->chant_data));
+    }
+
+  return result;
+}
+
+static gboolean
+gegl_buffer_load_op_process (GeglOperation        *operation,
+                             GeglOperationContext *context,
+                             const gchar          *output_pad,
+                             const GeglRectangle  *result)
+{
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+
+  gegl_buffer_load_op_ensure_buffer (o);
+
+  gegl_operation_context_take_object (context, output_pad, o->chant_data);
+  o->chant_data = NULL;
+
+  return TRUE;
+}
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+  GeglOperationClass *operation_class;
+
+  operation_class = GEGL_OPERATION_CLASS (klass);
+
+  operation_class->process          = gegl_buffer_load_op_process;
+  operation_class->get_bounding_box = gegl_buffer_load_op_get_bounding_box;
+
+  operation_class->name        = "gegl:gegl-buffer-load";
+  operation_class->categories  = "hidden";
+  operation_class->description = _("GeglBuffer file loader.");
+
+  gegl_extension_handler_register (".gegl", "gegl:gegl-buffer-load");
+}
+
+#endif
diff --git a/operations/common/gegl-buffer-save-op.c b/operations/common/gegl-buffer-save-op.c
new file mode 100644
index 0000000..55b88ae
--- /dev/null
+++ b/operations/common/gegl-buffer-save-op.c
@@ -0,0 +1,65 @@
+/* This file is an image processing operation for 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 2010 Martin Nordholts <martinn src gnome org>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+gegl_chant_file_path (path, _("File"), "/tmp/gegl-buffer.gegl", _("Target file path to write GeglBuffer to."))
+
+#else
+
+#define GEGL_CHANT_TYPE_SINK
+#define GEGL_CHANT_C_FILE       "gegl-buffer-save-op.c"
+
+#include "gegl-chant.h"
+
+
+static gboolean
+gegl_buffer_save_op_process (GeglOperation       *operation,
+                             GeglBuffer          *input,
+                             const GeglRectangle *result)
+{
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+
+  gegl_buffer_save (input, o->path, result);
+
+  return TRUE;
+}
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+  GeglOperationClass     *operation_class;
+  GeglOperationSinkClass *sink_class;
+
+  operation_class = GEGL_OPERATION_CLASS (klass);
+  sink_class      = GEGL_OPERATION_SINK_CLASS (klass);
+
+  sink_class->process    = gegl_buffer_save_op_process;
+  sink_class->needs_full = TRUE;
+
+  operation_class->name        = "gegl:gegl-buffer-save";
+  operation_class->categories  = "hidden";
+  operation_class->description = _("GeglBuffer file writer.");
+
+  gegl_extension_handler_register_saver (".gegl", "gegl:gegl-buffer-save");
+}
+
+#endif



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