[gimp/soc-2010-cage] gimpoperationcage: the gegl op now do a transformation, with cage vertices hardcoded



commit 60c47d2ded6683bfcbcca8f7ca7f5c2bafd3688b
Author: Michael Muré <batolettre gmail com>
Date:   Wed Jul 14 23:56:28 2010 +0200

    gimpoperationcage: the gegl op now do a transformation, with cage vertices hardcoded

 app/Makefile.am              |    9 ++-
 app/gegl/gimpoperationcage.c |  162 +++++++++++++++++++++++++++++++++--------
 app/gegl/gimpoperationcage.h |    5 ++
 3 files changed, 143 insertions(+), 33 deletions(-)
---
diff --git a/app/Makefile.am b/app/Makefile.am
index ebebdd3..7906900 100644
--- a/app/Makefile.am
+++ b/app/Makefile.am
@@ -134,6 +134,12 @@ workaround_that_file_depends_on_plug_in = \
 	-u $(SYMPREFIX)plug_in_icc_profile_apply_rgb	\
 	-u $(SYMPREFIX)gimp_image_map_config_get_type
 
+# FIXME: for test only
+workaround_to_test_cage = \
+	-u $(SYMPREFIX)gimp_cage_get_type \
+	-u $(SYMPREFIX)gimp_cage_add_cage_point \
+	-u $(SYMPREFIX)gimp_cage_compute_coefficient
+
 # core, vectors and gegl are on the same architectural layer, prevent
 # the linker from panicing
 calm_down_linker = \
@@ -149,7 +155,8 @@ AM_LDFLAGS = \
 	$(workaround_that_core_depends_on_xcf)		\
 	$(workaround_that_core_depends_on_pdb)		\
 	$(workaround_that_plug_in_depends_on_pdb)	\
-	$(workaround_that_file_depends_on_plug_in)
+	$(workaround_that_file_depends_on_plug_in)	\
+	$(workaround_to_test_cage)
 
 gimpconsoleldadd = \
 	xcf/libappxcf.a			\
diff --git a/app/gegl/gimpoperationcage.c b/app/gegl/gimpoperationcage.c
index 1efe2de..64c48e8 100644
--- a/app/gegl/gimpoperationcage.c
+++ b/app/gegl/gimpoperationcage.c
@@ -26,9 +26,6 @@
 #include "libgimpcolor/gimpcolor.h"
 #include "libgimpmath/gimpmath.h"
 
-
-#include "core/gimpcage.h"
-
 #include "gimpoperationcage.h"
 
 
@@ -54,12 +51,12 @@ gimp_operation_cage_class_init (GimpOperationCageClass *klass)
   operation_class = GEGL_OPERATION_CLASS (klass);
   filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
 
-  //FIXME: wrong categories and name, to appears in the gegl tool
-  operation_class->name        = "gegl:cage";
-  operation_class->categories  = "color";
-  operation_class->description = "GIMP cage transform";
+  /* FIXME: wrong categories and name, to appears in the gegl tool */
+  operation_class->name         = "gegl:cage";
+  operation_class->categories   = "color";
+  operation_class->description  = "GIMP cage transform";
 
-  operation_class->prepare = gimp_operation_cage_prepare;
+  operation_class->prepare      = gimp_operation_cage_prepare;
   
   filter_class->process         = gimp_operation_cage_process;
 }
@@ -67,6 +64,65 @@ gimp_operation_cage_class_init (GimpOperationCageClass *klass)
 static void
 gimp_operation_cage_init (GimpOperationCage *self)
 {
+  //FIXME: for test
+  self->cage = g_object_new (GIMP_TYPE_CAGE, NULL);
+  self->deformedCage = g_object_new (GIMP_TYPE_CAGE, NULL);
+  
+  #if 0
+  
+    #if 1
+    gimp_cage_add_cage_point(self->cage, 20, 20);
+    gimp_cage_add_cage_point(self->cage, 50, 50);
+    gimp_cage_add_cage_point(self->cage, 200, 80);
+    gimp_cage_add_cage_point(self->cage, 70, 200);
+    gimp_cage_add_cage_point(self->cage, 25, 80);
+    #else
+    gimp_cage_add_cage_point(self->cage, 25, 80);
+    gimp_cage_add_cage_point(self->cage, 70, 200);
+    gimp_cage_add_cage_point(self->cage, 200, 80);
+    gimp_cage_add_cage_point(self->cage, 50, 50);
+    gimp_cage_add_cage_point(self->cage, 20, 20);
+    #endif
+  
+  #else
+  
+    #if 0
+    gimp_cage_add_cage_point(self->cage, 20, 20); /* need reverse */
+    gimp_cage_add_cage_point(self->cage, 50, 20);
+    gimp_cage_add_cage_point(self->cage, 50, 60);
+    gimp_cage_add_cage_point(self->cage, 80, 60);
+    gimp_cage_add_cage_point(self->cage, 80, 20);
+    gimp_cage_add_cage_point(self->cage, 110, 20);
+    gimp_cage_add_cage_point(self->cage, 110, 120);
+    gimp_cage_add_cage_point(self->cage, 20, 120);
+    #else
+    gimp_cage_add_cage_point(self->cage, 40, 240);
+    gimp_cage_add_cage_point(self->cage, 220, 240);
+    gimp_cage_add_cage_point(self->cage, 220, 40);
+    gimp_cage_add_cage_point(self->cage, 160, 40);
+    gimp_cage_add_cage_point(self->cage, 160, 120);
+    gimp_cage_add_cage_point(self->cage, 100, 120);
+    gimp_cage_add_cage_point(self->cage, 100, 40);
+    gimp_cage_add_cage_point(self->cage, 40, 40);
+    
+    gimp_cage_add_cage_point(self->deformedCage, 40, 240);
+    gimp_cage_add_cage_point(self->deformedCage, 320, 320);
+    gimp_cage_add_cage_point(self->deformedCage, 220, 40);
+    gimp_cage_add_cage_point(self->deformedCage, 160, 40);
+    gimp_cage_add_cage_point(self->deformedCage, 160, 120);
+    gimp_cage_add_cage_point(self->deformedCage, 100, 120);
+    gimp_cage_add_cage_point(self->deformedCage, 100, 40);
+    gimp_cage_add_cage_point(self->deformedCage, 40, 40);
+    #endif
+    
+  #endif
+}
+
+static void
+gimp_operation_cage_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
@@ -75,46 +131,88 @@ gimp_operation_cage_process (GeglOperation       *operation,
                              GeglBuffer          *out_buf,
                              const GeglRectangle *roi)
 {
-  GeglBufferIterator *i;
-  Babl *format = babl_format ("RGBA float");
+  GimpOperationCage *op_cage  = GIMP_OPERATION_CAGE (operation);
+  GimpCage *cage = op_cage->cage;
+  GimpCage *deformedCage = op_cage->deformedCage;
+  
+  Babl *format_io = babl_format ("RGBA float");
+  Babl *format_coef = babl_format_n (babl_type ("float"), op_cage->cage->cage_vertice_number);
+  
+  gint in, coef_vertices, coef_edges;
+  gint i;
+  GeglRectangle rect;
+  GeglBufferIterator *it;
+  
+  rect.height = 1;
+  rect.width = 1;
   
-  i = gegl_buffer_iterator_new (out_buf, roi, format, GEGL_BUFFER_WRITE);
+  cage->extent.height = roi->height;
+  cage->extent.width = roi->width;
+  cage->extent.x = roi->x;
+  cage->extent.y = roi->y;
+  gimp_cage_compute_coefficient (cage);
   
-  //iterate on GeglBuffer
-  while (gegl_buffer_iterator_next (i))
+  it = gegl_buffer_iterator_new (in_buf, roi, format_io, GEGL_BUFFER_READ);
+  in = 0;
+  
+  coef_vertices = gegl_buffer_iterator_add (it, cage->cage_vertices_coef, roi, format_coef, GEGL_BUFFER_READ);
+  coef_edges = gegl_buffer_iterator_add (it, cage->cage_edges_coef, roi, format_coef, GEGL_BUFFER_READ);
+  
+  /* iterate on GeglBuffer */
+  while (gegl_buffer_iterator_next (it))
   {
-    //iterate inside the roi
-    gint        n_pixels = i->length;
-    gint        x = i->roi->x; /* initial x                   */
-    gint        y = i->roi->y; /*           and y coordinates */
+    /* iterate inside the roi */
+    gint        n_pixels = it->length;
+    gint        x = it->roi->x; /* initial x                   */
+    gint        y = it->roi->y; /*           and y coordinates */
     
-    gfloat      *dest = i->data[0];
+    gfloat      *source = it->data[in];
+    gfloat      *coef_v = it->data[coef_vertices];
+    gfloat      *coef_e = it->data[coef_edges];
     
     while(n_pixels--)
     {
-      dest[RED]   = 1.0;
-      dest[GREEN] = 0.0;
-      dest[BLUE]  = 1.0;
-      dest[ALPHA] = 1.0;
+      /* computing of the final position of the source pixel */
+      gfloat pos_x, pos_y;
+      
+      pos_x = 0;
+      pos_y = 0;
+      
+      for(i = 0; i < deformedCage->cage_vertice_number; i++)
+      {
+        pos_x += coef_v[i] * deformedCage->cage_vertices[i].x;
+        pos_y += coef_v[i] * deformedCage->cage_vertices[i].y;
+      }
+      
+      for(i = 0; i < deformedCage->cage_vertice_number; i++)
+      {
+        pos_x += coef_e[i] * gimp_cage_get_edge_normal (deformedCage, i).x;
+        pos_y += coef_e[i] * gimp_cage_get_edge_normal (deformedCage, i).y;
+      }
       
-      dest += 4;
+      rect.x = pos_x;
+      rect.y = pos_y;      
+      
+      /* copy the source pixel in the out buffer */
+      gegl_buffer_set(out_buf,
+                      &rect,
+                      format_io,
+                      source,
+                      GEGL_AUTO_ROWSTRIDE);
+      
+      source += 4;
+      coef_v += op_cage->cage->cage_vertice_number;
+      coef_e += op_cage->cage->cage_vertice_number;
       
       /* update x and y coordinates */
       x++;
-      if (x >= (i->roi->x + i->roi->width))
+      if (x >= (it->roi->x + it->roi->width))
       {
-        x = i->roi->x;
+        x = it->roi->x;
         y++;
       }
       
     }
   }
   return TRUE;
-}
-
-static void
-gimp_operation_cage_prepare (GeglOperation  *operation)
-{
-  gegl_operation_set_format (operation, "input", babl_format ("RGBA float"));
-  gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
 }
\ No newline at end of file
diff --git a/app/gegl/gimpoperationcage.h b/app/gegl/gimpoperationcage.h
index ea7c7d6..a998447 100644
--- a/app/gegl/gimpoperationcage.h
+++ b/app/gegl/gimpoperationcage.h
@@ -22,6 +22,7 @@
 
 #include <gegl-plugin.h>
 #include <operation/gegl-operation-filter.h>
+#include "core/gimpcage.h"
 
 #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,6 +37,10 @@ typedef struct _GimpOperationCageClass GimpOperationCageClass;
 struct _GimpOperationCage
 {
   GeglOperationFilter  parent_instance;
+  
+  /* FIXME: for test */
+  GimpCage             *cage;
+  GimpCage             *deformedCage;
 };
 
 struct _GimpOperationCageClass



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