diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c index 41c4b838a3..af76ff0fbc 100644 --- a/app/actions/filters-actions.c +++ b/app/actions/filters-actions.c @@ -69,6 +69,12 @@ static const GimpStringActionEntry filters_actions[] = "gegl:polar-coordinates", NULL /* FIXME GIMP_HELP_FILTER_POLAR_COORDINATES */ }, + { "filters-semi-flatten", GIMP_STOCK_GEGL, + NC_("filters-action", "_Semi-Flatten..."), NULL, + NC_("filters-action", "Replace partial transparency with a color"), + "gimp:semi-flatten", + NULL /* FIXME GIMP_HELP_FILTER_POLAR_COORDINATES */ }, + { "filters-threshold-alpha", GIMP_STOCK_GEGL, NC_("filters-action", "_Threshold Alpha..."), NULL, NC_("filters-action", "Make transparency all-or-nothing"), diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am index 03dc76544e..b8ff03a72f 100644 --- a/app/gegl/Makefile.am +++ b/app/gegl/Makefile.am @@ -72,6 +72,8 @@ libappgegl_a_sources = \ gimpoperationhistogramsink.h \ gimpoperationmaskcomponents.c \ gimpoperationmaskcomponents.h \ + gimpoperationsemiflatten.c \ + gimpoperationsemiflatten.h \ gimpoperationsetalpha.c \ gimpoperationsetalpha.h \ gimpoperationshapeburst.c \ diff --git a/app/gegl/gimp-gegl.c b/app/gegl/gimp-gegl.c index 2e78d24be5..f77477e71b 100644 --- a/app/gegl/gimp-gegl.c +++ b/app/gegl/gimp-gegl.c @@ -40,6 +40,7 @@ #include "gimpoperationgrow.h" #include "gimpoperationhistogramsink.h" #include "gimpoperationmaskcomponents.h" +#include "gimpoperationsemiflatten.h" #include "gimpoperationsetalpha.h" #include "gimpoperationshapeburst.h" #include "gimpoperationshrink.h" @@ -123,6 +124,7 @@ gimp_gegl_init (Gimp *gimp) g_type_class_ref (GIMP_TYPE_OPERATION_GROW); g_type_class_ref (GIMP_TYPE_OPERATION_HISTOGRAM_SINK); g_type_class_ref (GIMP_TYPE_OPERATION_MASK_COMPONENTS); + g_type_class_ref (GIMP_TYPE_OPERATION_SEMI_FLATTEN); g_type_class_ref (GIMP_TYPE_OPERATION_SET_ALPHA); g_type_class_ref (GIMP_TYPE_OPERATION_SHAPEBURST); g_type_class_ref (GIMP_TYPE_OPERATION_SHRINK); diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index d146c38446..af8522a887 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -28,7 +28,7 @@ #include "internal-procs.h" -/* 675 procedures registered total */ +/* 676 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 aca986a36a..5371b9136b 100644 --- a/app/pdb/plug-in-compat-cmds.c +++ b/app/pdb/plug-in-compat-cmds.c @@ -32,6 +32,7 @@ #include "pdb-types.h" +#include "core/gimpcontext.h" #include "core/gimpdrawable-operation.h" #include "core/gimpdrawable.h" #include "core/gimpparamspecs.h" @@ -225,6 +226,50 @@ plug_in_polar_coords_invoker (GimpProcedure *procedure, error ? *error : NULL); } +static GimpValueArray * +plug_in_semiflatten_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpDrawable *drawable; + + drawable = gimp_value_get_drawable (gimp_value_array_index (args, 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) && + gimp_drawable_has_alpha (drawable)) + { + GeglNode *node; + GimpRGB color; + + gimp_context_get_background (context, &color); + + node = + gegl_node_new_child (NULL, + "operation", "gimp:semi-flatten", + "color", &color, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Semi-Flatten"), + node); + + g_object_unref (node); + } + else + success = FALSE; + } + + return gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); +} + static GimpValueArray * plug_in_threshold_alpha_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -507,6 +552,42 @@ register_plug_in_compat_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-plug-in-semiflatten + */ + procedure = gimp_procedure_new (plug_in_semiflatten_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "plug-in-semiflatten"); + gimp_procedure_set_static_strings (procedure, + "plug-in-semiflatten", + "Replace partial transparency with the current background color", + "This plugin flattens pixels in an RGBA image that aren't completely transparent against the current GIMP background color.", + "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); + /* * gimp-plug-in-threshold-alpha */ diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in index bcb3eac71d..2ab542958d 100644 --- a/menus/image-menu.xml.in +++ b/menus/image-menu.xml.in @@ -431,6 +431,7 @@ + @@ -627,7 +628,9 @@ - + + + diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore index c9b9279202..04df9c13ac 100644 --- a/plug-ins/common/.gitignore +++ b/plug-ins/common/.gitignore @@ -238,8 +238,6 @@ /sample-colorize.exe /screenshot /screenshot.exe -/semi-flatten -/semi-flatten.exe /sharpen /sharpen.exe /shift diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am index b870a59a59..151caa1def 100644 --- a/plug-ins/common/Makefile.am +++ b/plug-ins/common/Makefile.am @@ -162,7 +162,6 @@ libexec_PROGRAMS = \ rotate \ sample-colorize \ $(SCREENSHOT) \ - semi-flatten \ sharpen \ shift \ sinus \ @@ -2231,21 +2230,6 @@ screenshot_LDADD = \ $(INTLLIBS) \ $(screenshot_RC) -semi_flatten_SOURCES = \ - semi-flatten.c - -semi_flatten_LDADD = \ - $(libgimp) \ - $(libgimpmath) \ - $(libgimpconfig) \ - $(libgimpcolor) \ - $(libgimpbase) \ - $(CAIRO_LIBS) \ - $(GDK_PIXBUF_LIBS) \ - $(RT_LIBS) \ - $(INTLLIBS) \ - $(semi_flatten_RC) - sharpen_SOURCES = \ sharpen.c diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common index 1f2792f3c4..edfc2c9045 100644 --- a/plug-ins/common/gimprc.common +++ b/plug-ins/common/gimprc.common @@ -116,7 +116,6 @@ ripple_RC = ripple.rc.o rotate_RC = rotate.rc.o sample_colorize_RC = sample-colorize.rc.o screenshot_RC = screenshot.rc.o -semi_flatten_RC = semi-flatten.rc.o sharpen_RC = sharpen.rc.o shift_RC = shift.rc.o sinus_RC = sinus.rc.o diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl index 5394dc3577..369bf296c5 100644 --- a/plug-ins/common/plugin-defs.pl +++ b/plug-ins/common/plugin-defs.pl @@ -117,7 +117,6 @@ 'rotate' => {}, 'sample-colorize' => { ui => 1 }, 'screenshot' => { ui => 1, optional => 1, libs => 'SCREENSHOT_LIBS', cflags => 'XFIXES_CFLAGS' }, - 'semi-flatten' => {}, 'sharpen' => { ui => 1 }, 'shift' => { ui => 1 }, 'sinus' => { ui => 1 }, diff --git a/plug-ins/common/semi-flatten.c b/plug-ins/common/semi-flatten.c deleted file mode 100644 index e3de754c8f..0000000000 --- a/plug-ins/common/semi-flatten.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Semi-Flatten plug-in v1.0 by Adam D. Moss, adam@foxbox.org. 1998/01/27 - */ - -/* 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 . - */ - -#include "config.h" - -#include - -#include "libgimp/stdplugins-intl.h" - - -#define PLUG_IN_PROC "plug-in-semiflatten" - - -/* Declare local functions. - */ -static void query (void); -static void run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals); - -static void semiflatten (GimpDrawable *drawable); - - -static guchar bgred, bggreen, bgblue; - -const GimpPlugInInfo PLUG_IN_INFO = -{ - NULL, /* init_proc */ - NULL, /* quit_proc */ - query, /* query_proc */ - run, /* run_proc */ -}; - -MAIN () - -static void -query (void) -{ - static const GimpParamDef args[] = - { - { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" }, - { GIMP_PDB_IMAGE, "image", "Input image (unused)" }, - { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" } - }; - - gimp_install_procedure (PLUG_IN_PROC, - N_("Replace partial transparency with the current background color"), - "This plugin flattens pixels in an RGBA image that " - "aren't completely transparent against the current " - "GIMP background color", - "Adam D. Moss (adam@foxbox.org)", - "Adam D. Moss (adam@foxbox.org)", - "27th January 1998", - N_("_Semi-Flatten"), - "RGBA", - GIMP_PLUGIN, - G_N_ELEMENTS (args), 0, - args, NULL); - - gimp_plugin_menu_register (PLUG_IN_PROC, "/Filters/Web"); - gimp_plugin_menu_register (PLUG_IN_PROC, "/Layer/Transparency/Modify"); -} - - -static void -run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals) -{ - static GimpParam values[1]; - GimpDrawable *drawable; - GimpPDBStatusType status = GIMP_PDB_SUCCESS; - - *nreturn_vals = 1; - *return_vals = values; - - values[0].type = GIMP_PDB_STATUS; - values[0].data.d_status = status; - - INIT_I18N(); - - /* Get the specified drawable */ - drawable = gimp_drawable_get (param[2].data.d_drawable); - - if (status == GIMP_PDB_SUCCESS) - { - /* Make sure that the drawable is indexed or RGB color */ - if (gimp_drawable_is_rgb (drawable->drawable_id)) - { - gimp_progress_init (_("Semi-Flattening")); - gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () - + 1)); - semiflatten (drawable); - gimp_displays_flush (); - } - else - { - status = GIMP_PDB_EXECUTION_ERROR; - } - } - - values[0].data.d_status = status; - - gimp_drawable_detach (drawable); -} - -static void -semiflatten_func (const guchar *src, - guchar *dest, - gint bpp, - gpointer data) -{ - dest[0] = (src[0] * src[3]) / 255 + (bgred * (255 - src[3])) / 255; - dest[1] = (src[1] * src[3]) / 255 + (bggreen * (255 - src[3])) / 255; - dest[2] = (src[2] * src[3]) / 255 + (bgblue * (255 - src[3])) / 255; - dest[3] = (src[3] == 0) ? 0 : 255; -} - -static void -semiflatten (GimpDrawable *drawable) -{ - GimpRGB background; - - gimp_context_get_background (&background); - gimp_rgb_get_uchar (&background, &bgred, &bggreen, &bgblue); - - gimp_rgn_iterate2 (drawable, 0 /* unused */, semiflatten_func, NULL); -} diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb index 07cc577672..7a119bf501 100644 --- a/tools/pdbgen/pdb/plug_in_compat.pdb +++ b/tools/pdbgen/pdb/plug_in_compat.pdb @@ -224,6 +224,57 @@ CODE ); } +sub plug_in_semiflatten { + $blurb = 'Replace partial transparency with the current background color'; + + $help = <<'HELP'; +This plugin flattens pixels in an RGBA image that aren't completely +transparent against the current GIMP background color. +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) && + gimp_drawable_has_alpha (drawable)) + { + GeglNode *node; + GimpRGB color; + + gimp_context_get_background (context, &color); + + node = + gegl_node_new_child (NULL, + "operation", "gimp:semi-flatten", + "color", &color, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Semi-Flatten"), + node); + + g_object_unref (node); + } + else + success = FALSE; +} +CODE + ); +} + sub plug_in_threshold_alpha { $blurb = 'Make transparency all-or-nothing'; @@ -321,6 +372,7 @@ CODE @headers = qw("libgimpbase/gimpbase.h" "gegl/gimp-gegl-utils.h" + "core/gimpcontext.h" "core/gimpdrawable.h" "core/gimpdrawable-operation.h" "gimppdb-utils.h" @@ -330,6 +382,7 @@ CODE plug_in_pixelize plug_in_pixelize2 plug_in_polar_coords + plug_in_semiflatten plug_in_threshold_alpha plug_in_vinvert);