2006-12-09 13:33:38 -08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 14:05:25 -08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
2009-01-17 14:28:01 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 14:05:25 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 14:28:01 -08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 14: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
|
2018-07-11 14:47:19 -07:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 14:05:25 -08:00
|
|
|
*/
|
2000-12-16 13:37:03 -08:00
|
|
|
|
2000-04-27 10:27:28 -07:00
|
|
|
#include "config.h"
|
2000-01-14 04:41:00 -08:00
|
|
|
|
2013-10-14 16:58:39 -07:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-09 13:24:04 -07:00
|
|
|
#include <gegl.h>
|
2000-01-14 04:41:00 -08:00
|
|
|
|
2002-02-14 11:31:16 -08:00
|
|
|
#include "paint-types.h"
|
2000-12-16 13:37:03 -08:00
|
|
|
|
2012-04-01 15:13:46 -07:00
|
|
|
#include "gegl/gimp-gegl-loops.h"
|
2012-04-01 07:27:12 -07:00
|
|
|
|
2001-07-07 05:17:23 -07:00
|
|
|
#include "core/gimp.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
|
#include "core/gimpdrawable.h"
|
2009-10-11 06:41:54 -07:00
|
|
|
#include "core/gimpdynamics.h"
|
2001-07-07 05:17:23 -07:00
|
|
|
#include "core/gimpimage.h"
|
2004-07-13 16:04:05 -07:00
|
|
|
#include "core/gimppickable.h"
|
2016-01-27 10:13:17 -08:00
|
|
|
#include "core/gimpsymmetry.h"
|
2012-04-08 15:59:20 -07:00
|
|
|
#include "core/gimptempbuf.h"
|
2001-04-19 06:01:44 -07:00
|
|
|
|
2002-02-14 11:31:16 -08:00
|
|
|
#include "gimpconvolve.h"
|
2003-02-05 06: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-14 16:23:52 -07:00
|
|
|
|
2003-03-25 08:38:19 -08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 06:14:29 -08:00
|
|
|
|
2000-04-27 10:27:28 -07:00
|
|
|
|
1999-04-08 15:25:54 -07: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 04:40:07 -08:00
|
|
|
|
2009-05-03 03:08:21 -07:00
|
|
|
static void gimp_convolve_paint (GimpPaintCore *paint_core,
|
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
|
GimpPaintOptions *paint_options,
|
2016-01-27 10:13:17 -08:00
|
|
|
GimpSymmetry *sym,
|
2009-05-03 03:08:21 -07:00
|
|
|
GimpPaintState paint_state,
|
|
|
|
|
guint32 time);
|
|
|
|
|
static void gimp_convolve_motion (GimpPaintCore *paint_core,
|
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
|
GimpPaintOptions *paint_options,
|
2016-01-27 10:13:17 -08:00
|
|
|
GimpSymmetry *sym);
|
2009-05-03 03:08:21 -07:00
|
|
|
|
|
|
|
|
static void gimp_convolve_calculate_matrix (GimpConvolve *convolve,
|
|
|
|
|
GimpConvolveType type,
|
|
|
|
|
gint radius_x,
|
|
|
|
|
gint radius_y,
|
|
|
|
|
gdouble rate);
|
|
|
|
|
static gdouble gimp_convolve_sum_matrix (const gfloat *matrix);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2004-05-25 13:41:09 -07:00
|
|
|
|
2006-05-15 02:46:31 -07:00
|
|
|
G_DEFINE_TYPE (GimpConvolve, gimp_convolve, GIMP_TYPE_BRUSH_CORE)
|
1997-11-24 14:05:25 -08:00
|
|
|
|
1999-04-08 15:25:54 -07:00
|
|
|
|
2002-02-27 05:57:49 -08:00
|
|
|
void
|
|
|
|
|
gimp_convolve_register (Gimp *gimp,
|
|
|
|
|
GimpPaintRegisterCallback callback)
|
|
|
|
|
{
|
2003-02-14 06:14:29 -08:00
|
|
|
(* callback) (gimp,
|
|
|
|
|
GIMP_TYPE_CONVOLVE,
|
|
|
|
|
GIMP_TYPE_CONVOLVE_OPTIONS,
|
2005-12-27 10:57:01 -08:00
|
|
|
"gimp-convolve",
|
|
|
|
|
_("Convolve"),
|
2005-12-27 12:51:24 -08:00
|
|
|
"gimp-tool-blur");
|
2002-02-27 05:57:49 -08:00
|
|
|
}
|
|
|
|
|
|
2001-04-19 06:01:44 -07:00
|
|
|
static void
|
2002-02-14 11:31:16 -08:00
|
|
|
gimp_convolve_class_init (GimpConvolveClass *klass)
|
2001-04-19 06:01:44 -07:00
|
|
|
{
|
2004-05-25 13:41:09 -07:00
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2002-02-14 11:31:16 -08:00
|
|
|
paint_core_class->paint = gimp_convolve_paint;
|
2001-04-19 06:01:44 -07:00
|
|
|
}
|
2000-01-14 04:41:00 -08:00
|
|
|
|
2001-04-19 06:01:44 -07:00
|
|
|
static void
|
2002-02-14 11:31:16 -08:00
|
|
|
gimp_convolve_init (GimpConvolve *convolve)
|
2001-04-19 06:01:44 -07:00
|
|
|
{
|
2007-05-05 12:18:25 -07:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
|
convolve->matrix[i] = 1.0;
|
|
|
|
|
|
|
|
|
|
convolve->matrix_divisor = 9.0;
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
2001-04-19 06:01:44 -07:00
|
|
|
static void
|
2004-07-19 07:37:40 -07:00
|
|
|
gimp_convolve_paint (GimpPaintCore *paint_core,
|
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
|
GimpPaintOptions *paint_options,
|
2016-01-27 10:13:17 -08:00
|
|
|
GimpSymmetry *sym,
|
2004-07-19 07:37:40 -07:00
|
|
|
GimpPaintState paint_state,
|
|
|
|
|
guint32 time)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2002-02-14 11:31:16 -08:00
|
|
|
switch (paint_state)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2004-07-19 07:37:40 -07:00
|
|
|
case GIMP_PAINT_STATE_MOTION:
|
2016-01-27 10:13:17 -08:00
|
|
|
gimp_convolve_motion (paint_core, drawable, paint_options, sym);
|
1997-11-24 14:05:25 -08:00
|
|
|
break;
|
2000-12-30 20:07:42 -08:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-26 19:09:03 -07:00
|
|
|
static void
|
2002-06-09 06:56:09 -07:00
|
|
|
gimp_convolve_motion (GimpPaintCore *paint_core,
|
|
|
|
|
GimpDrawable *drawable,
|
2009-05-03 03:08:21 -07:00
|
|
|
GimpPaintOptions *paint_options,
|
2016-01-27 10:13:17 -08:00
|
|
|
GimpSymmetry *sym)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2008-05-10 03:03:21 -07: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);
|
2009-10-13 11:34:01 -07:00
|
|
|
GimpDynamics *dynamics = GIMP_BRUSH_CORE (paint_core)->dynamics;
|
2012-05-06 17:48:11 -07:00
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2012-04-01 07:27:12 -07:00
|
|
|
GeglBuffer *paint_buffer;
|
|
|
|
|
gint paint_buffer_x;
|
|
|
|
|
gint paint_buffer_y;
|
2012-05-23 13:41:14 -07:00
|
|
|
GimpTempBuf *temp_buf;
|
2012-04-01 07:27:12 -07:00
|
|
|
GeglBuffer *convolve_buffer;
|
2009-10-13 11:34:01 -07:00
|
|
|
gdouble fade_point;
|
2003-07-16 04:25:37 -07:00
|
|
|
gdouble opacity;
|
|
|
|
|
gdouble rate;
|
2016-01-27 10:13:17 -08:00
|
|
|
const GimpCoords *coords;
|
|
|
|
|
GeglNode *op;
|
|
|
|
|
gint paint_width, paint_height;
|
|
|
|
|
gint n_strokes;
|
|
|
|
|
gint i;
|
2002-06-09 06:56:09 -07:00
|
|
|
|
2009-10-13 11:34:01 -07:00
|
|
|
fade_point = gimp_paint_options_get_fade (paint_options, image,
|
|
|
|
|
paint_core->pixel_dist);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2016-01-27 10:13:17 -08:00
|
|
|
coords = gimp_symmetry_get_origin (sym);
|
2012-04-28 02:42:33 -07:00
|
|
|
opacity = gimp_dynamics_get_linear_value (dynamics,
|
|
|
|
|
GIMP_DYNAMICS_OUTPUT_OPACITY,
|
|
|
|
|
coords,
|
|
|
|
|
paint_options,
|
|
|
|
|
fade_point);
|
2003-07-16 04:25:37 -07:00
|
|
|
if (opacity == 0.0)
|
2000-11-04 09:54:01 -08:00
|
|
|
return;
|
|
|
|
|
|
2016-01-27 10:13:17 -08:00
|
|
|
gimp_brush_core_eval_transform_dynamics (GIMP_BRUSH_CORE (paint_core),
|
|
|
|
|
drawable,
|
|
|
|
|
paint_options,
|
|
|
|
|
coords);
|
|
|
|
|
n_strokes = gimp_symmetry_get_size (sym);
|
|
|
|
|
for (i = 0; i < n_strokes; i++)
|
|
|
|
|
{
|
|
|
|
|
coords = gimp_symmetry_get_coords (sym, i);
|
|
|
|
|
|
|
|
|
|
paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable,
|
2017-01-20 15:27:48 -08:00
|
|
|
paint_options,
|
2017-08-12 12:35:47 -07:00
|
|
|
GIMP_LAYER_MODE_NORMAL,
|
2017-01-20 15:27:48 -08:00
|
|
|
coords,
|
2016-01-27 10:13:17 -08:00
|
|
|
&paint_buffer_x,
|
|
|
|
|
&paint_buffer_y,
|
|
|
|
|
&paint_width,
|
|
|
|
|
&paint_height);
|
|
|
|
|
if (! paint_buffer)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
op = gimp_symmetry_get_operation (sym, i,
|
|
|
|
|
paint_width,
|
|
|
|
|
paint_height);
|
|
|
|
|
|
|
|
|
|
rate = (options->rate *
|
|
|
|
|
gimp_dynamics_get_linear_value (dynamics,
|
|
|
|
|
GIMP_DYNAMICS_OUTPUT_RATE,
|
|
|
|
|
coords,
|
|
|
|
|
paint_options,
|
|
|
|
|
fade_point));
|
|
|
|
|
|
|
|
|
|
gimp_convolve_calculate_matrix (convolve, options->type,
|
|
|
|
|
gimp_brush_get_width (brush_core->brush) / 2,
|
|
|
|
|
gimp_brush_get_height (brush_core->brush) / 2,
|
|
|
|
|
rate);
|
|
|
|
|
|
|
|
|
|
/* need a linear buffer for gimp_gegl_convolve() */
|
|
|
|
|
temp_buf = gimp_temp_buf_new (gegl_buffer_get_width (paint_buffer),
|
|
|
|
|
gegl_buffer_get_height (paint_buffer),
|
|
|
|
|
gegl_buffer_get_format (paint_buffer));
|
|
|
|
|
convolve_buffer = gimp_temp_buf_create_buffer (temp_buf);
|
|
|
|
|
gimp_temp_buf_unref (temp_buf);
|
|
|
|
|
|
2018-05-24 07:21:21 -07:00
|
|
|
gimp_gegl_buffer_copy (
|
|
|
|
|
gimp_drawable_get_buffer (drawable),
|
|
|
|
|
GEGL_RECTANGLE (paint_buffer_x,
|
|
|
|
|
paint_buffer_y,
|
|
|
|
|
gegl_buffer_get_width (paint_buffer),
|
|
|
|
|
gegl_buffer_get_height (paint_buffer)),
|
|
|
|
|
GEGL_ABYSS_NONE,
|
|
|
|
|
convolve_buffer,
|
|
|
|
|
GEGL_RECTANGLE (0, 0, 0, 0));
|
2016-01-27 10:13:17 -08:00
|
|
|
|
|
|
|
|
gimp_gegl_convolve (convolve_buffer,
|
|
|
|
|
GEGL_RECTANGLE (0, 0,
|
|
|
|
|
gegl_buffer_get_width (convolve_buffer),
|
|
|
|
|
gegl_buffer_get_height (convolve_buffer)),
|
|
|
|
|
paint_buffer,
|
|
|
|
|
GEGL_RECTANGLE (0, 0,
|
|
|
|
|
gegl_buffer_get_width (paint_buffer),
|
|
|
|
|
gegl_buffer_get_height (paint_buffer)),
|
|
|
|
|
convolve->matrix, 3, convolve->matrix_divisor,
|
|
|
|
|
GIMP_NORMAL_CONVOL, TRUE);
|
|
|
|
|
|
|
|
|
|
g_object_unref (convolve_buffer);
|
|
|
|
|
|
|
|
|
|
gimp_brush_core_replace_canvas (brush_core, drawable,
|
|
|
|
|
coords,
|
|
|
|
|
MIN (opacity, GIMP_OPACITY_OPAQUE),
|
|
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
|
gimp_paint_options_get_brush_mode (paint_options),
|
|
|
|
|
1.0,
|
|
|
|
|
GIMP_PAINT_INCREMENTAL, op);
|
|
|
|
|
}
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-05-05 12:18:25 -07:00
|
|
|
gimp_convolve_calculate_matrix (GimpConvolve *convolve,
|
|
|
|
|
GimpConvolveType type,
|
2008-05-27 01:19:30 -07:00
|
|
|
gint radius_x,
|
|
|
|
|
gint radius_y,
|
2002-03-19 07:05:38 -08:00
|
|
|
gdouble rate)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
|
|
|
|
/* find percent of tool pressure */
|
2008-05-27 01:19:30 -07: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-24 14:05:25 -08:00
|
|
|
|
|
|
|
|
/* get the appropriate convolution matrix and size and divisor */
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
2014-04-29 13:44:58 -07:00
|
|
|
case GIMP_CONVOLVE_BLUR:
|
2007-05-05 12:18:25 -07:00
|
|
|
convolve->matrix[4] = MIN_BLUR + percent * (MAX_BLUR - MIN_BLUR);
|
1997-11-24 14:05:25 -08:00
|
|
|
break;
|
|
|
|
|
|
2014-04-29 13:44:58 -07:00
|
|
|
case GIMP_CONVOLVE_SHARPEN:
|
2007-05-05 12:18:25 -07:00
|
|
|
convolve->matrix[4] = MIN_SHARPEN + percent * (MAX_SHARPEN - MIN_SHARPEN);
|
1997-11-24 14:05:25 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-27 01:19:30 -07: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-05 12:18:25 -07:00
|
|
|
convolve->matrix_divisor = gimp_convolve_sum_matrix (convolve->matrix);
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
2004-05-31 00:45:50 -07:00
|
|
|
static gdouble
|
2007-05-05 12:18:25 -07:00
|
|
|
gimp_convolve_sum_matrix (const gfloat *matrix)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2004-05-31 00:45:50 -07:00
|
|
|
gdouble sum = 0.0;
|
2007-05-05 12:18:25 -07:00
|
|
|
gint i;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2007-05-05 12:18:25 -07:00
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
|
sum += matrix[i];
|
1997-11-24 14:05:25 -08:00
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
|
}
|