app: turn the posterize tool into an ordinary GEGL filter

which means replacing the whole thing by a few lines.
This commit is contained in:
Michael Natterer 2016-01-16 21:41:00 +01:00
parent 2334cb41a7
commit 7b009c6900
16 changed files with 126 additions and 413 deletions

View File

@ -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);

View File

@ -39,8 +39,6 @@ libappoperations_generic_a_sources = \
gimphuesaturationconfig.h \
gimplevelsconfig.c \
gimplevelsconfig.h \
gimpposterizeconfig.c \
gimpposterizeconfig.h \
gimpthresholdconfig.c \
gimpthresholdconfig.h \
\

View File

@ -24,13 +24,31 @@
#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"
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,
@ -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);
GimpOperationPosterize *posterize = GIMP_OPERATION_POSTERIZE (operation);
gfloat *src = in_buf;
gfloat *dest = out_buf;
gfloat levels;
if (! config)
return FALSE;
levels = config->levels - 1.0;
levels = posterize->levels - 1.0;
while (samples--)
{

View File

@ -39,6 +39,8 @@ typedef struct _GimpOperationPosterizeClass GimpOperationPosterizeClass;
struct _GimpOperationPosterize
{
GimpOperationPointFilter parent_instance;
gint levels;
};
struct _GimpOperationPosterizeClass

View File

@ -1,117 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpposterizeconfig.c
* Copyright (C) 2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpconfig/gimpconfig.h"
#include "operations-types.h"
#include "gimpposterizeconfig.h"
enum
{
PROP_0,
PROP_LEVELS
};
static void gimp_posterize_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_posterize_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE_WITH_CODE (GimpPosterizeConfig, gimp_posterize_config,
GIMP_TYPE_SETTINGS,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL))
#define parent_class gimp_posterize_config_parent_class
static void
gimp_posterize_config_class_init (GimpPosterizeConfigClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
object_class->set_property = gimp_posterize_config_set_property;
object_class->get_property = gimp_posterize_config_get_property;
viewable_class->default_icon_name = "gimp-tool-posterize";
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_LEVELS,
"levels",
"Posterize levels",
2, 256, 3, 0);
}
static void
gimp_posterize_config_init (GimpPosterizeConfig *self)
{
}
static void
gimp_posterize_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpPosterizeConfig *self = GIMP_POSTERIZE_CONFIG (object);
switch (property_id)
{
case PROP_LEVELS:
g_value_set_int (value, self->levels);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_posterize_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpPosterizeConfig *self = GIMP_POSTERIZE_CONFIG (object);
switch (property_id)
{
case PROP_LEVELS:
self->levels = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}

View File

@ -1,54 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpposterizeconfig.h
* Copyright (C) 2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_POSTERIZE_CONFIG_H__
#define __GIMP_POSTERIZE_CONFIG_H__
#include "core/gimpsettings.h"
#define GIMP_TYPE_POSTERIZE_CONFIG (gimp_posterize_config_get_type ())
#define GIMP_POSTERIZE_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_POSTERIZE_CONFIG, GimpPosterizeConfig))
#define GIMP_POSTERIZE_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_POSTERIZE_CONFIG, GimpPosterizeConfigClass))
#define GIMP_IS_POSTERIZE_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_POSTERIZE_CONFIG))
#define GIMP_IS_POSTERIZE_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_POSTERIZE_CONFIG))
#define GIMP_POSTERIZE_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_POSTERIZE_CONFIG, GimpPosterizeConfigClass))
typedef struct _GimpPosterizeConfigClass GimpPosterizeConfigClass;
struct _GimpPosterizeConfig
{
GimpSettings parent_instance;
gint levels;
};
struct _GimpPosterizeConfigClass
{
GimpSettingsClass parent_class;
};
GType gimp_posterize_config_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_POSTERIZE_CONFIG_H__ */

View File

@ -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,
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gimp:posterize",
"levels", levels,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
_("Posterize"),
"gimp:posterize",
config);
g_object_unref (config);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Posterize"),
node);
g_object_unref (node);
}
else
success = FALSE;

View File

@ -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,
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gimp:posterize",
"levels", levels,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Posterize"),
"gimp:posterize",
config);
g_object_unref (config);
node);
g_object_unref (node);
}
else
success = FALSE;

View File

@ -156,8 +156,6 @@ libapptools_a_sources = \
gimpperspectiveclonetool.h \
gimpperspectivetool.c \
gimpperspectivetool.h \
gimpposterizetool.c \
gimpposterizetool.h \
gimprectangleselecttool.c \
gimprectangleselecttool.h \
gimprectangleselectoptions.c \

View File

@ -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,

View File

@ -1,115 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "operations/gimpposterizeconfig.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpspinscale.h"
#include "gimpimagemapoptions.h"
#include "gimpposterizetool.h"
#include "gimp-intl.h"
static GeglNode * gimp_posterize_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config,
gchar **undo_desc);
static void gimp_posterize_tool_dialog (GimpImageMapTool *im_tool);
G_DEFINE_TYPE (GimpPosterizeTool, gimp_posterize_tool,
GIMP_TYPE_IMAGE_MAP_TOOL)
#define parent_class gimp_posterize_tool_parent_class
void
gimp_posterize_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_POSTERIZE_TOOL,
GIMP_TYPE_IMAGE_MAP_OPTIONS, NULL,
0,
"gimp-posterize-tool",
_("Posterize"),
_("Posterize Tool: Reduce to a limited set of colors"),
N_("_Posterize..."), NULL,
NULL, GIMP_HELP_TOOL_POSTERIZE,
GIMP_STOCK_TOOL_POSTERIZE,
data);
}
static void
gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass)
{
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
im_tool_class->dialog_desc = _("Posterize (Reduce Number of Colors)");
im_tool_class->get_operation = gimp_posterize_tool_get_operation;
im_tool_class->dialog = gimp_posterize_tool_dialog;
}
static void
gimp_posterize_tool_init (GimpPosterizeTool *posterize_tool)
{
}
static GeglNode *
gimp_posterize_tool_get_operation (GimpImageMapTool *image_map_tool,
GObject **config,
gchar **undo_desc)
{
*config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG, NULL);
return gegl_node_new_child (NULL,
"operation", "gimp:posterize",
"config", *config,
NULL);
}
/**********************/
/* Posterize dialog */
/**********************/
static void
gimp_posterize_tool_dialog (GimpImageMapTool *image_map_tool)
{
GtkWidget *main_vbox;
GtkWidget *scale;
main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
scale = gimp_prop_spin_scale_new (image_map_tool->config, "levels",
_("Posterize _levels"),
1.0, 10.0, 0);
gimp_spin_scale_set_gamma (GIMP_SPIN_SCALE (scale), 1.5);
gtk_box_pack_start (GTK_BOX (main_vbox), scale, FALSE, FALSE, 0);
gtk_widget_show (scale);
}

View File

@ -1,53 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_POSTERIZE_TOOL_H__
#define __GIMP_POSTERIZE_TOOL_H__
#include "gimpimagemaptool.h"
#define GIMP_TYPE_POSTERIZE_TOOL (gimp_posterize_tool_get_type ())
#define GIMP_POSTERIZE_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_POSTERIZE_TOOL, GimpPosterizeTool))
#define GIMP_POSTERIZE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_POSTERIZE_TOOL, GimpPosterizeToolClass))
#define GIMP_IS_POSTERIZE_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_POSTERIZE_TOOL))
#define GIMP_IS_POSTERIZE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_POSTERIZE_TOOL))
#define GIMP_POSTERIZE_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_POSTERIZE_TOOL, GimpPosterizeToolClass))
typedef struct _GimpPosterizeTool GimpPosterizeTool;
typedef struct _GimpPosterizeToolClass GimpPosterizeToolClass;
struct _GimpPosterizeTool
{
GimpImageMapTool parent_instance;
};
struct _GimpPosterizeToolClass
{
GimpImageMapToolClass parent_class;
};
void gimp_posterize_tool_register (GimpToolRegisterCallback callback,
gpointer data);
GType gimp_posterize_tool_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_POSTERIZE_TOOL_H__ */

View File

@ -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">

View File

@ -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

View File

@ -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,
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gimp:posterize",
"levels", levels,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
_("Posterize"),
"gimp:posterize",
config);
g_object_unref (config);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Posterize"),
node);
g_object_unref (node);
}
else
success = FALSE;

View File

@ -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,
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gimp:posterize",
"levels", levels,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Posterize"),
"gimp:posterize",
config);
g_object_unref (config);
node);
g_object_unref (node);
}
else
success = FALSE;