1997-11-25 06:05:25 +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
|
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
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
#include <glib-object.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
|
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
/* Different clip relationships between a blur-blob and edges:
|
2002-02-15 03:31:16 +08:00
|
|
|
* see convolve_motion
|
|
|
|
*/
|
2000-11-06 20:40:07 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
CONVOLVE_NCLIP, /* Left or top edge */
|
|
|
|
CONVOLVE_NOT_CLIPPED, /* No edges */
|
|
|
|
CONVOLVE_PCLIP /* Right or bottom edge */
|
|
|
|
} ConvolveClipType;
|
|
|
|
|
|
|
|
|
2004-05-31 15:45:50 +08:00
|
|
|
static void gimp_convolve_class_init (GimpConvolveClass *klass);
|
|
|
|
static void gimp_convolve_init (GimpConvolve *convolve);
|
|
|
|
|
|
|
|
static void gimp_convolve_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintCoreState paint_state,
|
|
|
|
guint32 time);
|
|
|
|
static void gimp_convolve_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options);
|
|
|
|
|
|
|
|
static void gimp_convolve_calculate_matrix (GimpConvolveType type,
|
|
|
|
gdouble rate);
|
|
|
|
static void gimp_convolve_copy_matrix (const gfloat *src,
|
|
|
|
gfloat *dest,
|
|
|
|
gint size);
|
|
|
|
static gdouble gimp_convolve_sum_matrix (const gfloat *matrix,
|
|
|
|
gint size);
|
|
|
|
|
|
|
|
|
|
|
|
static gint matrix_size;
|
|
|
|
static gdouble matrix_divisor;
|
|
|
|
|
|
|
|
static gfloat matrix[25] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
0, 0, 1, 0, 0,
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
};
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
static gfloat blur_matrix[25] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
0, 1, 1, 1, 0,
|
|
|
|
0, 1, MIN_BLUR, 1, 0,
|
|
|
|
0, 1, 1, 1, 0,
|
|
|
|
0, 0 ,0, 0, 0,
|
|
|
|
};
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
static gfloat sharpen_matrix[25] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
0, 1, 1, 1, 0,
|
|
|
|
0, 1, MIN_SHARPEN, 1, 0,
|
|
|
|
0, 1, 1, 1, 0,
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
};
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
static GimpBrushCoreClass *parent_class;
|
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,
|
|
|
|
_("Convolve"));
|
2002-02-27 21:57:49 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_convolve_get_type (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static GType type = 0;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
if (! type)
|
2001-04-19 21:01:44 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static const GTypeInfo info =
|
2001-04-19 21:01:44 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
sizeof (GimpConvolveClass),
|
2004-05-26 04:41:09 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_convolve_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpConvolve),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_convolve_init,
|
2001-04-19 21:01:44 +08:00
|
|
|
};
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
type = g_type_register_static (GIMP_TYPE_BRUSH_CORE,
|
2002-02-15 03:31:16 +08:00
|
|
|
"GimpConvolve",
|
|
|
|
&info, 0);
|
2001-04-19 21:01:44 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
return type;
|
2001-04-19 21:01:44 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +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
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (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
|
|
|
{
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-04-19 21:01:44 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_convolve_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
2002-02-22 00:02:30 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
2004-05-27 00:13:53 +08:00
|
|
|
GimpPaintCoreState 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
|
|
|
{
|
|
|
|
case MOTION_PAINT:
|
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
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core);
|
|
|
|
GimpConvolveOptions *options = GIMP_CONVOLVE_OPTIONS (paint_options);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
|
|
|
GimpPressureOptions *pressure_options = paint_options->pressure_options;
|
2003-07-16 19:25:37 +08:00
|
|
|
GimpImage *gimage;
|
2002-06-09 21:56:09 +08:00
|
|
|
TempBuf *area;
|
|
|
|
guchar *temp_data;
|
2003-07-14 22:50:41 +08:00
|
|
|
PixelRegion srcPR;
|
2002-06-09 21:56:09 +08:00
|
|
|
PixelRegion destPR;
|
2003-07-16 19:25:37 +08:00
|
|
|
gdouble opacity;
|
|
|
|
gdouble rate;
|
2002-06-09 21:56:09 +08:00
|
|
|
ConvolveClipType area_hclip = CONVOLVE_NOT_CLIPPED;
|
|
|
|
ConvolveClipType area_vclip = CONVOLVE_NOT_CLIPPED;
|
|
|
|
gint marginx = 0;
|
|
|
|
gint marginy = 0;
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
gimage = 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;
|
|
|
|
|
2000-11-05 01:54:01 +08:00
|
|
|
/* If the brush is smaller than the convolution matrix, don't convolve */
|
2004-05-26 04:41:09 +08:00
|
|
|
if (brush_core->brush->mask->width < matrix_size ||
|
|
|
|
brush_core->brush->mask->height < matrix_size)
|
2003-07-16 19:25:37 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
opacity = gimp_paint_options_get_fade (paint_options, gimage,
|
|
|
|
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;
|
|
|
|
|
2000-11-05 01:54:01 +08:00
|
|
|
/* configure the source pixel region */
|
2001-01-15 05:11:52 +08:00
|
|
|
pixel_region_init (&srcPR, gimp_drawable_data (drawable),
|
2000-04-28 01:27:28 +08:00
|
|
|
area->x, area->y, area->width, area->height, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
/* configure the destination pixel region */
|
2000-11-05 01:54:01 +08:00
|
|
|
destPR.bytes = area->bytes;
|
|
|
|
destPR.tiles = NULL;
|
2003-07-14 22:50:41 +08:00
|
|
|
destPR.x = 0;
|
2000-11-05 01:54:01 +08:00
|
|
|
destPR.y = 0;
|
|
|
|
destPR.w = area->width;
|
|
|
|
destPR.h = area->height;
|
1997-11-25 06:05:25 +08:00
|
|
|
destPR.rowstride = area->width * destPR.bytes;
|
2000-11-05 01:54:01 +08:00
|
|
|
destPR.data = temp_buf_data (area);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
rate = options->rate;
|
|
|
|
|
1999-11-13 09:02:27 +08:00
|
|
|
if (pressure_options->rate)
|
2004-05-24 21:11:43 +08:00
|
|
|
rate *= PRESSURE_SCALE * paint_core->cur_coords.pressure;
|
1999-11-13 09:02:27 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
gimp_convolve_calculate_matrix (options->type, rate);
|
2002-02-05 01:43:01 +08:00
|
|
|
|
2000-11-05 01:54:01 +08:00
|
|
|
/* Image region near edges? If so, paint area will be clipped */
|
|
|
|
/* with respect to brush mask + 1 pixel border (# 19285) */
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
marginx = ((gint) paint_core->cur_coords.x -
|
|
|
|
brush_core->brush->mask->width / 2 - 1);
|
|
|
|
|
|
|
|
if (marginx != area->x)
|
|
|
|
{
|
|
|
|
area_hclip = CONVOLVE_NCLIP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
marginx = area->width - brush_core->brush->mask->width - 2;
|
|
|
|
|
|
|
|
if (marginx != 0)
|
|
|
|
area_hclip = CONVOLVE_PCLIP;
|
|
|
|
}
|
2000-11-05 01:54:01 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
marginy = ((gint) paint_core->cur_coords.y -
|
|
|
|
brush_core->brush->mask->height / 2 - 1);
|
|
|
|
|
|
|
|
if (marginy != area->y)
|
|
|
|
{
|
|
|
|
area_vclip = CONVOLVE_NCLIP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
marginy = area->height - brush_core->brush->mask->height - 2;
|
|
|
|
|
|
|
|
if (marginy != 0)
|
|
|
|
area_vclip = CONVOLVE_PCLIP;
|
|
|
|
}
|
1999-02-05 07:28:09 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
/* Has the TempBuf been clipped by a canvas edge or two? */
|
|
|
|
if (area_hclip == CONVOLVE_NOT_CLIPPED &&
|
|
|
|
area_vclip == CONVOLVE_NOT_CLIPPED)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-11-05 01:54:01 +08:00
|
|
|
/* No clipping... */
|
|
|
|
/* Standard case: copy src to temp. convolve temp to dest. */
|
|
|
|
/* Brush defines pipe size and no edge adjustments are needed. */
|
|
|
|
|
|
|
|
/* If the source has no alpha, then add alpha pixels */
|
|
|
|
/* Because paint_core.c is alpha-only code. See below. */
|
|
|
|
|
|
|
|
PixelRegion tempPR;
|
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
tempPR.x = 0;
|
2000-11-05 01:54:01 +08:00
|
|
|
tempPR.y = 0;
|
|
|
|
tempPR.w = area->width;
|
|
|
|
tempPR.h = area->height;
|
|
|
|
tempPR.tiles = NULL;
|
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
if (! gimp_drawable_has_alpha (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-11-05 01:54:01 +08:00
|
|
|
/* note: this particular approach needlessly convolves the totally-
|
1997-12-08 09:13:10 +08:00
|
|
|
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. */
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
tempPR.bytes = srcPR.bytes + 1;
|
|
|
|
tempPR.rowstride = tempPR.bytes * tempPR.w;
|
|
|
|
temp_data = g_malloc (tempPR.h * tempPR.rowstride);
|
|
|
|
tempPR.data = temp_data;
|
|
|
|
|
|
|
|
add_alpha_region (&srcPR, &tempPR);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
tempPR.bytes = srcPR.bytes;
|
|
|
|
tempPR.rowstride = tempPR.bytes * tempPR.w;
|
|
|
|
temp_data = g_malloc (tempPR.h * tempPR.rowstride);
|
|
|
|
tempPR.data = temp_data;
|
|
|
|
|
|
|
|
copy_region (&srcPR, &tempPR);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convolve the region */
|
2000-11-05 01:54:01 +08:00
|
|
|
|
|
|
|
tempPR.x = 0;
|
|
|
|
tempPR.y = 0;
|
|
|
|
tempPR.w = area->width;
|
|
|
|
tempPR.h = area->height;
|
|
|
|
tempPR.data = temp_data;
|
2001-04-19 21:01:44 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
convolve_region (&tempPR, &destPR, matrix, matrix_size,
|
2004-05-31 18:36:06 +08:00
|
|
|
matrix_divisor, GIMP_NORMAL_CONVOL, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Free the allocated temp space */
|
|
|
|
g_free (temp_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-04-19 21:01:44 +08:00
|
|
|
/* TempBuf clipping has occured on at least one edge...
|
|
|
|
* Edge case: expand area under brush margin px on near edge(s), convolve
|
|
|
|
* expanded buffers. copy src -> ovrsz1 convolve ovrsz1 -> ovrsz2
|
|
|
|
* copy-with-crop ovrsz2 -> dest
|
|
|
|
*/
|
2003-07-16 19:25:37 +08:00
|
|
|
PixelRegion ovrsz1PR;
|
|
|
|
PixelRegion ovrsz2PR;
|
|
|
|
guchar *ovrsz1_data = NULL;
|
|
|
|
guchar *ovrsz2_data = NULL;
|
|
|
|
guchar *fillcolor;
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2004-07-14 07:04:05 +08:00
|
|
|
fillcolor = gimp_pickable_get_color_at
|
|
|
|
(GIMP_PICKABLE (drawable),
|
2004-05-26 04:41:09 +08:00
|
|
|
CLAMP ((gint) paint_core->cur_coords.x,
|
2003-05-08 21:12:46 +08:00
|
|
|
0, gimp_item_width (GIMP_ITEM (drawable)) - 1),
|
2004-05-26 04:41:09 +08:00
|
|
|
CLAMP ((gint) paint_core->cur_coords.y,
|
2003-05-08 21:12:46 +08:00
|
|
|
0, gimp_item_height (GIMP_ITEM (drawable)) - 1));
|
2000-11-05 01:54:01 +08:00
|
|
|
|
|
|
|
marginx *= (marginx < 0) ? -1 : 0;
|
|
|
|
marginy *= (marginy < 0) ? -1 : 0;
|
|
|
|
|
|
|
|
ovrsz2PR.x = 0;
|
|
|
|
ovrsz2PR.y = 0;
|
|
|
|
ovrsz2PR.w = area->width + marginx;
|
|
|
|
ovrsz2PR.h = area->height + marginy;
|
2002-02-15 03:31:16 +08:00
|
|
|
ovrsz2PR.bytes = (gimp_drawable_has_alpha (drawable) ?
|
|
|
|
srcPR.bytes : srcPR.bytes + 1);
|
2000-11-05 01:54:01 +08:00
|
|
|
ovrsz2PR.offx = 0;
|
|
|
|
ovrsz2PR.offy = 0;
|
|
|
|
ovrsz2PR.rowstride = ovrsz2PR.bytes * ovrsz2PR.w;
|
|
|
|
ovrsz2PR.tiles = NULL;
|
|
|
|
ovrsz2_data = g_malloc (ovrsz2PR.h * ovrsz2PR.rowstride);
|
|
|
|
ovrsz2PR.data = ovrsz2_data;
|
|
|
|
|
|
|
|
ovrsz1PR.x = 0;
|
|
|
|
ovrsz1PR.y = 0;
|
|
|
|
ovrsz1PR.w = area->width + marginx;
|
|
|
|
ovrsz1PR.h = area->height + marginy;
|
2002-02-15 03:31:16 +08:00
|
|
|
ovrsz1PR.bytes = (gimp_drawable_has_alpha (drawable) ?
|
|
|
|
srcPR.bytes : srcPR.bytes + 1);
|
2000-11-05 01:54:01 +08:00
|
|
|
ovrsz1PR.offx = 0;
|
|
|
|
ovrsz1PR.offy = 0;
|
|
|
|
ovrsz1PR.rowstride = ovrsz2PR.bytes * ovrsz2PR.w;
|
|
|
|
ovrsz1PR.tiles = NULL;
|
|
|
|
ovrsz1_data = g_malloc (ovrsz1PR.h * ovrsz1PR.rowstride);
|
|
|
|
ovrsz1PR.data = ovrsz1_data;
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
color_region (&ovrsz1PR, fillcolor);
|
2000-11-05 01:54:01 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
ovrsz1PR.x = (area_hclip == CONVOLVE_NCLIP)? marginx : 0;
|
2000-11-05 01:54:01 +08:00
|
|
|
ovrsz1PR.y = (area_vclip == CONVOLVE_NCLIP)? marginy : 0;
|
|
|
|
ovrsz1PR.w = area->width;
|
|
|
|
ovrsz1PR.h = area->height;
|
2002-02-15 03:31:16 +08:00
|
|
|
ovrsz1PR.data = (ovrsz1_data +
|
|
|
|
(ovrsz1PR.rowstride * ovrsz1PR.y) +
|
|
|
|
(ovrsz1PR.bytes * ovrsz1PR.x));
|
2000-11-05 01:54:01 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
if (! gimp_drawable_has_alpha (drawable))
|
2000-11-05 01:54:01 +08:00
|
|
|
add_alpha_region (&srcPR, &ovrsz1PR);
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2000-11-05 01:54:01 +08:00
|
|
|
copy_region (&srcPR, &ovrsz1PR);
|
|
|
|
|
|
|
|
/* Convolve the region */
|
|
|
|
|
|
|
|
ovrsz1PR.x = 0;
|
|
|
|
ovrsz1PR.y = 0;
|
|
|
|
ovrsz1PR.w = area->width + marginx;
|
|
|
|
ovrsz1PR.h = area->height + marginy;
|
|
|
|
ovrsz1PR.data = ovrsz1_data;
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2000-11-05 01:54:01 +08:00
|
|
|
convolve_region (&ovrsz1PR, &ovrsz2PR, matrix, matrix_size,
|
2004-05-31 18:36:06 +08:00
|
|
|
matrix_divisor, GIMP_NORMAL_CONVOL, TRUE);
|
2000-11-05 01:54:01 +08:00
|
|
|
|
|
|
|
/* Crop and copy to destination */
|
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
ovrsz2PR.x = (area_hclip == CONVOLVE_NCLIP)? marginx : 0;
|
|
|
|
ovrsz2PR.y = (area_vclip == CONVOLVE_NCLIP)? marginy : 0;
|
2000-11-05 01:54:01 +08:00
|
|
|
ovrsz2PR.w = area->width;
|
|
|
|
ovrsz2PR.h = area->height;
|
2002-02-15 03:31:16 +08:00
|
|
|
ovrsz2PR.data = (ovrsz2_data +
|
|
|
|
(ovrsz2PR.rowstride * ovrsz2PR.y) +
|
|
|
|
(ovrsz2PR.bytes * ovrsz2PR.x));
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2000-11-05 01:54:01 +08:00
|
|
|
copy_region (&ovrsz2PR, &destPR);
|
2001-04-19 21:01:44 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
g_free (ovrsz1_data);
|
|
|
|
g_free (ovrsz2_data);
|
|
|
|
g_free (fillcolor);
|
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),
|
2002-03-04 01:38:12 +08:00
|
|
|
gimp_context_get_opacity (context),
|
2003-07-14 22:50:41 +08:00
|
|
|
gimp_paint_options_get_brush_mode (paint_options),
|
2002-03-19 23:05:38 +08:00
|
|
|
GIMP_PAINT_INCREMENTAL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-19 23:05:38 +08:00
|
|
|
gimp_convolve_calculate_matrix (GimpConvolveType type,
|
|
|
|
gdouble rate)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-31 15:45:50 +08:00
|
|
|
gdouble percent;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* find percent of tool pressure */
|
1999-11-13 09:02:27 +08:00
|
|
|
percent = MIN (rate / 100.0, 1.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:
|
1997-11-25 06:05:25 +08:00
|
|
|
matrix_size = 5;
|
2004-05-26 04:41:09 +08:00
|
|
|
blur_matrix[12] = MIN_BLUR + percent * (MAX_BLUR - MIN_BLUR);
|
2004-05-31 15:45:50 +08:00
|
|
|
gimp_convolve_copy_matrix (blur_matrix, matrix, matrix_size);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-19 23:05:38 +08:00
|
|
|
case GIMP_SHARPEN_CONVOLVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
matrix_size = 5;
|
2004-05-26 04:41:09 +08:00
|
|
|
sharpen_matrix[12] = MIN_SHARPEN + percent * (MAX_SHARPEN - MIN_SHARPEN);
|
2004-05-31 15:45:50 +08:00
|
|
|
gimp_convolve_copy_matrix (sharpen_matrix, matrix, matrix_size);
|
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
|
|
|
matrix_size = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
matrix_divisor = gimp_convolve_sum_matrix (matrix, matrix_size);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (!matrix_divisor)
|
2004-05-31 15:45:50 +08:00
|
|
|
matrix_divisor = 1.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_convolve_copy_matrix (const gfloat *src,
|
|
|
|
gfloat *dest,
|
|
|
|
gint size)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-31 15:45:50 +08:00
|
|
|
size *= size;
|
|
|
|
while (size --)
|
1997-11-25 06:05:25 +08:00
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
|
2004-05-31 15:45:50 +08:00
|
|
|
static gdouble
|
|
|
|
gimp_convolve_sum_matrix (const gfloat *matrix,
|
|
|
|
gint size)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-31 15:45:50 +08:00
|
|
|
gdouble sum = 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
size *= size;
|
|
|
|
while (size --)
|
|
|
|
sum += *matrix++;
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|