[gimp/soc-2010-cage-2] fill the original cage position with a plain color + UI



commit f44dcf26b3dda6a3b7155fc2766529d26598ae28
Author: Michael Muré <batolettre gmail com>
Date:   Sun Aug 15 14:20:47 2010 +0200

    fill the original cage position with a plain color + UI

 app/gegl/gimpoperationcagetransform.c |   62 ++++++++++++++++++++++++--------
 app/gegl/gimpoperationcagetransform.h |    5 ++-
 app/tools/gimpcageoptions.c           |   23 ++++++++++++-
 app/tools/gimpcageoptions.h           |    3 +-
 app/tools/gimpcagetool.c              |   17 ++++-----
 app/tools/gimpcagetool.h              |    2 +-
 6 files changed, 83 insertions(+), 29 deletions(-)
---
diff --git a/app/gegl/gimpoperationcagetransform.c b/app/gegl/gimpoperationcagetransform.c
index 05d364d..c1a28f3 100644
--- a/app/gegl/gimpoperationcagetransform.c
+++ b/app/gegl/gimpoperationcagetransform.c
@@ -105,6 +105,13 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
                                                         GIMP_TYPE_CAGE_CONFIG,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (object_class, GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL,
+                                   g_param_spec_boolean ("fill_plain_color",
+                                                         "Blocking render",
+                                                         "Fill the original position of the cage with a plain color",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE));
 }
 
 static void
@@ -141,6 +148,10 @@ gimp_operation_cage_transform_get_property  (GObject      *object,
       g_value_set_object (value, self->config);
       break;
 
+    case GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL:
+      g_value_set_boolean (value, self->fill_plain_color);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -163,7 +174,11 @@ gimp_operation_cage_transform_set_property  (GObject        *object,
       self->config = g_value_dup_object (value);
       break;
 
-   default:
+    case GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL:
+      self->fill_plain_color = g_value_get_boolean (value);
+      break;
+
+    default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
     }
@@ -192,10 +207,11 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
 
   gint x, y;
   GeglRectangle cage_bb = gimp_cage_config_get_bounding_box (config);
-  GeglRectangle buffer_bb = *gegl_operation_source_get_bounding_box (operation, "input");
   gfloat *coords = g_slice_alloc ( 2 * sizeof (gfloat));
   GimpVector2 p1_d, p2_d, p3_d, p4_d;
   GimpVector2 p1_s, p2_s, p3_s, p4_s;
+  GimpVector2 plain_color;
+  gboolean plain_color_set = FALSE;
 
   /* pre-fill the out buffer with no-displacement coordinate */
   GeglBufferIterator *it = gegl_buffer_iterator_new (out_buf, roi, NULL, GEGL_BUFFER_WRITE);
@@ -211,8 +227,22 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
 
     while(n_pixels--)
     {
-      output[0] = x;
-      output[1] = y;
+      if (oct->fill_plain_color && gimp_cage_config_point_inside(config, x, y))
+      {
+        if (!plain_color_set)
+        {
+          plain_color.x = x;
+          plain_color.y = y;
+          plain_color_set = TRUE;
+        }
+        output[0] = plain_color.x;
+        output[1] = plain_color.y;
+      }
+      else
+      {
+        output[0] = x;
+        output[1] = y;
+      }
 
       output += 2;
 
@@ -241,21 +271,21 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
 
     for (y = cage_bb.y; y < cage_bb.y + cage_bb.height - 1; y++)
     {
-    p1_s = p4_s;
-    p2_s = p3_s;
-    p3_s.y = y+1;
-    p4_s.y = y+1;
+      p1_s = p4_s;
+      p2_s = p3_s;
+      p3_s.y = y+1;
+      p4_s.y = y+1;
 
-    p1_d = p4_d;
-    p2_d = p3_d;
-    p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
-    p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
+      p1_d = p4_d;
+      p2_d = p3_d;
+      p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
+      p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
 
       if (gimp_cage_config_point_inside(config, x, y))
       {
         gimp_operation_cage_transform_interpolate_source_coords_recurs  (oct,
                                                                          out_buf,
-                                                                         &buffer_bb,
+                                                                         roi,
                                                                          p1_s, p1_d,
                                                                          p2_s, p2_d,
                                                                          p3_s, p3_d,
@@ -264,7 +294,7 @@ gimp_operation_cage_transform_process (GeglOperation       *operation,
 
         gimp_operation_cage_transform_interpolate_source_coords_recurs  (oct,
                                                                          out_buf,
-                                                                         &buffer_bb,
+                                                                         roi,
                                                                          p1_s, p1_d,
                                                                          p3_s, p3_d,
                                                                          p4_s, p4_d,
@@ -344,8 +374,8 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCag
     rect.x = xmax;
     rect.y = ymax;
 
-    x = (gfloat) xmax;
-    y = (gfloat) ymax;
+    x = (gdouble) xmax;
+    y = (gdouble) ymax;
 
     denom = (p2_d.x - p1_d.x) * p3_d.y + (p1_d.x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * p1_d.y;
     a = ((p2_d.x - x) * p3_d.y + (x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * y) / denom;
diff --git a/app/gegl/gimpoperationcagetransform.h b/app/gegl/gimpoperationcagetransform.h
index 35da429..092a9a5 100644
--- a/app/gegl/gimpoperationcagetransform.h
+++ b/app/gegl/gimpoperationcagetransform.h
@@ -26,7 +26,8 @@
 enum
 {
   GIMP_OPERATION_CAGE_TRANSFORM_PROP_0,
-  GIMP_OPERATION_CAGE_TRANSFORM_PROP_CONFIG
+  GIMP_OPERATION_CAGE_TRANSFORM_PROP_CONFIG,
+  GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL
 };
 
 #define GIMP_TYPE_OPERATION_CAGE_TRANSFORM            (gimp_operation_cage_transform_get_type ())
@@ -44,6 +45,8 @@ struct _GimpOperationCageTransform
   GeglOperationComposer  parent_instance;
 
   GimpCageConfig        *config;
+  gboolean               fill_plain_color;
+
   Babl                  *format_coords;
 };
 
diff --git a/app/tools/gimpcageoptions.c b/app/tools/gimpcageoptions.c
index 145c10f..ecc3c07 100644
--- a/app/tools/gimpcageoptions.c
+++ b/app/tools/gimpcageoptions.c
@@ -43,7 +43,8 @@
 enum
 {
   PROP_0,
-  PROP_CAGE_MODE
+  PROP_CAGE_MODE,
+  PROP_FILL_PLAIN_COLOR
 };
 
 static void gimp_cage_options_set_property  (GObject      *object,
@@ -75,6 +76,11 @@ gimp_cage_options_class_init (GimpCageOptionsClass *klass)
                                  GIMP_TYPE_CAGE_MODE,
                                  GIMP_CAGE_MODE_CAGE_CHANGE,
                                  GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FILL_PLAIN_COLOR,
+                                    "fill-plain-color", NULL,
+                                    FALSE,
+                                    GIMP_PARAM_STATIC_STRINGS);
 }
 
 static void
@@ -97,6 +103,10 @@ gimp_cage_options_set_property  (GObject      *object,
       options->cage_mode = g_value_get_enum (value);
       break;
 
+    case PROP_FILL_PLAIN_COLOR:
+      options->fill_plain_color = g_value_get_boolean (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -117,6 +127,10 @@ gimp_cage_options_get_property  (GObject    *object,
       g_value_set_enum (value, options->cage_mode);
       break;
 
+    case PROP_FILL_PLAIN_COLOR:
+      g_value_set_boolean (value, options->fill_plain_color);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -130,6 +144,7 @@ gimp_cage_options_gui (GimpToolOptions *tool_options)
   GtkWidget *vbox   = gimp_tool_options_gui (tool_options);
   GtkWidget *hbox;
   GtkWidget *mode;
+  GtkWidget *button;
 
   hbox = gtk_hbox_new (FALSE, 2);
   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
@@ -139,6 +154,12 @@ gimp_cage_options_gui (GimpToolOptions *tool_options)
   mode = gimp_prop_enum_radio_box_new (config, "cage-mode", 0, 0);
   gtk_box_pack_start (GTK_BOX (vbox), mode, FALSE, FALSE, 0);
   gtk_widget_show (mode);
+
+
+  button = gimp_prop_check_button_new (config, "fill-plain-color",
+                                       _("Fill the original cage position with a plain color"));
+  gtk_box_pack_start (GTK_BOX (vbox),  button, FALSE, FALSE, 0);
+  gtk_widget_show (button);
   
   return vbox;
 }
diff --git a/app/tools/gimpcageoptions.h b/app/tools/gimpcageoptions.h
index 404a672..b449c7f 100644
--- a/app/tools/gimpcageoptions.h
+++ b/app/tools/gimpcageoptions.h
@@ -41,6 +41,7 @@ struct _GimpCageOptions
   GimpTransformOptions    parent_instance;
   
   GimpCageMode            cage_mode;
+  gboolean                fill_plain_color;
 };
 
 
@@ -54,4 +55,4 @@ GType       gimp_cage_options_get_type (void) G_GNUC_CONST;
 
 GtkWidget * gimp_cage_options_gui      (GimpToolOptions *tool_options);
 
-#endif  /*  __GIMP_CAGE_OPTIONS_H__  */
\ No newline at end of file
+#endif  /*  __GIMP_CAGE_OPTIONS_H__  */
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index 2c1f6f3..a925e44 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -673,7 +673,6 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
   GimpCageConfig    *config   = ct->config;
 
   Babl *format;
-  GeglRectangle rect;
   GeglNode *gegl, *input, *output;
   GeglProcessor *processor;
   GimpProgress *progress;
@@ -687,7 +686,10 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
   }
 
   format = babl_format_n(babl_type("float"), config->cage_vertice_number * 2);
-  rect = gimp_cage_config_get_bounding_box (config);
+
+  progress = gimp_progress_start (GIMP_PROGRESS (display),
+                                _("Coefficient computation"),
+                                FALSE);
 
   gegl = gegl_node_new ();
 
@@ -705,11 +707,6 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
   gegl_node_connect_to (input, "output",
                           output, "input");
 
-
-  progress = gimp_progress_start (GIMP_PROGRESS (display),
-                                _("Coefficient computation"),
-                                FALSE);
-
   processor = gegl_node_new_processor (output, NULL);
 
   while (gegl_processor_work (processor, &value))
@@ -728,8 +725,9 @@ static void
 gimp_cage_tool_process (GimpCageTool *ct,
                         GimpDisplay  *display)
 {
-  TileManager  *new_tiles;
-  GeglRectangle rect;
+  GimpCageOptions   *options  = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+  TileManager       *new_tiles;
+  GeglRectangle      rect;
 
   GimpImage     *image    = gimp_display_get_image (display);
   GimpDrawable  *drawable = gimp_image_get_active_drawable (image);
@@ -783,6 +781,7 @@ gimp_cage_tool_process (GimpCageTool *ct,
       cage = gegl_node_new_child (gegl,
                                   "operation", "gimp:cage_transform",
                                   "config", ct->config,
+                                  "fill_plain_color", options->fill_plain_color,
                                   NULL);
 
       coef = gegl_node_new_child (gegl,
diff --git a/app/tools/gimpcagetool.h b/app/tools/gimpcagetool.h
index 2beeb7e..a51cf62 100644
--- a/app/tools/gimpcagetool.h
+++ b/app/tools/gimpcagetool.h
@@ -52,7 +52,7 @@ struct _GimpCageTool
 
   GeglNode             *node_preview;
 
-  guint                  idle_id;
+  guint                 idle_id;
 
 };
 



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