2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-06-26 04:19:54 +08:00
|
|
|
* 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 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gimp plug-in dog.c: (C) 2004 William Skaggs
|
|
|
|
*
|
|
|
|
* Edge detection using the "Difference of Gaussians" method.
|
|
|
|
* Finds edges by doing two Gaussian blurs with different radius, and
|
|
|
|
* subtracting the results. Blurring is done using code taken from
|
|
|
|
* gauss_rle.c (as of Gimp 2.1, incorporated into gauss.c).
|
|
|
|
*/
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
|
|
|
|
#define PLUG_IN_PROC "plug-in-dog"
|
2008-03-24 23:29:55 +08:00
|
|
|
#define PLUG_IN_BINARY "edge-dog"
|
2005-08-14 05:39:56 +08:00
|
|
|
|
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gdouble inner;
|
|
|
|
gdouble outer;
|
|
|
|
gboolean normalize;
|
|
|
|
gboolean invert;
|
|
|
|
} DoGValues;
|
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
/* Declare local functions.
|
|
|
|
*/
|
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
2004-06-28 17:28:49 +08:00
|
|
|
static gint dog_dialog (gint32 image_ID,
|
|
|
|
GimpDrawable *drawable);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-06-28 17:28:49 +08:00
|
|
|
static void gauss_rle (GimpDrawable *drawable,
|
|
|
|
gdouble radius,
|
|
|
|
gint pass,
|
|
|
|
gboolean show_progress);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-06-28 17:28:49 +08:00
|
|
|
static void compute_difference (GimpDrawable *drawable,
|
|
|
|
GimpDrawable *drawable1,
|
|
|
|
GimpDrawable *drawable2,
|
|
|
|
guchar *maxval);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-06-28 17:28:49 +08:00
|
|
|
static void normalize (GimpDrawable *drawable,
|
|
|
|
guint maxval);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-11-26 11:52:01 +08:00
|
|
|
static void dog (gint32 image_ID,
|
|
|
|
GimpDrawable *drawable,
|
2004-06-28 17:28:49 +08:00
|
|
|
gdouble inner,
|
|
|
|
gdouble outer,
|
|
|
|
gboolean show_progress);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-09-29 23:33:02 +08:00
|
|
|
static void preview_update_preview (GimpPreview *preview,
|
|
|
|
GimpDrawable *drawable);
|
|
|
|
static void change_radius_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gaussian blur helper functions
|
|
|
|
*/
|
2004-06-28 17:28:49 +08:00
|
|
|
static gint * make_curve (gdouble sigma,
|
|
|
|
gint *length);
|
|
|
|
static void run_length_encode (guchar *src,
|
|
|
|
gint *dest,
|
|
|
|
gint bytes,
|
|
|
|
gint width);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
|
|
|
};
|
|
|
|
|
|
|
|
static DoGValues dogvals =
|
|
|
|
{
|
2004-07-06 02:18:32 +08:00
|
|
|
3.0, /* inner radius */
|
2004-09-25 18:42:12 +08:00
|
|
|
1.0, /* outer radius */
|
|
|
|
TRUE, /* normalize */
|
2007-09-21 21:27:33 +08:00
|
|
|
TRUE /* invert */
|
2004-06-26 04:19:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
|
|
|
query (void)
|
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef args[] =
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
2005-08-14 05:39:56 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
|
|
|
{ GIMP_PDB_FLOAT, "inner", "Radius of inner gaussian blur (in pixels, > 0.0)" },
|
|
|
|
{ GIMP_PDB_FLOAT, "outer", "Radius of outer gaussian blur (in pixels, > 0.0)" },
|
|
|
|
{ GIMP_PDB_INT32, "normalize", "True, False" },
|
|
|
|
{ GIMP_PDB_INT32, "invert", "True, False" }
|
2004-06-26 04:19:54 +08:00
|
|
|
};
|
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_PROC,
|
2006-03-17 17:29:48 +08:00
|
|
|
N_("Edge detection with control of edge thickness"),
|
2004-06-26 04:19:54 +08:00
|
|
|
"Applies two Gaussian blurs to the drawable, and "
|
|
|
|
"subtracts the results. This is robust and widely "
|
2006-08-29 21:09:19 +08:00
|
|
|
"used method for detecting edges.",
|
2004-06-26 04:19:54 +08:00
|
|
|
"Spencer Kimball, Peter Mattis, Sven Neumann, William Skaggs",
|
|
|
|
"Spencer Kimball, Peter Mattis, Sven Neumann, William Skaggs",
|
|
|
|
"1995-2004",
|
2005-03-17 07:56:18 +08:00
|
|
|
N_("_Difference of Gaussians..."),
|
2004-07-06 02:18:32 +08:00
|
|
|
"RGB*, GRAY*",
|
2004-06-26 04:19:54 +08:00
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (args), 0,
|
|
|
|
args, NULL);
|
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Edge-Detect");
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
|
|
|
{
|
2008-08-20 22:19:35 +08:00
|
|
|
static GimpParam values[2];
|
2004-06-26 04:19:54 +08:00
|
|
|
gint32 image_ID;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2008-09-19 03:31:26 +08:00
|
|
|
GError *error = NULL;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
|
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
2008-09-19 03:31:26 +08:00
|
|
|
if (! gimp_drawable_is_layer (param[2].data.d_drawable))
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
2008-09-19 03:31:26 +08:00
|
|
|
g_set_error (&error, 0, 0, "%s",
|
|
|
|
_("Can operate on layers only "
|
|
|
|
"(but was called on channel or mask)."));
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2008-09-19 03:31:26 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Get the specified image and drawable */
|
|
|
|
image_ID = param[1].data.d_image;
|
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2008-09-19 03:31:26 +08:00
|
|
|
/* set the tile cache size so that the gaussian blur works well */
|
|
|
|
gimp_tile_cache_ntiles (2 *
|
|
|
|
(MAX (drawable->width, drawable->height) /
|
|
|
|
gimp_tile_width () + 1));
|
2007-05-04 18:46:48 +08:00
|
|
|
|
2008-09-19 03:31:26 +08:00
|
|
|
if (strcmp (name, PLUG_IN_PROC) == 0)
|
|
|
|
{
|
|
|
|
switch (run_mode)
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
2008-09-19 03:31:26 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data (PLUG_IN_PROC, &dogvals);
|
|
|
|
|
|
|
|
/* First acquire information with a dialog */
|
|
|
|
if (! dog_dialog (image_ID, drawable))
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != 7)
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
|
|
|
dogvals.inner = param[3].data.d_float;
|
|
|
|
dogvals.outer = param[4].data.d_float;
|
|
|
|
dogvals.normalize = param[5].data.d_int32;
|
|
|
|
dogvals.invert = param[6].data.d_int32;
|
|
|
|
|
|
|
|
if (dogvals.inner <= 0.0 || dogvals.outer <= 0.0)
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data (PLUG_IN_PROC, &dogvals);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-19 03:31:26 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
2007-05-04 18:46:48 +08:00
|
|
|
}
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Make sure that the drawable is gray or RGB color */
|
|
|
|
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
|
|
|
|
gimp_drawable_is_gray (drawable->drawable_id))
|
|
|
|
{
|
|
|
|
gimp_progress_init (_("DoG Edge Detect"));
|
|
|
|
|
|
|
|
/* run the Difference of Gaussians */
|
|
|
|
gimp_image_undo_group_start (image_ID);
|
2007-05-04 18:46:48 +08:00
|
|
|
|
2004-11-26 11:52:01 +08:00
|
|
|
dog (image_ID, drawable, dogvals.inner, dogvals.outer, TRUE);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
gimp_image_undo_group_end (image_ID);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2007-05-04 18:46:48 +08:00
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
/* Store data */
|
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_set_data (PLUG_IN_PROC, &dogvals, sizeof (DoGValues));
|
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
gimp_displays_flush ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-20 22:19:35 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
*nreturn_vals = 2;
|
2008-09-19 03:31:26 +08:00
|
|
|
|
2008-08-20 22:19:35 +08:00
|
|
|
values[1].type = GIMP_PDB_STRING;
|
|
|
|
values[1].data.d_string = _("Cannot operate on indexed color images.");
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
}
|
|
|
|
|
2008-09-19 03:31:26 +08:00
|
|
|
if (status != GIMP_PDB_SUCCESS && error)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_STRING;
|
|
|
|
values[1].data.d_string = error->message;
|
|
|
|
}
|
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
dog_dialog (gint32 image_ID,
|
|
|
|
GimpDrawable *drawable)
|
|
|
|
{
|
2004-09-25 18:42:12 +08:00
|
|
|
GtkWidget *dialog;
|
2004-06-26 04:19:54 +08:00
|
|
|
GtkWidget *frame;
|
2004-06-28 17:28:49 +08:00
|
|
|
GtkWidget *button;
|
2004-09-25 18:42:12 +08:00
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *preview;
|
|
|
|
GtkWidget *coord;
|
2004-06-26 04:19:54 +08:00
|
|
|
GimpUnit unit;
|
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
gboolean run;
|
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
dialog = gimp_dialog_new (_("DoG Edge Detect"), PLUG_IN_BINARY,
|
2004-09-25 18:42:12 +08:00
|
|
|
NULL, 0,
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
NULL);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-08-14 05:39:56 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
2005-09-06 05:40:29 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
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);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
preview = gimp_drawable_preview_new (drawable, NULL);
|
2008-07-21 21:41:00 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), preview, FALSE, FALSE, 0);
|
2004-09-25 18:42:12 +08:00
|
|
|
gtk_widget_show (preview);
|
2008-07-21 21:41:00 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
g_signal_connect (preview, "invalidated",
|
|
|
|
G_CALLBACK (preview_update_preview),
|
|
|
|
drawable);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2005-08-23 08:18:08 +08:00
|
|
|
frame = gimp_frame_new (_("Smoothing Parameters"));
|
2004-09-25 18:42:12 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
2004-06-28 17:28:49 +08:00
|
|
|
gtk_widget_show (frame);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
/* Get the image resolution and unit */
|
|
|
|
gimp_image_get_resolution (image_ID, &xres, &yres);
|
|
|
|
unit = gimp_image_get_unit (image_ID);
|
|
|
|
|
|
|
|
coord = gimp_coordinates_new (unit, "%a", TRUE, FALSE, -1,
|
2004-07-06 06:28:09 +08:00
|
|
|
GIMP_SIZE_ENTRY_UPDATE_SIZE,
|
|
|
|
|
|
|
|
FALSE,
|
|
|
|
TRUE,
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-07-06 06:28:09 +08:00
|
|
|
_("_Radius 1:"), dogvals.inner, xres,
|
|
|
|
0, 8 * MAX (drawable->width, drawable->height),
|
|
|
|
0, 0,
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-07-06 06:28:09 +08:00
|
|
|
_("R_adius 2:"), dogvals.outer, yres,
|
|
|
|
0, 8 * MAX (drawable->width, drawable->height),
|
|
|
|
0, 0);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), coord);
|
2004-06-28 17:28:49 +08:00
|
|
|
gtk_widget_show (coord);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
gimp_size_entry_set_pixel_digits (GIMP_SIZE_ENTRY (coord), 1);
|
|
|
|
g_signal_connect (coord, "value-changed",
|
|
|
|
G_CALLBACK (change_radius_callback),
|
2004-07-06 06:28:09 +08:00
|
|
|
preview);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
button = gtk_check_button_new_with_mnemonic (_("_Normalize"));
|
2004-09-25 18:42:12 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
|
2004-06-26 04:19:54 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), dogvals.normalize);
|
|
|
|
g_signal_connect (button, "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&dogvals.normalize);
|
2004-09-25 18:42:12 +08:00
|
|
|
g_signal_connect_swapped (button, "toggled",
|
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2004-06-26 04:19:54 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
button = gtk_check_button_new_with_mnemonic (_("_Invert"));
|
2004-09-25 18:42:12 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
|
2004-06-26 04:19:54 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), dogvals.invert);
|
|
|
|
g_signal_connect (button, "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&dogvals.invert);
|
2004-09-25 18:42:12 +08:00
|
|
|
g_signal_connect_swapped (button, "toggled",
|
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2004-06-26 04:19:54 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
gtk_widget_show (dialog);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
if (run)
|
|
|
|
{
|
|
|
|
dogvals.inner = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (coord), 0);
|
2004-06-28 17:28:49 +08:00
|
|
|
dogvals.outer = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (coord), 1);
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
return run;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Convert from separated to premultiplied alpha, on a single scan line. */
|
|
|
|
static void
|
|
|
|
multiply_alpha (guchar *buf,
|
|
|
|
gint width,
|
|
|
|
gint bytes)
|
|
|
|
{
|
2004-07-06 06:28:09 +08:00
|
|
|
gint i, j;
|
2004-06-26 04:19:54 +08:00
|
|
|
gdouble alpha;
|
|
|
|
|
|
|
|
for (i = 0; i < width * bytes; i += bytes)
|
|
|
|
{
|
|
|
|
alpha = buf[i + bytes - 1] * (1.0 / 255.0);
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (j = 0; j < bytes - 1; j++)
|
|
|
|
buf[i + j] *= alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert from premultiplied to separated alpha, on a single scan
|
|
|
|
line. */
|
|
|
|
static void
|
|
|
|
separate_alpha (guchar *buf,
|
|
|
|
gint width,
|
|
|
|
gint bytes)
|
|
|
|
{
|
2004-07-06 06:28:09 +08:00
|
|
|
gint i, j;
|
|
|
|
guchar alpha;
|
2004-06-26 04:19:54 +08:00
|
|
|
gdouble recip_alpha;
|
2004-07-06 06:28:09 +08:00
|
|
|
gint new_val;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
for (i = 0; i < width * bytes; i += bytes)
|
|
|
|
{
|
|
|
|
alpha = buf[i + bytes - 1];
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (alpha != 0 && alpha != 255)
|
|
|
|
{
|
|
|
|
recip_alpha = 255.0 / alpha;
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (j = 0; j < bytes - 1; j++)
|
|
|
|
{
|
|
|
|
new_val = buf[i + j] * recip_alpha;
|
|
|
|
buf[i + j] = MIN (255, new_val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-26 11:52:01 +08:00
|
|
|
dog (gint32 image_ID,
|
|
|
|
GimpDrawable *drawable,
|
2004-06-28 17:28:49 +08:00
|
|
|
gdouble inner,
|
|
|
|
gdouble outer,
|
|
|
|
gboolean show_progress)
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
|
|
|
GimpDrawable *drawable1;
|
|
|
|
GimpDrawable *drawable2;
|
2004-07-06 06:28:09 +08:00
|
|
|
gint32 drawable_id = drawable->drawable_id;
|
|
|
|
gint32 layer1;
|
|
|
|
gint32 layer2;
|
|
|
|
gint width, height;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
guchar maxval = 255;
|
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable_id, &x1, &y1, &x2, &y2);
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
width = (x2 - x1);
|
|
|
|
height = (y2 - y1);
|
|
|
|
|
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
|
|
|
|
layer1 = gimp_layer_copy (drawable_id);
|
2004-11-26 11:52:01 +08:00
|
|
|
gimp_drawable_set_visible (layer1, FALSE);
|
|
|
|
gimp_drawable_set_name (layer1, "dog_scratch_layer1");
|
|
|
|
gimp_image_add_layer (image_ID, layer1, 0);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
layer2 = gimp_layer_copy (drawable_id);
|
2004-11-26 11:52:01 +08:00
|
|
|
gimp_drawable_set_visible (layer2, FALSE);
|
|
|
|
gimp_drawable_set_name (layer2, "dog_scratch_layer2");
|
|
|
|
gimp_image_add_layer (image_ID, layer2, 0);
|
|
|
|
|
|
|
|
drawable1 = gimp_drawable_get (layer1);
|
2004-06-26 04:19:54 +08:00
|
|
|
drawable2 = gimp_drawable_get (layer2);
|
|
|
|
|
|
|
|
gauss_rle (drawable1, inner, 0, show_progress);
|
|
|
|
gauss_rle (drawable2, outer, 1, show_progress);
|
|
|
|
|
|
|
|
compute_difference (drawable, drawable1, drawable2, &maxval);
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable1);
|
|
|
|
gimp_drawable_detach (drawable2);
|
|
|
|
|
2004-11-26 11:52:01 +08:00
|
|
|
gimp_image_remove_layer (image_ID, layer1);
|
|
|
|
gimp_image_remove_layer (image_ID, layer2);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
gimp_drawable_merge_shadow (drawable_id, TRUE);
|
|
|
|
gimp_drawable_update (drawable_id, x1, y1, width, height);
|
|
|
|
|
|
|
|
if (dogvals.normalize)
|
|
|
|
{
|
|
|
|
normalize (drawable, maxval);
|
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
gimp_drawable_merge_shadow (drawable_id, TRUE);
|
|
|
|
gimp_drawable_update (drawable_id, x1, y1, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dogvals.invert)
|
2004-07-06 02:18:32 +08:00
|
|
|
gimp_invert (drawable_id);
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
compute_difference (GimpDrawable *drawable,
|
|
|
|
GimpDrawable *drawable1,
|
|
|
|
GimpDrawable *drawable2,
|
2004-06-28 17:28:49 +08:00
|
|
|
guchar *maxval)
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
|
|
|
GimpPixelRgn src1_rgn, src2_rgn, dest_rgn;
|
2004-06-28 17:28:49 +08:00
|
|
|
gint width, height;
|
|
|
|
gint bpp;
|
|
|
|
gpointer pr;
|
|
|
|
gint x, y, k;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gboolean has_alpha;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
*maxval = 0;
|
|
|
|
|
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
width = (x2 - x1);
|
|
|
|
height = (y2 - y1);
|
|
|
|
|
|
|
|
if (width < 1 || height < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bpp = drawable->bpp;
|
2004-11-27 02:55:41 +08:00
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&src1_rgn,
|
|
|
|
drawable1, 0, 0, drawable1->width, drawable1->height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&src2_rgn,
|
|
|
|
drawable2, 0, 0, drawable1->width, drawable1->height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&dest_rgn,
|
|
|
|
drawable, 0, 0, drawable->width, drawable->height,
|
|
|
|
TRUE, TRUE);
|
|
|
|
|
|
|
|
for (pr = gimp_pixel_rgns_register (3, &src1_rgn, &src2_rgn, &dest_rgn);
|
|
|
|
pr != NULL;
|
|
|
|
pr = gimp_pixel_rgns_process (pr))
|
|
|
|
{
|
2004-06-28 17:28:49 +08:00
|
|
|
guchar *src1 = src1_rgn.data;
|
|
|
|
guchar *src2 = src2_rgn.data;
|
2004-06-26 04:19:54 +08:00
|
|
|
guchar *dest = dest_rgn.data;
|
2004-06-28 17:28:49 +08:00
|
|
|
gint row = src1_rgn.y - y1;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
for (y = 0; y < src1_rgn.h; y++, row++)
|
|
|
|
{
|
2004-06-28 17:28:49 +08:00
|
|
|
guchar *s1 = src1;
|
|
|
|
guchar *s2 = src2;
|
|
|
|
guchar *d = dest;
|
|
|
|
gint col = src1_rgn.x - x1;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
for (x = 0; x < src1_rgn.w; x++, col++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
{
|
|
|
|
for (k = 0; k < bpp-1; k++)
|
|
|
|
{
|
|
|
|
d[k] = CLAMP0255 (s1[k] - s2[k]);
|
|
|
|
*maxval = MAX (d[k], *maxval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (k = 0; k < bpp; k++)
|
|
|
|
{
|
|
|
|
d[k] = CLAMP0255 (s1[k] - s2[k]);
|
|
|
|
*maxval = MAX (d[k], *maxval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s1 += bpp;
|
|
|
|
s2 += bpp;
|
|
|
|
d += bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
src1 += src1_rgn.rowstride;
|
|
|
|
src2 += src2_rgn.rowstride;
|
|
|
|
dest += dest_rgn.rowstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
normalize (GimpDrawable *drawable,
|
2004-06-28 17:28:49 +08:00
|
|
|
guint maxval)
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
|
|
|
GimpPixelRgn src_rgn, dest_rgn;
|
2004-06-28 17:28:49 +08:00
|
|
|
gint bpp;
|
|
|
|
gpointer pr;
|
|
|
|
gint x, y, k;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gboolean has_alpha;
|
|
|
|
gdouble factor;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
if (maxval == 0)
|
|
|
|
return;
|
|
|
|
else
|
2004-07-06 06:28:09 +08:00
|
|
|
factor = 255.0 / maxval;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
|
|
|
bpp = drawable->bpp;
|
|
|
|
has_alpha = gimp_drawable_has_alpha(drawable->drawable_id);
|
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&src_rgn,
|
|
|
|
drawable, 0, 0, drawable->width, drawable->height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&dest_rgn,
|
|
|
|
drawable, 0, 0, drawable->width, drawable->height,
|
|
|
|
TRUE, TRUE);
|
|
|
|
|
|
|
|
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
|
|
|
|
pr != NULL;
|
|
|
|
pr = gimp_pixel_rgns_process (pr))
|
|
|
|
{
|
|
|
|
guchar *src = src_rgn.data;
|
|
|
|
guchar *dest = dest_rgn.data;
|
2004-06-28 17:28:49 +08:00
|
|
|
gint row = src_rgn.y - y1;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
for (y = 0; y < src_rgn.h; y++, row++)
|
|
|
|
{
|
2004-06-28 17:28:49 +08:00
|
|
|
guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
gint col = src_rgn.x - x1;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
for (x = 0; x < src_rgn.w; x++, col++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
{
|
|
|
|
for (k = 0; k < bpp-1; k++)
|
|
|
|
d[k] = factor * s[k];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (k = 0; k < bpp; k++)
|
|
|
|
d[k] = factor * s[k];
|
|
|
|
}
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
s += bpp;
|
|
|
|
d += bpp;
|
|
|
|
}
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
src += src_rgn.rowstride;
|
|
|
|
dest += dest_rgn.rowstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gauss_rle (GimpDrawable *drawable,
|
2004-06-28 17:28:49 +08:00
|
|
|
gdouble radius,
|
|
|
|
gint pass,
|
|
|
|
gboolean show_progress)
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
|
|
|
GimpPixelRgn src_rgn, dest_rgn;
|
|
|
|
gint width, height;
|
|
|
|
gint bytes;
|
|
|
|
gint has_alpha;
|
|
|
|
guchar *dest, *dp;
|
|
|
|
guchar *src, *sp;
|
|
|
|
gint *buf, *bb;
|
|
|
|
gint pixels;
|
|
|
|
gint total = 1;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint i, row, col, b;
|
|
|
|
gint start, end;
|
|
|
|
gdouble progress, max_progress;
|
|
|
|
gint *curve;
|
|
|
|
gint *sum = NULL;
|
|
|
|
gint val;
|
|
|
|
gint length;
|
|
|
|
gint initial_p, initial_m;
|
|
|
|
gdouble std_dev;
|
|
|
|
|
|
|
|
if (radius <= 0.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
width = (x2 - x1);
|
|
|
|
height = (y2 - y1);
|
|
|
|
|
|
|
|
if (width < 1 || height < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bytes = drawable->bpp;
|
|
|
|
has_alpha = gimp_drawable_has_alpha(drawable->drawable_id);
|
|
|
|
|
|
|
|
buf = g_new (gint, MAX (width, height) * 2);
|
|
|
|
|
|
|
|
/* allocate buffers for source and destination pixels */
|
|
|
|
src = g_new (guchar, MAX (width, height) * bytes);
|
|
|
|
dest = g_new (guchar, MAX (width, height) * bytes);
|
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&src_rgn,
|
|
|
|
drawable, 0, 0, drawable->width, drawable->height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&dest_rgn,
|
|
|
|
drawable, 0, 0, drawable->width, drawable->height,
|
|
|
|
TRUE, TRUE);
|
|
|
|
|
|
|
|
progress = 0.0;
|
2005-03-11 22:12:38 +08:00
|
|
|
max_progress = 2 * width * height;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
/* First the vertical pass */
|
|
|
|
radius = fabs (radius) + 1.0;
|
|
|
|
std_dev = sqrt (-(radius * radius) / (2 * log (1.0 / 255.0)));
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
curve = make_curve (std_dev, &length);
|
|
|
|
sum = g_new (gint, 2 * length + 1);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
sum[0] = 0;
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (i = 1; i <= length*2; i++)
|
|
|
|
sum[i] = curve[i-length-1] + sum[i-1];
|
|
|
|
sum += length;
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
total = sum[length] - sum[-length];
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (col = 0; col < width; col++)
|
|
|
|
{
|
|
|
|
gimp_pixel_rgn_get_col (&src_rgn, src, col + x1, y1, (y2 - y1));
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (has_alpha)
|
|
|
|
multiply_alpha (src, height, bytes);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
sp = src;
|
|
|
|
dp = dest;
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
{
|
|
|
|
initial_p = sp[b];
|
|
|
|
initial_m = sp[(height-1) * bytes + b];
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
/* Determine a run-length encoded version of the row */
|
|
|
|
run_length_encode (sp + b, buf, bytes, height);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
start = (row < length) ? -row : -length;
|
|
|
|
end = (height <= (row + length) ?
|
|
|
|
(height - row - 1) : length);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
val = 0;
|
|
|
|
i = start;
|
|
|
|
bb = buf + (row + i) * 2;
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (start != -length)
|
|
|
|
val += initial_p * (sum[start] - sum[-length]);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
while (i < end)
|
|
|
|
{
|
|
|
|
pixels = bb[0];
|
|
|
|
i += pixels;
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (i > end)
|
|
|
|
i = end;
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
val += bb[1] * (sum[i] - sum[start]);
|
|
|
|
bb += (pixels * 2);
|
|
|
|
start = i;
|
|
|
|
}
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (end != length)
|
|
|
|
val += initial_m * (sum[length] - sum[end]);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
dp[row * bytes + b] = val / total;
|
|
|
|
}
|
|
|
|
}
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (has_alpha)
|
|
|
|
separate_alpha (dest, height, bytes);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
gimp_pixel_rgn_set_col (&dest_rgn, dest, col + x1, y1, (y2 - y1));
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (show_progress)
|
|
|
|
{
|
2005-03-11 22:12:38 +08:00
|
|
|
progress += height;
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2007-05-04 18:46:48 +08:00
|
|
|
if ((col % 32) == 0)
|
2005-03-11 22:12:38 +08:00
|
|
|
gimp_progress_update (0.5 * (pass + (progress / max_progress)));
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
}
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
/* prepare for the horizontal pass */
|
|
|
|
gimp_pixel_rgn_init (&src_rgn,
|
|
|
|
drawable, 0, 0, drawable->width, drawable->height,
|
|
|
|
FALSE, TRUE);
|
|
|
|
|
|
|
|
/* Now the horizontal pass */
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
gimp_pixel_rgn_get_row (&src_rgn, src, x1, row + y1, (x2 - x1));
|
|
|
|
if (has_alpha)
|
|
|
|
multiply_alpha (src, width, bytes);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
sp = src;
|
|
|
|
dp = dest;
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
{
|
|
|
|
initial_p = sp[b];
|
|
|
|
initial_m = sp[(width-1) * bytes + b];
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
/* Determine a run-length encoded version of the row */
|
|
|
|
run_length_encode (sp + b, buf, bytes, width);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
for (col = 0; col < width; col++)
|
|
|
|
{
|
|
|
|
start = (col < length) ? -col : -length;
|
|
|
|
end = (width <= (col + length)) ? (width - col - 1) : length;
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
val = 0;
|
|
|
|
i = start;
|
|
|
|
bb = buf + (col + i) * 2;
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (start != -length)
|
|
|
|
val += initial_p * (sum[start] - sum[-length]);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
while (i < end)
|
|
|
|
{
|
|
|
|
pixels = bb[0];
|
|
|
|
i += pixels;
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (i > end)
|
|
|
|
i = end;
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
val += bb[1] * (sum[i] - sum[start]);
|
|
|
|
bb += (pixels * 2);
|
|
|
|
start = i;
|
|
|
|
}
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (end != length)
|
|
|
|
val += initial_m * (sum[length] - sum[end]);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
dp[col * bytes + b] = val / total;
|
|
|
|
}
|
|
|
|
}
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (has_alpha)
|
|
|
|
separate_alpha (dest, width, bytes);
|
2004-06-28 16:47:51 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
gimp_pixel_rgn_set_row (&dest_rgn, dest, x1, row + y1, (x2 - x1));
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-06-26 04:19:54 +08:00
|
|
|
if (show_progress)
|
|
|
|
{
|
2005-03-11 22:12:38 +08:00
|
|
|
progress += width;
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2007-05-04 18:46:48 +08:00
|
|
|
if ((row % 32) == 0)
|
2005-03-11 22:12:38 +08:00
|
|
|
gimp_progress_update (0.5 * (pass + (progress / max_progress)));
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* merge the shadow, update the drawable */
|
2004-07-06 06:28:09 +08:00
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
|
|
|
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
/* free buffers */
|
|
|
|
g_free (buf);
|
|
|
|
g_free (src);
|
|
|
|
g_free (dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The equations: g(r) = exp (- r^2 / (2 * sigma^2))
|
|
|
|
* r = sqrt (x^2 + y ^2)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gint *
|
|
|
|
make_curve (gdouble sigma,
|
|
|
|
gint *length)
|
|
|
|
{
|
2004-06-28 17:28:49 +08:00
|
|
|
gint *curve;
|
|
|
|
gdouble sigma2;
|
|
|
|
gdouble l;
|
|
|
|
gint temp;
|
|
|
|
gint i, n;
|
2004-06-26 04:19:54 +08:00
|
|
|
|
|
|
|
sigma2 = 2 * sigma * sigma;
|
|
|
|
l = sqrt (-sigma2 * log (1.0 / 255.0));
|
|
|
|
|
|
|
|
n = ceil (l) * 2;
|
|
|
|
if ((n % 2) == 0)
|
|
|
|
n += 1;
|
|
|
|
|
|
|
|
curve = g_new (gint, n);
|
|
|
|
|
|
|
|
*length = n / 2;
|
|
|
|
curve += *length;
|
|
|
|
curve[0] = 255;
|
|
|
|
|
|
|
|
for (i = 1; i <= *length; i++)
|
|
|
|
{
|
|
|
|
temp = (gint) (exp (- (i * i) / sigma2) * 255);
|
|
|
|
curve[-i] = temp;
|
|
|
|
curve[i] = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return curve;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_length_encode (guchar *src,
|
|
|
|
gint *dest,
|
|
|
|
gint bytes,
|
|
|
|
gint width)
|
|
|
|
{
|
|
|
|
gint start;
|
|
|
|
gint i;
|
|
|
|
gint j;
|
|
|
|
guchar last;
|
|
|
|
|
|
|
|
last = *src;
|
|
|
|
src += bytes;
|
|
|
|
start = 0;
|
|
|
|
|
|
|
|
for (i = 1; i < width; i++)
|
|
|
|
{
|
|
|
|
if (*src != last)
|
|
|
|
{
|
|
|
|
for (j = start; j < i; j++)
|
|
|
|
{
|
|
|
|
*dest++ = (i - j);
|
|
|
|
*dest++ = last;
|
|
|
|
}
|
|
|
|
start = i;
|
|
|
|
last = *src;
|
|
|
|
}
|
|
|
|
src += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = start; j < i; j++)
|
|
|
|
{
|
|
|
|
*dest++ = (i - j);
|
|
|
|
*dest++ = last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-28 16:47:51 +08:00
|
|
|
static void
|
2004-09-29 23:33:02 +08:00
|
|
|
preview_update_preview (GimpPreview *preview,
|
|
|
|
GimpDrawable *drawable)
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
2004-09-25 18:42:12 +08:00
|
|
|
gint x1, y1;
|
|
|
|
gint width, height;
|
|
|
|
gint bpp;
|
|
|
|
guchar *buffer;
|
|
|
|
GimpPixelRgn src_rgn;
|
|
|
|
GimpPixelRgn preview_rgn;
|
2004-11-27 02:55:41 +08:00
|
|
|
gint32 image_id, src_image_id;
|
2004-09-25 18:42:12 +08:00
|
|
|
gint32 preview_id;
|
|
|
|
GimpDrawable *preview_drawable;
|
2004-07-06 02:18:32 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
bpp = gimp_drawable_bpp (drawable->drawable_id);
|
2004-07-06 06:28:09 +08:00
|
|
|
|
2004-09-29 23:33:02 +08:00
|
|
|
gimp_preview_get_position (preview, &x1, &y1);
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
2004-07-06 02:18:32 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
buffer = g_new (guchar, width * height * bpp);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable,
|
|
|
|
x1, y1, width, height, FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_get_rect (&src_rgn, buffer,
|
|
|
|
x1, y1, width, height);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
/* set up gimp drawable for rendering preview into */
|
2004-11-27 02:55:41 +08:00
|
|
|
src_image_id = gimp_drawable_get_image (drawable->drawable_id);
|
|
|
|
image_id = gimp_image_new (width, height,
|
|
|
|
gimp_image_base_type (src_image_id));
|
2004-09-25 18:42:12 +08:00
|
|
|
preview_id = gimp_layer_new (image_id, "preview", width, height,
|
|
|
|
gimp_drawable_type (drawable->drawable_id),
|
|
|
|
100,
|
|
|
|
GIMP_NORMAL_MODE);
|
|
|
|
preview_drawable = gimp_drawable_get (preview_id);
|
|
|
|
gimp_image_add_layer (image_id, preview_id, 0);
|
|
|
|
gimp_layer_set_offsets (preview_id, 0, 0);
|
|
|
|
gimp_pixel_rgn_init (&preview_rgn, preview_drawable,
|
|
|
|
0, 0, width, height, TRUE, TRUE);
|
|
|
|
gimp_pixel_rgn_set_rect (&preview_rgn, buffer,
|
|
|
|
0, 0, width, height);
|
|
|
|
gimp_drawable_flush (preview_drawable);
|
|
|
|
gimp_drawable_merge_shadow (preview_id, TRUE);
|
|
|
|
gimp_drawable_update (preview_id, 0, 0, width, height);
|
|
|
|
|
2004-11-26 11:52:01 +08:00
|
|
|
dog (image_id, preview_drawable, dogvals.inner, dogvals.outer, FALSE);
|
2004-09-25 18:42:12 +08:00
|
|
|
|
|
|
|
gimp_pixel_rgn_get_rect (&preview_rgn, buffer,
|
|
|
|
0, 0, width, height);
|
|
|
|
|
2004-09-29 23:33:02 +08:00
|
|
|
gimp_preview_draw_buffer (preview, buffer, width * bpp);
|
2004-09-25 18:42:12 +08:00
|
|
|
|
|
|
|
gimp_image_delete (image_id);
|
|
|
|
g_free (buffer);
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-25 18:42:12 +08:00
|
|
|
change_radius_callback (GtkWidget *coord,
|
2004-06-28 17:28:49 +08:00
|
|
|
gpointer data)
|
2004-06-26 04:19:54 +08:00
|
|
|
{
|
2004-09-25 18:42:12 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (data);
|
|
|
|
|
|
|
|
dogvals.inner = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (coord), 0);
|
|
|
|
dogvals.outer = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (coord), 1);
|
2004-06-26 04:19:54 +08:00
|
|
|
|
2004-09-25 18:42:12 +08:00
|
|
|
gimp_preview_invalidate (preview);
|
2004-06-26 04:19:54 +08:00
|
|
|
}
|