2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-07-09 13:31:06 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimp_brush_generated module Copyright 1998 Jay Cox <jaycox@earthlink.net>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2004-01-19 09:54:11 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
#include "gimpbrushgenerated.h"
|
2006-10-03 20:29:07 +08:00
|
|
|
#include "gimpbrushgenerated-load.h"
|
|
|
|
#include "gimpbrushgenerated-save.h"
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
#define OVERSAMPLING 5
|
|
|
|
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 08:58:43 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2004-08-01 11:06:58 +08:00
|
|
|
PROP_SHAPE,
|
2004-06-25 08:58:43 +08:00
|
|
|
PROP_RADIUS,
|
2004-08-02 01:20:00 +08:00
|
|
|
PROP_SPIKES,
|
2004-06-25 08:58:43 +08:00
|
|
|
PROP_HARDNESS,
|
2004-06-25 21:41:24 +08:00
|
|
|
PROP_ASPECT_RATIO,
|
|
|
|
PROP_ANGLE
|
2004-06-25 08:58:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
/* local function prototypes */
|
2004-01-30 00:19:57 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
static void gimp_brush_generated_set_property (GObject *object,
|
2004-06-25 08:58:43 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2004-06-25 21:41:24 +08:00
|
|
|
static void gimp_brush_generated_get_property (GObject *object,
|
2004-06-25 08:58:43 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_brush_generated_dirty (GimpData *data);
|
|
|
|
static gchar * gimp_brush_generated_get_extension (GimpData *data);
|
2005-06-08 19:27:31 +08:00
|
|
|
static GimpData * gimp_brush_generated_duplicate (GimpData *data);
|
2006-11-09 22:54:49 +08:00
|
|
|
static TempBuf * gimp_brush_generated_scale_mask (GimpBrush *gbrush,
|
|
|
|
gdouble scale);
|
1998-07-15 20:15:24 +08:00
|
|
|
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpBrushGenerated, gimp_brush_generated, GIMP_TYPE_BRUSH)
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_brush_generated_parent_class
|
1998-07-09 13:31:06 +08:00
|
|
|
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
2006-11-09 22:54:49 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
|
|
|
|
GimpBrushClass *brush_class = GIMP_BRUSH_CLASS (klass);
|
1998-07-09 13:31:06 +08:00
|
|
|
|
2007-03-12 17:33:57 +08:00
|
|
|
object_class->set_property = gimp_brush_generated_set_property;
|
|
|
|
object_class->get_property = gimp_brush_generated_get_property;
|
2004-06-25 08:58:43 +08:00
|
|
|
|
2007-03-12 17:33:57 +08:00
|
|
|
data_class->save = gimp_brush_generated_save;
|
|
|
|
data_class->dirty = gimp_brush_generated_dirty;
|
|
|
|
data_class->get_extension = gimp_brush_generated_get_extension;
|
|
|
|
data_class->duplicate = gimp_brush_generated_duplicate;
|
2004-06-25 08:58:43 +08:00
|
|
|
|
2007-03-12 17:33:57 +08:00
|
|
|
brush_class->scale_mask = gimp_brush_generated_scale_mask;
|
2006-11-09 22:54:49 +08:00
|
|
|
|
2004-08-01 11:06:58 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_SHAPE,
|
|
|
|
g_param_spec_enum ("shape", NULL, NULL,
|
|
|
|
GIMP_TYPE_BRUSH_GENERATED_SHAPE,
|
|
|
|
GIMP_BRUSH_GENERATED_CIRCLE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-08-01 11:06:58 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
2004-06-25 08:58:43 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_RADIUS,
|
|
|
|
g_param_spec_double ("radius", NULL, NULL,
|
2006-08-14 20:45:33 +08:00
|
|
|
0.1, 4000.0, 5.0,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-06-25 08:58:43 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
2004-08-02 01:20:00 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_SPIKES,
|
|
|
|
g_param_spec_int ("spikes", NULL, NULL,
|
|
|
|
2, 20, 2,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-08-02 01:20:00 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
2004-06-25 08:58:43 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_HARDNESS,
|
|
|
|
g_param_spec_double ("hardness", NULL, NULL,
|
|
|
|
0.0, 1.0, 0.0,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-06-25 08:58:43 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
g_object_class_install_property (object_class, PROP_ASPECT_RATIO,
|
|
|
|
g_param_spec_double ("aspect-ratio",
|
|
|
|
NULL, NULL,
|
|
|
|
1.0, 20.0, 1.0,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-06-25 08:58:43 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
2004-06-25 21:41:24 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_ANGLE,
|
|
|
|
g_param_spec_double ("angle", NULL, NULL,
|
|
|
|
0.0, 180.0, 0.0,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-06-25 21:41:24 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
1998-07-16 19:44:56 +08:00
|
|
|
}
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_generated_init (GimpBrushGenerated *brush)
|
1998-07-16 19:44:56 +08:00
|
|
|
{
|
2004-08-01 11:06:58 +08:00
|
|
|
brush->shape = GIMP_BRUSH_GENERATED_CIRCLE;
|
2001-02-11 09:39:24 +08:00
|
|
|
brush->radius = 5.0;
|
|
|
|
brush->hardness = 0.0;
|
|
|
|
brush->aspect_ratio = 1.0;
|
2004-06-25 21:41:24 +08:00
|
|
|
brush->angle = 0.0;
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
|
|
|
|
2004-06-25 08:58:43 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_generated_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2004-08-01 11:06:58 +08:00
|
|
|
case PROP_SHAPE:
|
|
|
|
gimp_brush_generated_set_shape (brush, g_value_get_enum (value));
|
|
|
|
break;
|
2004-06-25 08:58:43 +08:00
|
|
|
case PROP_RADIUS:
|
|
|
|
gimp_brush_generated_set_radius (brush, g_value_get_double (value));
|
|
|
|
break;
|
2004-08-02 01:20:00 +08:00
|
|
|
case PROP_SPIKES:
|
|
|
|
gimp_brush_generated_set_spikes (brush, g_value_get_int (value));
|
|
|
|
break;
|
2004-06-25 08:58:43 +08:00
|
|
|
case PROP_HARDNESS:
|
2004-06-25 21:41:24 +08:00
|
|
|
gimp_brush_generated_set_hardness (brush, g_value_get_double (value));
|
2004-06-25 08:58:43 +08:00
|
|
|
break;
|
|
|
|
case PROP_ASPECT_RATIO:
|
2004-06-25 21:41:24 +08:00
|
|
|
gimp_brush_generated_set_aspect_ratio (brush, g_value_get_double (value));
|
|
|
|
break;
|
|
|
|
case PROP_ANGLE:
|
|
|
|
gimp_brush_generated_set_angle (brush, g_value_get_double (value));
|
2004-06-25 08:58:43 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_generated_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2004-08-01 11:06:58 +08:00
|
|
|
case PROP_SHAPE:
|
|
|
|
g_value_set_enum (value, brush->shape);
|
|
|
|
break;
|
2004-06-25 08:58:43 +08:00
|
|
|
case PROP_RADIUS:
|
2004-08-02 01:20:00 +08:00
|
|
|
g_value_set_double (value, brush->radius);
|
|
|
|
break;
|
|
|
|
case PROP_SPIKES:
|
|
|
|
g_value_set_int (value, brush->spikes);
|
2004-06-25 08:58:43 +08:00
|
|
|
break;
|
|
|
|
case PROP_HARDNESS:
|
|
|
|
g_value_set_double (value, brush->hardness);
|
|
|
|
break;
|
|
|
|
case PROP_ASPECT_RATIO:
|
|
|
|
g_value_set_double (value, brush->aspect_ratio);
|
|
|
|
break;
|
2004-06-25 21:41:24 +08:00
|
|
|
case PROP_ANGLE:
|
|
|
|
g_value_set_double (value, brush->angle);
|
|
|
|
break;
|
2004-06-25 08:58:43 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_brush_generated_get_extension (GimpData *data)
|
|
|
|
{
|
|
|
|
return GIMP_BRUSH_GENERATED_FILE_EXTENSION;
|
|
|
|
}
|
|
|
|
|
2001-02-19 03:44:28 +08:00
|
|
|
static GimpData *
|
2005-06-08 19:27:31 +08:00
|
|
|
gimp_brush_generated_duplicate (GimpData *data)
|
2001-02-19 03:44:28 +08:00
|
|
|
{
|
2004-01-30 00:19:57 +08:00
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
|
2001-02-19 03:44:28 +08:00
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
return gimp_brush_generated_new (GIMP_OBJECT (brush)->name,
|
2004-08-01 11:06:58 +08:00
|
|
|
brush->shape,
|
2004-01-30 00:19:57 +08:00
|
|
|
brush->radius,
|
2004-08-02 01:20:00 +08:00
|
|
|
brush->spikes,
|
2004-08-01 11:06:58 +08:00
|
|
|
brush->hardness,
|
|
|
|
brush->aspect_ratio,
|
2005-06-08 19:27:31 +08:00
|
|
|
brush->angle);
|
2001-02-19 03:44:28 +08:00
|
|
|
}
|
|
|
|
|
2003-04-09 23:31:45 +08:00
|
|
|
static gdouble
|
1999-10-27 02:27:27 +08:00
|
|
|
gauss (gdouble f)
|
2003-11-14 23:33:40 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
/* this aint' a real gauss function */
|
2003-04-09 23:31:45 +08:00
|
|
|
if (f < -0.5)
|
1998-07-24 16:56:18 +08:00
|
|
|
{
|
2000-09-29 20:00:00 +08:00
|
|
|
f = -1.0 - f;
|
2000-02-24 19:39:26 +08:00
|
|
|
return (2.0 * f*f);
|
1998-07-24 16:56:18 +08:00
|
|
|
}
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2003-04-09 23:31:45 +08:00
|
|
|
if (f < 0.5)
|
2000-02-24 19:39:26 +08:00
|
|
|
return (1.0 - 2.0 * f*f);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2003-04-09 23:31:45 +08:00
|
|
|
f = 1.0 - f;
|
2000-02-24 19:39:26 +08:00
|
|
|
return (2.0 * f*f);
|
1998-07-24 16:56:18 +08:00
|
|
|
}
|
1998-07-15 20:15:24 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
static TempBuf *
|
|
|
|
gimp_brush_generated_calc (GimpBrushGenerated *brush,
|
|
|
|
GimpBrushGeneratedShape shape,
|
|
|
|
gfloat radius,
|
|
|
|
gint spikes,
|
|
|
|
gfloat hardness,
|
|
|
|
gfloat aspect_ratio,
|
|
|
|
gfloat angle,
|
|
|
|
GimpVector2 *xaxis,
|
|
|
|
GimpVector2 *yaxis)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
2006-11-09 22:54:49 +08:00
|
|
|
gint x, y;
|
|
|
|
guchar *centerp;
|
|
|
|
gdouble d;
|
|
|
|
gdouble exponent;
|
|
|
|
guchar a;
|
|
|
|
gint length;
|
2007-03-12 17:33:57 +08:00
|
|
|
gint width = 0;
|
|
|
|
gint height = 0;
|
2006-11-09 22:54:49 +08:00
|
|
|
guchar *lookup;
|
|
|
|
gdouble sum;
|
|
|
|
gdouble c, s, cs, ss;
|
2007-03-12 17:33:57 +08:00
|
|
|
gdouble short_radius;
|
2006-11-09 22:54:49 +08:00
|
|
|
gdouble buffer[OVERSAMPLING];
|
|
|
|
GimpVector2 x_axis;
|
|
|
|
GimpVector2 y_axis;
|
|
|
|
TempBuf *mask;
|
|
|
|
|
2007-03-12 17:33:57 +08:00
|
|
|
s = sin (gimp_deg_to_rad (angle));
|
|
|
|
c = cos (gimp_deg_to_rad (angle));
|
|
|
|
|
|
|
|
short_radius = radius / aspect_ratio;
|
|
|
|
|
|
|
|
x_axis.x = c * radius;
|
|
|
|
x_axis.y = -1.0 * s * radius;
|
|
|
|
y_axis.x = s * short_radius;
|
|
|
|
y_axis.y = c * short_radius;
|
|
|
|
|
|
|
|
switch (shape)
|
|
|
|
{
|
|
|
|
case GIMP_BRUSH_GENERATED_CIRCLE:
|
|
|
|
width = ceil (sqrt (x_axis.x * x_axis.x + y_axis.x * y_axis.x));
|
|
|
|
height = ceil (sqrt (x_axis.y * x_axis.y + y_axis.y * y_axis.y));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BRUSH_GENERATED_SQUARE:
|
|
|
|
width = ceil (fabs (x_axis.x) + fabs (y_axis.x));
|
|
|
|
height = ceil (fabs (x_axis.y) + fabs (y_axis.y));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BRUSH_GENERATED_DIAMOND:
|
|
|
|
width = ceil (MAX (fabs (x_axis.x), fabs (y_axis.x)));
|
|
|
|
height = ceil (MAX (fabs (x_axis.y), fabs (y_axis.y)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spikes > 2)
|
|
|
|
{
|
|
|
|
/* could be optimized by respecting the angle */
|
|
|
|
width = height = ceil (sqrt (radius * radius +
|
|
|
|
short_radius * short_radius));
|
|
|
|
y_axis.x = s * radius;
|
|
|
|
y_axis.y = c * radius;
|
|
|
|
}
|
2004-08-02 01:20:00 +08:00
|
|
|
|
2007-03-12 17:33:57 +08:00
|
|
|
mask = temp_buf_new (width * 2 + 1,
|
|
|
|
height * 2 + 1,
|
|
|
|
1, width, height, NULL);
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2007-03-12 17:33:57 +08:00
|
|
|
centerp = temp_buf_data (mask) + height * mask->width + width;
|
2003-04-09 23:31:45 +08:00
|
|
|
|
|
|
|
/* set up lookup table */
|
|
|
|
length = OVERSAMPLING * ceil (1 + sqrt (2 *
|
2006-11-09 22:54:49 +08:00
|
|
|
ceil (radius + 1.0) *
|
|
|
|
ceil (radius + 1.0)));
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if ((1.0 - hardness) < 0.0000004)
|
2003-11-14 23:33:40 +08:00
|
|
|
exponent = 1000000.0;
|
1998-07-09 13:31:06 +08:00
|
|
|
else
|
2006-11-09 22:54:49 +08:00
|
|
|
exponent = 0.4 / (1.0 - hardness);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
lookup = g_malloc (length);
|
1998-07-09 13:31:06 +08:00
|
|
|
sum = 0.0;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
for (x = 0; x < OVERSAMPLING; x++)
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
2000-09-29 20:00:00 +08:00
|
|
|
d = fabs ((x + 0.5) / OVERSAMPLING - 0.5);
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if (d > radius)
|
2004-08-01 11:06:58 +08:00
|
|
|
buffer[x] = 0.0;
|
2000-09-29 20:00:00 +08:00
|
|
|
else
|
2006-11-09 22:54:49 +08:00
|
|
|
buffer[x] = gauss (pow (d / radius, exponent));
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2000-09-29 20:00:00 +08:00
|
|
|
sum += buffer[x];
|
|
|
|
}
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
for (x = 0; d < radius || sum > 0.00001; d += 1.0 / OVERSAMPLING)
|
2000-09-29 20:00:00 +08:00
|
|
|
{
|
|
|
|
sum -= buffer[x % OVERSAMPLING];
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if (d > radius)
|
2004-08-01 11:06:58 +08:00
|
|
|
buffer[x % OVERSAMPLING] = 0.0;
|
1999-10-27 02:27:27 +08:00
|
|
|
else
|
2006-11-09 22:54:49 +08:00
|
|
|
buffer[x % OVERSAMPLING] = gauss (pow (d / radius, exponent));
|
2003-04-09 23:31:45 +08:00
|
|
|
|
|
|
|
sum += buffer[x % OVERSAMPLING];
|
2000-09-29 20:00:00 +08:00
|
|
|
lookup[x++] = RINT (sum * (255.0 / OVERSAMPLING));
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
2003-04-09 23:31:45 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
while (x < length)
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
|
|
|
lookup[x++] = 0;
|
|
|
|
}
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
cs = cos (- 2 * G_PI / spikes);
|
|
|
|
ss = sin (- 2 * G_PI / spikes);
|
2004-08-02 01:20:00 +08:00
|
|
|
|
2004-08-03 05:34:12 +08:00
|
|
|
/* for an even number of spikes compute one half and mirror it */
|
2007-03-12 17:33:57 +08:00
|
|
|
for (y = (spikes % 2 ? -height : 0); y <= height; y++)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
2007-03-12 17:33:57 +08:00
|
|
|
for (x = -width; x <= width; x++)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
2004-08-02 01:20:00 +08:00
|
|
|
gdouble tx, ty, angle;
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2004-08-01 11:06:58 +08:00
|
|
|
tx = c*x - s*y;
|
2004-08-02 01:20:00 +08:00
|
|
|
ty = fabs (s*x + c*y);
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if (spikes > 2)
|
2004-08-02 01:20:00 +08:00
|
|
|
{
|
|
|
|
angle = atan2 (ty, tx);
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
while (angle > G_PI / spikes)
|
2004-08-02 01:20:00 +08:00
|
|
|
{
|
|
|
|
gdouble sx = tx, sy = ty;
|
2004-08-03 20:56:19 +08:00
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
tx = cs * sx - ss * sy;
|
|
|
|
ty = ss * sx + cs * sy;
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
angle -= 2 * G_PI / spikes;
|
2004-08-02 01:20:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
ty *= aspect_ratio;
|
|
|
|
switch (shape)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
2004-08-03 20:56:19 +08:00
|
|
|
case GIMP_BRUSH_GENERATED_CIRCLE:
|
|
|
|
d = sqrt (tx*tx + ty*ty);
|
|
|
|
break;
|
|
|
|
case GIMP_BRUSH_GENERATED_SQUARE:
|
|
|
|
d = MAX (fabs (tx), fabs (ty));
|
|
|
|
break;
|
|
|
|
case GIMP_BRUSH_GENERATED_DIAMOND:
|
|
|
|
d = fabs (tx) + fabs (ty);
|
|
|
|
break;
|
2004-08-01 11:06:58 +08:00
|
|
|
}
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if (d < radius + 1)
|
2004-08-01 11:06:58 +08:00
|
|
|
a = lookup[(gint) RINT (d * OVERSAMPLING)];
|
|
|
|
else
|
|
|
|
a = 0;
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
centerp[ y * mask->width + x] = a;
|
2004-08-02 01:20:00 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if (spikes % 2 == 0)
|
|
|
|
centerp[-1 * y * mask->width - x] = a;
|
2004-08-01 11:06:58 +08:00
|
|
|
}
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
2001-02-07 11:14:38 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
g_free (lookup);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if (xaxis) *xaxis = x_axis;
|
|
|
|
if (yaxis) *yaxis = y_axis;
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_generated_dirty (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
|
|
|
|
GimpBrush *gbrush = GIMP_BRUSH (brush);
|
|
|
|
|
|
|
|
if (gbrush->mask)
|
|
|
|
temp_buf_free (gbrush->mask);
|
|
|
|
|
|
|
|
gbrush->mask = gimp_brush_generated_calc (brush,
|
|
|
|
brush->shape,
|
|
|
|
brush->radius,
|
|
|
|
brush->spikes,
|
|
|
|
brush->hardness,
|
|
|
|
brush->aspect_ratio,
|
|
|
|
brush->angle,
|
|
|
|
&gbrush->x_axis,
|
|
|
|
&gbrush->y_axis);
|
|
|
|
|
2006-05-23 23:39:45 +08:00
|
|
|
GIMP_DATA_CLASS (parent_class)->dirty (data);
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
static TempBuf *
|
|
|
|
gimp_brush_generated_scale_mask (GimpBrush *gbrush,
|
|
|
|
gdouble scale)
|
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (gbrush);
|
|
|
|
|
|
|
|
return gimp_brush_generated_calc (brush,
|
|
|
|
brush->shape,
|
|
|
|
brush->radius * scale,
|
|
|
|
brush->spikes,
|
|
|
|
brush->hardness,
|
|
|
|
brush->aspect_ratio,
|
|
|
|
brush->angle,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2001-02-14 22:57:14 +08:00
|
|
|
GimpData *
|
2004-08-01 11:06:58 +08:00
|
|
|
gimp_brush_generated_new (const gchar *name,
|
|
|
|
GimpBrushGeneratedShape shape,
|
|
|
|
gfloat radius,
|
2004-08-02 01:20:00 +08:00
|
|
|
gint spikes,
|
2004-08-01 11:06:58 +08:00
|
|
|
gfloat hardness,
|
|
|
|
gfloat aspect_ratio,
|
2005-06-08 19:27:31 +08:00
|
|
|
gfloat angle)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush;
|
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2004-10-04 17:39:27 +08:00
|
|
|
g_return_val_if_fail (*name != '\0', NULL);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED,
|
2004-06-25 21:41:24 +08:00
|
|
|
"name", name,
|
2005-05-26 07:25:45 +08:00
|
|
|
"mime-type", "application/x-gimp-brush-generated",
|
2006-12-07 19:53:02 +08:00
|
|
|
"spacing", 20.0,
|
2004-10-04 17:39:27 +08:00
|
|
|
"shape", shape,
|
2004-06-25 21:41:24 +08:00
|
|
|
"radius", radius,
|
2004-08-02 01:20:00 +08:00
|
|
|
"spikes", spikes,
|
2004-06-25 21:41:24 +08:00
|
|
|
"hardness", hardness,
|
|
|
|
"aspect-ratio", aspect_ratio,
|
|
|
|
"angle", angle,
|
2004-01-30 00:19:57 +08:00
|
|
|
NULL);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2001-02-14 22:57:14 +08:00
|
|
|
return GIMP_DATA (brush);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2004-08-01 11:06:58 +08:00
|
|
|
GimpBrushGeneratedShape
|
|
|
|
gimp_brush_generated_set_shape (GimpBrushGenerated *brush,
|
|
|
|
GimpBrushGeneratedShape shape)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush),
|
|
|
|
GIMP_BRUSH_GENERATED_CIRCLE);
|
|
|
|
|
|
|
|
if (brush->shape != shape)
|
|
|
|
{
|
|
|
|
brush->shape = shape;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (brush), "shape");
|
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
|
|
|
}
|
|
|
|
|
|
|
|
return brush->shape;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
|
|
|
gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
2004-08-01 11:06:58 +08:00
|
|
|
gfloat radius)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
radius = CLAMP (radius, 0.0, 32767.0);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
if (brush->radius != radius)
|
|
|
|
{
|
|
|
|
brush->radius = radius;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 08:58:43 +08:00
|
|
|
g_object_notify (G_OBJECT (brush), "radius");
|
2004-06-13 06:13:31 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2004-01-30 00:19:57 +08:00
|
|
|
}
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->radius;
|
|
|
|
}
|
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
gint
|
|
|
|
gimp_brush_generated_set_spikes (GimpBrushGenerated *brush,
|
|
|
|
gint spikes)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1);
|
|
|
|
|
|
|
|
spikes = CLAMP (spikes, 2, 20);
|
|
|
|
|
|
|
|
if (brush->spikes != spikes)
|
|
|
|
{
|
|
|
|
brush->spikes = spikes;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (brush), "spikes");
|
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
|
|
|
}
|
|
|
|
|
|
|
|
return brush->spikes;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
|
|
|
gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
2004-08-01 11:06:58 +08:00
|
|
|
gfloat hardness)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
hardness = CLAMP (hardness, 0.0, 1.0);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
if (brush->hardness != hardness)
|
|
|
|
{
|
|
|
|
brush->hardness = hardness;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 08:58:43 +08:00
|
|
|
g_object_notify (G_OBJECT (brush), "hardness");
|
2004-06-13 06:13:31 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2004-01-30 00:19:57 +08:00
|
|
|
}
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->hardness;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
2004-06-25 21:41:24 +08:00
|
|
|
gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
2004-08-01 11:06:58 +08:00
|
|
|
gfloat ratio)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
ratio = CLAMP (ratio, 1.0, 1000.0);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
if (brush->aspect_ratio != ratio)
|
2004-01-30 00:19:57 +08:00
|
|
|
{
|
2004-06-25 21:41:24 +08:00
|
|
|
brush->aspect_ratio = ratio;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
g_object_notify (G_OBJECT (brush), "aspect-ratio");
|
2004-06-13 06:13:31 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2004-01-30 00:19:57 +08:00
|
|
|
}
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
return brush->aspect_ratio;
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
2004-06-25 21:41:24 +08:00
|
|
|
gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
2004-08-01 11:06:58 +08:00
|
|
|
gfloat angle)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
if (angle < 0.0)
|
|
|
|
angle = -1.0 * fmod (angle, 180.0);
|
|
|
|
else if (angle > 180.0)
|
|
|
|
angle = fmod (angle, 180.0);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
if (brush->angle != angle)
|
2004-01-30 00:19:57 +08:00
|
|
|
{
|
2004-06-25 21:41:24 +08:00
|
|
|
brush->angle = angle;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
g_object_notify (G_OBJECT (brush), "angle");
|
2004-06-13 06:13:31 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2004-01-30 00:19:57 +08:00
|
|
|
}
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
return brush->angle;
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
|
|
|
|
2004-08-01 11:06:58 +08:00
|
|
|
GimpBrushGeneratedShape
|
|
|
|
gimp_brush_generated_get_shape (const GimpBrushGenerated *brush)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush),
|
|
|
|
GIMP_BRUSH_GENERATED_CIRCLE);
|
|
|
|
|
|
|
|
return brush->shape;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
|
|
|
gimp_brush_generated_get_radius (const GimpBrushGenerated *brush)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->radius;
|
|
|
|
}
|
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
gint
|
|
|
|
gimp_brush_generated_get_spikes (const GimpBrushGenerated *brush)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1);
|
|
|
|
|
|
|
|
return brush->spikes;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
2000-09-29 20:00:00 +08:00
|
|
|
gimp_brush_generated_get_hardness (const GimpBrushGenerated *brush)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->hardness;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
2004-06-25 21:41:24 +08:00
|
|
|
gimp_brush_generated_get_aspect_ratio (const GimpBrushGenerated *brush)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
return brush->aspect_ratio;
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
2004-06-25 21:41:24 +08:00
|
|
|
gimp_brush_generated_get_angle (const GimpBrushGenerated *brush)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
|
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
return brush->angle;
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|