Replace the semi-flatten plug-in by a GEGL operation

This commit is contained in:
Michael Natterer
2012-05-04 23:55:39 +02:00
parent c16c61f458
commit f1a771439a
12 changed files with 149 additions and 172 deletions

View File

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

View File

@ -72,6 +72,8 @@ libappgegl_a_sources = \
gimpoperationhistogramsink.h \
gimpoperationmaskcomponents.c \
gimpoperationmaskcomponents.h \
gimpoperationsemiflatten.c \
gimpoperationsemiflatten.h \
gimpoperationsetalpha.c \
gimpoperationsetalpha.h \
gimpoperationshapeburst.c \

View File

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

View File

@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 675 procedures registered total */
/* 676 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

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

View File

@ -431,6 +431,7 @@
<menuitem action="layers-alpha-add" />
<menuitem action="layers-alpha-remove" />
<menuitem action="filters-color-to-alpha" />
<menuitem action="filters-semi-flatten" />
<menuitem action="filters-threshold-alpha" />
</placeholder>
<separator />
@ -627,7 +628,9 @@
<menu action="plug-in-render-pattern-menu" name="Pattern" />
<separator />
</menu>
<menu action="plug-in-web-menu" name="Web" />
<menu action="plug-in-web-menu" name="Web">
<menuitem action="filters-semi-flatten" />
</menu>
<menu action="plug-in-animation-menu" name="Animation" >
<placeholder name="Animators" />
<separator />

View File

@ -238,8 +238,6 @@
/sample-colorize.exe
/screenshot
/screenshot.exe
/semi-flatten
/semi-flatten.exe
/sharpen
/sharpen.exe
/shift

View File

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

View File

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

View File

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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <libgimp/gimp.h>
#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, "<Image>/Filters/Web");
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/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);
}

View File

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