[gimp] Replace the semi-flatten plug-in by a GEGL operation



commit f1a771439ae8abe7b3db1adabca17421cba5eea7
Author: Michael Natterer <mitch gimp org>
Date:   Fri May 4 23:55:39 2012 +0200

    Replace the semi-flatten plug-in by a GEGL operation

 app/actions/filters-actions.c       |    6 ++
 app/gegl/Makefile.am                |    2 +
 app/gegl/gimp-gegl.c                |    2 +
 app/pdb/internal-procs.c            |    2 +-
 app/pdb/plug-in-compat-cmds.c       |   81 +++++++++++++++++++
 menus/image-menu.xml.in             |    5 +-
 plug-ins/common/.gitignore          |    2 -
 plug-ins/common/Makefile.am         |   16 ----
 plug-ins/common/gimprc.common       |    1 -
 plug-ins/common/plugin-defs.pl      |    1 -
 plug-ins/common/semi-flatten.c      |  150 -----------------------------------
 tools/pdbgen/pdb/plug_in_compat.pdb |   53 ++++++++++++
 12 files changed, 149 insertions(+), 172 deletions(-)
---
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
index 41c4b83..af76ff0 100644
--- a/app/actions/filters-actions.c
+++ b/app/actions/filters-actions.c
@@ -69,6 +69,12 @@ static const GimpStringActionEntry filters_actions[] =
     "gegl:polar-coordinates",
     NULL /* FIXME GIMP_HELP_FILTER_POLAR_COORDINATES */ },
 
+  { "filters-semi-flatten", GIMP_STOCK_GEGL,
+    NC_("filters-action", "_Semi-Flatten..."), NULL,
+    NC_("filters-action", "Replace partial transparency with a color"),
+    "gimp:semi-flatten",
+    NULL /* FIXME GIMP_HELP_FILTER_POLAR_COORDINATES */ },
+
   { "filters-threshold-alpha", GIMP_STOCK_GEGL,
     NC_("filters-action", "_Threshold Alpha..."), NULL,
     NC_("filters-action", "Make transparency all-or-nothing"),
diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am
index 03dc765..b8ff03a 100644
--- a/app/gegl/Makefile.am
+++ b/app/gegl/Makefile.am
@@ -72,6 +72,8 @@ libappgegl_a_sources = \
 	gimpoperationhistogramsink.h		\
 	gimpoperationmaskcomponents.c		\
 	gimpoperationmaskcomponents.h		\
+	gimpoperationsemiflatten.c		\
+	gimpoperationsemiflatten.h		\
 	gimpoperationsetalpha.c			\
 	gimpoperationsetalpha.h			\
 	gimpoperationshapeburst.c		\
diff --git a/app/gegl/gimp-gegl.c b/app/gegl/gimp-gegl.c
index 2e78d24..f77477e 100644
--- a/app/gegl/gimp-gegl.c
+++ b/app/gegl/gimp-gegl.c
@@ -40,6 +40,7 @@
 #include "gimpoperationgrow.h"
 #include "gimpoperationhistogramsink.h"
 #include "gimpoperationmaskcomponents.h"
+#include "gimpoperationsemiflatten.h"
 #include "gimpoperationsetalpha.h"
 #include "gimpoperationshapeburst.h"
 #include "gimpoperationshrink.h"
@@ -123,6 +124,7 @@ gimp_gegl_init (Gimp *gimp)
   g_type_class_ref (GIMP_TYPE_OPERATION_GROW);
   g_type_class_ref (GIMP_TYPE_OPERATION_HISTOGRAM_SINK);
   g_type_class_ref (GIMP_TYPE_OPERATION_MASK_COMPONENTS);
+  g_type_class_ref (GIMP_TYPE_OPERATION_SEMI_FLATTEN);
   g_type_class_ref (GIMP_TYPE_OPERATION_SET_ALPHA);
   g_type_class_ref (GIMP_TYPE_OPERATION_SHAPEBURST);
   g_type_class_ref (GIMP_TYPE_OPERATION_SHRINK);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index d146c38..af8522a 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 675 procedures registered total */
+/* 676 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 aca986a..5371b91 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -32,6 +32,7 @@
 
 #include "pdb-types.h"
 
+#include "core/gimpcontext.h"
 #include "core/gimpdrawable-operation.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpparamspecs.h"
@@ -226,6 +227,50 @@ plug_in_polar_coords_invoker (GimpProcedure      *procedure,
 }
 
 static GimpValueArray *
+plug_in_semiflatten_invoker (GimpProcedure      *procedure,
+                             Gimp                  *gimp,
+                             GimpContext           *context,
+                             GimpProgress          *progress,
+                             const GimpValueArray  *args,
+                             GError               **error)
+{
+  gboolean success = TRUE;
+  GimpDrawable *drawable;
+
+  drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
+
+  if (success)
+    {
+      if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
+          gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
+          gimp_drawable_has_alpha (drawable))
+        {
+          GeglNode *node;
+          GimpRGB   color;
+
+          gimp_context_get_background (context, &color);
+
+          node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gimp:semi-flatten",
+                                 "color",     &color,
+                                 NULL);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Semi-Flatten"),
+                                         node);
+
+          g_object_unref (node);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 plug_in_threshold_alpha_invoker (GimpProcedure      *procedure,
                                  Gimp                  *gimp,
                                  GimpContext           *context,
@@ -508,6 +553,42 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-plug-in-semiflatten
+   */
+  procedure = gimp_procedure_new (plug_in_semiflatten_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-semiflatten");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-semiflatten",
+                                     "Replace partial transparency with the current background color",
+                                     "This plugin flattens pixels in an RGBA image that aren't completely transparent against the current GIMP background color.",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "1997",
+                                     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_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-plug-in-threshold-alpha
    */
   procedure = gimp_procedure_new (plug_in_threshold_alpha_invoker);
diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in
index bcb3eac..2ab5429 100644
--- a/menus/image-menu.xml.in
+++ b/menus/image-menu.xml.in
@@ -431,6 +431,7 @@
           <menuitem action="layers-alpha-add" />
           <menuitem action="layers-alpha-remove" />
           <menuitem action="filters-color-to-alpha" />
+          <menuitem action="filters-semi-flatten" />
           <menuitem action="filters-threshold-alpha" />
         </placeholder>
         <separator />
@@ -627,7 +628,9 @@
         <menu action="plug-in-render-pattern-menu" name="Pattern" />
         <separator />
       </menu>
-      <menu action="plug-in-web-menu" name="Web" />
+      <menu action="plug-in-web-menu" name="Web">
+        <menuitem action="filters-semi-flatten" />
+      </menu>
       <menu action="plug-in-animation-menu" name="Animation" >
         <placeholder name="Animators" />
         <separator />
diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore
index c9b9279..04df9c1 100644
--- a/plug-ins/common/.gitignore
+++ b/plug-ins/common/.gitignore
@@ -238,8 +238,6 @@
 /sample-colorize.exe
 /screenshot
 /screenshot.exe
-/semi-flatten
-/semi-flatten.exe
 /sharpen
 /sharpen.exe
 /shift
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index b870a59..151caa1 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -162,7 +162,6 @@ libexec_PROGRAMS = \
 	rotate \
 	sample-colorize \
 	$(SCREENSHOT) \
-	semi-flatten \
 	sharpen \
 	shift \
 	sinus \
@@ -2231,21 +2230,6 @@ screenshot_LDADD = \
 	$(INTLLIBS)		\
 	$(screenshot_RC)
 
-semi_flatten_SOURCES = \
-	semi-flatten.c
-
-semi_flatten_LDADD = \
-	$(libgimp)		\
-	$(libgimpmath)		\
-	$(libgimpconfig)	\
-	$(libgimpcolor)		\
-	$(libgimpbase)		\
-	$(CAIRO_LIBS)		\
-	$(GDK_PIXBUF_LIBS)	\
-	$(RT_LIBS)		\
-	$(INTLLIBS)		\
-	$(semi_flatten_RC)
-
 sharpen_SOURCES = \
 	sharpen.c
 
diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common
index 1f2792f..edfc2c9 100644
--- a/plug-ins/common/gimprc.common
+++ b/plug-ins/common/gimprc.common
@@ -116,7 +116,6 @@ ripple_RC = ripple.rc.o
 rotate_RC = rotate.rc.o
 sample_colorize_RC = sample-colorize.rc.o
 screenshot_RC = screenshot.rc.o
-semi_flatten_RC = semi-flatten.rc.o
 sharpen_RC = sharpen.rc.o
 shift_RC = shift.rc.o
 sinus_RC = sinus.rc.o
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 5394dc3..369bf29 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -117,7 +117,6 @@
     'rotate' => {},
     'sample-colorize' => { ui => 1 },
     'screenshot' => { ui => 1, optional => 1, libs => 'SCREENSHOT_LIBS', cflags => 'XFIXES_CFLAGS' },
-    'semi-flatten' => {},
     'sharpen' => { ui => 1 },
     'shift' => { ui => 1 },
     'sinus' => { ui => 1 },
diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb
index 07cc577..7a119bf 100644
--- a/tools/pdbgen/pdb/plug_in_compat.pdb
+++ b/tools/pdbgen/pdb/plug_in_compat.pdb
@@ -224,6 +224,57 @@ CODE
     );
 }
 
+sub plug_in_semiflatten {
+    $blurb = 'Replace partial transparency with the current background color';
+
+    $help = <<'HELP';
+This plugin flattens pixels in an RGBA image that aren't completely
+transparent against the current GIMP background color.
+HELP
+
+    &std_pdb_misc;
+    $date = '1997';
+
+    @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' }
+    );
+
+    %invoke = (
+	code => <<'CODE'
+{
+  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
+      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
+      gimp_drawable_has_alpha (drawable))
+    {
+      GeglNode *node;
+      GimpRGB   color;
+
+      gimp_context_get_background (context, &color);
+
+      node =
+        gegl_node_new_child (NULL,
+                             "operation", "gimp:semi-flatten",
+                             "color",     &color,
+                             NULL);
+
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Semi-Flatten"),
+                                     node);
+
+      g_object_unref (node);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub plug_in_threshold_alpha {
     $blurb = 'Make transparency all-or-nothing';
 
@@ -321,6 +372,7 @@ CODE
 
 @headers = qw("libgimpbase/gimpbase.h"
               "gegl/gimp-gegl-utils.h"
+              "core/gimpcontext.h"
               "core/gimpdrawable.h"
               "core/gimpdrawable-operation.h"
               "gimppdb-utils.h"
@@ -330,6 +382,7 @@ CODE
             plug_in_pixelize
             plug_in_pixelize2
             plug_in_polar_coords
+            plug_in_semiflatten
 	    plug_in_threshold_alpha
             plug_in_vinvert);
 



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