[gegl/soc-2010-cage] add an operation that sample input with an auxiliar buffer that contain source coordinates
- From: Michael Muré <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2010-cage] add an operation that sample input with an auxiliar buffer that contain source coordinates
- Date: Mon, 2 Aug 2010 10:08:38 +0000 (UTC)
commit 58e03a190eed5dfa53584bad3c23317a3006d0bc
Author: Michael Muré <batolettre gmail com>
Date: Mon Aug 2 12:07:55 2010 +0200
add an operation that sample input with an auxiliar buffer that contain source coordinates
operations/common/render_mapping.c | 133 ++++++++++++++++++++++++++++++++++++
1 files changed, 133 insertions(+), 0 deletions(-)
---
diff --git a/operations/common/render_mapping.c b/operations/common/render_mapping.c
new file mode 100644
index 0000000..4e8f9d5
--- /dev/null
+++ b/operations/common/render_mapping.c
@@ -0,0 +1,133 @@
+/* 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 Michael Muré <batolettre gmail com>
+ *
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#include <gegl.h>
+#include <gegl-plugin.h>
+#include <gegl-utils.h>
+#include "buffer/gegl-sampler.h"
+#include "buffer/gegl-buffer-iterator.h"
+
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+#else
+
+#define GEGL_CHANT_TYPE_POINT_COMPOSER
+#define GEGL_CHANT_C_FILE "render_mapping.c"
+
+#include "gegl-chant.h"
+
+
+static void prepare (GeglOperation *operation)
+{
+ Babl *format = babl_format ("RGBA float");
+
+ gegl_operation_set_format (operation, "input", format);
+ gegl_operation_set_format (operation, "aux", babl_format_n (babl_type ("float"), 2));
+ gegl_operation_set_format (operation, "output", format);
+}
+
+static gboolean
+process (GeglOperation *operation,
+ GeglBuffer *input,
+ GeglBuffer *aux,
+ GeglBuffer *output,
+ const GeglRectangle *result)
+{
+ Babl *format_io, *format_coords;
+ GeglSampler *sampler;
+ GType desired_type;
+ GeglInterpolation interpolation;
+ GeglBufferIterator *it;
+ gint index_out, index_coords;
+
+ format_io = babl_format ("RGBA float");
+ format_coords = babl_format_n (babl_type ("float"), 2);
+
+ interpolation = gegl_buffer_interpolation_from_string ("cubic");
+ desired_type = gegl_sampler_type_from_interpolation (interpolation);
+
+ sampler = g_object_new (desired_type,
+ "format", format_io,
+ "buffer", input,
+ NULL);
+
+ gegl_sampler_prepare (sampler);
+
+ if (aux != NULL)
+ {
+ it = gegl_buffer_iterator_new (output, result, format_io, GEGL_BUFFER_WRITE);
+ index_out = 0;
+
+ index_coords = gegl_buffer_iterator_add (it, aux, result, format_coords, GEGL_BUFFER_READ);
+
+ while (gegl_buffer_iterator_next (it))
+ {
+ gint i;
+ gint n_pixels = it->length;
+ gfloat *out = it->data[index_out];
+ gfloat *coords = it->data[index_coords];
+ gfloat *sample;
+
+ for (i=0; i<n_pixels; i++)
+ {
+ sample = gegl_sampler_get_from_buffer (sampler, coords[0], coords[1]);
+
+ out[0] = sample[0];
+ out[1] = sample[1];
+ out[2] = sample[2];
+ out[3] = sample[3];
+
+ coords += 2;
+ out += 4;
+ }
+ }
+
+ }
+ else
+ {
+ gegl_buffer_copy (input, result, output, result);
+ }
+
+ g_object_unref (sampler);
+
+ return TRUE;
+}
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+ GeglOperationClass *operation_class;
+ GeglOperationComposerClass *composer_class;
+
+ operation_class = GEGL_OPERATION_CLASS (klass);
+ composer_class = GEGL_OPERATION_COMPOSER_CLASS (klass);
+
+ composer_class->process = process;
+ operation_class->prepare = prepare;
+
+ operation_class->name = "gegl:render_mapping";
+
+ operation_class->categories = "transform";
+ operation_class->description = _("sample input with an auxiliar buffer that contain source coordinates");
+}
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]