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>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-07-09 13:31:06 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-07-09 13:31:06 +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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1998-07-09 13:31:06 +08:00
|
|
|
*/
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2012-04-09 00:47:49 +08:00
|
|
|
#include <gegl.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
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
#include "gimpbrush-private.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"
|
2012-04-09 06:59:20 +08:00
|
|
|
#include "gimptempbuf.h"
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2009-03-20 04:40:43 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2007-03-29 22:04:54 +08:00
|
|
|
#define OVERSAMPLING 4
|
1998-07-09 13:31:06 +08:00
|
|
|
|
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
|
|
|
|
2008-09-12 18:35:35 +08:00
|
|
|
static void gimp_brush_generated_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_brush_generated_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_brush_generated_dirty (GimpData *data);
|
|
|
|
static const gchar * gimp_brush_generated_get_extension (GimpData *data);
|
|
|
|
static GimpData * gimp_brush_generated_duplicate (GimpData *data);
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
static void gimp_brush_generated_transform_size(GimpBrush *gbrush,
|
2009-04-26 01:53:09 +08:00
|
|
|
gdouble scale,
|
|
|
|
gdouble aspect_ratio,
|
2009-02-06 05:47:57 +08:00
|
|
|
gdouble angle,
|
2008-09-12 18:35:35 +08:00
|
|
|
gint *width,
|
|
|
|
gint *height);
|
2012-04-09 02:25:49 +08:00
|
|
|
static GimpTempBuf * gimp_brush_generated_transform_mask(GimpBrush *gbrush,
|
2009-04-26 01:53:09 +08:00
|
|
|
gdouble scale,
|
|
|
|
gdouble aspect_ratio,
|
2010-01-01 21:41:07 +08:00
|
|
|
gdouble angle,
|
|
|
|
gdouble hardness);
|
2008-09-12 18:35:35 +08:00
|
|
|
|
2012-04-09 02:25:49 +08:00
|
|
|
static GimpTempBuf * gimp_brush_generated_calc (GimpBrushGenerated *brush,
|
2008-09-12 18:35:35 +08:00
|
|
|
GimpBrushGeneratedShape shape,
|
|
|
|
gfloat radius,
|
|
|
|
gint spikes,
|
|
|
|
gfloat hardness,
|
|
|
|
gfloat aspect_ratio,
|
|
|
|
gfloat angle,
|
|
|
|
GimpVector2 *xaxis,
|
|
|
|
GimpVector2 *yaxis);
|
2014-10-21 18:31:24 +08:00
|
|
|
static void gimp_brush_generated_get_size (GimpBrushGenerated *gbrush,
|
2008-09-12 18:35:35 +08:00
|
|
|
GimpBrushGeneratedShape shape,
|
|
|
|
gfloat radius,
|
|
|
|
gint spikes,
|
|
|
|
gfloat hardness,
|
|
|
|
gfloat aspect_ratio,
|
|
|
|
gdouble angle_in_degrees,
|
2014-10-21 18:31:24 +08:00
|
|
|
gint *width,
|
|
|
|
gint *height,
|
2008-09-12 18:35:35 +08:00
|
|
|
gdouble *_s,
|
|
|
|
gdouble *_c,
|
|
|
|
GimpVector2 *_x_axis,
|
|
|
|
GimpVector2 *_y_axis);
|
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
|
|
|
|
2009-02-01 19:08:22 +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
|
|
|
|
2009-02-01 19:08:22 +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
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
brush_class->transform_size = gimp_brush_generated_transform_size;
|
|
|
|
brush_class->transform_mask = gimp_brush_generated_transform_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,
|
2009-03-20 04:40:43 +08:00
|
|
|
g_param_spec_enum ("shape", NULL,
|
|
|
|
_("Brush Shape"),
|
2004-08-01 11:06:58 +08:00
|
|
|
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));
|
2008-03-11 19:01:19 +08:00
|
|
|
|
2004-06-25 08:58:43 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_RADIUS,
|
2009-03-20 04:40:43 +08:00
|
|
|
g_param_spec_double ("radius", NULL,
|
|
|
|
_("Brush Radius"),
|
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));
|
2008-03-11 19:01:19 +08:00
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_SPIKES,
|
2009-03-20 04:40:43 +08:00
|
|
|
g_param_spec_int ("spikes", NULL,
|
|
|
|
_("Brush Spikes"),
|
2004-08-02 01:20:00 +08:00
|
|
|
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));
|
2008-03-11 19:01:19 +08:00
|
|
|
|
2004-06-25 08:58:43 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_HARDNESS,
|
2009-03-20 04:40:43 +08:00
|
|
|
g_param_spec_double ("hardness", NULL,
|
|
|
|
_("Brush Hardness"),
|
2004-06-25 08:58:43 +08:00
|
|
|
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));
|
2008-03-11 19:01:19 +08:00
|
|
|
|
2004-06-25 08:58:43 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_ASPECT_RATIO,
|
|
|
|
g_param_spec_double ("aspect-ratio",
|
2009-03-20 04:40:43 +08:00
|
|
|
NULL,
|
|
|
|
_("Brush Aspect Ratio"),
|
2004-06-25 08:58:43 +08:00
|
|
|
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));
|
2008-03-11 19:01:19 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_ANGLE,
|
2009-03-20 04:40:43 +08:00
|
|
|
g_param_spec_double ("angle", NULL,
|
|
|
|
_("Brush Angle"),
|
2004-06-25 21:41:24 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-11 19:01:19 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_generated_dirty (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
|
|
|
|
GimpBrush *gbrush = GIMP_BRUSH (brush);
|
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
if (gbrush->priv->mask)
|
|
|
|
gimp_temp_buf_unref (gbrush->priv->mask);
|
|
|
|
|
|
|
|
gbrush->priv->mask = gimp_brush_generated_calc (brush,
|
|
|
|
brush->shape,
|
|
|
|
brush->radius,
|
|
|
|
brush->spikes,
|
|
|
|
brush->hardness,
|
|
|
|
brush->aspect_ratio,
|
|
|
|
brush->angle,
|
|
|
|
&gbrush->priv->x_axis,
|
|
|
|
&gbrush->priv->y_axis);
|
2008-03-11 19:01:19 +08:00
|
|
|
|
|
|
|
GIMP_DATA_CLASS (parent_class)->dirty (data);
|
|
|
|
}
|
|
|
|
|
2008-09-12 18:35:35 +08:00
|
|
|
static const gchar *
|
2001-02-14 03:53:07 +08:00
|
|
|
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
|
|
|
|
2009-08-29 18:40:40 +08:00
|
|
|
return gimp_brush_generated_new (gimp_object_get_name (brush),
|
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
|
|
|
}
|
|
|
|
|
2008-03-11 19:01:19 +08:00
|
|
|
static void
|
2009-02-01 19:08:22 +08:00
|
|
|
gimp_brush_generated_transform_size (GimpBrush *gbrush,
|
2009-04-26 01:53:09 +08:00
|
|
|
gdouble scale,
|
|
|
|
gdouble aspect_ratio,
|
2009-02-06 05:47:57 +08:00
|
|
|
gdouble angle,
|
2009-02-01 19:08:22 +08:00
|
|
|
gint *width,
|
|
|
|
gint *height)
|
2008-03-11 19:01:19 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (gbrush);
|
2010-05-15 01:57:48 +08:00
|
|
|
gdouble ratio;
|
2008-03-11 19:01:19 +08:00
|
|
|
|
2016-10-11 06:57:25 +08:00
|
|
|
ratio = fabs (aspect_ratio) * 19.0 / 20.0 + 1.0;
|
|
|
|
ratio = MIN (ratio, 20);
|
|
|
|
|
|
|
|
/* Since generated brushes are symmetric they don't have aspect
|
|
|
|
* ratios < 1.0. it's the same as rotating by 90 degrees and 1 /
|
|
|
|
* ratio, so we fix the input for this case.
|
|
|
|
*/
|
|
|
|
if (aspect_ratio < 0.0)
|
|
|
|
angle = angle + 0.25;
|
|
|
|
|
|
|
|
angle *= 360;
|
|
|
|
|
|
|
|
if (angle < 0.0)
|
|
|
|
angle = -1.0 * fmod (angle, 180.0);
|
|
|
|
else if (angle > 180.0)
|
|
|
|
angle = fmod (angle, 180.0);
|
2009-04-26 01:53:09 +08:00
|
|
|
|
2014-10-21 18:31:24 +08:00
|
|
|
gimp_brush_generated_get_size (brush,
|
|
|
|
brush->shape,
|
|
|
|
brush->radius * scale,
|
|
|
|
brush->spikes,
|
|
|
|
brush->hardness,
|
|
|
|
ratio,
|
2016-10-11 06:57:25 +08:00
|
|
|
angle,
|
2014-10-21 18:31:24 +08:00
|
|
|
width, height,
|
|
|
|
NULL, NULL, NULL, NULL);
|
2008-03-11 19:01:19 +08:00
|
|
|
}
|
|
|
|
|
2012-04-09 02:25:49 +08:00
|
|
|
static GimpTempBuf *
|
2009-02-01 19:08:22 +08:00
|
|
|
gimp_brush_generated_transform_mask (GimpBrush *gbrush,
|
2009-04-26 01:53:09 +08:00
|
|
|
gdouble scale,
|
|
|
|
gdouble aspect_ratio,
|
2010-01-01 21:41:07 +08:00
|
|
|
gdouble angle,
|
|
|
|
gdouble hardness)
|
2008-03-11 19:01:19 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (gbrush);
|
2010-05-15 01:57:48 +08:00
|
|
|
gdouble ratio;
|
2008-03-11 19:01:19 +08:00
|
|
|
|
2016-10-11 06:57:25 +08:00
|
|
|
ratio = fabs (aspect_ratio) * 19.0 / 20.0 + 1.0;
|
|
|
|
ratio = MIN (ratio, 20);
|
|
|
|
|
|
|
|
/* Since generated brushes are symmetric they don't have aspect
|
|
|
|
* ratios < 1.0. it's the same as rotating by 90 degrees and 1 /
|
|
|
|
* ratio, so we fix the input for this case.
|
|
|
|
*/
|
|
|
|
if (aspect_ratio < 0.0)
|
|
|
|
angle = angle + 0.25;
|
2010-05-15 01:57:48 +08:00
|
|
|
|
2016-10-11 06:57:25 +08:00
|
|
|
angle *= 360;
|
2010-05-15 01:57:48 +08:00
|
|
|
|
2016-10-11 06:57:25 +08:00
|
|
|
if (angle < 0.0)
|
|
|
|
angle = -1.0 * fmod (angle, 180.0);
|
|
|
|
else if (angle > 180.0)
|
|
|
|
angle = fmod (angle, 180.0);
|
2009-04-26 01:53:09 +08:00
|
|
|
|
2017-06-15 03:08:55 +08:00
|
|
|
if (scale == 1.0 &&
|
|
|
|
ratio == brush->aspect_ratio &&
|
|
|
|
angle == brush->angle &&
|
|
|
|
hardness == brush->hardness)
|
|
|
|
{
|
|
|
|
return gimp_temp_buf_copy (gimp_brush_get_mask (gbrush));
|
|
|
|
}
|
|
|
|
|
2008-03-11 19:01:19 +08:00
|
|
|
return gimp_brush_generated_calc (brush,
|
|
|
|
brush->shape,
|
2012-01-21 03:11:02 +08:00
|
|
|
brush->radius * scale,
|
2008-03-11 19:01:19 +08:00
|
|
|
brush->spikes,
|
2014-11-20 05:00:18 +08:00
|
|
|
hardness,
|
2010-05-15 01:57:48 +08:00
|
|
|
ratio,
|
2016-10-11 06:57:25 +08:00
|
|
|
angle,
|
2008-03-11 19:01:19 +08:00
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* the actual brush rendering functions */
|
|
|
|
|
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
|
|
|
|
2007-03-29 22:04:54 +08:00
|
|
|
/* set up lookup table */
|
|
|
|
static guchar *
|
|
|
|
gimp_brush_generated_calc_lut (gdouble radius,
|
|
|
|
gdouble hardness)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
2007-03-29 22:04:54 +08:00
|
|
|
guchar *lookup;
|
|
|
|
gint length;
|
|
|
|
gint x;
|
|
|
|
gdouble d;
|
|
|
|
gdouble sum;
|
|
|
|
gdouble exponent;
|
|
|
|
gdouble buffer[OVERSAMPLING];
|
2006-11-09 22:54:49 +08:00
|
|
|
|
2007-03-29 22:04:54 +08:00
|
|
|
length = OVERSAMPLING * ceil (1 + sqrt (2 * SQR (ceil (radius + 1.0))));
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2007-03-29 22:04:54 +08:00
|
|
|
lookup = g_malloc (length);
|
|
|
|
sum = 0.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
|
|
|
|
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
|
|
|
|
2007-03-29 22:04:54 +08:00
|
|
|
return lookup;
|
|
|
|
}
|
|
|
|
|
2012-04-09 02:25:49 +08:00
|
|
|
static GimpTempBuf *
|
2007-03-29 22:04:54 +08:00
|
|
|
gimp_brush_generated_calc (GimpBrushGenerated *brush,
|
|
|
|
GimpBrushGeneratedShape shape,
|
|
|
|
gfloat radius,
|
|
|
|
gint spikes,
|
|
|
|
gfloat hardness,
|
|
|
|
gfloat aspect_ratio,
|
|
|
|
gfloat angle,
|
|
|
|
GimpVector2 *xaxis,
|
|
|
|
GimpVector2 *yaxis)
|
|
|
|
{
|
|
|
|
guchar *centerp;
|
|
|
|
guchar *lookup;
|
|
|
|
guchar a;
|
|
|
|
gint x, y;
|
|
|
|
gdouble c, s, cs, ss;
|
|
|
|
GimpVector2 x_axis;
|
|
|
|
GimpVector2 y_axis;
|
2012-04-09 02:25:49 +08:00
|
|
|
GimpTempBuf *mask;
|
2014-10-21 18:31:24 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint half_width;
|
|
|
|
gint half_height;
|
|
|
|
|
|
|
|
gimp_brush_generated_get_size (brush,
|
|
|
|
shape,
|
|
|
|
radius,
|
|
|
|
spikes,
|
|
|
|
hardness,
|
|
|
|
aspect_ratio,
|
|
|
|
angle,
|
|
|
|
&width, &height,
|
|
|
|
&s, &c, &x_axis, &y_axis);
|
|
|
|
|
|
|
|
mask = gimp_temp_buf_new (width, height,
|
2012-04-09 05:56:52 +08:00
|
|
|
babl_format ("Y u8"));
|
2007-03-29 22:04:54 +08:00
|
|
|
|
2014-10-21 18:31:24 +08:00
|
|
|
half_width = width / 2;
|
|
|
|
half_height = height / 2;
|
2012-04-23 15:40:56 +08:00
|
|
|
|
2012-04-09 05:56:52 +08:00
|
|
|
centerp = gimp_temp_buf_get_data (mask) +
|
2014-10-21 18:31:24 +08:00
|
|
|
half_height * width + half_width;
|
2007-03-29 22:04:54 +08:00
|
|
|
|
|
|
|
lookup = gimp_brush_generated_calc_lut (radius, hardness);
|
|
|
|
|
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 */
|
2012-09-21 16:40:44 +08:00
|
|
|
for (y = ((spikes % 2) ? -half_height : 0); y <= half_height; y++)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
2007-03-14 08:18:01 +08:00
|
|
|
for (x = -half_width; x <= half_width; x++)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
2007-03-29 22:09:12 +08:00
|
|
|
gdouble d = 0;
|
|
|
|
gdouble tx = c * x - s * y;
|
|
|
|
gdouble ty = fabs (s * x + c * y);
|
2004-08-02 01:20:00 +08:00
|
|
|
|
2009-12-30 19:21:26 +08:00
|
|
|
if (spikes > 2)
|
2009-12-27 06:27:29 +08:00
|
|
|
{
|
2009-12-30 19:21:26 +08:00
|
|
|
gdouble angle = atan2 (ty, tx);
|
|
|
|
|
|
|
|
while (angle > G_PI / spikes)
|
|
|
|
{
|
|
|
|
gdouble sx = tx;
|
|
|
|
gdouble sy = ty;
|
2004-08-03 20:56:19 +08:00
|
|
|
|
2009-12-30 19:21:26 +08:00
|
|
|
tx = cs * sx - ss * sy;
|
|
|
|
ty = ss * sx + cs * sy;
|
2004-08-02 01:20:00 +08:00
|
|
|
|
2009-12-30 19:21:26 +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;
|
2007-03-29 22:04:54 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
switch (shape)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
2004-08-03 20:56:19 +08:00
|
|
|
case GIMP_BRUSH_GENERATED_CIRCLE:
|
2007-03-29 22:09:12 +08:00
|
|
|
d = sqrt (SQR (tx) + SQR (ty));
|
2004-08-03 20:56:19 +08:00
|
|
|
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;
|
|
|
|
|
2014-10-21 18:31:24 +08:00
|
|
|
centerp[y * width + x] = a;
|
2004-08-02 01:20:00 +08:00
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
if (spikes % 2 == 0)
|
2014-10-21 18:31:24 +08:00
|
|
|
centerp[-1 * y * 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
|
|
|
|
2007-03-29 22:09:12 +08:00
|
|
|
if (xaxis)
|
|
|
|
*xaxis = x_axis;
|
|
|
|
|
|
|
|
if (yaxis)
|
|
|
|
*yaxis = y_axis;
|
2006-11-09 22:54:49 +08:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
/* This function is shared between gimp_brush_generated_transform_size and
|
2007-03-14 18:23:18 +08:00
|
|
|
* gimp_brush_generated_calc, therefore we provide a bunch of optional
|
|
|
|
* pointers for returnvalues.
|
2007-03-14 08:18:01 +08:00
|
|
|
*/
|
|
|
|
static void
|
2014-10-21 18:31:24 +08:00
|
|
|
gimp_brush_generated_get_size (GimpBrushGenerated *gbrush,
|
|
|
|
GimpBrushGeneratedShape shape,
|
|
|
|
gfloat radius,
|
|
|
|
gint spikes,
|
|
|
|
gfloat hardness,
|
|
|
|
gfloat aspect_ratio,
|
|
|
|
gdouble angle_in_degrees,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
gdouble *_s,
|
|
|
|
gdouble *_c,
|
|
|
|
GimpVector2 *_x_axis,
|
|
|
|
GimpVector2 *_y_axis)
|
2007-03-14 08:18:01 +08:00
|
|
|
{
|
2014-10-21 18:31:24 +08:00
|
|
|
gdouble half_width = 0.0;
|
|
|
|
gdouble half_height = 0.0;
|
|
|
|
gint w, h;
|
2007-03-14 08:18:01 +08:00
|
|
|
gdouble c, s;
|
|
|
|
gdouble short_radius;
|
|
|
|
GimpVector2 x_axis;
|
|
|
|
GimpVector2 y_axis;
|
|
|
|
|
2010-03-07 21:56:38 +08:00
|
|
|
/* Since floatongpoint is not really accurate,
|
|
|
|
* we need to round to limit the errors.
|
|
|
|
* Errors in some border cases resulted in
|
|
|
|
* different height and width reported for
|
2009-12-30 21:10:34 +08:00
|
|
|
* the same input value on calling procedure side.
|
|
|
|
* This became problem at the rise of dynamics that
|
|
|
|
* allows for any angle to turn up.
|
|
|
|
**/
|
|
|
|
|
|
|
|
angle_in_degrees = ROUND (angle_in_degrees * 1000.0) / 1000.0;
|
|
|
|
|
2007-03-14 08:18:01 +08:00
|
|
|
s = sin (gimp_deg_to_rad (angle_in_degrees));
|
|
|
|
c = cos (gimp_deg_to_rad (angle_in_degrees));
|
|
|
|
|
|
|
|
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:
|
2014-10-21 18:31:24 +08:00
|
|
|
half_width = sqrt (x_axis.x * x_axis.x + y_axis.x * y_axis.x);
|
|
|
|
half_height = sqrt (x_axis.y * x_axis.y + y_axis.y * y_axis.y);
|
2007-03-14 08:18:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BRUSH_GENERATED_SQUARE:
|
2014-10-21 18:31:24 +08:00
|
|
|
half_width = fabs (x_axis.x) + fabs (y_axis.x);
|
|
|
|
half_height = fabs (x_axis.y) + fabs (y_axis.y);
|
2007-03-14 08:18:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BRUSH_GENERATED_DIAMOND:
|
2014-10-21 18:31:24 +08:00
|
|
|
half_width = MAX (fabs (x_axis.x), fabs (y_axis.x));
|
|
|
|
half_height = MAX (fabs (x_axis.y), fabs (y_axis.y));
|
2007-03-14 08:18:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spikes > 2)
|
|
|
|
{
|
|
|
|
/* could be optimized by respecting the angle */
|
2014-10-21 18:31:24 +08:00
|
|
|
half_width = half_height = sqrt (radius * radius +
|
|
|
|
short_radius * short_radius);
|
2007-03-14 08:18:01 +08:00
|
|
|
y_axis.x = s * radius;
|
|
|
|
y_axis.y = c * radius;
|
|
|
|
}
|
|
|
|
|
2014-10-21 18:31:24 +08:00
|
|
|
w = MAX (1, ceil (half_width * 2));
|
|
|
|
h = MAX (1, ceil (half_height * 2));
|
|
|
|
|
|
|
|
if (! (w & 0x1)) w++;
|
|
|
|
if (! (h & 0x1)) h++;
|
|
|
|
|
|
|
|
*width = w;
|
|
|
|
*height = h;
|
|
|
|
|
2007-03-14 18:23:18 +08:00
|
|
|
/* These will typically be set then this function is called by
|
|
|
|
* gimp_brush_generated_calc, which needs the values in its algorithms.
|
|
|
|
*/
|
2007-03-14 08:18:01 +08:00
|
|
|
if (_s != NULL)
|
|
|
|
*_s = s;
|
|
|
|
|
|
|
|
if (_c != NULL)
|
|
|
|
*_c = c;
|
|
|
|
|
|
|
|
if (_x_axis != NULL)
|
|
|
|
*_x_axis = x_axis;
|
|
|
|
|
|
|
|
if (_y_axis != NULL)
|
|
|
|
*_y_axis = y_axis;
|
|
|
|
}
|
|
|
|
|
2006-11-09 22:54:49 +08:00
|
|
|
|
2008-03-11 19:01:19 +08:00
|
|
|
/* public functions */
|
2006-11-09 22:54:49 +08:00
|
|
|
|
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
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_brush_generated_get_shape (GimpBrushGenerated *brush)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
|
|
|
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
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_brush_generated_get_radius (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
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_brush_generated_get_spikes (GimpBrushGenerated *brush)
|
2004-08-02 01:20:00 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1);
|
|
|
|
|
|
|
|
return brush->spikes;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_brush_generated_get_hardness (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
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_brush_generated_get_aspect_ratio (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
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_brush_generated_get_angle (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
|
|
|
}
|