[gimp/metadata-browser] Replace the color-to-alpha plug-in by GEGL filter dialog



commit 246426eb98075520a5b9446c7fdce067938f1db1
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 1 01:13:03 2012 +0200

    Replace the color-to-alpha plug-in by GEGL filter dialog

 app/actions/filters-actions.c       |   23 ++-
 app/pdb/internal-procs.c            |    2 +-
 app/pdb/plug-in-compat-cmds.c       |   91 +++++++
 menus/image-menu.xml.in             |    2 +
 plug-ins/common/.gitignore          |    2 -
 plug-ins/common/Makefile.am         |   18 --
 plug-ins/common/color-to-alpha.c    |  441 -----------------------------------
 plug-ins/common/gimprc.common       |    1 -
 plug-ins/common/plugin-defs.pl      |    1 -
 tools/pdbgen/pdb/plug_in_compat.pdb |   55 +++++-
 10 files changed, 165 insertions(+), 471 deletions(-)
---
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
index 7245855..32dd68f 100644
--- a/app/actions/filters-actions.c
+++ b/app/actions/filters-actions.c
@@ -39,14 +39,20 @@
 
 static const GimpStringActionEntry filters_actions[] =
 {
+  { "filters-color-to-alpha", GIMP_STOCK_GEGL,
+    NC_("filters-action", "Color to _Alpha..."), NULL,
+    NC_("filters-action", "Convert a specified color to transparency"),
+    "gegl:color-to-alpha",
+    NULL /* FIXME GIMP_HELP_FILTER_PIXELIZE */ },
+
   { "filters-pixelize", GIMP_STOCK_GEGL,
-    NC_("filters-action", "_Pixelize"), NULL,
+    NC_("filters-action", "_Pixelize..."), NULL,
     NC_("filters-action", "Simplify image into an array of solid-colored squares"),
     "gegl:pixelize",
     NULL /* FIXME GIMP_HELP_FILTER_PIXELIZE */ },
 
   { "filters-gaussian-blur", GIMP_STOCK_GEGL,
-    NC_("filters-action", "_Gaussian Blur"), NULL,
+    NC_("filters-action", "_Gaussian Blur..."), NULL,
     NC_("filters-action", "Apply a gaussian blur"),
     "gegl:gaussian-blur",
     NULL /* FIXME GIMP_HELP_FILTER_GAUSSIAN_BLUR */ },
@@ -68,7 +74,8 @@ filters_actions_update (GimpActionGroup *group,
   GimpImage    *image;
   GimpDrawable *drawable = NULL;
   gboolean      writable = FALSE;
-  gboolean      children = FALSE;
+  gboolean      gray     = FALSE;
+  gboolean      alpha    = FALSE;
 
   image = action_data_get_image (data);
 
@@ -80,6 +87,9 @@ filters_actions_update (GimpActionGroup *group,
         {
           GimpItem *item;
 
+          alpha = gimp_drawable_has_alpha (drawable);
+          gray  = gimp_drawable_is_gray (drawable);
+
           if (GIMP_IS_LAYER_MASK (drawable))
             item = GIMP_ITEM (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
           else
@@ -88,15 +98,16 @@ filters_actions_update (GimpActionGroup *group,
           writable = ! gimp_item_is_content_locked (item);
 
           if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
-            children = TRUE;
+            writable = FALSE;
         }
     }
 
 #define SET_SENSITIVE(action,condition) \
         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
 
-  SET_SENSITIVE ("filters-pixelize",      writable && !children);
-  SET_SENSITIVE ("filters-gaussian-blur", writable && !children);
+  SET_SENSITIVE ("filters-color-to-alpha", writable && !gray && alpha);
+  SET_SENSITIVE ("filters-pixelize",       writable);
+  SET_SENSITIVE ("filters-gaussian-blur",  writable);
 
 #undef SET_SENSITIVE
 }
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 3543e22..6dc41e6 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 665 procedures registered total */
+/* 666 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 7a189bf..844f1f4 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -19,15 +19,19 @@
 
 #include "config.h"
 
+#include <cairo.h>
+
 #include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpcolor/gimpcolor.h"
 
 #include "pdb-types.h"
 
 #include "core/gimpdrawable-operation.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpparamspecs.h"
+#include "gegl/gimp-gegl-utils.h"
 
 #include "gimppdb.h"
 #include "gimppdb-utils.h"
@@ -38,6 +42,50 @@
 
 
 static GValueArray *
+plug_in_colortoalpha_invoker (GimpProcedure      *procedure,
+                              Gimp               *gimp,
+                              GimpContext        *context,
+                              GimpProgress       *progress,
+                              const GValueArray  *args,
+                              GError            **error)
+{
+  gboolean success = TRUE;
+  GimpDrawable *drawable;
+  GimpRGB color;
+
+  drawable = gimp_value_get_drawable (&args->values[2], gimp);
+  gimp_value_get_rgb (&args->values[3], &color);
+
+  if (success)
+    {
+      if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
+          gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
+        {
+          /* XXX: fixme disable for gray, and add alpha when needed */
+
+          GeglColor *gegl_color = gimp_gegl_color_new (&color);
+          GeglNode  *node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gegl:color-to-alpha",
+                                 "color",     gegl_color,
+                                 NULL);
+          g_object_unref (gegl_color);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Color to Alpha"),
+                                         node);
+
+          g_object_unref (node);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GValueArray *
 plug_in_pixelize_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
@@ -127,6 +175,49 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   GimpProcedure *procedure;
 
   /*
+   * gimp-plug-in-colortoalpha
+   */
+  procedure = gimp_procedure_new (plug_in_colortoalpha_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-colortoalpha");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-colortoalpha",
+                                     "Convert a specified color to transparency",
+                                     "This replaces as much of a given color as possible in each pixel with a corresponding amount of alpha, then readjusts the color accordingly.",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "1999",
+                                     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,
+                               gimp_param_spec_rgb ("color",
+                                                    "color",
+                                                    "Color to remove",
+                                                    FALSE,
+                                                    NULL,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-plug-in-pixelize
    */
   procedure = gimp_procedure_new (plug_in_pixelize_invoker);
diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in
index 8acf747..3641f4e 100644
--- a/menus/image-menu.xml.in
+++ b/menus/image-menu.xml.in
@@ -422,6 +422,7 @@
         <placeholder name="Modify">
           <menuitem action="layers-alpha-add" />
           <menuitem action="layers-alpha-remove" />
+          <menuitem action="filters-color-to-alpha" />
         </placeholder>
         <separator />
         <placeholder name="Selection">
@@ -516,6 +517,7 @@
         <menuitem action="dialogs-histogram" />
       </menu>
       <separator />
+      <menuitem action="filters-color-to-alpha" />
       <placeholder name="Modify" />
     </menu>
 
diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore
index 54ba89f..1edb630 100644
--- a/plug-ins/common/.gitignore
+++ b/plug-ins/common/.gitignore
@@ -42,8 +42,6 @@
 /color-enhance.exe
 /color-exchange
 /color-exchange.exe
-/color-to-alpha
-/color-to-alpha.exe
 /colorify
 /colorify.exe
 /colormap-remap
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 485a9dd..2e4859a 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -64,7 +64,6 @@ libexec_PROGRAMS = \
 	color-cube-analyze \
 	color-enhance \
 	color-exchange \
-	color-to-alpha \
 	colorify \
 	colormap-remap \
 	compose \
@@ -558,23 +557,6 @@ color_exchange_LDADD = \
 	$(INTLLIBS)		\
 	$(color_exchange_RC)
 
-color_to_alpha_SOURCES = \
-	color-to-alpha.c
-
-color_to_alpha_LDADD = \
-	$(libgimpui)		\
-	$(libgimpwidgets)	\
-	$(libgimpmodule)	\
-	$(libgimp)		\
-	$(libgimpmath)		\
-	$(libgimpconfig)	\
-	$(libgimpcolor)		\
-	$(libgimpbase)		\
-	$(GTK_LIBS)		\
-	$(RT_LIBS)		\
-	$(INTLLIBS)		\
-	$(color_to_alpha_RC)
-
 colorify_SOURCES = \
 	colorify.c
 
diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common
index 83d4056..537c585 100644
--- a/plug-ins/common/gimprc.common
+++ b/plug-ins/common/gimprc.common
@@ -18,7 +18,6 @@ cml_explorer_RC = cml-explorer.rc.o
 color_cube_analyze_RC = color-cube-analyze.rc.o
 color_enhance_RC = color-enhance.rc.o
 color_exchange_RC = color-exchange.rc.o
-color_to_alpha_RC = color-to-alpha.rc.o
 colorify_RC = colorify.rc.o
 colormap_remap_RC = colormap-remap.rc.o
 compose_RC = compose.rc.o
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 1c5bb28..fcfebcd 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -19,7 +19,6 @@
     'color-cube-analyze' => { ui => 1 },
     'color-enhance' => { ui => 1 },
     'color-exchange' => { ui => 1 },
-    'color-to-alpha' => { ui => 1 },
     'colorify' => { ui => 1 },
     'colormap-remap' => { ui => 1 },
     'compose' => { ui => 1 },
diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb
index df7fba3..2f06c30 100644
--- a/tools/pdbgen/pdb/plug_in_compat.pdb
+++ b/tools/pdbgen/pdb/plug_in_compat.pdb
@@ -16,6 +16,57 @@
 
 # "Perlized" from C source by Manish Singh <yosh gimp org>
 
+sub plug_in_colortoalpha {
+    $blurb = 'Convert a specified color to transparency';
+
+    $help = <<'HELP';
+This replaces as much of a given color as possible in each pixel with
+a corresponding amount of alpha, then readjusts the color accordingly.
+HELP
+
+    &std_pdb_misc;
+    $date = '1999';
+
+    @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 => 'color', type => 'color',
+	  desc => 'Color to remove' }
+    );
+
+    %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))
+    {
+      /* XXX: fixme disable for gray, and add alpha when needed */
+
+      GeglColor *gegl_color = gimp_gegl_color_new (&color);
+      GeglNode  *node =
+        gegl_node_new_child (NULL,
+                             "operation", "gegl:color-to-alpha",
+                             "color",     gegl_color,
+                             NULL);
+      g_object_unref (gegl_color);
+
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Color to Alpha"),
+                                     node);
+
+      g_object_unref (node);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub plug_in_pixelize {
     $blurb = 'Simplify image into an array of solid-colored squares';
 
@@ -116,12 +167,14 @@ CODE
 
 
 @headers = qw("libgimpbase/gimpbase.h"
+              "gegl/gimp-gegl-utils.h"
               "core/gimpdrawable.h"
               "core/gimpdrawable-operation.h"
               "gimppdb-utils.h"
               "gimp-intl.h");
 
- procs = qw(plug_in_pixelize
+ procs = qw(plug_in_colortoalpha
+            plug_in_pixelize
             plug_in_pixelize2);
 
 %exports = (app => [ procs], lib => []);



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