[gimp] plug-ins, pdb: remove the cartoon plug-in and add a PDB compat procedure



commit 529ee9efc8e29d5afc1f71da34dea7a53e0b0de4
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 11 11:41:06 2019 +0200

    plug-ins, pdb: remove the cartoon plug-in and add a PDB compat procedure
    
    The result of the GEGL op is a bitt different but so what, this is an
    artistic effect and the result can be tweaked with parameters.

 app/pdb/internal-procs.c       |   2 +-
 app/pdb/plug-in-compat-cmds.c  |  92 +++++
 pdb/groups/plug_in_compat.pdb  |  67 +++
 plug-ins/common/.gitignore     |   2 -
 plug-ins/common/Makefile.am    |  19 -
 plug-ins/common/cartoon.c      | 895 -----------------------------------------
 plug-ins/common/gimprc.common  |   1 -
 plug-ins/common/plugin-defs.pl |   1 -
 po-plug-ins/POTFILES.in        |   1 -
 9 files changed, 160 insertions(+), 920 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 271e2f7741..6d307a4147 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 735 procedures registered total */
+/* 736 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c
index d28d0d7006..17a8d7b165 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -870,6 +870,49 @@ plug_in_c_astretch_invoker (GimpProcedure         *procedure,
                                            error ? *error : NULL);
 }
 
+static GimpValueArray *
+plug_in_cartoon_invoker (GimpProcedure         *procedure,
+                         Gimp                  *gimp,
+                         GimpContext           *context,
+                         GimpProgress          *progress,
+                         const GimpValueArray  *args,
+                         GError               **error)
+{
+  gboolean success = TRUE;
+  GimpDrawable *drawable;
+  gdouble mask_radius;
+  gdouble pct_black;
+
+  drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
+  mask_radius = g_value_get_double (gimp_value_array_index (args, 3));
+  pct_black = g_value_get_double (gimp_value_array_index (args, 4));
+
+  if (success)
+    {
+      if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
+                                     GIMP_PDB_ITEM_CONTENT, error) &&
+          gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
+        {
+          GeglNode *node =
+            gegl_node_new_child (NULL,
+                                 "operation",   "gegl:cartoon",
+                                 "mask-radius", mask_radius,
+                                 "pct-black",   pct_black,
+                                 NULL);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Cartoon"),
+                                         node);
+          g_object_unref (node);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 static GimpValueArray *
 plug_in_colors_channel_mixer_invoker (GimpProcedure         *procedure,
                                       Gimp                  *gimp,
@@ -4783,6 +4826,55 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 
+  /*
+   * gimp-plug-in-cartoon
+   */
+  procedure = gimp_procedure_new (plug_in_cartoon_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-cartoon");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-cartoon",
+                                     "Simulate a cartoon by enhancing edges",
+                                     "Propagates dark values in an image based on each pixel's relative 
darkness to a neighboring average. The idea behind this filter is to give the look of a black felt pen 
drawing subsequently shaded with color. This is achieved by darkening areas of the image which are measured 
to be darker than a neighborhood average. In this way, sufficiently large shifts in intensity are darkened to 
black. The rate at which they are darkened to black is determined by the second pct_black parameter. The 
mask_radius parameter controls the size of the pixel neighborhood over which the average intensity is 
computed and then compared to each pixel in the neighborhood to decide whether or not to darken it to black. 
Large values for mask_radius result in very thick black areas bordering the shaded regions of color and much 
less detail for black areas everywhere including inside regions of color. Small values result in more subtle 
pen strokes and detail everywh
 ere. Sma
 ll values for the pct_black make the\n"
+                                     "blend from the color regions to the black border lines smoother and 
the lines themselves thinner and less noticeable; larger values achieve the opposite effect.",
+                                     "Compatibility procedure. Please see 'gegl:cartoon' for credits.",
+                                     "Compatibility procedure. Please see 'gegl:cartoon' for credits.",
+                                     "2019",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("run-mode",
+                                                  "run mode",
+                                                  "The run mode",
+                                                  GIMP_TYPE_RUN_MODE,
+                                                  GIMP_RUN_INTERACTIVE,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image_id ("image",
+                                                         "image",
+                                                         "Input image (unused)",
+                                                         pdb->gimp, FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_drawable_id ("drawable",
+                                                            "drawable",
+                                                            "Input drawable",
+                                                            pdb->gimp, FALSE,
+                                                            GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("mask-radius",
+                                                    "mask radius",
+                                                    "Cartoon mask radius (radius of pixel neighborhood)",
+                                                    1.0, 50.0, 1.0,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("pct-black",
+                                                    "pct black",
+                                                    "Percentage of darkened pixels to set to black",
+                                                    0.0, 1.0, 0.0,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
   /*
    * gimp-plug-in-colors-channel-mixer
    */
diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb
index 7fa3dff515..0f63f8e424 100644
--- a/pdb/groups/plug_in_compat.pdb
+++ b/pdb/groups/plug_in_compat.pdb
@@ -608,6 +608,72 @@ CODE
     );
 }
 
+sub plug_in_cartoon {
+    $blurb = 'Simulate a cartoon by enhancing edges';
+
+    $help = <<'HELP';
+Propagates dark values in an image based on each pixel's relative
+darkness to a neighboring average. The idea behind this filter is to
+give the look of a black felt pen drawing subsequently shaded with
+color. This is achieved by darkening areas of the image which are
+measured to be darker than a neighborhood average. In this way,
+sufficiently large shifts in intensity are darkened to black. The rate
+at which they are darkened to black is determined by the second
+pct_black parameter. The mask_radius parameter controls the size of
+the pixel neighborhood over which the average intensity is computed
+and then compared to each pixel in the neighborhood to decide whether
+or not to darken it to black. Large values for mask_radius result in
+very thick black areas bordering the shaded regions of color and much
+less detail for black areas everywhere including inside regions of
+color. Small values result in more subtle pen strokes and detail
+everywhere. Small values for the pct_black make the blend from the
+color regions to the black border lines smoother and the lines
+themselves thinner and less noticeable; larger values achieve the
+opposite effect.
+HELP
+
+    &std_pdb_compat('gegl:cartoon');
+    $date = '2019';
+
+    @inargs = (
+       { name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
+         desc => 'The run mode' },
+       { name => 'image', type => 'image', dead => 1,
+         desc => 'Input image (unused)' },
+       { name => 'drawable', type => 'drawable',
+         desc => 'Input drawable' },
+       { name => 'mask_radius', type => '1.0 <= float <= 50.0',
+         desc => 'Cartoon mask radius (radius of pixel neighborhood)' },
+       { name => 'pct_black', type => '0.0 <= float <= 1.0',
+         desc => 'Percentage of darkened pixels to set to black' },
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
+                                 GIMP_PDB_ITEM_CONTENT, error) &&
+      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
+    {
+      GeglNode *node =
+        gegl_node_new_child (NULL,
+                             "operation",   "gegl:cartoon",
+                            "mask-radius", mask_radius,
+                            "pct-black",   pct_black,
+                             NULL);
+
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Cartoon"),
+                                     node);
+      g_object_unref (node);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub plug_in_colors_channel_mixer {
     $blurb = 'Alter colors by mixing RGB Channels';
 
@@ -4727,6 +4793,7 @@ CODE
             plug_in_bump_map
             plug_in_bump_map_tiled
             plug_in_c_astretch
+            plug_in_cartoon
             plug_in_colors_channel_mixer
             plug_in_colortoalpha
             plug_in_convmatrix
diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore
index 404be7ec19..c712fc03d3 100644
--- a/plug-ins/common/.gitignore
+++ b/plug-ins/common/.gitignore
@@ -14,8 +14,6 @@
 /border-average.exe
 /busy-dialog
 /busy-dialog.exe
-/cartoon
-/cartoon.exe
 /checkerboard
 /checkerboard.exe
 /cml-explorer
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 4ac9230869..361fa46093 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -52,7 +52,6 @@ blinds_libexecdir = $(gimpplugindir)/plug-ins/blinds
 blur_libexecdir = $(gimpplugindir)/plug-ins/blur
 border_average_libexecdir = $(gimpplugindir)/plug-ins/border-average
 busy_dialog_libexecdir = $(gimpplugindir)/plug-ins/busy-dialog
-cartoon_libexecdir = $(gimpplugindir)/plug-ins/cartoon
 checkerboard_libexecdir = $(gimpplugindir)/plug-ins/checkerboard
 cml_explorer_libexecdir = $(gimpplugindir)/plug-ins/cml-explorer
 color_cube_analyze_libexecdir = $(gimpplugindir)/plug-ins/color-cube-analyze
@@ -144,7 +143,6 @@ blinds_libexec_PROGRAMS = blinds
 blur_libexec_PROGRAMS = blur
 border_average_libexec_PROGRAMS = border-average
 busy_dialog_libexec_PROGRAMS = busy-dialog
-cartoon_libexec_PROGRAMS = cartoon
 checkerboard_libexec_PROGRAMS = checkerboard
 cml_explorer_libexec_PROGRAMS = cml-explorer
 color_cube_analyze_libexec_PROGRAMS = color-cube-analyze
@@ -356,23 +354,6 @@ busy_dialog_LDADD = \
        $(INTLLIBS)             \
        $(busy_dialog_RC)
 
-cartoon_SOURCES = \
-       cartoon.c
-
-cartoon_LDADD = \
-       $(libgimpui)            \
-       $(libgimpwidgets)       \
-       $(libgimpmodule)        \
-       $(libgimp)              \
-       $(libgimpmath)          \
-       $(libgimpconfig)        \
-       $(libgimpcolor)         \
-       $(libgimpbase)          \
-       $(GTK_LIBS)             \
-       $(RT_LIBS)              \
-       $(INTLLIBS)             \
-       $(cartoon_RC)
-
 checkerboard_SOURCES = \
        checkerboard.c
 
diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common
index d910e7db8b..ecbdb64552 100644
--- a/plug-ins/common/gimprc.common
+++ b/plug-ins/common/gimprc.common
@@ -4,7 +4,6 @@ blinds_RC = blinds.rc.o
 blur_RC = blur.rc.o
 border_average_RC = border-average.rc.o
 busy_dialog_RC = busy-dialog.rc.o
-cartoon_RC = cartoon.rc.o
 checkerboard_RC = checkerboard.rc.o
 cml_explorer_RC = cml-explorer.rc.o
 color_cube_analyze_RC = color-cube-analyze.rc.o
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index db248ea9d1..57c666e7b5 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -6,7 +6,6 @@
     'blur' => {},
     'border-average' => { ui => 1, gegl => 1 },
     'busy-dialog' => { ui => 1, gegl => 1 },
-    'cartoon' => { ui => 1 },
     'checkerboard' => { ui => 1, gegl => 1 },
     'cml-explorer' => { ui => 1 },
     'color-cube-analyze' => { ui => 1 },
diff --git a/po-plug-ins/POTFILES.in b/po-plug-ins/POTFILES.in
index 723f73617a..acb41e2f1b 100644
--- a/po-plug-ins/POTFILES.in
+++ b/po-plug-ins/POTFILES.in
@@ -10,7 +10,6 @@ plug-ins/common/blinds.c
 plug-ins/common/blur.c
 plug-ins/common/border-average.c
 plug-ins/common/busy-dialog.c
-plug-ins/common/cartoon.c
 plug-ins/common/checkerboard.c
 plug-ins/common/cml-explorer.c
 plug-ins/common/color-cube-analyze.c


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