plugins: Add compat wrappers for antialias

And remove the old plugin
This commit is contained in:
Téo Mazars 2013-08-04 09:05:38 +02:00
parent 8bad383a3b
commit 2b58fb4e69
9 changed files with 120 additions and 346 deletions

View File

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

View File

@ -120,6 +120,44 @@ plug_in_alienmap2_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
plug_in_antialias_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,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gegl:antialias",
NULL);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Antialias"),
node);
g_object_unref (node);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
plug_in_autocrop_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -1291,6 +1329,42 @@ register_plug_in_compat_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-plug-in-antialias
*/
procedure = gimp_procedure_new (plug_in_antialias_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"plug-in-antialias");
gimp_procedure_set_static_strings (procedure,
"plug-in-antialias",
"Antialias using the Scale3X edge-extrapolation algorithm",
"No more help.",
"Compatibility procedure. Please see 'gegl:antialias' for credits.",
"Compatibility procedure. Please see 'gegl:antialias' for credits.",
"2013",
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-autocrop
*/

View File

@ -8,8 +8,6 @@
/animation-optimize.exe
/animation-play
/animation-play.exe
/antialias
/antialias.exe
/apply-canvas
/apply-canvas.exe
/blinds

View File

@ -47,7 +47,6 @@ libexec_PROGRAMS = \
align-layers \
animation-optimize \
animation-play \
antialias \
apply-canvas \
blinds \
blur \
@ -257,21 +256,6 @@ animation_play_LDADD = \
$(INTLLIBS) \
$(animation_play_RC)
antialias_SOURCES = \
antialias.c
antialias_LDADD = \
$(libgimp) \
$(libgimpmath) \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
$(antialias_RC)
apply_canvas_SOURCES = \
apply-canvas.c

View File

@ -1,324 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* Auntie Alias 0.92 --- image filter plug-in
*
* Copyright (C) 2005 Adam D. Moss (adam@gimp.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this plug-in (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/* This plugin performs a pseudo-antialiasing effect on hard-edged source
* material. It does this by performing a 'clever' edge extrapolation for
* each pixel which is then resampled back to a single pixel for output.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
/* Constants */
#define PLUG_IN_PROC "plug-in-antialias"
/* Local function prototypes */
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static void render (GimpDrawable *drawable);
/* Local variables */
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN ()
static void
query (void)
{
static GimpParamDef args[] =
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
};
gimp_install_procedure (PLUG_IN_PROC,
N_("Antialias using the Scale3X edge-extrapolation "
"algorithm"),
"Help - write me",
"Adam D. Moss <adam@gimp.org>",
"Adam D. Moss <adam@gimp.org>",
"2005",
N_("_Antialias"),
"RGB*, GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Enhance");
}
static void
run (const gchar *name,
gint n_params,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
INIT_I18N ();
*nreturn_vals = 1;
*return_vals = values;
run_mode = param[0].data.d_int32;
if (strcmp (name, PLUG_IN_PROC) == 0)
{
switch (run_mode)
{
case GIMP_RUN_NONINTERACTIVE:
if (n_params != 3)
status = GIMP_PDB_CALLING_ERROR;
break;
case GIMP_RUN_INTERACTIVE:
break;
case GIMP_RUN_WITH_LAST_VALS:
break;
default:
break;
}
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
if (status == GIMP_PDB_SUCCESS)
{
GimpDrawable *drawable;
drawable = gimp_drawable_get (param[2].data.d_drawable);
gimp_progress_init (_("Antialiasing..."));
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
render (drawable);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
gimp_drawable_detach (drawable);
}
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
}
static int
extrapolate9 (const int bytes,
unsigned char *E0, unsigned char *E1, unsigned char *E2,
unsigned char *E3, unsigned char *E4, unsigned char *E5,
unsigned char *E6, unsigned char *E7, unsigned char *E8,
unsigned char *A, unsigned char *B, unsigned char *C,
unsigned char *D, unsigned char *E, unsigned char *F,
unsigned char *G, unsigned char *H, unsigned char *I)
{
#define PEQ(X,Y) (0==memcmp(X,Y,bytes))
#define PCPY(DST,SRC) do{memcpy(DST,SRC,bytes);}while(0)
/* an implementation of the Scale3X edge-extrapolation algorithm */
if ( (!PEQ(B,H)) && (!PEQ(D,F)) )
{
if (PEQ(D,B)) PCPY(E0,D); else PCPY(E0,E);
if ((PEQ(D,B) && !PEQ(E,C)) || (PEQ(B,F) && !PEQ(E,A)))
PCPY(E1,B); else PCPY(E1,E);
if (PEQ(B,F)) PCPY(E2,F); else PCPY(E2,E);
if ((PEQ(D,B) && !PEQ(E,G)) || (PEQ(D,H) && !PEQ(E,A)))
PCPY(E3,D); else PCPY(E3,E);
PCPY(E4,E);
if ((PEQ(B,F) && !PEQ(E,I)) || (PEQ(H,F) && !PEQ(E,C)))
PCPY(E5,F); else PCPY(E5,E);
if (PEQ(D,H)) PCPY(E6,D); else PCPY(E6,E);
if ((PEQ(D,H) && !PEQ(E,I)) || (PEQ(H,F) && !PEQ(E,G)))
PCPY(E7,H); else PCPY(E7,E);
if (PEQ(H,F)) PCPY(E8,F); else PCPY(E8,E);
return 1;
}
else
{
return 0;
}
#undef PEQ
#undef PCPY
}
static void
render (GimpDrawable *drawable)
{
gint width, height, bytes;
gint x, y, w, h;
gint row, col, b;
GimpPixelRgn srcPR, destPR;
guchar *rowbefore;
guchar *rowthis;
guchar *rowafter;
guchar *dest;
guchar *ninepix;
gboolean has_alpha;
guint alpha;
/* get bounds of working area */
if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x, &y, &w, &h))
return;
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
alpha = bytes - 1;
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE);
rowbefore = g_new (guchar, (width + 2) * bytes);
rowthis = g_new (guchar, (width + 2) * bytes);
rowafter = g_new (guchar, (width + 2) * bytes);
dest = g_new (guchar, (width + 2) * bytes);
ninepix = g_new (guchar, 9 * bytes);
gimp_pixel_rgn_get_row (&srcPR, &rowthis[bytes], 0, y, width);
memcpy (&rowthis[0], &rowthis[bytes], bytes);
memcpy (&rowthis[(width+1)*bytes], &rowthis[(width)*bytes], bytes);
memcpy (rowbefore, rowthis, (width+2)*bytes);
memcpy (rowafter, rowthis, (width+2)*bytes);
for (row = y; row < (y + h); ++row)
{
guchar *tmp;
gint srcrowafter = row + 1;
if (srcrowafter >= (y + h - 1))
srcrowafter = y + h - 1;
/* rotate pointers */
tmp = rowbefore;
rowbefore = rowthis;
rowthis = rowafter;
rowafter = tmp;
/* populate new after-row */
gimp_pixel_rgn_get_row (&srcPR, &rowafter[bytes], 0, srcrowafter, width);
memcpy (&rowafter[0], &rowafter[bytes], bytes);
memcpy (&rowafter[(width + 1) * bytes], &rowafter[width * bytes], bytes);
/* this macro returns the current pixel if it has some opacity. Otherwise
* it returns the center pixel of the current 3x3 area. */
#define USE_IF_ALPHA(p) (((!has_alpha) || *((p)+alpha)) ? (p) : &rowthis[(col+1)*bytes])
for (col = x; col < (x + w); ++col)
{
/* do 9x extrapolation pass */
if (((!has_alpha) || (rowthis[(col+1)*bytes+alpha])) &&
extrapolate9 (bytes,
&ninepix[0*bytes],
&ninepix[1*bytes],
&ninepix[2*bytes],
&ninepix[3*bytes],
&ninepix[4*bytes],
&ninepix[5*bytes],
&ninepix[6*bytes],
&ninepix[7*bytes],
&ninepix[8*bytes],
USE_IF_ALPHA (&rowbefore[(col+0)*bytes]),
USE_IF_ALPHA (&rowbefore[(col+1)*bytes]),
USE_IF_ALPHA (&rowbefore[(col+2)*bytes]),
USE_IF_ALPHA (&rowthis [(col+0)*bytes]),
&rowthis [(col+1)*bytes],
USE_IF_ALPHA (&rowthis [(col+2)*bytes]),
USE_IF_ALPHA (&rowafter [(col+0)*bytes]),
USE_IF_ALPHA (&rowafter [(col+1)*bytes]),
USE_IF_ALPHA (&rowafter [(col+2)*bytes])
))
{
/* subsample results and put into dest */
for (b = 0; b < bytes; ++b)
{
dest[(col * bytes) + b] =
(3*ninepix[0*bytes+b]+5*ninepix[1*bytes+b]+3*ninepix[2*bytes+b]+
5*ninepix[3*bytes+b]+6*ninepix[4*bytes+b]+5*ninepix[5*bytes+b]+
3*ninepix[6*bytes+b]+5*ninepix[7*bytes+b]+3*ninepix[8*bytes+b]+
19) / 38;
}
}
else
{
memcpy (&dest[col * bytes], &rowthis[(col + 1) * bytes], bytes);
}
}
#undef USE_IF_ALPHA
/* write result row to dest */
gimp_pixel_rgn_set_row (&destPR, &dest[x * bytes],
x, row, w);
if ((row & 31) == 0)
gimp_progress_update ((gdouble) row / (gdouble) h);
}
gimp_progress_update (1.0);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x, y, w, h);
g_free (rowbefore);
g_free (rowthis);
g_free (rowafter);
g_free (dest);
g_free (ninepix);
}

View File

@ -1,7 +1,6 @@
align_layers_RC = align-layers.rc.o
animation_optimize_RC = animation-optimize.rc.o
animation_play_RC = animation-play.rc.o
antialias_RC = antialias.rc.o
apply_canvas_RC = apply-canvas.rc.o
blinds_RC = blinds.rc.o
blur_RC = blur.rc.o

View File

@ -2,7 +2,6 @@
'align-layers' => { ui => 1 },
'animation-optimize' => {},
'animation-play' => { ui => 1, gegl => 1 },
'antialias' => {},
'apply-canvas' => { ui => 1 },
'blinds' => { ui => 1 },
'blur' => {},

View File

@ -9,7 +9,6 @@ plug-ins/color-rotate/color-rotate.c
plug-ins/common/align-layers.c
plug-ins/common/animation-optimize.c
plug-ins/common/animation-play.c
plug-ins/common/antialias.c
plug-ins/common/apply-canvas.c
plug-ins/common/blinds.c
plug-ins/common/blur.c

View File

@ -90,6 +90,50 @@ CODE
);
}
sub plug_in_antialias {
$blurb = 'Antialias using the Scale3X edge-extrapolation algorithm';
$help = <<'HELP';
No more help.
HELP
&std_pdb_compat('gegl:antialias');
$date = '2013';
@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,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gegl:antialias",
NULL);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Antialias"),
node);
g_object_unref (node);
}
else
success = FALSE;
}
CODE
);
}
sub plug_in_autocrop {
$blurb = 'Remove empty borders from the image';
@ -1328,6 +1372,7 @@ CODE
"gimp-intl.h");
@procs = qw(plug_in_alienmap2
plug_in_antialias
plug_in_autocrop
plug_in_autocrop_layer
plug_in_colortoalpha