[gimp/soc-2010-cage-2] solve the problem result cropped to the bounding box of the cage



commit 34b40a6c7efbdd6e4ed5212f4315c03366a109a0
Author: Michael Muré <batolettre gmail com>
Date:   Mon Aug 9 23:33:11 2010 +0200

    solve the problem result cropped to the bounding box of the cage

 app/gegl/gimpcageconfig.c             |    3 +-
 app/gegl/gimpoperationcagetransform.c |   54 ++++++++++--------
 app/gegl/gimpoperationcagetransform.h |   10 ++--
 app/tools/gimpcagetool.c              |  100 ++++++++++++++++++++++++---------
 app/tools/gimpcagetool.h              |    4 +-
 5 files changed, 115 insertions(+), 56 deletions(-)
---
diff --git a/app/gegl/gimpcageconfig.c b/app/gegl/gimpcageconfig.c
index 4d0f952..cac44c0 100644
--- a/app/gegl/gimpcageconfig.c
+++ b/app/gegl/gimpcageconfig.c
@@ -38,6 +38,7 @@
 
 #include "gimpcageconfig.h"
 
+
 G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config,
                          GIMP_TYPE_IMAGE_MAP_CONFIG,
                          G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
@@ -366,7 +367,7 @@ gimp_cage_config_reverse_cage_if_needed (GimpCageConfig *gcc)
     sum += z;
   }
   
-  /* sum > 0 mean a cage defined clockwise, so we reverse it */
+  /* sum > 0 mean a cage defined counter-clockwise, so we reverse it */
   if (sum > 0)
   {
     gimp_cage_config_reverse_cage (gcc);
diff --git a/app/gegl/gimpoperationcagetransform.c b/app/gegl/gimpoperationcagetransform.c
index bd5b915..6ed3a3d 100644
--- a/app/gegl/gimpoperationcagetransform.c
+++ b/app/gegl/gimpoperationcagetransform.c
@@ -41,6 +41,7 @@ static void           gimp_operation_cage_transform_set_property              (G
 static void           gimp_operation_cage_transform_prepare                   (GeglOperation       *operation);
 static gboolean       gimp_operation_cage_transform_process                   (GeglOperation       *operation,
                                                                                GeglBuffer          *in_buf,
+                                                                               GeglBuffer          *aux_buf,
                                                                                GeglBuffer          *out_buf,
                                                                                const GeglRectangle *roi);
 static void           gimp_operation_cage_transform_interpolate_source_coords_recurs  (GimpOperationCageTransform  *oct,
@@ -57,9 +58,10 @@ GeglRectangle         gimp_operation_cage_transform_get_cached_region         (G
 GeglRectangle         gimp_operation_cage_transform_get_required_for_output   (GeglOperation        *operation,
                                                                                const gchar         *input_pad,
                                                                                const GeglRectangle *roi);
-                                        
+GeglRectangle         gimp_operation_cage_get_bounding_box                    (GeglOperation *operation);
+
 G_DEFINE_TYPE (GimpOperationCageTransform, gimp_operation_cage_transform, 
-                      GEGL_TYPE_OPERATION_FILTER)
+                      GEGL_TYPE_OPERATION_COMPOSER)
 
 #define parent_class gimp_operation_cage_transform_parent_class
 
@@ -71,7 +73,7 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
 {
   GObjectClass                    *object_class     = G_OBJECT_CLASS (klass);
   GeglOperationClass              *operation_class  = GEGL_OPERATION_CLASS (klass);
-  GeglOperationFilterClass        *filter_class   = GEGL_OPERATION_FILTER_CLASS (klass);
+  GeglOperationComposerClass      *filter_class     = GEGL_OPERATION_COMPOSER_CLASS (klass);
 
   object_class->get_property          = gimp_operation_cage_transform_get_property;
   object_class->set_property          = gimp_operation_cage_transform_set_property;
@@ -87,6 +89,7 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
   operation_class->get_required_for_output = gimp_operation_cage_transform_get_required_for_output;
   operation_class->get_cached_region = gimp_operation_cage_transform_get_cached_region;
   operation_class->no_cache     = FALSE;
+  operation_class->get_bounding_box = gimp_operation_cage_get_bounding_box;
   
   filter_class->process         = gimp_operation_cage_transform_process;
   
@@ -174,6 +177,7 @@ gimp_operation_cage_transform_prepare (GeglOperation  *operation)
 static gboolean
 gimp_operation_cage_transform_process (GeglOperation       *operation,
                                        GeglBuffer          *in_buf,
+                                       GeglBuffer          *aux_buf,
                                        GeglBuffer          *out_buf,
                                        const GeglRectangle *roi)
 {
@@ -181,11 +185,12 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
   GimpCageConfig                *config = GIMP_CAGE_CONFIG (oct->config);
   
   gint x, y;
-  GeglRectangle bounding_box = gimp_cage_config_get_bounding_box (config);
+  GeglRectangle cage_bb = gimp_cage_config_get_bounding_box (config);
+  GeglRectangle buffer_bb = *gegl_operation_source_get_bounding_box (operation, "input");
   
-  for (x = bounding_box.x; x < bounding_box.x + bounding_box.width - 1; x++)
+  for (x = cage_bb.x; x < cage_bb.x + cage_bb.width - 1; x++)
   {
-    for (y = bounding_box.y; y < bounding_box.y + bounding_box.height - 1; y++)
+    for (y = cage_bb.y; y < cage_bb.y + cage_bb.height - 1; y++)
     {
       GimpCoords p1_s = {x, y, };
       GimpCoords p2_s = {x+1, y, };
@@ -194,21 +199,21 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
       
       GimpCoords p1_d, p2_d, p3_d, p4_d;
       
-      p1_d = gimp_cage_transform_compute_destination (config, in_buf, p1_s);
-      p2_d = gimp_cage_transform_compute_destination (config, in_buf, p2_s);
-      p3_d = gimp_cage_transform_compute_destination (config, in_buf, p3_s);
-      p4_d = gimp_cage_transform_compute_destination (config, in_buf, p4_s);
+      p1_d = gimp_cage_transform_compute_destination (config, aux_buf, p1_s);
+      p2_d = gimp_cage_transform_compute_destination (config, aux_buf, p2_s);
+      p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
+      p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
       
       gimp_operation_cage_transform_interpolate_source_coords_recurs  (oct,
                                                                       out_buf,
-                                                                      roi,
+                                                                      &buffer_bb,
                                                                       p1_s, p1_d,
                                                                       p2_s, p2_d,
                                                                       p3_s, p3_d);
       
       gimp_operation_cage_transform_interpolate_source_coords_recurs  (oct,
                                                                       out_buf,
-                                                                      roi,
+                                                                      &buffer_bb,
                                                                       p1_s, p1_d,
                                                                       p3_s, p3_d,
                                                                       p4_s, p4_d);
@@ -362,8 +367,8 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs  (GimpOperationCa
 
 static GimpCoords
 gimp_cage_transform_compute_destination (GimpCageConfig *config,
-                                         GeglBuffer *coef_buf,
-                                         GimpCoords coords)
+                                         GeglBuffer     *coef_buf,
+                                         GimpCoords      coords)
 {
   gfloat     *coef;
   gdouble     pos_x, pos_y;
@@ -373,9 +378,6 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
   gint cvn = config->cage_vertice_number;
   Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn);
   
-  gfloat coefeu;
-  
-  
   rect.height = 1;
   rect.width = 1;
   rect.x = coords.x;
@@ -390,7 +392,6 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
   
   for(i = 0; i < cvn; i++)
   {
-    coefeu = coef[i];
     
     if (!isnan(coef[i]))
     {
@@ -404,7 +405,6 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
   
   for(i = 0; i < cvn; i++)
   {
-    coefeu = coef[i + cvn];
     
     if (!isnan(coef[i]))
     {
@@ -426,17 +426,25 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
 
 GeglRectangle
 gimp_operation_cage_transform_get_cached_region  (GeglOperation        *operation,
-                                                  const GeglRectangle *roi)
+                                                  const GeglRectangle  *roi)
 {
   GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
-  
+
   return result;
 }
 
 GeglRectangle
 gimp_operation_cage_transform_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;
+}
+
+GeglRectangle
+gimp_operation_cage_get_bounding_box  (GeglOperation *operation)
 {
   GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
   
diff --git a/app/gegl/gimpoperationcagetransform.h b/app/gegl/gimpoperationcagetransform.h
index f5c00bb..e31a52d 100644
--- a/app/gegl/gimpoperationcagetransform.h
+++ b/app/gegl/gimpoperationcagetransform.h
@@ -21,7 +21,7 @@
 #define __GIMP_OPERATION_CAGE_TRANSFORM_H__
 
 #include <gegl-plugin.h>
-#include <operation/gegl-operation-filter.h>
+#include <operation/gegl-operation-composer.h>
 
 enum
 {
@@ -41,15 +41,15 @@ typedef struct _GimpOperationCageTransformClass GimpOperationCageTransformClass;
 
 struct _GimpOperationCageTransform
 {
-  GeglOperationFilter  parent_instance;
+  GeglOperationComposer  parent_instance;
   
-  GimpCageConfig       *config;
-  Babl                 *format_coords;
+  GimpCageConfig        *config;
+  Babl                  *format_coords;
 };
 
 struct _GimpOperationCageTransformClass
 {
-  GeglOperationFilterClass  parent_class;
+  GeglOperationComposerClass  parent_class;
 };
 
 
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index 5e9a81e..5350a7e 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -43,6 +43,7 @@
 #include "core/gimpdrawable.h"
 #include "core/gimpdrawable-operation.h"
 #include "core/gimpdrawable-shadow.h"
+#include "core/gimpimagemap.h"
 #include "base/tile-manager.h"
 
 #include "widgets/gimphelp-ids.h"
@@ -102,6 +103,8 @@ static void         gimp_cage_tool_compute_coef   (GimpCageTool *ct,
                                                    GimpDisplay  *display);
 static void         gimp_cage_tool_process        (GimpCageTool *ct,
                                                    GimpDisplay  *display);
+static void         gimp_cage_tool_prepare_preview (GimpCageTool *ct,
+                                                   GimpDisplay  *display);
 
 G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL)
 
@@ -191,6 +194,8 @@ gimp_cage_tool_start (GimpCageTool       *ct,
   gimp_tool_control_activate (tool->control);
 
   tool->display = display;
+  
+  //gimp_cage_tool_prepare_preview (ct, display);
 
   gimp_draw_tool_start (draw_tool, display);
 }
@@ -218,6 +223,9 @@ gimp_cage_tool_halt (GimpCageTool *ct)
   
   gegl_buffer_destroy (ct->coef);
   ct->coef = NULL;
+  
+  //g_object_unref (ct->image_map);
+  //ct->image_map = NULL;
 }
 
 static void 
@@ -346,6 +354,12 @@ gimp_cage_tool_motion (GimpTool         *tool,
                                       coords->y);
   }
 
+/*  {
+    GeglRectangle rect = {0, 0, 300, 300};
+    gimp_image_map_apply (ct->image_map, &rect);
+  }*/
+  
+  
   gimp_draw_tool_resume (draw_tool);
 }
 
@@ -603,52 +617,54 @@ gimp_cage_tool_process (GimpCageTool *ct,
     GeglNode *coef, *cage, *render, *input, *output;
     
     input  = gegl_node_new_child (gegl,
-                              "operation",    "gimp:tilemanager-source",
-                              "tile-manager", gimp_drawable_get_tiles (drawable),
-                              "linear",       TRUE,
-                              NULL);
+                                  "operation",    "gimp:tilemanager-source",
+                                  "tile-manager", gimp_drawable_get_tiles (drawable),
+                                  "linear",       TRUE,
+                                  NULL);
 
     cage = gegl_node_new_child (gegl,
-                                  "operation", "gegl:cage_transform",
-                                  "config", ct->config,
-                                  NULL);
+                                "operation", "gegl:cage_transform",
+                                "config", ct->config,
+                                NULL);
     
     coef = gegl_node_new_child (gegl,
                                 "operation", "gegl:buffer-source",
                                 "buffer",    ct->coef,
                                 NULL);
 
-    gegl_node_connect_to (coef, "output",
-                          cage, "input");
-                          
     render = gegl_node_new_child (gegl,
                                   "operation", "gegl:render_mapping",
                                   NULL);
-    
-    gegl_node_connect_to (cage, "output",
-                          render, "aux");
-    
+
+    new_tiles = gimp_drawable_get_shadow_tiles (drawable);
+    output = gegl_node_new_child (gegl,
+                                  "operation",    "gimp:tilemanager-sink",
+                                  "tile-manager", new_tiles,
+                                  "linear",       TRUE,
+                                  NULL);
 
 /*    render = gegl_node_new_child (gegl,
                                   "operation", "gegl:debugit",
                                   NULL);*/
-    
+
+    gegl_node_connect_to (input, "output",
+                          cage, "input");
+
     gegl_node_connect_to (input, "output",
                           render, "input");
-                          
+
+    gegl_node_connect_to (coef, "output",
+                          cage, "aux");
+
+    gegl_node_connect_to (cage, "output",
+                          render, "aux");
+
+    gegl_node_connect_to (render, "output",
+                          output, "input");
+
 /*    gimp_drawable_apply_operation (drawable, progress, _("Cage transform"),
                                    render, TRUE);*/
     
-    new_tiles = gimp_drawable_get_shadow_tiles (drawable);
-    
-    output = gegl_node_new_child (gegl,
-                                "operation",    "gimp:tilemanager-sink",
-                                "tile-manager", new_tiles,
-                                "linear",       TRUE,
-                                NULL);
-    
-    gegl_node_connect_to (render, "output",
-                          output, "input");
 
     gegl_node_process (output);
     
@@ -674,3 +690,35 @@ gimp_cage_tool_process (GimpCageTool *ct,
 }
 
 
+static void
+gimp_cage_tool_prepare_preview (GimpCageTool *ct,
+                                GimpDisplay  *display)
+{
+  GimpImage    *image    = gimp_display_get_image (display);
+  GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+  GimpImageMap *image_map;
+  
+  GeglNode *gegl = gegl_node_new ();
+  GeglNode *coef, *cage;
+  
+  coef = gegl_node_new_child (gegl,
+                              "operation", "gegl:buffer-source",
+                              "buffer",    ct->coef,
+                              NULL);
+
+  cage = gegl_node_new_child (gegl,
+                                "operation", "gegl:cage",
+                                "config", ct->config,
+                                NULL);
+
+  gegl_node_connect_to (coef, "output",
+                        cage, "aux");
+
+  image_map = gimp_image_map_new (drawable,
+                                  _("Cage transform"),
+                                  cage,
+                                  NULL,
+                                  NULL);
+
+  g_object_unref (gegl);
+}
diff --git a/app/tools/gimpcagetool.h b/app/tools/gimpcagetool.h
index 6be9254..0b0871f 100644
--- a/app/tools/gimpcagetool.h
+++ b/app/tools/gimpcagetool.h
@@ -46,7 +46,9 @@ struct _GimpCageTool
   gint                  handle_moved;
   gboolean              cage_complete;
   
-  GeglBuffer					 *coef;
+  GeglBuffer           *coef;
+  
+  GimpImageMap         *image_map;
 };
 
 



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