1997-11-25 06:05:25 +08:00
|
|
|
/* edge filter for the GIMP
|
|
|
|
* -Peter Mattis
|
|
|
|
*
|
|
|
|
* This filter performs edge detection on the input image.
|
|
|
|
* The code for this filter is based on "pgmedge", a program
|
|
|
|
* that is part of the netpbm package.
|
2004-05-27 01:29:30 +08:00
|
|
|
*
|
|
|
|
* The GIMP -- an 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 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.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* pgmedge.c - edge-detect a portable graymap
|
2004-09-07 20:13:29 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 1989 by Jef Poskanzer.
|
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ported to GIMP Plug-in API 1.0
|
|
|
|
* version 1.07
|
|
|
|
* This version requires GIMP v0.99.10 or above.
|
|
|
|
*
|
|
|
|
* This plug-in performs edge detection. The code is based on edge.c
|
|
|
|
* for GIMP 0.54 by Peter Mattis.
|
|
|
|
*
|
2003-07-30 04:55:37 +08:00
|
|
|
* Eiichi Takamori <taka@ma1.seikyou.ne.jp>
|
|
|
|
* http://ha1.seikyou.ne.jp/home/taka/gimp/
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
|
|
|
* Tips: you can enter arbitrary value into entry.
|
2003-07-30 04:55:37 +08:00
|
|
|
* (not bounded between 1.0 and 10.0)
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
/* 29 July 2003 Dave Neary <bolsh@gimp.org>
|
2003-08-27 17:37:19 +08:00
|
|
|
* Added more edge detection routines, from the thin_line
|
2003-07-30 04:55:37 +08:00
|
|
|
* plug-in by iccii
|
|
|
|
*/
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
#include "config.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-12 01:41:07 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
1999-12-22 18:03:19 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#ifdef RCSID
|
2000-01-12 01:41:07 +08:00
|
|
|
static gchar rcsid[] = "$Id$";
|
1997-11-25 06:05:25 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Some useful macros */
|
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
#define PLUG_IN_PROC "plug-in-edge"
|
|
|
|
#define PLUG_IN_BINARY "edge"
|
1997-11-25 06:05:25 +08:00
|
|
|
#define TILE_CACHE_SIZE 48
|
|
|
|
|
2003-08-27 17:37:19 +08:00
|
|
|
enum
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
SOBEL,
|
|
|
|
PREWITT,
|
|
|
|
GRADIENT,
|
|
|
|
ROBERTS,
|
|
|
|
DIFFERENTIAL,
|
2004-07-30 08:57:22 +08:00
|
|
|
LAPLACE
|
2003-07-30 04:55:37 +08:00
|
|
|
};
|
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2003-07-30 04:55:37 +08:00
|
|
|
gdouble amount;
|
|
|
|
gint edgemode;
|
|
|
|
gint wrapmode;
|
2004-09-12 03:11:04 +08:00
|
|
|
gboolean update_preview;
|
1997-11-25 06:05:25 +08:00
|
|
|
} EdgeVals;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function prototypes.
|
|
|
|
*/
|
|
|
|
|
2004-08-13 06:28:15 +08:00
|
|
|
static void query (void);
|
2004-09-29 23:33:02 +08:00
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
2004-08-13 06:28:15 +08:00
|
|
|
|
2004-09-29 23:33:02 +08:00
|
|
|
static void edge (GimpDrawable *drawable);
|
|
|
|
static gboolean edge_dialog (GimpDrawable *drawable);
|
|
|
|
static void edge_preview_update (GimpPreview *preview);
|
2004-08-13 06:28:15 +08:00
|
|
|
|
|
|
|
static gint edge_detect (const guchar *data);
|
|
|
|
static gint prewitt (const guchar *data);
|
|
|
|
static gint gradient (const guchar *data);
|
|
|
|
static gint roberts (const guchar *data);
|
|
|
|
static gint differential (const guchar *data);
|
|
|
|
static gint laplace (const guchar *data);
|
|
|
|
static gint sobel (const guchar *data);
|
2000-01-13 23:39:26 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/***** Local vars *****/
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-13 23:39:26 +08:00
|
|
|
NULL, /* init */
|
|
|
|
NULL, /* quit */
|
|
|
|
query, /* query */
|
|
|
|
run, /* run */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static EdgeVals evals =
|
|
|
|
{
|
2004-09-12 05:39:36 +08:00
|
|
|
2.0, /* amount */
|
|
|
|
SOBEL, /* Edge detection algorithm */
|
|
|
|
GIMP_PIXEL_FETCHER_EDGE_SMEAR, /* wrapmode */
|
|
|
|
TRUE /* update_preview */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/***** Functions *****/
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
2000-05-01 05:03:44 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParamDef args[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-08-14 05:39:56 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
2005-08-14 05:39:56 +08:00
|
|
|
{ GIMP_PDB_FLOAT, "amount", "Edge detection amount" },
|
|
|
|
{ GIMP_PDB_INT32, "wrapmode", "Edge detection behavior: { WRAP (0), SMEAR (1), BLACK (2) }" },
|
|
|
|
{ GIMP_PDB_INT32, "edgemode", "Edge detection algorithm: { SOBEL (0), PREWITT (1), GRADIENT (2), ROBERTS (3), DIFFERENTIAL (4), LAPLACE (5) }" }
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
2000-05-01 05:03:44 +08:00
|
|
|
|
2004-05-07 08:30:24 +08:00
|
|
|
const gchar *help_string =
|
2003-07-30 04:55:37 +08:00
|
|
|
"Perform edge detection on the contents of the specified drawable."
|
|
|
|
"AMOUNT is an arbitrary constant, WRAPMODE is like displace plug-in "
|
2003-08-27 07:43:48 +08:00
|
|
|
"(useful for tilable image). EDGEMODE sets the kind of matrix "
|
|
|
|
"transform applied to the pixels, SOBEL was the method used in older "
|
|
|
|
"versions.";
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_PROC,
|
2003-07-30 04:55:37 +08:00
|
|
|
"Perform edge detection on the contents of the specified drawable",
|
|
|
|
help_string,
|
|
|
|
"Peter Mattis & (ported to 1.0 by) Eiichi Takamori",
|
|
|
|
"Peter Mattis",
|
|
|
|
"1996",
|
2004-05-07 08:30:24 +08:00
|
|
|
N_("_Edge..."),
|
2003-07-30 04:55:37 +08:00
|
|
|
"RGB*, GRAY*",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (args), 0,
|
|
|
|
args, NULL);
|
2004-05-07 08:30:24 +08:00
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Edge-Detect");
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-02 19:07:41 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-12-29 21:26:29 +08:00
|
|
|
static GimpParam values[1];
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2004-09-12 03:11:04 +08:00
|
|
|
GimpDrawable *drawable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Get the specified drawable */
|
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
2001-12-29 21:26:29 +08:00
|
|
|
*return_vals = values;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1997-11-25 06:05:25 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Possibly retrieve data */
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &evals);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* First acquire information with a dialog */
|
|
|
|
if (! edge_dialog (drawable))
|
2003-07-30 04:55:37 +08:00
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
2003-09-01 22:40:23 +08:00
|
|
|
if (nparams != 5 && nparams != 6)
|
2003-08-27 17:37:19 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
evals.amount = param[3].data.d_float;
|
2003-08-27 07:43:48 +08:00
|
|
|
evals.wrapmode = param[4].data.d_int32;
|
2003-08-27 17:37:19 +08:00
|
|
|
evals.edgemode = nparams > 5 ? param[5].data.d_int32 : SOBEL;
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Possibly retrieve data */
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &evals);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-02-01 09:58:47 +08:00
|
|
|
/* make sure the drawable exist and is not indexed */
|
2001-06-15 04:07:38 +08:00
|
|
|
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
|
|
|
|
gimp_drawable_is_gray (drawable->drawable_id))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-13 23:39:26 +08:00
|
|
|
gimp_progress_init (_("Edge Detection..."));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* set the tile cache size */
|
|
|
|
gimp_tile_cache_ntiles (TILE_CACHE_SIZE);
|
|
|
|
|
|
|
|
/* run the edge effect */
|
|
|
|
edge (drawable);
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2003-07-30 04:55:37 +08:00
|
|
|
gimp_displays_flush ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Store data */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_set_data (PLUG_IN_PROC, &evals, sizeof (EdgeVals));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-02-01 09:58:47 +08:00
|
|
|
else
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
1998-02-01 09:58:47 +08:00
|
|
|
/* gimp_message ("edge: cannot operate on indexed color images"); */
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
1998-02-01 09:58:47 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* Edge Detection main */
|
|
|
|
/********************************************************/
|
|
|
|
|
|
|
|
static void
|
2000-08-22 09:26:57 +08:00
|
|
|
edge (GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-08-13 01:14:25 +08:00
|
|
|
GimpPixelRgn src_rgn, dest_rgn;
|
|
|
|
gpointer pr;
|
2002-11-22 06:04:39 +08:00
|
|
|
GimpPixelFetcher *pft;
|
2004-08-13 01:14:25 +08:00
|
|
|
guchar *srcrow, *src;
|
|
|
|
guchar *destrow, *dest;
|
|
|
|
guchar pix00[4], pix01[4], pix02[4];
|
|
|
|
guchar pix10[4], pix11[4], pix12[4];
|
|
|
|
guchar pix20[4], pix21[4], pix22[4];
|
|
|
|
glong width, height;
|
2004-09-07 20:13:29 +08:00
|
|
|
gint alpha;
|
|
|
|
gboolean has_alpha;
|
|
|
|
gint chan;
|
2004-08-13 01:14:25 +08:00
|
|
|
gint x, y;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint maxval;
|
|
|
|
gint cur_progress;
|
|
|
|
gint max_progress;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
if (evals.amount < 1.0)
|
|
|
|
evals.amount = 1.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-03-13 06:46:25 +08:00
|
|
|
pft = gimp_pixel_fetcher_new (drawable, FALSE);
|
2003-12-27 04:46:30 +08:00
|
|
|
gimp_pixel_fetcher_set_edge_mode (pft, evals.wrapmode);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-07 20:13:29 +08:00
|
|
|
width = gimp_drawable_width (drawable->drawable_id);
|
|
|
|
height = gimp_drawable_height (drawable->drawable_id);
|
|
|
|
alpha = gimp_drawable_bpp (drawable->drawable_id);
|
2001-06-15 04:07:38 +08:00
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
2000-01-13 23:39:26 +08:00
|
|
|
if (has_alpha)
|
|
|
|
alpha--;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
maxval = 255;
|
|
|
|
|
|
|
|
cur_progress = 0;
|
|
|
|
max_progress = (x2 - x1) * (y2 - y1);
|
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, x2-x1, y2-y1, FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, x2-x1, y2-y1, TRUE, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-08-27 17:37:19 +08:00
|
|
|
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
|
1997-11-25 06:05:25 +08:00
|
|
|
pr != NULL;
|
2000-01-13 23:39:26 +08:00
|
|
|
pr = gimp_pixel_rgns_process (pr))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-03-13 06:46:25 +08:00
|
|
|
srcrow = src_rgn.data;
|
1997-11-25 06:05:25 +08:00
|
|
|
destrow = dest_rgn.data;
|
2004-03-13 06:46:25 +08:00
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
for (y = dest_rgn.y;
|
2004-03-13 06:46:25 +08:00
|
|
|
y < (dest_rgn.y + dest_rgn.h);
|
|
|
|
y++, srcrow += src_rgn.rowstride, destrow += dest_rgn.rowstride)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
2004-03-13 06:46:25 +08:00
|
|
|
src = srcrow;
|
2003-07-30 04:55:37 +08:00
|
|
|
dest = destrow;
|
2004-03-13 06:46:25 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
for (x = dest_rgn.x;
|
|
|
|
x < (dest_rgn.x + dest_rgn.w);
|
|
|
|
x++, src += src_rgn.bpp, dest += dest_rgn.bpp)
|
|
|
|
{
|
2004-03-13 06:46:25 +08:00
|
|
|
if (dest_rgn.x < x && x < dest_rgn.x + dest_rgn.w - 2 &&
|
|
|
|
dest_rgn.y < y && y < dest_rgn.y + dest_rgn.h - 2)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
/*
|
2004-09-07 20:13:29 +08:00
|
|
|
* 3x3 kernel is inside of the tile -- do fast
|
|
|
|
* version
|
|
|
|
*/
|
2003-07-30 04:55:37 +08:00
|
|
|
for (chan = 0; chan < alpha; chan++)
|
|
|
|
{
|
2003-08-27 17:37:19 +08:00
|
|
|
/* get the 3x3 kernel into a guchar array,
|
2003-07-30 04:55:37 +08:00
|
|
|
* and send it to edge_detect */
|
|
|
|
guchar kernel[9];
|
2004-03-13 06:46:25 +08:00
|
|
|
gint i,j;
|
|
|
|
|
1998-01-09 17:26:28 +08:00
|
|
|
#define PIX(X,Y) src[ (Y-1)*(int)src_rgn.rowstride + (X-1)*(int)src_rgn.bpp + chan ]
|
2003-07-30 04:55:37 +08:00
|
|
|
/* make convolution */
|
|
|
|
for(i = 0; i < 3; i++)
|
|
|
|
for(j = 0; j < 3; j++)
|
|
|
|
kernel[3*i + j] = PIX(i,j);
|
2004-03-13 06:46:25 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#undef PIX
|
2004-03-13 06:46:25 +08:00
|
|
|
|
2004-09-07 20:13:29 +08:00
|
|
|
dest[chan] = edge_detect (kernel);
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2004-09-07 20:13:29 +08:00
|
|
|
* The kernel is not inside of the tile -- do slow
|
|
|
|
* version
|
|
|
|
*/
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2003-12-27 01:26:36 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x-1, y-1, pix00);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x , y-1, pix10);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x+1, y-1, pix20);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x-1, y , pix01);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x , y , pix11);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x+1, y , pix21);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x-1, y+1, pix02);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x , y+1, pix12);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, x+1, y+1, pix22);
|
2003-07-30 04:55:37 +08:00
|
|
|
|
|
|
|
for (chan = 0; chan < alpha; chan++)
|
|
|
|
{
|
|
|
|
guchar kernel[9];
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
kernel[0] = pix00[chan];
|
|
|
|
kernel[1] = pix01[chan];
|
|
|
|
kernel[2] = pix02[chan];
|
|
|
|
kernel[3] = pix10[chan];
|
|
|
|
kernel[4] = pix11[chan];
|
|
|
|
kernel[5] = pix12[chan];
|
|
|
|
kernel[6] = pix20[chan];
|
|
|
|
kernel[7] = pix21[chan];
|
|
|
|
kernel[8] = pix22[chan];
|
|
|
|
|
|
|
|
dest[chan] = edge_detect (kernel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (has_alpha)
|
|
|
|
dest[alpha] = src[alpha];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
cur_progress += dest_rgn.w * dest_rgn.h;
|
2000-01-13 23:39:26 +08:00
|
|
|
gimp_progress_update ((double) cur_progress / (double) max_progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-11-22 06:04:39 +08:00
|
|
|
gimp_pixel_fetcher_destroy (pft);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_drawable_flush (drawable);
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
|
|
|
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
/* *********************** Edge Detection ******************** */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Edge detect switcher function
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gint
|
2004-08-13 06:28:15 +08:00
|
|
|
edge_detect (const guchar *data)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
gint ret;
|
2004-09-07 20:13:29 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
switch (evals.edgemode)
|
|
|
|
{
|
2004-09-07 20:13:29 +08:00
|
|
|
case SOBEL:
|
|
|
|
ret = sobel (data);
|
|
|
|
break;
|
|
|
|
case PREWITT:
|
|
|
|
ret = prewitt (data);
|
|
|
|
break;
|
|
|
|
case GRADIENT:
|
|
|
|
ret = gradient (data);
|
|
|
|
break;
|
|
|
|
case ROBERTS:
|
|
|
|
ret = roberts (data);
|
|
|
|
break;
|
|
|
|
case DIFFERENTIAL:
|
|
|
|
ret = differential (data);
|
|
|
|
break;
|
|
|
|
case LAPLACE:
|
|
|
|
ret = laplace (data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -1;
|
|
|
|
break;
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
2004-09-07 20:13:29 +08:00
|
|
|
|
2004-05-27 01:29:30 +08:00
|
|
|
return CLAMP0255 (ret);
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sobel Edge detector
|
|
|
|
*/
|
|
|
|
static gint
|
2004-08-13 06:28:15 +08:00
|
|
|
sobel (const guchar *data)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
gint v_kernel[9] = {-1, 0, 1,
|
|
|
|
-2, 0, 2,
|
|
|
|
-1, 0, 1};
|
|
|
|
gint h_kernel[9] = {-1, -2, -1,
|
|
|
|
0, 0, 0,
|
|
|
|
1, 2, 1};
|
|
|
|
|
|
|
|
gint i;
|
|
|
|
gint v_grad, h_grad;
|
|
|
|
|
|
|
|
v_grad = 0;
|
|
|
|
h_grad = 0;
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
for (i = 0; i < 9; i++)
|
2003-08-27 17:37:19 +08:00
|
|
|
{
|
2003-07-30 04:55:37 +08:00
|
|
|
v_grad += v_kernel[i] * data[i];
|
|
|
|
h_grad += h_kernel[i] * data[i];
|
|
|
|
}
|
2004-05-27 01:29:30 +08:00
|
|
|
return sqrt (v_grad * v_grad * evals.amount +
|
2004-08-13 01:14:25 +08:00
|
|
|
h_grad * h_grad * evals.amount);
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Edge detector via template matting
|
|
|
|
* -- Prewitt
|
|
|
|
*/
|
|
|
|
static gint
|
2004-08-13 06:28:15 +08:00
|
|
|
prewitt (const guchar *data)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
gint k, max;
|
|
|
|
gint m[8];
|
|
|
|
|
2003-08-27 17:37:19 +08:00
|
|
|
m[0] = data [0] + data [1] + data [2]
|
|
|
|
+ data [3] - 2*data [4] + data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
- data [6] - data [7] - data [8];
|
2003-08-27 17:37:19 +08:00
|
|
|
m[1] = data [0] + data [1] + data [2]
|
|
|
|
+ data [3] - 2*data [4] - data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
+ data [6] - data [7] - data [8];
|
2003-08-27 17:37:19 +08:00
|
|
|
m[2] = data [0] + data [1] - data [2]
|
|
|
|
+ data [3] - 2*data [4] - data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
+ data [6] + data [7] - data [8];
|
2003-08-27 17:37:19 +08:00
|
|
|
m[3] = data [0] - data [1] - data [2]
|
|
|
|
+ data [3] - 2*data [4] - data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
+ data [6] + data [7] + data [8];
|
2003-08-27 17:37:19 +08:00
|
|
|
m[4] = - data [0] - data [1] - data [2]
|
|
|
|
+ data [3] - 2*data [4] + data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
+ data [6] + data [7] + data [8];
|
2003-08-27 17:37:19 +08:00
|
|
|
m[5] = - data [0] - data [1] + data [2]
|
|
|
|
- data [3] - 2*data [4] + data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
+ data [6] + data [7] + data [8];
|
2003-08-27 17:37:19 +08:00
|
|
|
m[6] = - data [0] + data [1] + data [2]
|
|
|
|
- data [3] - 2*data [4] + data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
- data [6] + data [7] + data [8];
|
2003-08-27 17:37:19 +08:00
|
|
|
m[7] = data [0] + data [1] + data [2]
|
|
|
|
- data [3] - 2*data [4] + data [5]
|
2003-07-30 04:55:37 +08:00
|
|
|
- data [6] - data [7] + data [8];
|
|
|
|
|
|
|
|
max = 0;
|
|
|
|
for (k = 0; k < 8; k++)
|
|
|
|
if (max < m[k])
|
|
|
|
max = m[k];
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2004-05-27 01:29:30 +08:00
|
|
|
return evals.amount * max;
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gradient Edge detector
|
|
|
|
*/
|
|
|
|
static gint
|
2004-08-13 06:28:15 +08:00
|
|
|
gradient (const guchar *data)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
gint v_kernel[9] = { 0, 0, 0,
|
|
|
|
0, 4, -4,
|
|
|
|
0, 0, 0};
|
|
|
|
gint h_kernel[9] = { 0, 0, 0,
|
|
|
|
0, -4, 0,
|
|
|
|
0, 4, 0};
|
|
|
|
|
|
|
|
gint i;
|
|
|
|
gint v_grad, h_grad;
|
|
|
|
|
|
|
|
v_grad = 0;
|
|
|
|
h_grad = 0;
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
for (i = 0; i < 9; i++)
|
2003-08-27 17:37:19 +08:00
|
|
|
{
|
2003-07-30 04:55:37 +08:00
|
|
|
v_grad += v_kernel[i] * data[i];
|
|
|
|
h_grad += h_kernel[i] * data[i];
|
|
|
|
}
|
|
|
|
|
2004-05-27 01:29:30 +08:00
|
|
|
return sqrt (v_grad * v_grad * evals.amount +
|
2004-08-13 01:14:25 +08:00
|
|
|
h_grad * h_grad * evals.amount);
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Roberts Edge detector
|
|
|
|
*/
|
|
|
|
static gint
|
2004-08-13 06:28:15 +08:00
|
|
|
roberts (const guchar *data)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
gint v_kernel[9] = {0, 0, 0,
|
|
|
|
0, 4, 0,
|
|
|
|
0, 0, -4};
|
|
|
|
gint h_kernel[9] = {0, 0, 0,
|
|
|
|
0, 0, 4,
|
|
|
|
0, -4, 0};
|
|
|
|
|
|
|
|
gint i;
|
|
|
|
gint v_grad, h_grad;
|
|
|
|
|
|
|
|
v_grad = 0;
|
|
|
|
h_grad = 0;
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
for (i = 0; i < 9; i++)
|
2003-08-27 17:37:19 +08:00
|
|
|
{
|
2003-07-30 04:55:37 +08:00
|
|
|
v_grad += v_kernel[i] * data[i];
|
|
|
|
h_grad += h_kernel[i] * data[i];
|
|
|
|
}
|
|
|
|
|
2004-05-27 01:29:30 +08:00
|
|
|
return sqrt (v_grad * v_grad * evals.amount +
|
2004-08-13 01:14:25 +08:00
|
|
|
h_grad * h_grad * evals.amount);
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Differential Edge detector
|
|
|
|
*/
|
|
|
|
static gint
|
2004-08-13 06:28:15 +08:00
|
|
|
differential (const guchar *data)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
gint v_kernel[9] = { 0, 0, 0,
|
|
|
|
0, 2, -2,
|
|
|
|
0, 2, -2};
|
|
|
|
gint h_kernel[9] = { 0, 0, 0,
|
|
|
|
0, -2, -2,
|
|
|
|
0, 2, 2};
|
|
|
|
|
|
|
|
|
|
|
|
gint i;
|
|
|
|
gint v_grad, h_grad;
|
|
|
|
|
|
|
|
v_grad = 0;
|
|
|
|
h_grad = 0;
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
for (i = 0; i < 9; i++)
|
2003-08-27 17:37:19 +08:00
|
|
|
{
|
2003-07-30 04:55:37 +08:00
|
|
|
v_grad += v_kernel[i] * data[i];
|
|
|
|
h_grad += h_kernel[i] * data[i];
|
|
|
|
}
|
|
|
|
|
2004-05-27 01:29:30 +08:00
|
|
|
return sqrt (v_grad * v_grad * evals.amount +
|
2004-08-13 01:14:25 +08:00
|
|
|
h_grad * h_grad * evals.amount);
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Laplace Edge detector
|
|
|
|
*/
|
|
|
|
static gint
|
2004-08-13 06:28:15 +08:00
|
|
|
laplace (const guchar *data)
|
2003-07-30 04:55:37 +08:00
|
|
|
{
|
|
|
|
gint kernel[9] = { 1, 1, 1,
|
|
|
|
1, -8, 1,
|
|
|
|
1, 1, 1};
|
|
|
|
|
|
|
|
gint i;
|
2004-05-27 01:29:30 +08:00
|
|
|
gint grad;
|
2003-07-30 04:55:37 +08:00
|
|
|
|
|
|
|
grad = 0;
|
2003-08-27 17:37:19 +08:00
|
|
|
|
2003-07-30 04:55:37 +08:00
|
|
|
for (i = 0; i < 9; i++)
|
2003-08-27 17:37:19 +08:00
|
|
|
{
|
2003-07-30 04:55:37 +08:00
|
|
|
grad += kernel[i] * data[i];
|
|
|
|
}
|
|
|
|
|
2004-05-27 01:29:30 +08:00
|
|
|
return grad * evals.amount;
|
2003-07-30 04:55:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/*******************************************************/
|
|
|
|
/* Dialog */
|
|
|
|
/*******************************************************/
|
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
static gboolean
|
2000-08-22 09:26:57 +08:00
|
|
|
edge_dialog (GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-12 03:11:04 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *preview;
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *hbox;
|
2004-08-13 06:28:15 +08:00
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *combo;
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *toggle;
|
|
|
|
GtkObject *scale_data;
|
2003-11-06 23:27:05 +08:00
|
|
|
GSList *group = NULL;
|
|
|
|
gboolean run;
|
2000-01-12 01:41:07 +08:00
|
|
|
|
2003-12-27 01:26:36 +08:00
|
|
|
gboolean use_wrap = (evals.wrapmode == GIMP_PIXEL_FETCHER_EDGE_WRAP);
|
|
|
|
gboolean use_smear = (evals.wrapmode == GIMP_PIXEL_FETCHER_EDGE_SMEAR);
|
|
|
|
gboolean use_black = (evals.wrapmode == GIMP_PIXEL_FETCHER_EDGE_BLACK);
|
2000-01-12 01:41:07 +08:00
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
dialog = gimp_dialog_new (_("Edge Detection"), PLUG_IN_BINARY,
|
2004-09-12 03:11:04 +08:00
|
|
|
NULL, 0,
|
2005-08-14 05:39:56 +08:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2004-09-12 03:11:04 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2004-09-12 03:11:04 +08:00
|
|
|
NULL);
|
2004-05-19 07:07:29 +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-12 03:11:04 +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-08-13 01:14:25 +08:00
|
|
|
|
2004-09-12 03:11:04 +08:00
|
|
|
preview = gimp_drawable_preview_new (drawable, &evals.update_preview);
|
|
|
|
gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
|
|
|
|
gtk_widget_show (preview);
|
|
|
|
g_signal_connect (preview, "invalidated",
|
|
|
|
G_CALLBACK (edge_preview_update),
|
|
|
|
NULL);
|
2004-08-13 01:14:25 +08:00
|
|
|
|
2004-08-13 06:28:15 +08:00
|
|
|
table = gtk_table_new (3, 3, FALSE);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
2004-09-12 03:11:04 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_widget_show (table);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-13 06:28:15 +08:00
|
|
|
combo = gimp_int_combo_box_new (_("Sobel"), SOBEL,
|
|
|
|
_("Prewitt"), PREWITT,
|
|
|
|
_("Gradient"), GRADIENT,
|
|
|
|
_("Roberts"), ROBERTS,
|
|
|
|
_("Differential"), DIFFERENTIAL,
|
|
|
|
_("Laplace"), LAPLACE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
|
|
|
|
evals.edgemode,
|
|
|
|
G_CALLBACK (gimp_int_combo_box_get_active),
|
|
|
|
&evals.edgemode);
|
|
|
|
|
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("_Algorithm:"), 0.0, 0.5,
|
|
|
|
combo, 2, FALSE);
|
2004-08-13 07:31:15 +08:00
|
|
|
g_signal_connect_swapped (combo, "changed",
|
2004-09-12 03:11:04 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2004-08-13 06:28:15 +08:00
|
|
|
|
2000-01-12 01:41:07 +08:00
|
|
|
/* Label, scale, entry for evals.amount */
|
2004-08-13 06:28:15 +08:00
|
|
|
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
|
|
|
_("A_mount:"), 100, 0,
|
2003-07-30 04:55:37 +08:00
|
|
|
evals.amount, 1.0, 10.0, 0.1, 1.0, 1,
|
2004-09-07 20:13:29 +08:00
|
|
|
FALSE, 1.0, G_MAXFLOAT,
|
2003-07-30 04:55:37 +08:00
|
|
|
NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (scale_data, "value-changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&evals.amount);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect_swapped (scale_data, "value-changed",
|
2004-09-12 03:11:04 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-12 01:41:07 +08:00
|
|
|
/* Radio buttons WRAP, SMEAR, BLACK */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-12 01:41:07 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
2004-08-13 06:28:15 +08:00
|
|
|
gtk_table_attach (GTK_TABLE (table), hbox, 0, 3, 2, 3,
|
2003-07-30 04:55:37 +08:00
|
|
|
GTK_FILL, GTK_FILL, 0, 0);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_show (hbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-26 02:10:04 +08:00
|
|
|
toggle = gtk_radio_button_new_with_mnemonic (group, _("_Wrap"));
|
2001-12-29 21:26:29 +08:00
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
|
1999-01-16 01:35:04 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), use_wrap);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&use_wrap);
|
2004-08-13 01:14:25 +08:00
|
|
|
g_signal_connect_swapped (toggle, "toggled",
|
2004-09-12 03:11:04 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2002-05-26 02:10:04 +08:00
|
|
|
toggle = gtk_radio_button_new_with_mnemonic (group, _("_Smear"));
|
2001-12-29 21:26:29 +08:00
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
|
1999-01-16 01:35:04 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), use_smear);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&use_smear);
|
2004-08-13 01:14:25 +08:00
|
|
|
g_signal_connect_swapped (toggle, "toggled",
|
2004-09-12 03:11:04 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2002-05-26 02:10:04 +08:00
|
|
|
toggle = gtk_radio_button_new_with_mnemonic (group, _("_Black"));
|
2001-12-29 21:26:29 +08:00
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
|
1999-01-16 01:35:04 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), use_black);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (toggle);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&use_black);
|
2004-08-13 01:14:25 +08:00
|
|
|
g_signal_connect_swapped (toggle, "toggled",
|
2004-09-12 03:11:04 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-12 03:11:04 +08:00
|
|
|
gtk_widget_show (dialog);
|
2004-08-13 01:14:25 +08:00
|
|
|
|
2004-09-12 03:11:04 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-09-12 03:11:04 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (use_wrap)
|
2003-12-27 01:26:36 +08:00
|
|
|
evals.wrapmode = GIMP_PIXEL_FETCHER_EDGE_WRAP;
|
1997-11-25 06:05:25 +08:00
|
|
|
else if (use_smear)
|
2003-12-27 01:26:36 +08:00
|
|
|
evals.wrapmode = GIMP_PIXEL_FETCHER_EDGE_SMEAR;
|
1997-11-25 06:05:25 +08:00
|
|
|
else if (use_black)
|
2003-12-27 01:26:36 +08:00
|
|
|
evals.wrapmode = GIMP_PIXEL_FETCHER_EDGE_BLACK;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2004-08-13 01:14:25 +08:00
|
|
|
|
|
|
|
static void
|
2004-09-29 23:33:02 +08:00
|
|
|
edge_preview_update (GimpPreview *preview)
|
2004-08-13 01:14:25 +08:00
|
|
|
{
|
|
|
|
/* drawable */
|
2004-09-29 23:33:02 +08:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
glong bytes;
|
|
|
|
gint alpha;
|
|
|
|
gboolean has_alpha;
|
2004-08-13 01:14:25 +08:00
|
|
|
|
|
|
|
/* preview */
|
|
|
|
guchar *src = NULL; /* Buffer to hold source image */
|
|
|
|
guchar *render_buffer = NULL; /* Buffer to hold rendered image */
|
|
|
|
guchar *dest;
|
2004-09-12 03:11:04 +08:00
|
|
|
gint width; /* Width of preview widget */
|
|
|
|
gint height; /* Height of preview widget */
|
|
|
|
gint x1; /* Upper-left X of preview */
|
|
|
|
gint y1; /* Upper-left Y of preview */
|
2004-08-13 01:14:25 +08:00
|
|
|
GimpPixelRgn srcPR; /* Pixel regions */
|
|
|
|
|
|
|
|
/* algorithm */
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
/* Get drawable info */
|
2004-09-29 23:33:02 +08:00
|
|
|
drawable =
|
|
|
|
gimp_drawable_preview_get_drawable (GIMP_DRAWABLE_PREVIEW (preview));
|
|
|
|
bytes = gimp_drawable_bpp (drawable->drawable_id);
|
2004-08-13 01:14:25 +08:00
|
|
|
alpha = bytes;
|
2004-09-29 23:33:02 +08:00
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
2004-08-13 01:14:25 +08:00
|
|
|
if (has_alpha)
|
|
|
|
alpha--;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup for filter...
|
|
|
|
*/
|
2004-09-29 23:33:02 +08:00
|
|
|
gimp_preview_get_position (preview, &x1, &y1);
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
2004-08-13 01:14:25 +08:00
|
|
|
|
|
|
|
/* initialize pixel regions */
|
2004-09-29 23:33:02 +08:00
|
|
|
gimp_pixel_rgn_init (&srcPR, drawable,
|
2004-09-12 03:11:04 +08:00
|
|
|
x1, y1, width, height, FALSE, FALSE);
|
|
|
|
src = g_new (guchar, width * height * bytes);
|
|
|
|
render_buffer = g_new (guchar, width * height * bytes);
|
2004-08-13 01:14:25 +08:00
|
|
|
|
|
|
|
/* render image */
|
2004-09-12 03:11:04 +08:00
|
|
|
gimp_pixel_rgn_get_rect(&srcPR, src, x1, y1, width, height);
|
2004-08-13 01:14:25 +08:00
|
|
|
dest = render_buffer;
|
2004-09-12 03:11:04 +08:00
|
|
|
|
2004-08-13 01:14:25 +08:00
|
|
|
/* render algorithm */
|
2004-09-12 03:11:04 +08:00
|
|
|
for (y = 0 ; y < height ; y++)
|
|
|
|
for (x = 0 ; x < width ; x++)
|
2004-08-13 01:14:25 +08:00
|
|
|
{
|
|
|
|
gint chan;
|
|
|
|
for (chan = 0; chan < alpha; chan++)
|
|
|
|
{
|
|
|
|
guchar kernel[9];
|
|
|
|
|
2005-01-23 20:41:56 +08:00
|
|
|
#define SRC(X,Y) src[bytes * (CLAMP((X), 0, width-1) + \
|
|
|
|
width * CLAMP((Y), 0, height-1)) + chan]
|
|
|
|
|
|
|
|
kernel[0] = SRC (x - 1, y - 1);
|
|
|
|
kernel[1] = SRC (x - 1, y );
|
|
|
|
kernel[2] = SRC (x - 1, y + 1);
|
|
|
|
kernel[3] = SRC (x , y - 1);
|
|
|
|
kernel[4] = SRC (x , y );
|
|
|
|
kernel[5] = SRC (x , y + 1);
|
|
|
|
kernel[6] = SRC (x + 1, y - 1);
|
|
|
|
kernel[7] = SRC (x + 1, y );
|
|
|
|
kernel[8] = SRC (x + 1, y + 1);
|
|
|
|
|
2004-08-13 01:14:25 +08:00
|
|
|
#undef SRC
|
2004-09-07 20:13:29 +08:00
|
|
|
dest[chan] = edge_detect (kernel);
|
2004-08-13 01:14:25 +08:00
|
|
|
}
|
|
|
|
if (has_alpha)
|
2004-09-12 03:11:04 +08:00
|
|
|
dest[alpha] = src[bytes * (x + width * y) + alpha];
|
2004-08-13 01:14:25 +08:00
|
|
|
dest += bytes;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Draw the preview image on the screen...
|
|
|
|
*/
|
2004-09-29 23:33:02 +08:00
|
|
|
gimp_preview_draw_buffer (preview, render_buffer, width * bytes);
|
2004-08-13 01:14:25 +08:00
|
|
|
|
|
|
|
g_free (render_buffer);
|
|
|
|
g_free (src);
|
|
|
|
}
|