Hi all,

I've attached a pretty trivial patch which creates Erode and
Dilate menu items. These are basically the vpropagate plug-in
called with default values. This stems from me spending about an
hour looking for this functionality today and not finding it.

Eventually someone told me "Those are the more white/black
functions in value propagate", which seemed a little obscure for
what I reckon are fairly basic functions. So I did this.

People may think it's useless, so I'll mail it here and let
people decide whether it's useless enough to get dumped. :)

Cheers,
Dave.

-- 
David Neary,               E-Mail [EMAIL PROTECTED]
Palamon Technologies Ltd.  Phone +353-1-634-5059      

Index: plug-ins/common/vpropagate.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/common/vpropagate.c,v
retrieving revision 1.26
diff -u -r1.26 vpropagate.c
--- plug-ins/common/vpropagate.c        2001/11/29 13:23:38     1.26
+++ plug-ins/common/vpropagate.c        2001/12/05 18:18:10
@@ -41,8 +41,11 @@
 #include "libgimp/stdplugins-intl.h"
 
 
-#define        PLUG_IN_NAME    "plug_in_vpropagate"
+#define        DEFAULT_PLUG_IN_NAME    "plug_in_vpropagate"
+#define PLUG_IN_IMAGE_TYPES "RGB*, GRAY*"
 #define SHORT_NAME     "vpropagate"
+#define ERODE_PLUG_IN_NAME "plug_in_erode"
+#define DILATE_PLUG_IN_NAME "plug_in_dilate"
 
 
 #define        VP_RGB          (1 << 0)
@@ -209,17 +212,41 @@
   };
   static gint nargs = sizeof (args) / sizeof (args[0]);
 
-  gimp_install_procedure (PLUG_IN_NAME,
+  gimp_install_procedure (DEFAULT_PLUG_IN_NAME,
                          "Propagate values of the layer",
                          "Propagate values of the layer",
                          "Shuji Narazaki ([EMAIL PROTECTED])",
                          "Shuji Narazaki",
                          "1996-1997",
                          N_("<Image>/Filters/Distorts/Value Propagate..."),
-                         "RGB*,GRAY*",
+                         PLUG_IN_IMAGE_TYPES,
                          GIMP_PLUGIN,
                          nargs, 0,
                          args, NULL);
+
+  gimp_install_procedure (ERODE_PLUG_IN_NAME,
+                         "Erode image",
+                         "Erode image",
+                         "Shuji Narazaki ([EMAIL PROTECTED])",
+                         "Shuji Narazaki",
+                         "1996-1997",
+                         N_("<Image>/Filters/Generic/Erode..."),
+                         PLUG_IN_IMAGE_TYPES,
+                         GIMP_PLUGIN,
+                         nargs, 0,
+                         args, NULL);
+
+  gimp_install_procedure (DILATE_PLUG_IN_NAME,
+                         "Dilate image",
+                         "Dilate image",
+                         "Shuji Narazaki ([EMAIL PROTECTED])",
+                         "Shuji Narazaki",
+                         "1996-1997",
+                         N_("<Image>/Filters/Generic/Dilate..."),
+                         PLUG_IN_IMAGE_TYPES,
+                         GIMP_PLUGIN,
+                         nargs, 0,
+                         args, NULL);
 }
 
 static void
@@ -245,43 +272,82 @@
   switch (run_mode)
     {
     case GIMP_RUN_INTERACTIVE:
-      INIT_I18N_UI();
-      gimp_get_data (PLUG_IN_NAME, &vpvals);
-      /* building the values of dialog variables from vpvals. */
-      propagate_alpha =
-       (vpvals.propagating_channel & PROPAGATING_ALPHA) ? TRUE : FALSE;
-      propagate_value =
-       (vpvals.propagating_channel & PROPAGATING_VALUE) ? TRUE : FALSE;
-      {
-       int     i;
-       for (i = 0; i < 4; i++)
-         direction_mask_vec[i] = (vpvals.direction_mask & (1 << i))
-           ? TRUE : FALSE;
-      }
-      if (! vpropagate_dialog (gimp_drawable_type(drawable_id)))
-       return;
+      if (strcmp (name, DEFAULT_PLUG_IN_NAME) == 0)
+       {
+         INIT_I18N_UI();
+         gimp_get_data (DEFAULT_PLUG_IN_NAME, &vpvals);
+         /* building the values of dialog variables from vpvals. */
+         propagate_alpha =
+           (vpvals.propagating_channel & PROPAGATING_ALPHA) ? TRUE : FALSE;
+         propagate_value =
+           (vpvals.propagating_channel & PROPAGATING_VALUE) ? TRUE : FALSE;
+         {
+           int i;
+           for (i = 0; i < 4; i++)
+             direction_mask_vec[i] = (vpvals.direction_mask & (1 << i))
+               ? TRUE : FALSE;
+         }
+         if (! vpropagate_dialog (gimp_drawable_type(drawable_id)))
+           return;
+       }
+      else if (strcmp (name, ERODE_PLUG_IN_NAME) == 0 || 
+              strcmp (name, DILATE_PLUG_IN_NAME) == 0)
+       {
+         INIT_I18N();
+         vpvals.propagating_channel = PROPAGATING_VALUE;
+         vpvals.propagating_rate = 1.0;
+         vpvals.direction_mask = 15;
+         vpvals.lower_limit = 0;
+         vpvals.upper_limit = 255;
+
+         if(strcmp(name, ERODE_PLUG_IN_NAME) == 0)
+           vpvals.propagate_mode = 0;
+         else if(strcmp(name, DILATE_PLUG_IN_NAME) == 0)
+           vpvals.propagate_mode = 1;
+       }
       break;
     case GIMP_RUN_NONINTERACTIVE:
       INIT_I18N();
-      vpvals.propagate_mode = param[3].data.d_int32;
-      vpvals.propagating_channel = param[4].data.d_int32;
-      vpvals.propagating_rate = param[5].data.d_float;
-      vpvals.direction_mask = param[6].data.d_int32;
-      vpvals.lower_limit = param[7].data.d_int32;
-      vpvals.upper_limit = param[8].data.d_int32;
+
+      if (strcmp (name, DEFAULT_PLUG_IN_NAME) == 0)
+       {
+         vpvals.propagate_mode = param[3].data.d_int32;
+         vpvals.propagating_channel = param[4].data.d_int32;
+         vpvals.propagating_rate = param[5].data.d_float;
+         vpvals.direction_mask = param[6].data.d_int32;
+         vpvals.lower_limit = param[7].data.d_int32;
+         vpvals.upper_limit = param[8].data.d_int32;
+       }
+      else if (strcmp (name, ERODE_PLUG_IN_NAME) == 0 || 
+              strcmp (name, DILATE_PLUG_IN_NAME) == 0)
+       {
+         INIT_I18N();
+         vpvals.propagating_channel = PROPAGATING_VALUE;
+         vpvals.propagating_rate = 1.0;
+         vpvals.direction_mask = 15;
+         vpvals.lower_limit = 0;
+         vpvals.upper_limit = 255;
+
+         if(strcmp(name, ERODE_PLUG_IN_NAME) == 0)
+           vpvals.propagate_mode = 0;
+         else if(strcmp(name, DILATE_PLUG_IN_NAME) == 0)
+           vpvals.propagate_mode = 1;
+       }
       break;
     case GIMP_RUN_WITH_LAST_VALS:
       INIT_I18N();
-      gimp_get_data (PLUG_IN_NAME, &vpvals);
+      gimp_get_data (DEFAULT_PLUG_IN_NAME, &vpvals);
       break;
     }
   
   status = value_propagate (drawable_id);
 
-  if (run_mode != GIMP_RUN_NONINTERACTIVE)
+  if (run_mode != GIMP_RUN_NONINTERACTIVE || 
+      strcmp(name, DEFAULT_PLUG_IN_NAME) != 0)
     gimp_displays_flush();
-  if (run_mode == GIMP_RUN_INTERACTIVE && status == GIMP_PDB_SUCCESS)
-    gimp_set_data (PLUG_IN_NAME, &vpvals, sizeof (VPValueType));
+  if (run_mode == GIMP_RUN_INTERACTIVE && status == GIMP_PDB_SUCCESS 
+      && strcmp(name, DEFAULT_PLUG_IN_NAME) != 0)
+    gimp_set_data (DEFAULT_PLUG_IN_NAME, &vpvals, sizeof (VPValueType));
 
   values[0].type = GIMP_PDB_STATUS;
   values[0].data.d_status = status;

Reply via email to