[gimp/soc-2010-cage] gimpoperationcage: now inherit from GeglOperationComposer, to have an aux buffer for the coef
- From: Michael Muré <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2010-cage] gimpoperationcage: now inherit from GeglOperationComposer, to have an aux buffer for the coef
- Date: Mon, 26 Jul 2010 17:25:05 +0000 (UTC)
commit e4c77bf97e8e2ef4f39564716e8ffebc999d2a67
Author: Michael Muré <mure michael gmail com>
Date: Mon Jul 26 19:17:49 2010 +0200
gimpoperationcage: now inherit from GeglOperationComposer, to have an aux buffer for the coef
app/gegl/gimpoperationcage.c | 223 +++++++++++++++++++++++------------------
app/gegl/gimpoperationcage.h | 16 ++-
2 files changed, 135 insertions(+), 104 deletions(-)
---
diff --git a/app/gegl/gimpoperationcage.c b/app/gegl/gimpoperationcage.c
index 755f4b4..24ac40e 100644
--- a/app/gegl/gimpoperationcage.c
+++ b/app/gegl/gimpoperationcage.c
@@ -27,24 +27,32 @@
#include "libgimpmath/gimpmath.h"
#include "gimpoperationcage.h"
+#include "gimpcageconfig.h"
-// FIXME: for test
-#include <stdio.h>
+static void gimp_operation_cage_finalize (GObject *object);
+static void gimp_operation_cage_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gimp_operation_cage_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gimp_operation_cage_prepare (GeglOperation *operation);
static gboolean gimp_operation_cage_process (GeglOperation *operation,
GeglBuffer *in_buf,
+ GeglBuffer *aux_buf,
GeglBuffer *out_buf,
const GeglRectangle *roi);
-static void gimp_operation_cage_prepare (GeglOperation *operation);
GeglRectangle gimp_operation_cage_get_cached_region (GeglOperation *operation,
const GeglRectangle *roi);
-GeglRectangle
-gimp_operation_cage_get_required_for_output (GeglOperation *operation,
- const gchar *input_pad,
- const GeglRectangle *roi);
+GeglRectangle gimp_operation_cage_get_required_for_output (GeglOperation *operation,
+ const gchar *input_pad,
+ const GeglRectangle *roi);
G_DEFINE_TYPE (GimpOperationCage, gimp_operation_cage,
- GEGL_TYPE_OPERATION_FILTER)
+ GEGL_TYPE_OPERATION_COMPOSER)
#define parent_class gimp_operation_cage_parent_class
@@ -52,11 +60,13 @@ G_DEFINE_TYPE (GimpOperationCage, gimp_operation_cage,
static void
gimp_operation_cage_class_init (GimpOperationCageClass *klass)
{
- GeglOperationClass *operation_class;
- GeglOperationFilterClass *filter_class;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
+ GeglOperationComposerClass *composer_class = GEGL_OPERATION_COMPOSER_CLASS (klass);
- operation_class = GEGL_OPERATION_CLASS (klass);
- filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
+ object_class->get_property = gimp_operation_cage_get_property;
+ object_class->set_property = gimp_operation_cage_set_property;
+ object_class->finalize = gimp_operation_cage_finalize;
/* FIXME: wrong categories and name, to appears in the gegl tool */
operation_class->name = "gegl:cage";
@@ -69,69 +79,80 @@ gimp_operation_cage_class_init (GimpOperationCageClass *klass)
operation_class->get_cached_region = gimp_operation_cage_get_cached_region;
operation_class->no_cache = FALSE;
- filter_class->process = gimp_operation_cage_process;
+ composer_class->process = gimp_operation_cage_process;
+
+ g_object_class_install_property (object_class,
+ GIMP_OPERATION_CAGE_PROP_CONFIG,
+ g_param_spec_object ("config", NULL, NULL,
+ GIMP_TYPE_CAGE_CONFIG,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
}
static void
gimp_operation_cage_init (GimpOperationCage *self)
{
- //FIXME: for test
- self->cage = g_object_new (GIMP_TYPE_CAGE, NULL);
-
- #if 0
-
- #if 0
- gimp_cage_add_cage_point(self->cage, 70, 20);
- gimp_cage_add_cage_point(self->cage, 70, 300);
- gimp_cage_add_cage_point(self->cage, 450, 300);
- gimp_cage_add_cage_point(self->cage, 450, 20);
-
- gimp_cage_move_cage_point_d (self->cage, 1, 100, 250);
-
- #else
-
- gimp_cage_add_cage_point(self->cage, 450, 20); /* need reverse */
- gimp_cage_add_cage_point(self->cage, 450, 300);
- gimp_cage_add_cage_point(self->cage, 70, 300);
- gimp_cage_add_cage_point(self->cage, 70, 20);
-
- gimp_cage_move_cage_point_d (self->cage, 2, 100, 250);
- gimp_cage_move_cage_point_d (self->cage, 1, 750, 550);
- #endif
-
- #else
-
- #if 1
- gimp_cage_add_cage_point(self->cage, 160, 160); /* need reverse */
- gimp_cage_add_cage_point(self->cage, 250, 160);
- gimp_cage_add_cage_point(self->cage, 250, 280);
- gimp_cage_add_cage_point(self->cage, 340, 280);
- gimp_cage_add_cage_point(self->cage, 340, 160);
- gimp_cage_add_cage_point(self->cage, 430, 160);
- gimp_cage_add_cage_point(self->cage, 430, 460);
- gimp_cage_add_cage_point(self->cage, 160, 460);
-
- //gimp_cage_move_cage_point_d (self->cage, 6, 500, 500);
-
- #else
-
- gimp_cage_add_cage_point(self->cage, 160, 460);
- gimp_cage_add_cage_point(self->cage, 430, 460);
- gimp_cage_add_cage_point(self->cage, 430, 160);
- gimp_cage_add_cage_point(self->cage, 340, 160);
- gimp_cage_add_cage_point(self->cage, 340, 280);
- gimp_cage_add_cage_point(self->cage, 250, 280);
- gimp_cage_add_cage_point(self->cage, 250, 160);
- gimp_cage_add_cage_point(self->cage, 160, 160);
-
- gimp_cage_move_cage_point_d (self->cage, 1, 500, 500);
-
- #endif
-
- #endif
+
+}
+
+static void
+gimp_operation_cage_finalize (GObject *object)
+{
+ GimpOperationCage *self = GIMP_OPERATION_CAGE (object);
+
+ if (self->config)
+ {
+ g_object_unref (self->config);
+ self->config = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
+gimp_operation_cage_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GimpOperationCage *self = GIMP_OPERATION_CAGE (object);
+
+ switch (property_id)
+ {
+ case GIMP_OPERATION_CAGE_PROP_CONFIG:
+ g_value_set_object (value, self->config);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gimp_operation_cage_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GimpOperationCage *self = GIMP_OPERATION_CAGE (object);
+
+ switch (property_id)
+ {
+ case GIMP_OPERATION_CAGE_PROP_CONFIG:
+ if (self->config)
+ g_object_unref (self->config);
+ self->config = g_value_dup_object (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
gimp_operation_cage_prepare (GeglOperation *operation)
{
gegl_operation_set_format (operation, "input", babl_format ("RGBA float"));
@@ -141,35 +162,35 @@ gimp_operation_cage_prepare (GeglOperation *operation)
static gboolean
gimp_operation_cage_process (GeglOperation *operation,
GeglBuffer *in_buf,
+ GeglBuffer *aux_buf,
GeglBuffer *out_buf,
const GeglRectangle *roi)
{
- GimpOperationCage *op_cage = GIMP_OPERATION_CAGE (operation);
- GimpCage *cage = op_cage->cage;
+ GimpOperationCage *oc = GIMP_OPERATION_CAGE (operation);
+ GimpCageConfig *config = GIMP_CAGE_CONFIG (oc->config);
Babl *format_io = babl_format ("RGBA float");
- Babl *format_coef = babl_format_n (babl_type ("float"), op_cage->cage->cage_vertice_number);
+ Babl *format_coef = babl_format_n (babl_type ("float"), 2 * config->cage_vertice_number);
- gint in, coef_vertices, coef_edges;
+ gint in_index, coef_index, dest_index;
gint i;
- GeglRectangle rect;
+ GeglRectangle rect, bb_cage;
GeglBufferIterator *it;
rect.height = 1;
rect.width = 1;
- gimp_cage_compute_coefficient (cage);
+ bb_cage = gimp_cage_config_get_bounding_box (config);
- it = gegl_buffer_iterator_new (in_buf, roi, format_io, GEGL_BUFFER_READ);
- in = 0;
+ it = gegl_buffer_iterator_new (in_buf, &bb_cage, format_io, GEGL_BUFFER_READ);
+ in_index = 0;
- coef_vertices = gegl_buffer_iterator_add (it, cage->cage_vertices_coef, &cage->bounding_box, format_coef, GEGL_BUFFER_READ);
- coef_edges = gegl_buffer_iterator_add (it, cage->cage_edges_coef, &cage->bounding_box, format_coef, GEGL_BUFFER_READ);
-
+ coef_index = gegl_buffer_iterator_add (it, aux_buf, &bb_cage, format_coef, GEGL_BUFFER_READ);
+ dest_index = gegl_buffer_iterator_add (it, out_buf, &bb_cage, format_io, GEGL_BUFFER_WRITE);
/* pre-copy the input buffer to the out buffer */
- /*gegl_buffer_copy (in_buf, roi, out_buf, roi);*/
+ //gegl_buffer_copy (aux_buf, roi, out_buf, roi);
/* iterate on GeglBuffer */
while (gegl_buffer_iterator_next (it))
@@ -178,10 +199,11 @@ gimp_operation_cage_process (GeglOperation *operation,
gint n_pixels = it->length;
gint x = it->roi->x; /* initial x */
gint y = it->roi->y; /* and y coordinates */
+ gint cvn = config->cage_vertice_number;
- gfloat *source = it->data[in];
- gfloat *coef_v = it->data[coef_vertices];
- gfloat *coef_e = it->data[coef_edges];
+ gfloat *source = it->data[in_index];
+ gfloat *coef = it->data[coef_index];
+ gfloat *dest = it->data[dest_index];
while(n_pixels--)
{
@@ -191,16 +213,16 @@ gimp_operation_cage_process (GeglOperation *operation,
pos_x = 0;
pos_y = 0;
- for(i = 0; i < cage->cage_vertice_number; i++)
+ for(i = 0; i < cvn; i++)
{
- pos_x += coef_v[i] * cage->cage_vertices_d[i].x;
- pos_y += coef_v[i] * cage->cage_vertices_d[i].y;
+ pos_x += coef[i] * config->cage_vertices_d[i].x;
+ pos_y += coef[i] * config->cage_vertices_d[i].y;
}
- for(i = 0; i < cage->cage_vertice_number; i++)
+ for(i = 0; i < cvn; i++)
{
- pos_x += coef_e[i] * cage->scaling_factor[i] * gimp_cage_get_edge_normal (cage, i).x;
- pos_y += coef_e[i] * cage->scaling_factor[i] * gimp_cage_get_edge_normal (cage, i).y;
+ pos_x += coef[i + cvn] * config->scaling_factor[i] * gimp_cage_config_get_edge_normal (config, i).x;
+ pos_y += coef[i + cvn] * config->scaling_factor[i] * gimp_cage_config_get_edge_normal (config, i).y;
}
rect.x = (gint) rint(pos_x);
@@ -215,15 +237,20 @@ gimp_operation_cage_process (GeglOperation *operation,
}*/
/* copy the source pixel in the out buffer */
- gegl_buffer_set(out_buf,
- &rect,
- format_io,
- source,
- GEGL_AUTO_ROWSTRIDE);
+ //gegl_buffer_set(out_buf,
+ //&rect,
+ //format_io,
+ //source,
+ //GEGL_AUTO_ROWSTRIDE);
+ //printf("x: %d pos_x: %f y: %d pos_y: %f \n",x,pos_x,y,pos_y);
+
+ dest[RED] = coef[0];
+ dest[GREEN] = coef[1];
+ dest[BLUE] = coef[2]; //coef[2]; //(pos_x - x) / 500000;
+
source += 4;
- coef_v += cage->cage_vertice_number;
- coef_e += cage->cage_vertice_number;
+ coef += 2 * cvn;
/* update x and y coordinates */
x++;
@@ -249,10 +276,10 @@ gimp_operation_cage_get_cached_region (GeglOperation *operation,
GeglRectangle
gimp_operation_cage_get_required_for_output (GeglOperation *operation,
- const gchar *input_pad,
- const GeglRectangle *roi)
+ const gchar *input_pad,
+ const GeglRectangle *roi)
{
GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
return result;
-}
\ No newline at end of file
+}
diff --git a/app/gegl/gimpoperationcage.h b/app/gegl/gimpoperationcage.h
index 26e74a0..df2767c 100644
--- a/app/gegl/gimpoperationcage.h
+++ b/app/gegl/gimpoperationcage.h
@@ -21,8 +21,13 @@
#define __GIMP_OPERATION_CAGE_H__
#include <gegl-plugin.h>
-#include <operation/gegl-operation-filter.h>
-#include "core/gimpcage.h"
+#include <operation/gegl-operation-composer.h>
+
+enum
+{
+ GIMP_OPERATION_CAGE_PROP_0,
+ GIMP_OPERATION_CAGE_PROP_CONFIG
+};
#define GIMP_TYPE_OPERATION_CAGE (gimp_operation_cage_get_type ())
#define GIMP_OPERATION_CAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_CAGE, GimpOperationCage))
@@ -36,15 +41,14 @@ typedef struct _GimpOperationCageClass GimpOperationCageClass;
struct _GimpOperationCage
{
- GeglOperationFilter parent_instance;
+ GeglOperationComposer parent_instance;
- /* FIXME: for test */
- GimpCage *cage;
+ GimpCageConfig *config;
};
struct _GimpOperationCageClass
{
- GeglOperationFilterClass parent_class;
+ GeglOperationComposerClass parent_class;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]