2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "paint-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimpimage.h"
|
2004-07-14 07:04:05 +08:00
|
|
|
#include "core/gimppickable.h"
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "gimpconvolve.h"
|
2003-02-05 22:39:40 +08:00
|
|
|
#include "gimpconvolveoptions.h"
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
#define FIELD_COLS 4
|
|
|
|
#define MIN_BLUR 64 /* (8/9 original pixel) */
|
|
|
|
#define MAX_BLUR 0.25 /* (1/33 original pixel) */
|
|
|
|
#define MIN_SHARPEN -512
|
|
|
|
#define MAX_SHARPEN -64
|
|
|
|
|
2000-11-06 20:40:07 +08:00
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
static void gimp_convolve_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time);
|
|
|
|
static void gimp_convolve_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options);
|
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
static void gimp_convolve_calculate_matrix (GimpConvolve *convolve,
|
|
|
|
GimpConvolveType type,
|
2008-05-27 16:19:30 +08:00
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
2004-07-19 22:37:40 +08:00
|
|
|
gdouble rate);
|
2007-05-06 03:18:25 +08:00
|
|
|
static gdouble gimp_convolve_sum_matrix (const gfloat *matrix);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpConvolve, gimp_convolve, GIMP_TYPE_BRUSH_CORE)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2002-02-27 21:57:49 +08:00
|
|
|
void
|
|
|
|
gimp_convolve_register (Gimp *gimp,
|
|
|
|
GimpPaintRegisterCallback callback)
|
|
|
|
{
|
2003-02-14 22:14:29 +08:00
|
|
|
(* callback) (gimp,
|
|
|
|
GIMP_TYPE_CONVOLVE,
|
|
|
|
GIMP_TYPE_CONVOLVE_OPTIONS,
|
2005-12-28 02:57:01 +08:00
|
|
|
"gimp-convolve",
|
|
|
|
_("Convolve"),
|
2005-12-28 04:51:24 +08:00
|
|
|
"gimp-tool-blur");
|
2002-02-27 21:57:49 +08:00
|
|
|
}
|
|
|
|
|
2001-04-19 21:01:44 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_convolve_class_init (GimpConvolveClass *klass)
|
2001-04-19 21:01:44 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
paint_core_class->paint = gimp_convolve_paint;
|
2001-04-19 21:01:44 +08:00
|
|
|
}
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2001-04-19 21:01:44 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_convolve_init (GimpConvolve *convolve)
|
2001-04-19 21:01:44 +08:00
|
|
|
{
|
2007-05-06 03:18:25 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
convolve->matrix[i] = 1.0;
|
|
|
|
|
|
|
|
convolve->matrix_divisor = 9.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-04-19 21:01:44 +08:00
|
|
|
static void
|
2004-07-19 22:37:40 +08:00
|
|
|
gimp_convolve_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
switch (paint_state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-19 22:37:40 +08:00
|
|
|
case GIMP_PAINT_STATE_MOTION:
|
2002-06-09 21:56:09 +08:00
|
|
|
gimp_convolve_motion (paint_core, drawable, paint_options);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-27 10:09:03 +08:00
|
|
|
static void
|
2002-06-09 21:56:09 +08:00
|
|
|
gimp_convolve_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2008-05-10 18:03:21 +08:00
|
|
|
GimpConvolve *convolve = GIMP_CONVOLVE (paint_core);
|
|
|
|
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core);
|
|
|
|
GimpConvolveOptions *options = GIMP_CONVOLVE_OPTIONS (paint_options);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2002-06-09 21:56:09 +08:00
|
|
|
TempBuf *area;
|
2003-07-14 22:50:41 +08:00
|
|
|
PixelRegion srcPR;
|
2002-06-09 21:56:09 +08:00
|
|
|
PixelRegion destPR;
|
2007-05-06 03:18:25 +08:00
|
|
|
PixelRegion tempPR;
|
|
|
|
guchar *buffer;
|
2003-07-16 19:25:37 +08:00
|
|
|
gdouble opacity;
|
|
|
|
gdouble rate;
|
2007-05-06 03:18:25 +08:00
|
|
|
gint bytes;
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
opacity = gimp_paint_options_get_fade (paint_options, image,
|
2003-07-16 19:25:37 +08:00
|
|
|
paint_core->pixel_dist);
|
|
|
|
if (opacity == 0.0)
|
2000-11-05 01:54:01 +08:00
|
|
|
return;
|
|
|
|
|
2004-05-26 17:32:03 +08:00
|
|
|
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
|
|
|
|
if (! area)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
rate = options->rate;
|
|
|
|
|
2008-05-10 18:03:21 +08:00
|
|
|
rate *= gimp_paint_options_get_dynamic_rate (paint_options,
|
2008-07-18 03:00:13 +08:00
|
|
|
&paint_core->cur_coords);
|
1999-11-13 09:02:27 +08:00
|
|
|
|
2008-05-27 16:19:30 +08:00
|
|
|
gimp_convolve_calculate_matrix (convolve, options->type,
|
|
|
|
brush_core->brush->mask->width / 2,
|
|
|
|
brush_core->brush->mask->height / 2,
|
|
|
|
rate);
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
/* configure the source pixel region */
|
|
|
|
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
|
|
|
|
area->x, area->y, area->width, area->height, FALSE);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2007-05-06 03:18:25 +08:00
|
|
|
bytes = srcPR.bytes;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
buffer = g_malloc (area->height * bytes * area->width);
|
2000-11-05 01:54:01 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
pixel_region_init_data (&tempPR, buffer,
|
|
|
|
bytes, bytes * area->width,
|
|
|
|
0, 0, area->width, area->height);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
copy_region (&srcPR, &tempPR);
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-06 03:18:25 +08:00
|
|
|
/* note: this particular approach needlessly convolves the totally-
|
|
|
|
opaque alpha channel. A faster approach would be to keep
|
|
|
|
tempPR the same number of bytes as srcPR, and extend the
|
|
|
|
paint_core_replace_canvas API to handle non-alpha images. */
|
2000-11-05 01:54:01 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
bytes = srcPR.bytes + 1;
|
2000-11-05 01:54:01 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
buffer = g_malloc (area->height * bytes * area->width);
|
1997-12-08 09:13:10 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
pixel_region_init_data (&tempPR, buffer,
|
|
|
|
bytes, bytes * area->width,
|
|
|
|
0, 0, area->width, area->height);
|
2005-09-04 01:16:58 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
add_alpha_region (&srcPR, &tempPR);
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
/* Convolve the region */
|
|
|
|
pixel_region_init_data (&tempPR, buffer,
|
|
|
|
bytes, bytes * area->width,
|
|
|
|
0, 0, area->width, area->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
pixel_region_init_temp_buf (&destPR, area,
|
2005-09-04 01:16:58 +08:00
|
|
|
0, 0, area->width, area->height);
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
convolve_region (&tempPR, &destPR,
|
|
|
|
convolve->matrix, 3, convolve->matrix_divisor,
|
|
|
|
GIMP_NORMAL_CONVOL, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
g_free (buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_replace_canvas (brush_core, drawable,
|
2003-07-16 19:25:37 +08:00
|
|
|
MIN (opacity, GIMP_OPACITY_OPAQUE),
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
gimp_paint_options_get_brush_mode (paint_options),
|
2008-05-23 00:38:57 +08:00
|
|
|
1.0,
|
2002-03-19 23:05:38 +08:00
|
|
|
GIMP_PAINT_INCREMENTAL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-05-06 03:18:25 +08:00
|
|
|
gimp_convolve_calculate_matrix (GimpConvolve *convolve,
|
|
|
|
GimpConvolveType type,
|
2008-05-27 16:19:30 +08:00
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
2002-03-19 23:05:38 +08:00
|
|
|
gdouble rate)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* find percent of tool pressure */
|
2008-05-27 16:19:30 +08:00
|
|
|
const gdouble percent = MIN (rate / 100.0, 1.0);
|
|
|
|
|
|
|
|
convolve->matrix[0] = (radius_x && radius_y) ? 1.0 : 0.0;
|
|
|
|
convolve->matrix[1] = (radius_y) ? 1.0 : 0.0;
|
|
|
|
convolve->matrix[2] = (radius_x && radius_y) ? 1.0 : 0.0;
|
|
|
|
convolve->matrix[3] = (radius_x) ? 1.0 : 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* get the appropriate convolution matrix and size and divisor */
|
|
|
|
switch (type)
|
|
|
|
{
|
2002-03-19 23:05:38 +08:00
|
|
|
case GIMP_BLUR_CONVOLVE:
|
2007-05-06 03:18:25 +08:00
|
|
|
convolve->matrix[4] = MIN_BLUR + percent * (MAX_BLUR - MIN_BLUR);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-19 23:05:38 +08:00
|
|
|
case GIMP_SHARPEN_CONVOLVE:
|
2007-05-06 03:18:25 +08:00
|
|
|
convolve->matrix[4] = MIN_SHARPEN + percent * (MAX_SHARPEN - MIN_SHARPEN);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-19 23:05:38 +08:00
|
|
|
case GIMP_CUSTOM_CONVOLVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-27 16:19:30 +08:00
|
|
|
convolve->matrix[5] = (radius_x) ? 1.0 : 0.0;
|
|
|
|
convolve->matrix[6] = (radius_x && radius_y) ? 1.0 : 0.0;
|
|
|
|
convolve->matrix[7] = (radius_y) ? 1.0 : 0.0;
|
|
|
|
convolve->matrix[8] = (radius_x && radius_y) ? 1.0 : 0.0;
|
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
convolve->matrix_divisor = gimp_convolve_sum_matrix (convolve->matrix);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-05-31 15:45:50 +08:00
|
|
|
static gdouble
|
2007-05-06 03:18:25 +08:00
|
|
|
gimp_convolve_sum_matrix (const gfloat *matrix)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-31 15:45:50 +08:00
|
|
|
gdouble sum = 0.0;
|
2007-05-06 03:18:25 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-05-06 03:18:25 +08:00
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
sum += matrix[i];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|