[gimp/goat-invasion: 400/418] Replace the value-invert plug-in by its GEGL counterpart



commit f6455d0014575070d2a91b47bbbdb9369081308f
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 2 02:44:57 2012 +0200

    Replace the value-invert plug-in by its GEGL counterpart

 app/actions/drawable-actions.c      |    7 +
 app/actions/drawable-commands.c     |   26 ++-
 app/actions/drawable-commands.h     |    2 +
 app/pdb/internal-procs.c            |    2 +-
 app/pdb/plug-in-compat-cmds.c       |   73 ++++++++
 menus/image-menu.xml.in             |    1 +
 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/value-invert.c      |  313 -----------------------------------
 tools/pdbgen/pdb/plug_in_compat.pdb |   50 ++++++-
 12 files changed, 149 insertions(+), 345 deletions(-)
---
diff --git a/app/actions/drawable-actions.c b/app/actions/drawable-actions.c
index d1718d7..03a16c7 100644
--- a/app/actions/drawable-actions.c
+++ b/app/actions/drawable-actions.c
@@ -53,6 +53,12 @@ static const GimpActionEntry drawable_actions[] =
     G_CALLBACK (drawable_invert_cmd_callback),
     GIMP_HELP_LAYER_INVERT },
 
+  { "drawable-value-invert", GIMP_STOCK_GEGL,
+    NC_("drawable-action", "_Value Invert"), NULL,
+    NC_("drawable-action", "Invert the brightness of each pixel"),
+    G_CALLBACK (drawable_value_invert_cmd_callback),
+    GIMP_HELP_LAYER_INVERT },
+
   { "drawable-levels-stretch", NULL,
     NC_("drawable-action", "_White Balance"), NULL,
     NC_("drawable-action", "Automatic white balance correction"),
@@ -212,6 +218,7 @@ drawable_actions_update (GimpActionGroup *group,
 
   SET_SENSITIVE ("drawable-equalize",       writable && !children && !is_indexed);
   SET_SENSITIVE ("drawable-invert",         writable && !children);
+  SET_SENSITIVE ("drawable-value-invert",   writable && !children);
   SET_SENSITIVE ("drawable-levels-stretch", writable && !children &&  is_rgb);
   SET_SENSITIVE ("drawable-offset",         writable && !children);
 
diff --git a/app/actions/drawable-commands.c b/app/actions/drawable-commands.c
index d7f1e7c..45202f4 100644
--- a/app/actions/drawable-commands.c
+++ b/app/actions/drawable-commands.c
@@ -74,18 +74,8 @@ drawable_invert_cmd_callback (GtkAction *action,
   GimpImage    *image;
   GimpDrawable *drawable;
   GimpDisplay  *display;
-  GtkWidget    *widget;
   return_if_no_drawable (image, drawable, data);
   return_if_no_display (display, data);
-  return_if_no_widget (widget, data);
-
-  if (gimp_drawable_is_indexed (drawable))
-    {
-      gimp_message_literal (image->gimp,
-			    G_OBJECT (widget), GIMP_MESSAGE_WARNING,
-			    _("Invert does not operate on indexed layers."));
-      return;
-    }
 
   gimp_drawable_apply_operation_by_name (drawable, GIMP_PROGRESS (display),
                                          _("Invert"), "gegl:invert",
@@ -94,6 +84,22 @@ drawable_invert_cmd_callback (GtkAction *action,
 }
 
 void
+drawable_value_invert_cmd_callback (GtkAction *action,
+                                    gpointer   data)
+{
+  GimpImage    *image;
+  GimpDrawable *drawable;
+  GimpDisplay  *display;
+  return_if_no_drawable (image, drawable, data);
+  return_if_no_display (display, data);
+
+  gimp_drawable_apply_operation_by_name (drawable, GIMP_PROGRESS (display),
+                                         _("Invert"), "gegl:value-invert",
+                                         NULL);
+  gimp_image_flush (image);
+}
+
+void
 drawable_levels_stretch_cmd_callback (GtkAction *action,
                                       gpointer   data)
 {
diff --git a/app/actions/drawable-commands.h b/app/actions/drawable-commands.h
index a184384..188347e 100644
--- a/app/actions/drawable-commands.h
+++ b/app/actions/drawable-commands.h
@@ -23,6 +23,8 @@ void   drawable_equalize_cmd_callback       (GtkAction *action,
                                              gpointer   data);
 void   drawable_invert_cmd_callback         (GtkAction *action,
                                              gpointer   data);
+void   drawable_value_invert_cmd_callback   (GtkAction *action,
+                                             gpointer   data);
 void   drawable_levels_stretch_cmd_callback (GtkAction *action,
                                              gpointer   data);
 void   drawable_offset_cmd_callback         (GtkAction *action,
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 6dc41e6..a257b9c 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 666 procedures registered total */
+/* 667 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 844f1f4..6a5602a 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -169,6 +169,43 @@ plug_in_pixelize2_invoker (GimpProcedure      *procedure,
                                            error ? *error : NULL);
 }
 
+static GValueArray *
+plug_in_vinvert_invoker (GimpProcedure      *procedure,
+                         Gimp               *gimp,
+                         GimpContext        *context,
+                         GimpProgress       *progress,
+                         const GValueArray  *args,
+                         GError            **error)
+{
+  gboolean success = TRUE;
+  GimpDrawable *drawable;
+
+  drawable = gimp_value_get_drawable (&args->values[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))
+        {
+          GeglNode *node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gegl:value-invert",
+                                 NULL);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Value Invert"),
+                                         node);
+
+          g_object_unref (node);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 void
 register_plug_in_compat_procs (GimpPDB *pdb)
 {
@@ -306,4 +343,40 @@ register_plug_in_compat_procs (GimpPDB *pdb)
                                                       GIMP_PARAM_READWRITE));
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
+
+  /*
+   * gimp-plug-in-vinvert
+   */
+  procedure = gimp_procedure_new (plug_in_vinvert_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-vinvert");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-vinvert",
+                                     "Invert the brightness of each pixel",
+                                     "This function takes an indexed/RGB image and inverts its 'value' in HSV space. The upshot of this is that the color and saturation at any given point remains the same, but its brightness is effectively inverted. Quite strange. Sometimes produces unpleasant color artifacts on images from lossy sources (ie. JPEG).",
+                                     "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);
 }
diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in
index 3641f4e..80dcd67 100644
--- a/menus/image-menu.xml.in
+++ b/menus/image-menu.xml.in
@@ -500,6 +500,7 @@
       <separator />
       <placeholder name="Invert">
         <menuitem action="drawable-invert" />
+        <menuitem action="drawable-value-invert" />
       </placeholder>
       <separator />
       <menuitem action="config-use-gegl" />
diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore
index 1edb630..1e7051b 100644
--- a/plug-ins/common/.gitignore
+++ b/plug-ins/common/.gitignore
@@ -270,8 +270,6 @@
 /unit-editor.exe
 /unsharp-mask
 /unsharp-mask.exe
-/value-invert
-/value-invert.exe
 /value-propagate
 /value-propagate.exe
 /van-gogh-lic
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 2e4859a..7c5fa92 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -178,7 +178,6 @@ libexec_PROGRAMS = \
 	tile-small \
 	unit-editor \
 	unsharp-mask \
-	value-invert \
 	value-propagate \
 	van-gogh-lic \
 	video \
@@ -2498,21 +2497,6 @@ unsharp_mask_LDADD = \
 	$(INTLLIBS)		\
 	$(unsharp_mask_RC)
 
-value_invert_SOURCES = \
-	value-invert.c
-
-value_invert_LDADD = \
-	$(libgimp)		\
-	$(libgimpmath)		\
-	$(libgimpconfig)	\
-	$(libgimpcolor)		\
-	$(libgimpbase)		\
-	$(CAIRO_LIBS)		\
-	$(GDK_PIXBUF_LIBS)	\
-	$(RT_LIBS)		\
-	$(INTLLIBS)		\
-	$(value_invert_RC)
-
 value_propagate_SOURCES = \
 	value-propagate.c
 
diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common
index 537c585..ab6c6b0 100644
--- a/plug-ins/common/gimprc.common
+++ b/plug-ins/common/gimprc.common
@@ -132,7 +132,6 @@ tile_seamless_RC = tile-seamless.rc.o
 tile_small_RC = tile-small.rc.o
 unit_editor_RC = unit-editor.rc.o
 unsharp_mask_RC = unsharp-mask.rc.o
-value_invert_RC = value-invert.rc.o
 value_propagate_RC = value-propagate.rc.o
 van_gogh_lic_RC = van-gogh-lic.rc.o
 video_RC = video.rc.o
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index fcfebcd..ef18f05 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -133,7 +133,6 @@
     'tile-small' => { ui => 1 },
     'unit-editor' => { ui => 1 },
     'unsharp-mask' => { ui => 1 },
-    'value-invert' => {},
     'value-propagate' => { ui => 1 },
     'van-gogh-lic' => { ui => 1 },
     'video' => { ui => 1 },
diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb
index 2f06c30..ee6c76e 100644
--- a/tools/pdbgen/pdb/plug_in_compat.pdb
+++ b/tools/pdbgen/pdb/plug_in_compat.pdb
@@ -165,6 +165,53 @@ CODE
     );
 }
 
+sub plug_in_vinvert {
+    $blurb = 'Invert the brightness of each pixel';
+
+    $help = <<'HELP';
+This function takes an indexed/RGB image and inverts its 'value' in
+HSV space.  The upshot of this is that the color and saturation at any
+given point remains the same, but its brightness is effectively
+inverted.  Quite strange.  Sometimes produces unpleasant color
+artifacts on images from lossy sources (ie. JPEG).
+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))
+    {
+      GeglNode *node =
+        gegl_node_new_child (NULL,
+                             "operation", "gegl:value-invert",
+                             NULL);
+
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Value Invert"),
+                                     node);
+
+      g_object_unref (node);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 
 @headers = qw("libgimpbase/gimpbase.h"
               "gegl/gimp-gegl-utils.h"
@@ -175,7 +222,8 @@ CODE
 
 @procs = qw(plug_in_colortoalpha
             plug_in_pixelize
-            plug_in_pixelize2);
+            plug_in_pixelize2
+            plug_in_vinvert);
 
 %exports = (app => [ procs], lib => []);
 



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