[gegl] ditto: An op to help test sampling of map ops



commit 60012f4e951ba74390ca414a6da5e7d1752b1c13
Author: Mukund Sivaraman <muks banu com>
Date:   Mon Sep 5 18:33:28 2011 +0530

    ditto: An op to help test sampling of map ops

 operations/workshop/ditto.c |  112 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/operations/workshop/ditto.c b/operations/workshop/ditto.c
new file mode 100644
index 0000000..b7b6cb4
--- /dev/null
+++ b/operations/workshop/ditto.c
@@ -0,0 +1,112 @@
+/* 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 2011 Michael Murà <batolettre gmail com>
+ * Copyright 2011 Robert Sasu <sasu robert gmail com>
+ * Copyright 2011 Hans Lo <hansshulo gmail com>
+ * Copyright 1997 Brian Degenhardt <bdegenha ucsd edu>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
+                 GEGL_SAMPLER_CUBIC, _("Sampler used internally"))
+
+#else
+
+#define GEGL_CHANT_TYPE_AREA_FILTER
+#define GEGL_CHANT_C_FILE       "ditto.c"
+
+#include "gegl-chant.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+static void prepare (GeglOperation *operation)
+{
+  gegl_operation_set_format (operation, "input",
+                             babl_format ("RGBA float"));
+  gegl_operation_set_format (operation, "output",
+                             babl_format ("RGBA float"));
+}
+
+static gboolean
+process (GeglOperation       *operation,
+         GeglBuffer          *input,
+         GeglBuffer          *output,
+         const GeglRectangle *result)
+{
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+
+  gint x = result->x; /* initial x                   */
+  gint y = result->y; /*           and y coordinates */
+
+  gfloat *dst_buf = g_slice_alloc (result->width * result->height * 4 * sizeof (float));
+  gfloat *out_pixel = dst_buf;
+
+  GeglSampler *sampler = gegl_buffer_sampler_new (input,
+                                                  babl_format ("RGBA float"),
+                                                  o->sampler_type);
+
+  gint n_pixels = result->width * result->height;
+
+  while (n_pixels--)
+    {
+      gegl_sampler_get (sampler,
+                        x,
+                        y,
+                        NULL,
+                        out_pixel);
+
+      out_pixel += 4;
+
+      /* update x and y coordinates */
+      x++;
+      if (x>=result->x + result->width)
+        {
+          x=result->x;
+          y++;
+        }
+    }
+
+  gegl_buffer_set (output, result, babl_format ("RGBA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
+  g_slice_free1 (result->width * result->height * 4 * sizeof(gfloat), dst_buf);
+
+  g_object_unref (sampler);
+
+  return  TRUE;
+}
+
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+  GeglOperationClass       *operation_class;
+  GeglOperationFilterClass *filter_class;
+
+  operation_class = GEGL_OPERATION_CLASS (klass);
+  filter_class    = GEGL_OPERATION_FILTER_CLASS (klass);
+
+  filter_class->process    = process;
+  operation_class->prepare = prepare;
+
+  operation_class->categories  = "distort";
+  operation_class->name        = "gegl:ditto";
+  operation_class->description = _("Test op to do a 1:1 map of input to output, while sampling");
+}
+
+#endif



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