[gimp] app: turn the desaturate tool into a normal GEGL filter



commit 149d3f441ffe7fc00386ced4fb04d50313aef413
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jan 16 22:38:12 2016 +0100

    app: turn the desaturate tool into a normal GEGL filter

 app/actions/filters-actions.c            |    6 ++
 app/operations/Makefile.am               |    2 -
 app/operations/gimpdesaturateconfig.c    |  121 -------------------------
 app/operations/gimpdesaturateconfig.h    |   54 -----------
 app/operations/gimpoperationdesaturate.c |  118 +++++++++++++++++-------
 app/operations/gimpoperationdesaturate.h |    2 +
 app/pdb/color-cmds.c                     |   35 ++++----
 app/pdb/drawable-color-cmds.c            |   20 ++--
 app/tools/Makefile.am                    |    2 -
 app/tools/gimp-tools.c                   |    2 -
 app/tools/gimpdesaturatetool.c           |  146 ------------------------------
 app/tools/gimpdesaturatetool.h           |   53 -----------
 menus/image-menu.xml.in                  |    3 +-
 po/POTFILES.in                           |    3 +-
 tools/pdbgen/pdb/color.pdb               |   36 ++++----
 tools/pdbgen/pdb/drawable_color.pdb      |   20 ++--
 16 files changed, 150 insertions(+), 473 deletions(-)
---
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
index e9833b2..daef8c6 100644
--- a/app/actions/filters-actions.c
+++ b/app/actions/filters-actions.c
@@ -187,6 +187,11 @@ static const GimpStringActionEntry filters_actions[] =
     "gegl:deinterlace",
     NULL /* FIXME GIMP_HELP_FILTER_DEINTERLACE */ },
 
+  { "filters-desaturate", GIMP_STOCK_TOOL_DESATURATE,
+    NC_("filters-action", "_Desaturate..."), NULL, NULL,
+    "gimp:desaturate",
+    GIMP_HELP_TOOL_DESATURATE },
+
   { "filters-difference-of-gaussians", GIMP_STOCK_GEGL,
     NC_("filters-action", "Difference of Gaussians..."), NULL, NULL,
     "gegl:difference-of-gaussians",
@@ -651,6 +656,7 @@ filters_actions_update (GimpActionGroup *group,
   SET_SENSITIVE ("filters-convolution-matrix",      writable);
   SET_SENSITIVE ("filters-cubism",                  writable);
   SET_SENSITIVE ("filters-deinterlace",             writable);
+  SET_SENSITIVE ("filters-desaturate",              writable && !gray);
   SET_SENSITIVE ("filters-difference-of-gaussians", writable);
   SET_SENSITIVE ("filters-diffraction-patterns",    writable);
   SET_SENSITIVE ("filters-displace",                writable);
diff --git a/app/operations/Makefile.am b/app/operations/Makefile.am
index 1adc703..a6f8b10 100644
--- a/app/operations/Makefile.am
+++ b/app/operations/Makefile.am
@@ -33,8 +33,6 @@ libappoperations_generic_a_sources = \
        gimpcolorizeconfig.h                    \
        gimpcurvesconfig.c                      \
        gimpcurvesconfig.h                      \
-       gimpdesaturateconfig.c                  \
-       gimpdesaturateconfig.h                  \
        gimphuesaturationconfig.c               \
        gimphuesaturationconfig.h               \
        gimplevelsconfig.c                      \
diff --git a/app/operations/gimpoperationdesaturate.c b/app/operations/gimpoperationdesaturate.c
index 5e8b87a..85a39b3 100644
--- a/app/operations/gimpoperationdesaturate.c
+++ b/app/operations/gimpoperationdesaturate.c
@@ -25,20 +25,38 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include "libgimpcolor/gimpcolor.h"
+#include "libgimpconfig/gimpconfig.h"
 
 #include "operations-types.h"
 
 #include "gimpoperationdesaturate.h"
-#include "gimpdesaturateconfig.h"
 
+#include "gimp-intl.h"
 
-static void      gimp_operation_desaturate_prepare (GeglOperation       *operation);
-static gboolean  gimp_operation_desaturate_process (GeglOperation       *operation,
-                                                    void                *in_buf,
-                                                    void                *out_buf,
-                                                    glong                samples,
-                                                    const GeglRectangle *roi,
-                                                    gint                 level);
+
+enum
+{
+  PROP_0,
+  PROP_MODE
+};
+
+
+static void     gimp_operation_desaturate_get_property (GObject             *object,
+                                                        guint                property_id,
+                                                        GValue              *value,
+                                                        GParamSpec          *pspec);
+static void     gimp_operation_desaturate_set_property (GObject             *object,
+                                                        guint                property_id,
+                                                        const GValue        *value,
+                                                        GParamSpec          *pspec);
+
+static void     gimp_operation_desaturate_prepare      (GeglOperation       *operation);
+static gboolean gimp_operation_desaturate_process      (GeglOperation       *operation,
+                                                        void                *in_buf,
+                                                        void                *out_buf,
+                                                        glong                samples,
+                                                        const GeglRectangle *roi,
+                                                        gint                 level);
 
 
 G_DEFINE_TYPE (GimpOperationDesaturate, gimp_operation_desaturate,
@@ -54,42 +72,78 @@ gimp_operation_desaturate_class_init (GimpOperationDesaturateClass *klass)
   GeglOperationClass            *operation_class = GEGL_OPERATION_CLASS (klass);
   GeglOperationPointFilterClass *point_class     = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
 
-  object_class->set_property   = gimp_operation_point_filter_set_property;
-  object_class->get_property   = gimp_operation_point_filter_get_property;
+  object_class->set_property = gimp_operation_desaturate_set_property;
+  object_class->get_property = gimp_operation_desaturate_get_property;
+
+  operation_class->prepare   = gimp_operation_desaturate_prepare;
+
+  point_class->process       = gimp_operation_desaturate_process;
 
   gegl_operation_class_set_keys (operation_class,
                                  "name",        "gimp:desaturate",
                                  "categories",  "color",
-                                 "description", "GIMP Desaturate operation",
+                                 "description", _("Turn colors into shades of gray"),
                                  NULL);
 
-  operation_class->prepare = gimp_operation_desaturate_prepare;
+  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_MODE,
+                                 "mode",
+                                 _("Choose shade of gray based on"),
+                                 GIMP_TYPE_DESATURATE_MODE,
+                                 GIMP_DESATURATE_LIGHTNESS, 0);
+}
+
+static void
+gimp_operation_desaturate_init (GimpOperationDesaturate *self)
+{
+}
+
+static void
+gimp_operation_desaturate_get_property (GObject    *object,
+                                        guint       property_id,
+                                        GValue     *value,
+                                        GParamSpec *pspec)
+{
+  GimpOperationDesaturate *desaturate = GIMP_OPERATION_DESATURATE (object);
 
-  point_class->process     = gimp_operation_desaturate_process;
+  switch (property_id)
+    {
+    case PROP_MODE:
+      g_value_set_enum (value, desaturate->mode);
+      break;
 
-  g_object_class_install_property (object_class,
-                                   GIMP_OPERATION_POINT_FILTER_PROP_CONFIG,
-                                   g_param_spec_object ("config",
-                                                        "Config",
-                                                        "The config object",
-                                                        GIMP_TYPE_DESATURATE_CONFIG,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT));
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
 }
 
 static void
-gimp_operation_desaturate_init (GimpOperationDesaturate *self)
+gimp_operation_desaturate_set_property (GObject      *object,
+                                        guint         property_id,
+                                        const GValue *value,
+                                        GParamSpec   *pspec)
 {
+  GimpOperationDesaturate *desaturate = GIMP_OPERATION_DESATURATE (object);
+
+  switch (property_id)
+    {
+    case PROP_MODE:
+      desaturate->mode = g_value_get_enum (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
 }
 
 static void
 gimp_operation_desaturate_prepare (GeglOperation *operation)
 {
-  GimpOperationPointFilter *point  = GIMP_OPERATION_POINT_FILTER (operation);
-  GimpDesaturateConfig     *config = GIMP_DESATURATE_CONFIG (point->config);
-  const Babl               *format;
+  GimpOperationDesaturate *desaturate = GIMP_OPERATION_DESATURATE (operation);
+  const Babl              *format;
 
-  if (config->mode == GIMP_DESATURATE_LUMINANCE)
+  if (desaturate->mode == GIMP_DESATURATE_LUMINANCE)
     {
       format = babl_format ("RGBA float");
     }
@@ -110,15 +164,11 @@ gimp_operation_desaturate_process (GeglOperation       *operation,
                                    const GeglRectangle *roi,
                                    gint                 level)
 {
-  GimpOperationPointFilter *point  = GIMP_OPERATION_POINT_FILTER (operation);
-  GimpDesaturateConfig     *config = GIMP_DESATURATE_CONFIG (point->config);
-  gfloat                   *src    = in_buf;
-  gfloat                   *dest   = out_buf;
-
-  if (! config)
-    return FALSE;
+  GimpOperationDesaturate *desaturate = GIMP_OPERATION_DESATURATE (operation);
+  gfloat                  *src        = in_buf;
+  gfloat                  *dest       = out_buf;
 
-  switch (config->mode)
+  switch (desaturate->mode)
     {
     case GIMP_DESATURATE_LIGHTNESS:
       while (samples--)
diff --git a/app/operations/gimpoperationdesaturate.h b/app/operations/gimpoperationdesaturate.h
index fb4507c..e6e1c18 100644
--- a/app/operations/gimpoperationdesaturate.h
+++ b/app/operations/gimpoperationdesaturate.h
@@ -39,6 +39,8 @@ typedef struct _GimpOperationDesaturateClass GimpOperationDesaturateClass;
 struct _GimpOperationDesaturate
 {
   GimpOperationPointFilter  parent_instance;
+
+  GimpDesaturateMode        mode;
 };
 
 struct _GimpOperationDesaturateClass
diff --git a/app/pdb/color-cmds.c b/app/pdb/color-cmds.c
index 38e62a2..87a3212 100644
--- a/app/pdb/color-cmds.c
+++ b/app/pdb/color-cmds.c
@@ -41,7 +41,6 @@
 #include "operations/gimpcolorbalanceconfig.h"
 #include "operations/gimpcolorizeconfig.h"
 #include "operations/gimpcurvesconfig.h"
-#include "operations/gimpdesaturateconfig.h"
 #include "operations/gimphuesaturationconfig.h"
 #include "operations/gimplevelsconfig.h"
 #include "operations/gimpthresholdconfig.h"
@@ -276,15 +275,16 @@ desaturate_invoker (GimpProcedure         *procedure,
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
           gimp_drawable_is_rgb (drawable))
         {
-          GObject *config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG,
-                                          "mode", GIMP_DESATURATE_LIGHTNESS,
-                                          NULL);
+          GeglNode *node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gimp:desaturate",
+                                 "mode",      GIMP_DESATURATE_LIGHTNESS,
+                                 NULL);
 
-          gimp_drawable_apply_operation_by_name (drawable, progress,
-                                                 _("Desaturate"),
-                                                 "gimp:desaturate",
-                                                 config);
-          g_object_unref (config);
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Desaturate"),
+                                         node);
+          g_object_unref (node);
         }
       else
         success = FALSE;
@@ -316,15 +316,16 @@ desaturate_full_invoker (GimpProcedure         *procedure,
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
           gimp_drawable_is_rgb (drawable))
         {
-          GObject *config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG,
-                                          "mode", desaturate_mode,
-                                          NULL);
+          GeglNode *node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gimp:desaturate",
+                                 "mode",      desaturate_mode,
+                                 NULL);
 
-          gimp_drawable_apply_operation_by_name (drawable, progress,
-                                                 _("Desaturate"),
-                                                 "gimp:desaturate",
-                                                 config);
-          g_object_unref (config);
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Desaturate"),
+                                         node);
+          g_object_unref (node);
         }
       else
         success = FALSE;
diff --git a/app/pdb/drawable-color-cmds.c b/app/pdb/drawable-color-cmds.c
index 9e984b7..49257fc 100644
--- a/app/pdb/drawable-color-cmds.c
+++ b/app/pdb/drawable-color-cmds.c
@@ -41,7 +41,6 @@
 #include "operations/gimpcolorbalanceconfig.h"
 #include "operations/gimpcolorizeconfig.h"
 #include "operations/gimpcurvesconfig.h"
-#include "operations/gimpdesaturateconfig.h"
 #include "operations/gimphuesaturationconfig.h"
 #include "operations/gimplevelsconfig.h"
 #include "operations/gimpthresholdconfig.h"
@@ -315,15 +314,16 @@ drawable_desaturate_invoker (GimpProcedure         *procedure,
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
           gimp_drawable_is_rgb (drawable))
         {
-          GObject *config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG,
-                                          "mode", desaturate_mode,
-                                          NULL);
+          GeglNode *node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gimp:desaturate",
+                                 "mode",      desaturate_mode,
+                                 NULL);
 
-          gimp_drawable_apply_operation_by_name (drawable, progress,
-                                                 C_("undo-type", "Desaturate"),
-                                                 "gimp:desaturate",
-                                                 config);
-          g_object_unref (config);
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Desaturate"),
+                                         node);
+          g_object_unref (node);
         }
       else
         success = FALSE;
diff --git a/app/tools/Makefile.am b/app/tools/Makefile.am
index d80d723..86f1cc8 100644
--- a/app/tools/Makefile.am
+++ b/app/tools/Makefile.am
@@ -68,8 +68,6 @@ libapptools_a_sources = \
        gimpcroptool.h                  \
        gimpcurvestool.c                \
        gimpcurvestool.h                \
-       gimpdesaturatetool.c            \
-       gimpdesaturatetool.h            \
        gimpdodgeburntool.c             \
        gimpdodgeburntool.h             \
        gimpdrawtool.c                  \
diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c
index 8d947e6..e0477cc 100644
--- a/app/tools/gimp-tools.c
+++ b/app/tools/gimp-tools.c
@@ -52,7 +52,6 @@
 #include "gimpconvolvetool.h"
 #include "gimpcroptool.h"
 #include "gimpcurvestool.h"
-#include "gimpdesaturatetool.h"
 #include "gimpdodgeburntool.h"
 #include "gimpellipseselecttool.h"
 #include "gimperasertool.h"
@@ -133,7 +132,6 @@ gimp_tools_init (Gimp *gimp)
     gimp_colorize_tool_register,
     gimp_hue_saturation_tool_register,
     gimp_color_balance_tool_register,
-    gimp_desaturate_tool_register,
 
     /*  paint tools  */
 
diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in
index ff2b904..15350db 100644
--- a/menus/image-menu.xml.in
+++ b/menus/image-menu.xml.in
@@ -533,7 +533,7 @@
       <menuitem action="tools-levels" />
       <menuitem action="tools-curves" />
       <menuitem action="filters-posterize" />
-      <menuitem action="tools-desaturate" />
+      <menuitem action="filters-desaturate" />
       <separator />
       <placeholder name="Invert">
         <menuitem action="drawable-invert" />
@@ -627,7 +627,6 @@
         <menuitem action="tools-threshold" />
         <menuitem action="tools-levels" />
         <menuitem action="tools-curves" />
-        <menuitem action="tools-desaturate" />
       </menu>
       <menuitem action="tools-vector" />
       <menuitem action="tools-color-picker" />
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 286d3f0..8ad628e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -249,11 +249,11 @@ app/operations/gimpbrightnesscontrastconfig.c
 app/operations/gimpcolorbalanceconfig.c
 app/operations/gimpcolorizeconfig.c
 app/operations/gimpcurvesconfig.c
-app/operations/gimpdesaturateconfig.c
 app/operations/gimphuesaturationconfig.c
 app/operations/gimplevelsconfig.c
 app/operations/gimpoperationcagecoefcalc.c
 app/operations/gimpoperationcagetransform.c
+app/operations/gimpoperationdesaturate.c
 app/operations/gimpoperationposterize.c
 app/operations/gimpoperationsemiflatten.c
 app/operations/gimpoperationthresholdalpha.c
@@ -365,7 +365,6 @@ app/tools/gimpconvolvetool.c
 app/tools/gimpcropoptions.c
 app/tools/gimpcroptool.c
 app/tools/gimpcurvestool.c
-app/tools/gimpdesaturatetool.c
 app/tools/gimpdodgeburntool.c
 app/tools/gimpeditselectiontool.c
 app/tools/gimpellipseselecttool.c
diff --git a/tools/pdbgen/pdb/color.pdb b/tools/pdbgen/pdb/color.pdb
index 9a6a6ae..5b78dac 100644
--- a/tools/pdbgen/pdb/color.pdb
+++ b/tools/pdbgen/pdb/color.pdb
@@ -204,7 +204,6 @@ sub desaturate {
     );
 
     %invoke = (
-       headers => [ qw("operations/gimpdesaturateconfig.h") ],
        code => <<'CODE'
 {
   if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
@@ -212,15 +211,16 @@ sub desaturate {
       gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
       gimp_drawable_is_rgb (drawable))
     {
-      GObject *config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG,
-                                      "mode", GIMP_DESATURATE_LIGHTNESS,
-                                      NULL);
+      GeglNode *node =
+        gegl_node_new_child (NULL,
+                             "operation", "gimp:desaturate",
+                             "mode",      GIMP_DESATURATE_LIGHTNESS,
+                             NULL);
 
-      gimp_drawable_apply_operation_by_name (drawable, progress,
-                                             _("Desaturate"),
-                                             "gimp:desaturate",
-                                             config);
-      g_object_unref (config);
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Desaturate"),
+                                     node);
+      g_object_unref (node);
     }
   else
     success = FALSE;
@@ -241,7 +241,6 @@ sub desaturate_full {
     );
 
     %invoke = (
-       headers => [ qw("operations/gimpdesaturateconfig.h") ],
        code => <<'CODE'
 {
   if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
@@ -249,15 +248,16 @@ sub desaturate_full {
       gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
       gimp_drawable_is_rgb (drawable))
     {
-      GObject *config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG,
-                                      "mode", desaturate_mode,
-                                      NULL);
+      GeglNode *node =
+        gegl_node_new_child (NULL,
+                             "operation", "gimp:desaturate",
+                             "mode",      desaturate_mode,
+                             NULL);
 
-      gimp_drawable_apply_operation_by_name (drawable, progress,
-                                             _("Desaturate"),
-                                             "gimp:desaturate",
-                                             config);
-      g_object_unref (config);
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Desaturate"),
+                                     node);
+      g_object_unref (node);
     }
   else
     success = FALSE;
diff --git a/tools/pdbgen/pdb/drawable_color.pdb b/tools/pdbgen/pdb/drawable_color.pdb
index 342f124..ca5c299 100644
--- a/tools/pdbgen/pdb/drawable_color.pdb
+++ b/tools/pdbgen/pdb/drawable_color.pdb
@@ -313,7 +313,6 @@ HELP
     );
 
     %invoke = (
-       headers => [ qw("operations/gimpdesaturateconfig.h") ],
        code => <<'CODE'
 {
   if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
@@ -321,15 +320,16 @@ HELP
       gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
       gimp_drawable_is_rgb (drawable))
     {
-      GObject *config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG,
-                                      "mode", desaturate_mode,
-                                      NULL);
+      GeglNode *node =
+        gegl_node_new_child (NULL,
+                             "operation", "gimp:desaturate",
+                             "mode",      desaturate_mode,
+                             NULL);
 
-      gimp_drawable_apply_operation_by_name (drawable, progress,
-                                             C_("undo-type", "Desaturate"),
-                                             "gimp:desaturate",
-                                             config);
-      g_object_unref (config);
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Desaturate"),
+                                     node);
+      g_object_unref (node);
     }
   else
     success = FALSE;


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