gimp/plug-ins/common/blur.c

372 lines
11 KiB
C
Raw Normal View History

/****************************************************************************
* This is a plugin for GIMP v 0.99.8 or later. Documentation is
* available at http://www.rru.com/~meo/gimp/ .
*
* Copyright (C) 1997-98 Miles O'Neal <meo@rru.com> http://www.rru.com/~meo/
* Blur code Copyright (C) 1995 Spencer Kimball and Peter Mattis
* GUI based on GTK code from:
* alienmap (Copyright (C) 1996, 1997 Daniel Cotting)
* plasma (Copyright (C) 1996 Stephen Norris),
* oilify (Copyright (C) 1996 Torsten Martinsen),
* ripple (Copyright (C) 1997 Brian Degenhardt) and
* whirl (Copyright (C) 1997 Federico Mena Quintero).
1997-11-25 06:05:25 +08:00
*
* This program is free software: you can redistribute it and/or modify
1997-11-25 06:05:25 +08:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
1997-11-25 06:05:25 +08:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
****************************************************************************/
/****************************************************************************
* Blur:
*
* blur version 2.1 (10 June 2004 WES)
* history
* 2.1 - 10 June 2004 WES
* removed dialog along with randomization and repeat options
* 2.0 - 1 May 1998 MEO
* based on randomize 1.7
*
* Please send any patches or suggestions to the author: meo@rru.com .
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 23:27:05 +08:00
*
* Blur applies a 3x3 blurring convolution kernel to the specified drawable.
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 23:27:05 +08:00
*
* For each pixel in the selection or image,
* whether to change the pixel is decided by picking a
* random number, weighted by the user's "randomization" percentage.
* If the random number is in range, the pixel is modified. For
* blurring, an average is determined from the current and adjacent
* pixels. *(Except for the random factor, the blur code came
* straight from the original S&P blur plug-in.)*
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 23:27:05 +08:00
*
* This works only with RGB and grayscale images.
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 23:27:05 +08:00
*
****************************************************************************/
2000-01-11 23:48:00 +08:00
#include "config.h"
New file. * plug-ins/makefile.msc: New file. * plug-ins/*/*.c (Well, not really all files, but many): Portability fixes. Include config.h, and guard inclusion of POSIX and Unix headers like <unistd.h>, <dirent.h> and <sys/time.h>. Include <string.h> if functions from it are used. Use g_ntohl() and g_htonl() insteead of ntohl() and htonl(), thus no need to include <netinet/in.h>. Include <io.h> on Win32 when using open/read/write (which actually are defined as _open/_read/_write by glib.h). Define S_* macros if necessary on Win32. Define rint() and M_PI if necessary (these definitions should be factored out somewhere, no sense repeating them in lots of files). Open files in binary mode when needed. * plug-ins/FractalExplorer/FractalExplorer.c: Use g_malloc()/g_free(). Use g_strdup_printf(). * plug-ins/dbbrowser/dbbrowser.c: No need to include <X11/Xlib.h>. * plug-ins/destripe/destripe.c: Guard use of SIGBUS. * plug-ins/{flame/flame,hrz/hrz,pnm/pnm}.c: No need to check for NULL returns from g_malloc() and g_new() as they abort on failure. Use g_strdup_printf(). * plug-ins/gz/gz.c: Win32 version of running the subprocess. * plug-ins/hrz/hrz.c: Win32 version. Use more generic tests for non-Unix (OS/2 and Win32), for instance HAVE_MMAP. * plug-ins/script-fu/interp_slib.c: Win32 version of myruntime(). * plug-ins/script-fu/interp_sliba.c: Handle \\ (escaped backslahsh). * plug-ins/script-fu/script-fu-console.c: Bypass on Win32. * plug-ins/script-fu/script-fu-scripts.c: Portability fixes. Use g_strdup_printf() instead of separate malloc() and sprintf(). Use g_strescape() for strings being passed to Scheme. Some Win32-only stuff.
1999-05-29 09:28:24 +08:00
#include <string.h>
2000-01-11 23:48:00 +08:00
#include <libgimp/gimp.h>
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-30 00:35:47 +08:00
#include "libgimp/stdplugins-intl.h"
/*********************************
*
* PLUGIN-SPECIFIC CONSTANTS
*
********************************/
1997-11-25 06:05:25 +08:00
#define PLUG_IN_PROC "plug-in-blur"
1997-11-25 06:05:25 +08:00
/*********************************
*
* LOCAL FUNCTIONS
*
********************************/
2000-01-11 23:48:00 +08:00
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
2000-01-11 23:48:00 +08:00
const GimpPlugInInfo PLUG_IN_INFO =
2000-01-11 23:48:00 +08:00
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
static void blur (GimpDrawable *drawable);
static inline void blur_prepare_row (GimpPixelRgn *pixel_rgn,
guchar *data,
gint x,
gint y,
gint w);
/************************************ Guts ***********************************/
2000-01-11 23:48:00 +08:00
MAIN ()
/*********************************
*
* query() - query_proc
*
* called by GIMP to learn about this plug-in
*
********************************/
1997-11-25 06:05:25 +08:00
static void
2000-01-11 23:48:00 +08:00
query (void)
1997-11-25 06:05:25 +08:00
{
static const GimpParamDef args[] =
2000-01-11 23:48:00 +08:00
{
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
2000-01-11 23:48:00 +08:00
};
gimp_install_procedure (PLUG_IN_PROC,
N_("Simple blur, fast but not very strong"),
"This plug-in blurs the specified drawable, using "
"a 3x3 blur. Indexed images are not supported.",
"Miles O'Neal <meo@rru.com>",
"Miles O'Neal, Spencer Kimball, Peter Mattis, "
"Torsten Martinsen, Brian Degenhardt, "
"Federico Mena Quintero, Stephen Norris, "
"Daniel Cotting",
"1995-1998",
N_("_Blur"),
"RGB*, GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
2000-01-11 23:48:00 +08:00
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Blur");
1997-11-25 06:05:25 +08:00
}
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
1997-11-25 06:05:25 +08:00
{
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
static GimpParam values[1];
2000-01-11 23:48:00 +08:00
INIT_I18N ();
2000-01-11 23:48:00 +08:00
values[0].type = GIMP_PDB_STATUS;
2000-01-11 23:48:00 +08:00
values[0].data.d_status = status;
2000-01-11 23:48:00 +08:00
*nreturn_vals = 1;
*return_vals = values;
if (strcmp (name, PLUG_IN_PROC) != 0 || nparams < 3)
{
values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
return;
}
run_mode = param[0].data.d_int32;
drawable = gimp_drawable_get (param[2].data.d_drawable);
2000-01-11 23:48:00 +08:00
/*
* Make sure the drawable type is appropriate.
*/
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
gimp_drawable_is_gray (drawable->drawable_id))
2000-01-11 23:48:00 +08:00
{
gimp_progress_init (_("Blurring"));
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
blur (drawable);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
{
gimp_displays_flush ();
}
1997-11-25 06:05:25 +08:00
}
2000-01-11 23:48:00 +08:00
else
{
status = GIMP_PDB_EXECUTION_ERROR;
2000-01-11 23:48:00 +08:00
}
2000-01-11 23:48:00 +08:00
values[0].data.d_status = status;
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
gimp_drawable_detach (drawable);
}
1997-11-25 06:05:25 +08:00
/*********************************
*
* blur_prepare_row()
*
* Get a row of pixels. If the requested row
* is off the edge, clone the edge row.
*
********************************/
1997-11-25 06:05:25 +08:00
static inline void
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 23:27:05 +08:00
blur_prepare_row (GimpPixelRgn *pixel_rgn,
guchar *data,
gint x,
gint y,
gint w)
{
gint b;
1997-11-25 06:05:25 +08:00
y = CLAMP (y, 0, pixel_rgn->h - 1);
gimp_pixel_rgn_get_row (pixel_rgn, data, x, y, w);
2000-01-11 23:48:00 +08:00
/*
* Fill in edge pixels
*/
for (b = 0; b < pixel_rgn->bpp; b++)
data[-(gint)pixel_rgn->bpp + b] = data[b];
for (b = 0; b < pixel_rgn->bpp; b++)
data[w * pixel_rgn->bpp + b] = data[(w - 1) * pixel_rgn->bpp + b];
1997-11-25 06:05:25 +08:00
}
/*********************************
*
* blur()
*
* Actually mess with the image.
*
********************************/
1997-11-25 06:05:25 +08:00
static void
blur (GimpDrawable *drawable)
1997-11-25 06:05:25 +08:00
{
GimpPixelRgn srcPR, destPR;
gint width, height;
gint bytes;
guchar *dest, *d;
guchar *prev_row, *pr;
guchar *cur_row, *cr;
guchar *next_row, *nr;
guchar *tmp;
gint row, col;
gint x1, y1, x2, y2;
gint ind;
gboolean has_alpha;
2000-01-11 23:48:00 +08:00
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
2000-01-11 23:48:00 +08:00
/*
* Get the size of the input image. (This will/must be the same
* as the size of the output image. Also get alpha info.
*/
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
2000-01-11 23:48:00 +08:00
/*
* allocate row buffers
*/
prev_row = g_new (guchar, (x2 - x1 + 2) * bytes);
cur_row = g_new (guchar, (x2 - x1 + 2) * bytes);
next_row = g_new (guchar, (x2 - x1 + 2) * bytes);
dest = g_new (guchar, (x2 - x1) * bytes);
2000-01-11 23:48:00 +08:00
/*
* initialize the pixel regions
*/
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE);
2000-01-11 23:48:00 +08:00
pr = prev_row + bytes;
cr = cur_row + bytes;
nr = next_row + bytes;
/*
* prepare the first row and previous row
*/
blur_prepare_row (&srcPR, pr, x1, y1 - 1, (x2 - x1));
blur_prepare_row (&srcPR, cr, x1, y1, (x2 - x1));
/*
* loop through the rows, applying the selected convolution
*/
for (row = y1; row < y2; row++)
2000-01-11 23:48:00 +08:00
{
/* prepare the next row */
blur_prepare_row (&srcPR, nr, x1, row + 1, (x2 - x1));
d = dest;
ind = 0;
for (col = 0; col < (x2 - x1) * bytes; col++)
{
ind++;
if (ind == bytes || !has_alpha)
{
/*
* If no alpha channel,
* or if there is one and this is it...
*/
*d++ = ((gint) pr[col - bytes] + (gint) pr[col] +
(gint) pr[col + bytes] +
(gint) cr[col - bytes] + (gint) cr[col] +
(gint) cr[col + bytes] +
(gint) nr[col - bytes] + (gint) nr[col] +
(gint) nr[col + bytes] + 4) / 9;
ind = 0;
}
else
{
/*
* otherwise we have an alpha channel,
* but this is a color channel
*/
*d++ = ROUND(
((gdouble) (pr[col - bytes] * pr[col - ind])
+ (gdouble) (pr[col] * pr[col + bytes - ind])
+ (gdouble) (pr[col + bytes] * pr[col + 2*bytes - ind])
+ (gdouble) (cr[col - bytes] * cr[col - ind])
+ (gdouble) (cr[col] * cr[col + bytes - ind])
+ (gdouble) (cr[col + bytes] * cr[col + 2*bytes - ind])
+ (gdouble) (nr[col - bytes] * nr[col - ind])
+ (gdouble) (nr[col] * nr[col + bytes - ind])
+ (gdouble) (nr[col + bytes] * nr[col + 2*bytes - ind]))
/ ((gdouble) pr[col - ind]
+ (gdouble) pr[col + bytes - ind]
+ (gdouble) pr[col + 2*bytes - ind]
+ (gdouble) cr[col - ind]
+ (gdouble) cr[col + bytes - ind]
+ (gdouble) cr[col + 2*bytes - ind]
+ (gdouble) nr[col - ind]
+ (gdouble) nr[col + bytes - ind]
+ (gdouble) nr[col + 2*bytes - ind]));
}
}
2000-01-11 23:48:00 +08:00
/*
* Save the modified row, shuffle the row pointers, and every
* so often, update the progress meter.
2000-01-11 23:48:00 +08:00
*/
gimp_pixel_rgn_set_row (&destPR, dest, x1, row, (x2 - x1));
tmp = pr;
pr = cr;
cr = nr;
nr = tmp;
if ((row % 32) == 0)
gimp_progress_update ((gdouble) row / (gdouble) (y2 - y1));
1997-11-25 06:05:25 +08:00
}
gimp_progress_update (1.0);
2000-01-11 23:48:00 +08:00
/*
* update the blurred region
*/
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
2000-01-11 23:48:00 +08:00
/*
* clean up after ourselves.
*/
g_free (prev_row);
g_free (cur_row);
g_free (next_row);
g_free (dest);
1997-11-25 06:05:25 +08:00
}