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
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
1999-04-28 05:06:00 +08:00
|
|
|
#include "gdk/gdkkeysyms.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "appenv.h"
|
|
|
|
#include "drawable.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "convolve.h"
|
|
|
|
#include "gdisplay.h"
|
|
|
|
#include "paint_funcs.h"
|
|
|
|
#include "paint_core.h"
|
1999-04-22 22:34:00 +08:00
|
|
|
#include "paint_options.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "selection.h"
|
1999-04-13 01:55:06 +08:00
|
|
|
#include "tool_options_ui.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "tools.h"
|
1998-06-29 08:24:44 +08:00
|
|
|
#include "gimage.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
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
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
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
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
/* defaults */
|
|
|
|
#define DEFAULT_CONVOLVE_PRESSURE 50.0
|
|
|
|
#define DEFAULT_CONVOLVE_TYPE BLUR_CONVOLVE
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the convolve structures */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
typedef struct _ConvolveOptions ConvolveOptions;
|
|
|
|
struct _ConvolveOptions
|
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintOptions paint_options;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
ConvolveType type;
|
1999-04-09 06:25:54 +08:00
|
|
|
ConvolveType type_d;
|
1999-04-28 05:06:00 +08:00
|
|
|
GtkWidget *type_w[2];
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
double pressure;
|
1999-04-09 06:25:54 +08:00
|
|
|
double pressure_d;
|
|
|
|
GtkObject *pressure_w;
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
/* the convolve tool options */
|
|
|
|
static ConvolveOptions * convolve_options = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* local variables */
|
|
|
|
static int matrix [25];
|
|
|
|
static int matrix_size;
|
|
|
|
static int matrix_divisor;
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
static ConvolveType non_gui_type;
|
|
|
|
static double non_gui_pressure;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static float custom_matrix [25] =
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
static float blur_matrix [25] =
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
static float sharpen_matrix [25] =
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* forward function declarations */
|
|
|
|
static void calculate_matrix (ConvolveType, double, double);
|
|
|
|
static void integer_matrix (float *, int *, int);
|
|
|
|
static void copy_matrix (float *, float *, int);
|
|
|
|
static int sum_matrix (int *, int);
|
|
|
|
|
1999-09-09 09:47:54 +08:00
|
|
|
static void convolve_motion (PaintCore *, GimpDrawable *, PaintPressureOptions *,
|
|
|
|
ConvolveType, double);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* functions */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
1999-04-13 01:55:06 +08:00
|
|
|
convolve_options_reset (void)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
|
|
|
ConvolveOptions *options = convolve_options;
|
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
paint_options_reset ((PaintOptions *) options);
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->pressure_w),
|
|
|
|
options->pressure_d);
|
1999-04-28 05:06:00 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->type_w[options->type_d]), TRUE);
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static ConvolveOptions *
|
1999-04-13 01:55:06 +08:00
|
|
|
convolve_options_new (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
ConvolveOptions *options;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
1999-04-09 06:25:54 +08:00
|
|
|
GtkWidget *scale;
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkWidget *frame;
|
1999-04-29 02:58:01 +08:00
|
|
|
gchar* type_label[2] = { N_("Blur"), N_("Sharpen") };
|
1999-04-28 05:06:00 +08:00
|
|
|
gint type_value[2] = { BLUR_CONVOLVE, SHARPEN_CONVOLVE };
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the new convolve tool options structure */
|
1997-11-25 06:05:25 +08:00
|
|
|
options = (ConvolveOptions *) g_malloc (sizeof (ConvolveOptions));
|
1999-04-22 22:34:00 +08:00
|
|
|
paint_options_init ((PaintOptions *) options,
|
|
|
|
CONVOLVE,
|
|
|
|
convolve_options_reset);
|
1999-07-20 06:42:49 +08:00
|
|
|
options->type = options->type_d = DEFAULT_CONVOLVE_TYPE;
|
|
|
|
options->pressure = options->pressure_d = DEFAULT_CONVOLVE_PRESSURE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* the main vbox */
|
1999-04-22 22:34:00 +08:00
|
|
|
vbox = ((ToolOptions *) options)->main_vbox;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* the pressure scale */
|
1999-04-22 22:34:00 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
label = gtk_label_new (_("Pressure:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
options->pressure_w =
|
|
|
|
gtk_adjustment_new (options->pressure_d, 0.0, 100.0, 1.0, 1.0, 0.0);
|
|
|
|
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->pressure_w));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
|
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->pressure_w), "value_changed",
|
1999-04-13 01:55:06 +08:00
|
|
|
(GtkSignalFunc) tool_options_double_adjustment_update,
|
1997-11-25 06:05:25 +08:00
|
|
|
&options->pressure);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_widget_show (scale);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
1999-08-22 13:56:27 +08:00
|
|
|
frame = tool_options_radio_buttons_new (_("Convolve Type"),
|
1999-04-28 05:06:00 +08:00
|
|
|
&options->type,
|
|
|
|
options->type_w,
|
|
|
|
type_label,
|
|
|
|
type_value,
|
|
|
|
2);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->type_w[options->type_d]), TRUE);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
1999-04-09 06:25:54 +08:00
|
|
|
convolve_paint_func (PaintCore *paint_core,
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable,
|
1999-04-09 06:25:54 +08:00
|
|
|
int state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case MOTION_PAINT:
|
1999-09-09 09:47:54 +08:00
|
|
|
convolve_motion (paint_core, drawable,
|
|
|
|
convolve_options->paint_options.pressure_options,
|
|
|
|
convolve_options->type, convolve_options->pressure);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-04-27 10:09:03 +08:00
|
|
|
static void
|
1999-04-28 05:06:00 +08:00
|
|
|
convolve_modifier_key_func (Tool *tool,
|
1999-06-08 06:38:20 +08:00
|
|
|
GdkEventKey *kevent,
|
|
|
|
gpointer gdisp_ptr)
|
1999-04-27 10:09:03 +08:00
|
|
|
{
|
1999-04-28 05:06:00 +08:00
|
|
|
switch (kevent->keyval)
|
1999-04-27 10:09:03 +08:00
|
|
|
{
|
1999-04-28 05:06:00 +08:00
|
|
|
case GDK_Alt_L: case GDK_Alt_R:
|
1999-04-27 10:09:03 +08:00
|
|
|
break;
|
1999-04-28 05:06:00 +08:00
|
|
|
case GDK_Shift_L: case GDK_Shift_R:
|
1999-06-08 06:38:20 +08:00
|
|
|
break;
|
|
|
|
case GDK_Control_L: case GDK_Control_R:
|
1999-04-28 05:06:00 +08:00
|
|
|
switch (convolve_options->type)
|
|
|
|
{
|
|
|
|
case BLUR_CONVOLVE:
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (convolve_options->type_w[SHARPEN_CONVOLVE]), TRUE);
|
|
|
|
break;
|
|
|
|
case SHARPEN_CONVOLVE:
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (convolve_options->type_w[BLUR_CONVOLVE]), TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1999-04-27 10:09:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
Tool *
|
|
|
|
tools_new_convolve ()
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
PaintCore * private;
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* The tool options */
|
1997-11-25 06:05:25 +08:00
|
|
|
if (! convolve_options)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
|
|
|
convolve_options = convolve_options_new ();
|
|
|
|
tools_register (CONVOLVE, (ToolOptions *) convolve_options);
|
1999-04-18 07:18:43 +08:00
|
|
|
|
|
|
|
/* press all default buttons */
|
|
|
|
convolve_options_reset ();
|
1999-04-13 01:55:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool = paint_core_new (CONVOLVE);
|
1999-04-28 05:06:00 +08:00
|
|
|
tool->modifier_key_func = convolve_modifier_key_func;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
private = (PaintCore *) tool->private;
|
|
|
|
private->paint_func = convolve_paint_func;
|
|
|
|
|
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tools_free_convolve (Tool *tool)
|
|
|
|
{
|
|
|
|
paint_core_free (tool);
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1999-09-09 09:47:54 +08:00
|
|
|
convolve_motion (PaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintPressureOptions *pressure_options,
|
|
|
|
ConvolveType type,
|
|
|
|
double pressure)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GImage *gimage;
|
|
|
|
TempBuf * area;
|
|
|
|
unsigned char *temp_data;
|
|
|
|
PixelRegion srcPR, destPR, tempPR;
|
1999-09-09 09:47:54 +08:00
|
|
|
gdouble scale;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! (gimage = drawable_gimage (drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If the image type is indexed, don't convolve */
|
1998-05-12 08:12:47 +08:00
|
|
|
if ((drawable_type (drawable) == INDEXED_GIMAGE) ||
|
|
|
|
(drawable_type (drawable) == INDEXEDA_GIMAGE))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1999-09-09 09:47:54 +08:00
|
|
|
if (pressure_options->size)
|
|
|
|
scale = paint_core->curpressure;
|
|
|
|
else
|
|
|
|
scale = 1.0;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Get a region which can be used to paint to */
|
1999-09-09 09:47:54 +08:00
|
|
|
if (! (area = paint_core_get_paint_area (paint_core, drawable, scale)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* configure the pixel regions correctly */
|
1998-01-22 15:02:57 +08:00
|
|
|
pixel_region_init (&srcPR, drawable_data (drawable), area->x, area->y, area->width, area->height, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
destPR.bytes = area->bytes;
|
|
|
|
destPR.x = 0; destPR.y = 0;
|
|
|
|
destPR.w = area->width;
|
|
|
|
destPR.h = area->height;
|
|
|
|
destPR.rowstride = area->width * destPR.bytes;
|
|
|
|
destPR.data = temp_buf_data (area);
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
calculate_matrix (type, pressure,
|
1999-02-05 07:28:09 +08:00
|
|
|
paint_core->curpressure);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* convolve the source image with the convolve mask */
|
|
|
|
if (srcPR.w >= matrix_size && srcPR.h >= matrix_size)
|
|
|
|
{
|
|
|
|
/* if the source has no alpha, then add alpha pixels */
|
1998-01-22 15:02:57 +08:00
|
|
|
if (!drawable_has_alpha (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1997-12-08 09:13:10 +08:00
|
|
|
/* note: this architecture 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. */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
tempPR.bytes = srcPR.bytes + 1;
|
|
|
|
tempPR.x = 0; tempPR.y = 0;
|
|
|
|
tempPR.w = area->width;
|
|
|
|
tempPR.h = area->height;
|
|
|
|
tempPR.rowstride = tempPR.bytes * tempPR.w;
|
|
|
|
temp_data = g_malloc (tempPR.h * tempPR.rowstride);
|
|
|
|
tempPR.data = temp_data;
|
|
|
|
|
|
|
|
add_alpha_region (&srcPR, &tempPR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tempPR.bytes = srcPR.bytes;
|
|
|
|
tempPR.x = 0; tempPR.y = 0;
|
|
|
|
tempPR.w = area->width;
|
|
|
|
tempPR.h = area->height;
|
|
|
|
tempPR.rowstride = tempPR.bytes * tempPR.w;
|
|
|
|
temp_data = g_malloc (tempPR.h * tempPR.rowstride);
|
|
|
|
tempPR.data = temp_data;
|
|
|
|
|
|
|
|
copy_region (&srcPR, &tempPR);
|
1997-12-08 09:13:10 +08:00
|
|
|
|
|
|
|
tempPR.x = 0; tempPR.y = 0;
|
|
|
|
tempPR.w = area->width;
|
|
|
|
tempPR.h = area->height;
|
|
|
|
tempPR.data = temp_data;
|
|
|
|
|
|
|
|
multiply_alpha_region (&tempPR);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tempPR.x = 0; tempPR.y = 0;
|
|
|
|
tempPR.w = area->width;
|
|
|
|
tempPR.h = area->height;
|
|
|
|
tempPR.data = temp_data;
|
|
|
|
|
|
|
|
/* Convolve the region */
|
|
|
|
convolve_region (&tempPR, &destPR, matrix, matrix_size,
|
Actually use the enum types GimpImageType, GimpImageBaseType,
* app/*.[ch]: Actually use the enum types GimpImageType,
GimpImageBaseType, LayerModeEffects, PaintApplicationMode,
BrushApplicationMode, GimpFillType and ConvertPaletteType, instead
of just int or gint. Hopefully I catched most of the places
where these should be used.
Add an enum ConvolutionType, suffix the too general constants
NORMAL, ABSOLUTE and NEGATIVE with _CONVOL. Use NORMAL_MODE
instead of NORMAL in some places (this was what was intended). Fix
some minor gccisms.
* app/apptypes.h: New file. This file contains the above
enumeration types, and some opaque struct typedefs. It was
necessary to collect these in one header that doesn't include
other headers, because when we started using the above mentioned
types in the headers, all hell broke loose because of the
spaghetti-like cross-inclusion mess between headers.
(An example: Header A includes header B, which includes header C
which includes A. B uses a type defined in A. This is not defined,
because A hasn't defined it yet at the point where it includes B,
and A included from B of course is skipped as we already are
reading A.)
1999-08-19 07:41:39 +08:00
|
|
|
matrix_divisor, NORMAL_CONVOL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (drawable_has_alpha (drawable))
|
1997-12-08 09:13:10 +08:00
|
|
|
separate_alpha_region (&destPR);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Free the allocated temp space */
|
|
|
|
g_free (temp_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if the source has no alpha, then add alpha pixels, otherwise copy */
|
1998-01-22 15:02:57 +08:00
|
|
|
if (!drawable_has_alpha (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
add_alpha_region (&srcPR, &destPR);
|
|
|
|
else
|
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* paste the newly painted canvas to the gimage which is being worked on */
|
1998-01-25 09:24:46 +08:00
|
|
|
paint_core_replace_canvas (paint_core, drawable, OPAQUE_OPACITY,
|
1999-07-06 23:18:25 +08:00
|
|
|
(int) (gimp_context_get_opacity (NULL) * 255),
|
1999-09-09 09:47:54 +08:00
|
|
|
SOFT, scale, INCREMENTAL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calculate_matrix (ConvolveType type,
|
1999-02-05 07:28:09 +08:00
|
|
|
double pressure,
|
|
|
|
double curpressure)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
float percent;
|
|
|
|
|
|
|
|
/* find percent of tool pressure */
|
1999-02-05 07:28:09 +08:00
|
|
|
percent = (pressure / 100.0) * curpressure;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* get the appropriate convolution matrix and size and divisor */
|
|
|
|
switch (type)
|
|
|
|
{
|
1999-04-19 05:22:41 +08:00
|
|
|
case BLUR_CONVOLVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
matrix_size = 5;
|
|
|
|
blur_matrix [12] = MIN_BLUR + percent * (MAX_BLUR - MIN_BLUR);
|
|
|
|
copy_matrix (blur_matrix, custom_matrix, matrix_size);
|
|
|
|
break;
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
case SHARPEN_CONVOLVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
matrix_size = 5;
|
|
|
|
sharpen_matrix [12] = MIN_SHARPEN + percent * (MAX_SHARPEN - MIN_SHARPEN);
|
|
|
|
copy_matrix (sharpen_matrix, custom_matrix, matrix_size);
|
|
|
|
break;
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
case CUSTOM_CONVOLVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
matrix_size = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
integer_matrix (custom_matrix, matrix, matrix_size);
|
|
|
|
matrix_divisor = sum_matrix (matrix, matrix_size);
|
|
|
|
|
|
|
|
if (!matrix_divisor)
|
|
|
|
matrix_divisor = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
integer_matrix (float *source,
|
|
|
|
int *dest,
|
|
|
|
int size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define PRECISION 10000
|
|
|
|
|
|
|
|
for (i = 0; i < size*size; i++)
|
|
|
|
*dest++ = (int) (*source ++ * PRECISION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_matrix (float *src,
|
|
|
|
float *dest,
|
|
|
|
int size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < size*size; i++)
|
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sum_matrix (int *matrix,
|
|
|
|
int size)
|
|
|
|
{
|
|
|
|
int sum = 0;
|
|
|
|
|
|
|
|
size *= size;
|
|
|
|
|
|
|
|
while (size --)
|
|
|
|
sum += *matrix++;
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
convolve_non_gui_paint_func (PaintCore *paint_core,
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable,
|
1997-11-25 06:05:25 +08:00
|
|
|
int state)
|
|
|
|
{
|
1999-09-09 09:47:54 +08:00
|
|
|
convolve_motion (paint_core, drawable, &non_gui_pressure_options,
|
|
|
|
non_gui_type, non_gui_pressure);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
gboolean
|
|
|
|
convolve_non_gui_default (GimpDrawable *drawable,
|
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array)
|
|
|
|
{
|
|
|
|
double pressure = DEFAULT_CONVOLVE_PRESSURE;
|
|
|
|
ConvolveType type = DEFAULT_CONVOLVE_TYPE;
|
|
|
|
ConvolveOptions *options = convolve_options;
|
|
|
|
|
|
|
|
if(options)
|
|
|
|
{
|
|
|
|
pressure = options->pressure;
|
|
|
|
type = options->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return convolve_non_gui(drawable,pressure,type,num_strokes,stroke_array);
|
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
gboolean
|
|
|
|
convolve_non_gui (GimpDrawable *drawable,
|
|
|
|
double pressure,
|
1999-07-20 06:42:49 +08:00
|
|
|
ConvolveType type,
|
1999-04-19 05:22:41 +08:00
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
if (paint_core_init (&non_gui_paint_core, drawable,
|
|
|
|
stroke_array[0], stroke_array[1]))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Set the paint core's paint func */
|
1997-11-25 06:05:25 +08:00
|
|
|
non_gui_paint_core.paint_func = convolve_non_gui_paint_func;
|
1999-07-20 06:42:49 +08:00
|
|
|
|
|
|
|
non_gui_type = type;
|
|
|
|
non_gui_pressure = pressure;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
non_gui_paint_core.startx = non_gui_paint_core.lastx = stroke_array[0];
|
|
|
|
non_gui_paint_core.starty = non_gui_paint_core.lasty = stroke_array[1];
|
|
|
|
|
1999-07-23 07:11:46 +08:00
|
|
|
convolve_non_gui_paint_func (&non_gui_paint_core, drawable, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
|
|
|
{
|
|
|
|
non_gui_paint_core.curx = stroke_array[i * 2 + 0];
|
|
|
|
non_gui_paint_core.cury = stroke_array[i * 2 + 1];
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
paint_core_interpolate (&non_gui_paint_core, drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
non_gui_paint_core.lastx = non_gui_paint_core.curx;
|
|
|
|
non_gui_paint_core.lasty = non_gui_paint_core.cury;
|
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Finish the painting */
|
1998-01-22 15:02:57 +08:00
|
|
|
paint_core_finish (&non_gui_paint_core, drawable, -1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Cleanup */
|
1997-11-25 06:05:25 +08:00
|
|
|
paint_core_cleanup ();
|
1999-04-19 05:22:41 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-04-19 05:22:41 +08:00
|
|
|
else
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|