[gimp] app: turn the posterize tool into an ordinary GEGL filter



commit 7b009c69000b6ce3409f6f6f9cda161d0c6f1a34
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jan 16 21:41:00 2016 +0100

    app: turn the posterize tool into an ordinary GEGL filter
    
    which means replacing the whole thing by a few lines.

 app/actions/filters-actions.c           |    8 ++-
 app/operations/Makefile.am              |    2 -
 app/operations/gimpoperationposterize.c |  108 +++++++++++++++++++++--------
 app/operations/gimpoperationposterize.h |    2 +
 app/operations/gimpposterizeconfig.c    |  117 -------------------------------
 app/operations/gimpposterizeconfig.h    |   54 --------------
 app/pdb/color-cmds.c                    |   20 +++---
 app/pdb/drawable-color-cmds.c           |   20 +++---
 app/tools/Makefile.am                   |    2 -
 app/tools/gimp-tools.c                  |    2 -
 app/tools/gimpposterizetool.c           |  115 ------------------------------
 app/tools/gimpposterizetool.h           |   53 --------------
 menus/image-menu.xml.in                 |    2 +-
 po/POTFILES.in                          |    2 +-
 tools/pdbgen/pdb/color.pdb              |   20 +++---
 tools/pdbgen/pdb/drawable_color.pdb     |   20 +++---
 16 files changed, 130 insertions(+), 417 deletions(-)
---
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
index 8c8de44..e9833b2 100644
--- a/app/actions/filters-actions.c
+++ b/app/actions/filters-actions.c
@@ -402,6 +402,11 @@ static const GimpStringActionEntry filters_actions[] =
     "gegl:polar-coordinates",
     NULL /* FIXME GIMP_HELP_FILTER_POLAR_COORDINATES */ },
 
+  { "filters-posterize", GIMP_STOCK_TOOL_POSTERIZE,
+    NC_("filters-action", "_Posterize..."), NULL, NULL,
+    "gimp:posterize",
+    GIMP_HELP_TOOL_POSTERIZE },
+
   { "filters-red-eye-removal", GIMP_STOCK_GEGL,
     NC_("filters-action", "_Red Eye Removal..."), NULL, NULL,
     "gegl:red-eye-removal",
@@ -415,7 +420,7 @@ static const GimpStringActionEntry filters_actions[] =
   { "filters-semi-flatten", GIMP_STOCK_GEGL,
     NC_("filters-action", "_Semi-Flatten..."), NULL, NULL,
     "gimp:semi-flatten",
-    NULL /* FIXME GIMP_HELP_FILTER_POLAR_COORDINATES */ },
+    NULL /* FIXME GIMP_HELP_FILTER_SEMI_FLATTEN */ },
 
   { "filters-sepia", GIMP_STOCK_GEGL,
     NC_("filters-action", "_Sepia..."), NULL, NULL,
@@ -689,6 +694,7 @@ filters_actions_update (GimpActionGroup *group,
   SET_SENSITIVE ("filters-pixelize",                writable);
   SET_SENSITIVE ("filters-plasma",                  writable);
   SET_SENSITIVE ("filters-polar-coordinates",       writable);
+  SET_SENSITIVE ("filters-posterize",               writable);
   SET_SENSITIVE ("filters-red-eye-removal",         writable && !gray);
   SET_SENSITIVE ("filters-ripple",                  writable);
   SET_SENSITIVE ("filters-semi-flatten",            writable && alpha);
diff --git a/app/operations/Makefile.am b/app/operations/Makefile.am
index 79cd653..1adc703 100644
--- a/app/operations/Makefile.am
+++ b/app/operations/Makefile.am
@@ -39,8 +39,6 @@ libappoperations_generic_a_sources = \
        gimphuesaturationconfig.h               \
        gimplevelsconfig.c                      \
        gimplevelsconfig.h                      \
-       gimpposterizeconfig.c                   \
-       gimpposterizeconfig.h                   \
        gimpthresholdconfig.c                   \
        gimpthresholdconfig.h                   \
        \
diff --git a/app/operations/gimpoperationposterize.c b/app/operations/gimpoperationposterize.c
index 9b7397e..891f1b8 100644
--- a/app/operations/gimpoperationposterize.c
+++ b/app/operations/gimpoperationposterize.c
@@ -24,20 +24,38 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
 
+#include "libgimpconfig/gimpconfig.h"
 #include "libgimpmath/gimpmath.h"
 
 #include "operations-types.h"
 
 #include "gimpoperationposterize.h"
-#include "gimpposterizeconfig.h"
 
+#include "gimp-intl.h"
 
-static gboolean gimp_operation_posterize_process (GeglOperation       *operation,
-                                                  void                *in_buf,
-                                                  void                *out_buf,
-                                                  glong                samples,
-                                                  const GeglRectangle *roi,
-                                                  gint                 level);
+
+enum
+{
+  PROP_0,
+  PROP_LEVELS
+};
+
+
+static void     gimp_operation_posterize_get_property (GObject             *object,
+                                                       guint                property_id,
+                                                       GValue              *value,
+                                                       GParamSpec          *pspec);
+static void     gimp_operation_posterize_set_property (GObject             *object,
+                                                       guint                property_id,
+                                                       const GValue        *value,
+                                                       GParamSpec          *pspec);
+
+static gboolean gimp_operation_posterize_process      (GeglOperation       *operation,
+                                                       void                *in_buf,
+                                                       void                *out_buf,
+                                                       glong                samples,
+                                                       const GeglRectangle *roi,
+                                                       gint                 level);
 
 
 G_DEFINE_TYPE (GimpOperationPosterize, gimp_operation_posterize,
@@ -53,25 +71,21 @@ gimp_operation_posterize_class_init (GimpOperationPosterizeClass *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_posterize_set_property;
+  object_class->get_property = gimp_operation_posterize_get_property;
+
+  point_class->process       = gimp_operation_posterize_process;
 
   gegl_operation_class_set_keys (operation_class,
                                  "name",        "gimp:posterize",
                                  "categories",  "color",
-                                 "description", "GIMP Posterize operation",
+                                 "description", _("Reduce to a limited set of colors"),
                                  NULL);
 
-  point_class->process = gimp_operation_posterize_process;
-
-  g_object_class_install_property (object_class,
-                                   GIMP_OPERATION_POINT_FILTER_PROP_CONFIG,
-                                   g_param_spec_object ("config",
-                                                        "Config",
-                                                        "The config object",
-                                                        GIMP_TYPE_POSTERIZE_CONFIG,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT));
+  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_LEVELS,
+                                "levels",
+                                _("Posterize levels"),
+                                2, 256, 3, 0);
 }
 
 static void
@@ -79,6 +93,46 @@ gimp_operation_posterize_init (GimpOperationPosterize *self)
 {
 }
 
+static void
+gimp_operation_posterize_get_property (GObject    *object,
+                                       guint       property_id,
+                                       GValue     *value,
+                                       GParamSpec *pspec)
+{
+  GimpOperationPosterize *posterize = GIMP_OPERATION_POSTERIZE (object);
+
+  switch (property_id)
+    {
+    case PROP_LEVELS:
+      g_value_set_int (value, posterize->levels);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_operation_posterize_set_property (GObject      *object,
+                                       guint         property_id,
+                                       const GValue *value,
+                                       GParamSpec   *pspec)
+{
+  GimpOperationPosterize *posterize = GIMP_OPERATION_POSTERIZE (object);
+
+  switch (property_id)
+    {
+    case PROP_LEVELS:
+      posterize->levels = g_value_get_int (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
 static gboolean
 gimp_operation_posterize_process (GeglOperation       *operation,
                                   void                *in_buf,
@@ -87,16 +141,12 @@ gimp_operation_posterize_process (GeglOperation       *operation,
                                   const GeglRectangle *roi,
                                   gint                 level)
 {
-  GimpOperationPointFilter *point  = GIMP_OPERATION_POINT_FILTER (operation);
-  GimpPosterizeConfig      *config = GIMP_POSTERIZE_CONFIG (point->config);
-  gfloat                   *src    = in_buf;
-  gfloat                   *dest   = out_buf;
-  gfloat                    levels;
-
-  if (! config)
-    return FALSE;
+  GimpOperationPosterize *posterize = GIMP_OPERATION_POSTERIZE (operation);
+  gfloat                 *src       = in_buf;
+  gfloat                 *dest      = out_buf;
+  gfloat                  levels;
 
-  levels = config->levels - 1.0;
+  levels = posterize->levels - 1.0;
 
   while (samples--)
     {
diff --git a/app/operations/gimpoperationposterize.h b/app/operations/gimpoperationposterize.h
index b023a9d..0158d6e 100644
--- a/app/operations/gimpoperationposterize.h
+++ b/app/operations/gimpoperationposterize.h
@@ -39,6 +39,8 @@ typedef struct _GimpOperationPosterizeClass GimpOperationPosterizeClass;
 struct _GimpOperationPosterize
 {
   GimpOperationPointFilter  parent_instance;
+
+  gint                      levels;
 };
 
 struct _GimpOperationPosterizeClass
diff --git a/app/pdb/color-cmds.c b/app/pdb/color-cmds.c
index aa412db..38e62a2 100644
--- a/app/pdb/color-cmds.c
+++ b/app/pdb/color-cmds.c
@@ -44,7 +44,6 @@
 #include "operations/gimpdesaturateconfig.h"
 #include "operations/gimphuesaturationconfig.h"
 #include "operations/gimplevelsconfig.h"
-#include "operations/gimpposterizeconfig.h"
 #include "operations/gimpthresholdconfig.h"
 #include "plug-in/gimpplugin.h"
 #include "plug-in/gimppluginmanager.h"
@@ -238,15 +237,16 @@ posterize_invoker (GimpProcedure         *procedure,
                                      GIMP_PDB_ITEM_CONTENT, error) &&
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
         {
-          GObject *config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG,
-                                          "levels", levels,
-                                          NULL);
-
-          gimp_drawable_apply_operation_by_name (drawable, progress,
-                                                 _("Posterize"),
-                                                 "gimp:posterize",
-                                                 config);
-          g_object_unref (config);
+          GeglNode *node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gimp:posterize",
+                                 "levels",    levels,
+                                 NULL);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Posterize"),
+                                         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 d563bf4..9e984b7 100644
--- a/app/pdb/drawable-color-cmds.c
+++ b/app/pdb/drawable-color-cmds.c
@@ -44,7 +44,6 @@
 #include "operations/gimpdesaturateconfig.h"
 #include "operations/gimphuesaturationconfig.h"
 #include "operations/gimplevelsconfig.h"
-#include "operations/gimpposterizeconfig.h"
 #include "operations/gimpthresholdconfig.h"
 #include "plug-in/gimpplugin.h"
 #include "plug-in/gimppluginmanager.h"
@@ -652,15 +651,16 @@ drawable_posterize_invoker (GimpProcedure         *procedure,
                                      GIMP_PDB_ITEM_CONTENT, error) &&
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
         {
-          GObject *config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG,
-                                          "levels", levels,
-                                          NULL);
-
-          gimp_drawable_apply_operation_by_name (drawable, progress,
-                                                 C_("undo-type", "Posterize"),
-                                                 "gimp:posterize",
-                                                 config);
-          g_object_unref (config);
+          GeglNode *node =
+            gegl_node_new_child (NULL,
+                                 "operation", "gimp:posterize",
+                                 "levels",    levels,
+                                 NULL);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Posterize"),
+                                         node);
+          g_object_unref (node);
         }
       else
         success = FALSE;
diff --git a/app/tools/Makefile.am b/app/tools/Makefile.am
index 7a19126..d80d723 100644
--- a/app/tools/Makefile.am
+++ b/app/tools/Makefile.am
@@ -156,8 +156,6 @@ libapptools_a_sources = \
        gimpperspectiveclonetool.h      \
        gimpperspectivetool.c           \
        gimpperspectivetool.h           \
-       gimpposterizetool.c             \
-       gimpposterizetool.h             \
        gimprectangleselecttool.c       \
        gimprectangleselecttool.h       \
        gimprectangleselectoptions.c    \
diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c
index 362ea00..8d947e6 100644
--- a/app/tools/gimp-tools.c
+++ b/app/tools/gimp-tools.c
@@ -77,7 +77,6 @@
 #include "gimppenciltool.h"
 #include "gimpperspectiveclonetool.h"
 #include "gimpperspectivetool.h"
-#include "gimpposterizetool.h"
 #include "gimpthresholdtool.h"
 #include "gimprectangleselecttool.h"
 #include "gimprotatetool.h"
@@ -127,7 +126,6 @@ gimp_tools_init (Gimp *gimp)
     /*  color tools  */
     gimp_operation_tool_register,
     gimp_gegl_tool_register,
-    gimp_posterize_tool_register,
     gimp_curves_tool_register,
     gimp_levels_tool_register,
     gimp_threshold_tool_register,
diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in
index 9a4e1b1..5a768bd 100644
--- a/menus/image-menu.xml.in
+++ b/menus/image-menu.xml.in
@@ -532,7 +532,7 @@
       <menuitem action="tools-threshold" />
       <menuitem action="tools-levels" />
       <menuitem action="tools-curves" />
-      <menuitem action="tools-posterize" />
+      <menuitem action="filters-posterize" />
       <menuitem action="tools-desaturate" />
       <separator />
       <placeholder name="Invert">
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9024cc5..286d3f0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -254,6 +254,7 @@ app/operations/gimphuesaturationconfig.c
 app/operations/gimplevelsconfig.c
 app/operations/gimpoperationcagecoefcalc.c
 app/operations/gimpoperationcagetransform.c
+app/operations/gimpoperationposterize.c
 app/operations/gimpoperationsemiflatten.c
 app/operations/gimpoperationthresholdalpha.c
 app/operations/gimpthresholdconfig.c
@@ -405,7 +406,6 @@ app/tools/gimppainttool.c
 app/tools/gimppenciltool.c
 app/tools/gimpperspectiveclonetool.c
 app/tools/gimpperspectivetool.c
-app/tools/gimpposterizetool.c
 app/tools/gimprectangleoptions.c
 app/tools/gimprectangleselectoptions.c
 app/tools/gimprectangleselecttool.c
diff --git a/tools/pdbgen/pdb/color.pdb b/tools/pdbgen/pdb/color.pdb
index fd17fc7..9a6a6ae 100644
--- a/tools/pdbgen/pdb/color.pdb
+++ b/tools/pdbgen/pdb/color.pdb
@@ -171,22 +171,22 @@ sub posterize {
     );
 
     %invoke = (
-        headers => [ qw("operations/gimpposterizeconfig.h") ],
        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))
     {
-      GObject *config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG,
-                                      "levels", levels,
-                                      NULL);
-
-      gimp_drawable_apply_operation_by_name (drawable, progress,
-                                             _("Posterize"),
-                                             "gimp:posterize",
-                                             config);
-      g_object_unref (config);
+      GeglNode *node =
+        gegl_node_new_child (NULL,
+                             "operation", "gimp:posterize",
+                             "levels",    levels,
+                             NULL);
+
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Posterize"),
+                                     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 0dd7bf9..342f124 100644
--- a/tools/pdbgen/pdb/drawable_color.pdb
+++ b/tools/pdbgen/pdb/drawable_color.pdb
@@ -710,22 +710,22 @@ HELP
     );
 
     %invoke = (
-        headers => [ qw("operations/gimpposterizeconfig.h") ],
        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))
     {
-      GObject *config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG,
-                                      "levels", levels,
-                                      NULL);
-
-      gimp_drawable_apply_operation_by_name (drawable, progress,
-                                             C_("undo-type", "Posterize"),
-                                             "gimp:posterize",
-                                             config);
-      g_object_unref (config);
+      GeglNode *node =
+        gegl_node_new_child (NULL,
+                             "operation", "gimp:posterize",
+                             "levels",    levels,
+                             NULL);
+
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Posterize"),
+                                     node);
+      g_object_unref (node);
     }
   else
     success = FALSE;


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