Commit 9027a192 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

plug-ins/common/Makefile.am plug-ins/common/plugin-defs.pl added Redeye

2006-04-23  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/Makefile.am
	* plug-ins/common/plugin-defs.pl
	* plug-ins/common/redeye.c: added Redeye Removal plug-in, written
	by Robert Merkel and Andreas Røsdal. Fixes bug #91795.
parent e0d48725
2006-04-23 Sven Neumann <sven@gimp.org>
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl
* plug-ins/common/redeye.c: added Redeye Removal plug-in, written
by Robert Merkel and Andreas Røsdal. Fixes bug #91795.
2006-04-23 Manish Singh <yosh@gimp.org>
* plug-ins/common/plugin-defs.pl: use PNG_CFLAGS for the png plugin.
......
......@@ -101,6 +101,7 @@ psd_save
psp
randomize
raw
redeye
retinex
ripple
rotate
......
......@@ -133,6 +133,7 @@ libexec_PROGRAMS = \
$(PSP) \
randomize \
raw \
redeye \
retinex \
ripple \
rotate \
......@@ -1668,6 +1669,21 @@ raw_LDADD = \
$(RT_LIBS) \
$(INTLLIBS)
redeye_SOURCES = \
redeye.c
redeye_LDADD = \
$(libgimpui) \
$(libgimpconfig) \
$(libgimpwidgets) \
$(libgimp) \
$(libgimpcolor) \
$(libgimpmath) \
$(libgimpbase) \
$(GTK_LIBS) \
$(RT_LIBS) \
$(INTLLIBS)
retinex_SOURCES = \
retinex.c
......
......@@ -97,6 +97,7 @@
'psd_save' => { libdep => 'gtk', ui => 1 },
'psp' => { libdep => 'gtk', ui => 1, optional => 1, libopt => 'z' },
'randomize' => { libdep => 'gtk', ui => 1 },
'redeye' => { libdep => 'gtk', ui => 1 },
'raw' => { libdep => 'gtk', ui => 1 },
'retinex' => { libdep => 'gtk', ui => 1 },
'ripple' => { libdep => 'gtk', ui => 1 },
......
/* The GIMP -- an image manipulation program
* Red Eye Plug-in for the GIMP.
*
* Copyright (C) 2004 Robert Merkel <robert.merkel@benambra.org>
* Copyright (C) 2006 Andreas Røsdal <andrearo@stud.ntnu.no>
*
* All Rights Reserved.
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The GNU General Public License is also available from
* http://www.fsf.org/copyleft/gpl.html
*
* This plugin is used for removing the red-eye effect
* that occurs in flash photos.
*
* Based on a GIMP 1.2 Perl plugin by Geoff Kuenning
*
* Version History:
* 0.1 - initial preliminary release, single file, only documentation
* in the header comments, 2004-05-26
* 0.2 - Bugfix of red levels, improved documentation.
* 0.3 - Add internationalization support, preview widget,
* improve red eye algorithm threshold and documentation.
*
*/
#include "config.h"
#include <string.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
/* 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 remove_redeye (GimpDrawable *drawable,
GimpPreview *preview);
#define RED_FACTOR 0.5133333
#define GREEN_FACTOR 1
#define BLUE_FACTOR 0.1933333
#define SCALE_WIDTH 100
#define PREVIEW_SIZE 290
#define PLUG_IN_PROC "plug-in-red-eye-removal"
#define PLUG_IN_BINARY "redeye"
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
gint threshold = 50;
gboolean preview_toggle = TRUE;
MAIN ()
static void
query (void)
{
static GimpParamDef args[] =
{
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
{ GIMP_PDB_INT32, "threshold", "Red eye threshold in percent" }
};
gimp_set_data (PLUG_IN_PROC, &threshold, sizeof (threshold));
gimp_install_procedure (PLUG_IN_PROC,
N_("Remove the red eye effect caused by camera "
"flashes"),
"This plug-in removes the red eye effect caused by "
"camera flashes by using a percentage based red "
"color threshold. Make a selection containing the "
"eyes, and apply the filter while adjusting the "
"threshold to accurately remove the red eyes.",
"Robert Merkel <robert.merkel@benambra.org>, "
"Andreas Røsdal <andrearo@stud.ntnu.no>",
"Copyright 2004-2006 Robert Merkel, Andreas Røsdal",
"2006",
N_("_Red Eye Removal..."),
"RGB*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Enhance");
}
/*
* Create dialog for red eye removal
*/
static gboolean
dialog (gint32 image_id,
GimpDrawable *drawable,
gint *current_threshold)
{
GtkWidget *dialog;
GtkWidget *preview;
GtkWidget *table;
GtkWidget *main_vbox;
GtkWidget *label;
GtkObject *adj;
gboolean run = FALSE;
gimp_ui_init (PLUG_IN_BINARY, TRUE);
dialog = gimp_dialog_new (_("Red Eye Removal"), PLUG_IN_BINARY,
NULL, 0,
gimp_standard_help_func, PLUG_IN_PROC,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
gimp_window_set_transient (GTK_WINDOW (dialog));
main_vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
gtk_widget_show (main_vbox);
preview = gimp_drawable_preview_new (drawable, &preview_toggle);
gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
gtk_widget_set_size_request (GTK_WIDGET (preview),
PREVIEW_SIZE, PREVIEW_SIZE);
gtk_widget_show (preview);
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (main_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
adj = gimp_scale_entry_new (GTK_TABLE (table), 1, 0,
_("_Threshold:"),
SCALE_WIDTH, 0,
threshold,
0, 100, 1, 5, 0,
TRUE,
0, 100,
_("Threshold for the red eye color to remove."),
NULL);
label = g_object_new (GTK_TYPE_LABEL,
"label", _("Manually selecting the eyes may "
"improve the results."),
"xalign", 0.0,
"wrap", TRUE,
NULL);
gimp_label_set_attributes (GTK_LABEL (label),
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-1);
gtk_box_pack_end (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);
if (gimp_selection_is_empty (gimp_drawable_get_image (drawable->drawable_id)))
gtk_widget_show (label);
g_signal_connect_swapped (preview, "invalidated",
G_CALLBACK (remove_redeye),
drawable);
g_signal_connect (adj, "value-changed",
G_CALLBACK (gimp_int_adjustment_update),
&threshold);
g_signal_connect_swapped (adj, "value-changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
gtk_widget_show (dialog);
remove_redeye (drawable, GIMP_PREVIEW (preview));
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
return run;
}
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 threshold;
gint32 image_ID;
run_mode = param[0].data.d_int32;
INIT_I18N ();
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
image_ID = param[1].data.d_image;
switch (run_mode)
{
case GIMP_RUN_NONINTERACTIVE:
if (nparams != 4)
status = GIMP_PDB_CALLING_ERROR;
else
threshold = param[3].data.d_int32;
break;
case GIMP_RUN_INTERACTIVE:
gimp_get_data (PLUG_IN_PROC, &threshold);
if (strncmp (name, PLUG_IN_PROC, strlen (PLUG_IN_PROC)) == 0)
{
if (! dialog (image_ID, drawable, &threshold))
status = GIMP_PDB_CANCEL;
}
else
{
threshold = 50;
}
break;
case GIMP_RUN_WITH_LAST_VALS:
gimp_get_data (PLUG_IN_PROC, &threshold);
break;
default:
break;
}
/* Make sure that the drawable is RGB color.
* Greyscale images don't have the red eye effect. */
if (status == GIMP_PDB_SUCCESS &&
gimp_drawable_is_rgb (drawable->drawable_id))
{
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
remove_redeye (drawable, NULL);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
/* if we ran in auto mode don't reset the threshold */
if (run_mode == GIMP_RUN_INTERACTIVE
&& strncmp (name, PLUG_IN_PROC, strlen (PLUG_IN_PROC)) == 0)
{
gimp_set_data (PLUG_IN_PROC, &threshold, sizeof (threshold));
}
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
gimp_drawable_detach (drawable);
}
/*
* Red Eye Removal Alorithm, based on using a threshold to detect
* red pixels. Having a user-made selection around the eyes will
* prevent incorrect pixels from being selected.
*/
static void
remove_redeye (GimpDrawable *drawable,
GimpPreview *preview)
{
GimpPixelRgn src_rgn;
GimpPixelRgn dest_rgn;
const guchar *src;
guchar *dest;
gint progress, max_progress;
gboolean has_alpha;
const gint red = 0;
const gint green = 1;
const gint blue = 2;
const gint alpha = 3;
gint x1, y1, x2, y2;
gint x, y, width, height;
gpointer pr;
if (! preview)
{
gimp_progress_init (_("Removing red eye"));
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
width = x2 - x1;
height = y2 - y1;
}
else
{
gimp_preview_get_position (preview, &x1, &y1);
gimp_preview_get_size (preview, &width, &height);
x2 = x1 + width;
y2 = y1 + height;
}
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
/* Initialize progress */
progress = 0;
max_progress = (x2 - x1) * (y2 - y1);
/* substitute pixel vales */
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, width, height, TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
src = src_rgn.data;
dest = dest_rgn.data;
for (y = 0; y < src_rgn.h; y++)
{
const guchar *s = src;
guchar *d = dest;
for (x = 0; x < src_rgn.w; x++)
{
gint adjusted_red = s[red] * RED_FACTOR;
gint adjusted_green = s[green] * GREEN_FACTOR;
gint adjusted_blue = s[blue] * BLUE_FACTOR;
gint adjusted_threshold = (threshold - 50) * 2;
if (adjusted_red >= adjusted_green - adjusted_threshold &&
adjusted_red >= adjusted_blue - adjusted_threshold)
{
d[red] = ((gdouble) (adjusted_green + adjusted_blue)
/ (2.0 * RED_FACTOR));
}
else
{
d[red] = s[red];
}
d[green] = s[green];
d[blue] = s[blue];
if (has_alpha)
d[alpha] = s[alpha];
s += src_rgn.bpp;
d += dest_rgn.bpp;
}
src += src_rgn.rowstride;
dest += dest_rgn.rowstride;
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
if (! preview)
gimp_progress_update ((double) progress / (double) max_progress);
}
if (preview)
{
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, width, height, TRUE, TRUE);
gimp_drawable_preview_draw_region (GIMP_DRAWABLE_PREVIEW (preview),
&dest_rgn);
}
else
{
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id,
x1, y1, (x2 - x1), (y2 - y1));
}
}
......@@ -113,6 +113,7 @@ plug-ins/common/psd_save.c
plug-ins/common/psp.c
plug-ins/common/randomize.c
plug-ins/common/raw.c
plug-ins/common/redeye.c
plug-ins/common/retinex.c
plug-ins/common/ripple.c
plug-ins/common/rotate.c
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment