1998-07-09 13:31:06 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* 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"
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
#include <errno.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
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"
|
|
|
|
|
2004-01-14 10:03:37 +08:00
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
#include "gimpbrushgenerated.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.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
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
/* local function prototypes */
|
2001-05-10 06:34:59 +08:00
|
|
|
static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass);
|
|
|
|
static void gimp_brush_generated_init (GimpBrushGenerated *brush);
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
static gboolean gimp_brush_generated_save (GimpData *data,
|
|
|
|
GError **error);
|
|
|
|
static void gimp_brush_generated_dirty (GimpData *data);
|
|
|
|
static gchar * gimp_brush_generated_get_extension (GimpData *data);
|
|
|
|
static GimpData * gimp_brush_generated_duplicate (GimpData *data,
|
|
|
|
gboolean stingy_memory_use);
|
1998-07-15 20:15:24 +08:00
|
|
|
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2001-01-10 08:36:54 +08:00
|
|
|
static GimpBrushClass *parent_class = NULL;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
GType
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_generated_get_type (void)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static GType brush_type = 0;
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
if (! brush_type)
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static const GTypeInfo brush_info =
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
sizeof (GimpBrushGeneratedClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_brush_generated_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
1999-10-27 02:27:27 +08:00
|
|
|
sizeof (GimpBrushGenerated),
|
2001-08-11 22:39:19 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_brush_generated_init,
|
1999-10-27 02:27:27 +08:00
|
|
|
};
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
brush_type = g_type_register_static (GIMP_TYPE_BRUSH,
|
2003-11-14 23:33:40 +08:00
|
|
|
"GimpBrushGenerated",
|
2001-08-11 22:39:19 +08:00
|
|
|
&brush_info, 0);
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
return brush_type;
|
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
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
GimpDataClass *data_class;
|
1998-07-09 13:31:06 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
data_class = GIMP_DATA_CLASS (klass);
|
1998-07-09 13:31:06 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
1998-07-09 13:31:06 +08:00
|
|
|
|
2001-02-14 03:53:07 +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;
|
2001-02-19 03:44:28 +08:00
|
|
|
data_class->duplicate = gimp_brush_generated_duplicate;
|
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
|
|
|
{
|
2001-02-11 09:39:24 +08:00
|
|
|
brush->radius = 5.0;
|
|
|
|
brush->hardness = 0.0;
|
|
|
|
brush->angle = 0.0;
|
|
|
|
brush->aspect_ratio = 1.0;
|
|
|
|
brush->freeze = 0;
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
static gboolean
|
2002-12-02 21:39:09 +08:00
|
|
|
gimp_brush_generated_save (GimpData *data,
|
|
|
|
GError **error)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush;
|
|
|
|
FILE *fp;
|
2001-10-29 20:51:21 +08:00
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
2001-02-05 01:34:30 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
brush = GIMP_BRUSH_GENERATED (data);
|
2001-02-05 01:34:30 +08:00
|
|
|
|
|
|
|
/* we are (finaly) ready to try to save the generated brush file */
|
2001-02-11 09:39:24 +08:00
|
|
|
if ((fp = fopen (data->filename, "wb")) == NULL)
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
2002-12-02 21:39:09 +08:00
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
|
|
|
|
_("Could not open '%s' for writing: %s"),
|
2004-01-14 10:03:37 +08:00
|
|
|
file_utils_filename_to_utf8 (data->filename),
|
|
|
|
g_strerror (errno));
|
2001-02-11 09:39:24 +08:00
|
|
|
return FALSE;
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write magic header */
|
|
|
|
fprintf (fp, "GIMP-VBR\n");
|
|
|
|
|
|
|
|
/* write version */
|
|
|
|
fprintf (fp, "1.0\n");
|
|
|
|
|
|
|
|
/* write name */
|
2001-01-14 11:55:56 +08:00
|
|
|
fprintf (fp, "%.255s\n", GIMP_OBJECT (brush)->name);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush spacing */
|
2003-11-14 23:33:40 +08:00
|
|
|
fprintf (fp, "%s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
2001-10-29 20:51:21 +08:00
|
|
|
GIMP_BRUSH (brush)->spacing));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush radius */
|
2003-11-14 23:33:40 +08:00
|
|
|
fprintf (fp, "%s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
2001-10-29 20:51:21 +08:00
|
|
|
brush->radius));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush hardness */
|
2001-10-29 20:51:21 +08:00
|
|
|
fprintf (fp, "%s\n",
|
2003-11-14 23:33:40 +08:00
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
2001-10-29 20:51:21 +08:00
|
|
|
brush->hardness));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush aspect_ratio */
|
2001-10-29 20:51:21 +08:00
|
|
|
fprintf (fp, "%s\n",
|
2003-11-14 23:33:40 +08:00
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
2001-10-29 20:51:21 +08:00
|
|
|
brush->aspect_ratio));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush angle */
|
2001-10-29 20:51:21 +08:00
|
|
|
fprintf (fp, "%s\n",
|
2003-11-14 23:33:40 +08:00
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
2001-10-29 20:51:21 +08:00
|
|
|
brush->angle));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
return TRUE;
|
1998-07-15 20:15:24 +08:00
|
|
|
}
|
1998-07-25 18:20:07 +08:00
|
|
|
|
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 *
|
2002-12-01 00:31:39 +08:00
|
|
|
gimp_brush_generated_duplicate (GimpData *data,
|
|
|
|
gboolean stingy_memory_use)
|
2001-02-19 03:44:28 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush;
|
|
|
|
|
|
|
|
brush = GIMP_BRUSH_GENERATED (data);
|
|
|
|
|
|
|
|
return gimp_brush_generated_new (brush->radius,
|
|
|
|
brush->hardness,
|
|
|
|
brush->angle,
|
2002-12-01 00:31:39 +08:00
|
|
|
brush->aspect_ratio,
|
|
|
|
stingy_memory_use);
|
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
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_generated_dirty (GimpData *data)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
2001-02-11 09:39:24 +08:00
|
|
|
GimpBrushGenerated *brush;
|
2003-04-09 23:31:45 +08:00
|
|
|
GimpBrush *gbrush = NULL;
|
|
|
|
gint x, y;
|
|
|
|
guchar *centerp;
|
|
|
|
gdouble d;
|
|
|
|
gdouble exponent;
|
|
|
|
guchar a;
|
|
|
|
gint length;
|
|
|
|
gint width, height;
|
|
|
|
guchar *lookup;
|
|
|
|
gdouble sum;
|
|
|
|
gdouble c, s;
|
|
|
|
gdouble short_radius;
|
|
|
|
gdouble buffer[OVERSAMPLING];
|
2000-02-24 19:39:26 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
brush = GIMP_BRUSH_GENERATED (data);
|
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (brush->freeze) /* if we are frozen defer rerendering till later */
|
1998-07-09 13:31:06 +08:00
|
|
|
return;
|
1998-07-25 18:20:07 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gbrush = GIMP_BRUSH (brush);
|
1998-07-25 18:20:07 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
if (gbrush->mask)
|
2003-04-09 23:31:45 +08:00
|
|
|
temp_buf_free (gbrush->mask);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2000-02-19 02:20:04 +08:00
|
|
|
s = sin (gimp_deg_to_rad (brush->angle));
|
|
|
|
c = cos (gimp_deg_to_rad (brush->angle));
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2003-04-09 23:31:45 +08:00
|
|
|
short_radius = brush->radius / brush->aspect_ratio;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2003-04-09 23:31:45 +08:00
|
|
|
gbrush->x_axis.x = c * brush->radius;
|
|
|
|
gbrush->x_axis.y = -1.0 * s * brush->radius;
|
|
|
|
gbrush->y_axis.x = s * short_radius;
|
|
|
|
gbrush->y_axis.y = c * short_radius;
|
2003-11-14 23:33:40 +08:00
|
|
|
|
2003-04-09 23:31:45 +08:00
|
|
|
width = ceil (sqrt (gbrush->x_axis.x * gbrush->x_axis.x +
|
|
|
|
gbrush->y_axis.x * gbrush->y_axis.x));
|
|
|
|
height = ceil (sqrt (gbrush->x_axis.y * gbrush->x_axis.y +
|
|
|
|
gbrush->y_axis.y * gbrush->y_axis.y));
|
|
|
|
|
|
|
|
gbrush->mask = temp_buf_new (width * 2 + 1,
|
2000-09-29 20:00:00 +08:00
|
|
|
height * 2 + 1,
|
1999-10-27 02:27:27 +08:00
|
|
|
1, width, height, 0);
|
2003-04-09 23:31:45 +08:00
|
|
|
|
|
|
|
centerp = temp_buf_data (gbrush->mask) + height * gbrush->mask->width + width;
|
|
|
|
|
|
|
|
/* set up lookup table */
|
|
|
|
length = OVERSAMPLING * ceil (1 + sqrt (2 *
|
|
|
|
ceil (brush->radius + 1.0) *
|
|
|
|
ceil (brush->radius + 1.0)));
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
if ((1.0 - brush->hardness) < 0.000001)
|
2003-11-14 23:33:40 +08:00
|
|
|
exponent = 1000000.0;
|
1998-07-09 13:31:06 +08:00
|
|
|
else
|
2003-04-09 23:31:45 +08:00
|
|
|
exponent = 1.0 / (1.0 - brush->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
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
if (d > brush->radius)
|
2000-09-29 20:00:00 +08:00
|
|
|
buffer[x] = 0.0;
|
|
|
|
else
|
2003-04-09 23:31:45 +08:00
|
|
|
buffer[x] = gauss (pow (d / brush->radius, exponent));
|
|
|
|
|
2000-09-29 20:00:00 +08:00
|
|
|
sum += buffer[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; d < brush->radius || sum > 0.00001; d += 1.0 / OVERSAMPLING)
|
|
|
|
{
|
|
|
|
sum -= buffer[x % OVERSAMPLING];
|
2003-04-09 23:31:45 +08:00
|
|
|
|
2000-09-29 20:00:00 +08:00
|
|
|
if (d > brush->radius)
|
|
|
|
buffer[x % OVERSAMPLING] = 0.0;
|
1999-10-27 02:27:27 +08:00
|
|
|
else
|
2003-04-09 23:31:45 +08:00
|
|
|
buffer[x % OVERSAMPLING] = gauss (pow (d / brush->radius, exponent));
|
|
|
|
|
|
|
|
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
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* compute one half and mirror it */
|
1998-07-09 13:31:06 +08:00
|
|
|
for (y = 0; y <= height; y++)
|
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
for (x = -width; x <= width; x++)
|
|
|
|
{
|
2003-04-09 23:31:45 +08:00
|
|
|
gdouble tx, ty;
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
tx = c*x - s*y;
|
|
|
|
ty = c*y + s*x;
|
|
|
|
ty *= brush->aspect_ratio;
|
|
|
|
d = sqrt (tx*tx + ty*ty);
|
2003-04-09 23:31:45 +08:00
|
|
|
|
|
|
|
if (d < brush->radius + 1)
|
2000-09-29 20:00:00 +08:00
|
|
|
a = lookup[(gint) RINT (d * OVERSAMPLING)];
|
1999-10-27 02:27:27 +08:00
|
|
|
else
|
|
|
|
a = 0;
|
2003-04-09 23:31:45 +08:00
|
|
|
|
|
|
|
centerp[ y * gbrush->mask->width + x] = a;
|
|
|
|
centerp[-1 * y * gbrush->mask->width - x] = a;
|
1999-10-27 02:27:27 +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
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
if (GIMP_DATA_CLASS (parent_class)->dirty)
|
|
|
|
GIMP_DATA_CLASS (parent_class)->dirty (data);
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
|
|
|
|
2001-02-14 22:57:14 +08:00
|
|
|
GimpData *
|
2002-12-01 00:31:39 +08:00
|
|
|
gimp_brush_generated_new (gfloat radius,
|
|
|
|
gfloat hardness,
|
|
|
|
gfloat angle,
|
|
|
|
gfloat aspect_ratio,
|
|
|
|
gboolean stingy_memory_use)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush;
|
|
|
|
|
|
|
|
/* set up normal brush data */
|
2003-08-29 07:33:15 +08:00
|
|
|
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (brush), "Untitled");
|
|
|
|
|
|
|
|
GIMP_BRUSH (brush)->spacing = 20;
|
|
|
|
|
|
|
|
/* set up gimp_brush_generated data */
|
|
|
|
brush->radius = radius;
|
|
|
|
brush->hardness = hardness;
|
|
|
|
brush->angle = angle;
|
|
|
|
brush->aspect_ratio = aspect_ratio;
|
|
|
|
|
|
|
|
/* render brush mask */
|
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
|
|
|
|
2002-12-01 00:31:39 +08:00
|
|
|
if (stingy_memory_use)
|
|
|
|
temp_buf_swap (GIMP_BRUSH (brush)->mask);
|
|
|
|
|
2001-02-14 22:57:14 +08:00
|
|
|
return GIMP_DATA (brush);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2001-02-14 22:57:14 +08:00
|
|
|
GimpData *
|
2002-12-02 21:39:09 +08:00
|
|
|
gimp_brush_generated_load (const gchar *filename,
|
|
|
|
gboolean stingy_memory_use,
|
|
|
|
GError **error)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush;
|
2001-02-14 22:57:14 +08:00
|
|
|
FILE *fp;
|
|
|
|
gchar string[256];
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
if ((fp = fopen (filename, "rb")) == NULL)
|
2002-12-02 21:39:09 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
|
|
|
|
_("Could not open '%s' for reading: %s"),
|
2004-01-14 10:03:37 +08:00
|
|
|
file_utils_filename_to_utf8 (filename), g_strerror (errno));
|
2002-12-02 21:39:09 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* make sure the file we are reading is the right type */
|
|
|
|
fgets (string, 255, fp);
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
if (strncmp (string, "GIMP-VBR", 8) != 0)
|
2002-12-02 21:39:09 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
2003-11-14 23:33:40 +08:00
|
|
|
_("Fatal parse error in brush file '%s': "
|
|
|
|
"Not a GIMP brush file."),
|
2004-01-14 10:03:37 +08:00
|
|
|
file_utils_filename_to_utf8 (filename));
|
2002-12-02 21:39:09 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-14 22:57:14 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
/* make sure we are reading a compatible version */
|
|
|
|
fgets (string, 255, fp);
|
2001-10-29 20:51:21 +08:00
|
|
|
if (strncmp (string, "1.0", 3))
|
2002-12-02 21:39:09 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
2003-11-14 23:33:40 +08:00
|
|
|
_("Fatal parse error in brush file '%s': "
|
|
|
|
"Unknown GIMP brush version."),
|
2004-01-14 10:03:37 +08:00
|
|
|
file_utils_filename_to_utf8 (filename));
|
2002-12-02 21:39:09 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* create new brush */
|
2003-08-29 07:33:15 +08:00
|
|
|
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
gimp_data_set_filename (GIMP_DATA (brush), filename);
|
|
|
|
|
|
|
|
gimp_brush_generated_freeze (brush);
|
|
|
|
|
|
|
|
/* read name */
|
|
|
|
fgets (string, 255, fp);
|
|
|
|
if (string[strlen (string) - 1] == '\n')
|
|
|
|
string[strlen (string) - 1] = 0;
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (brush), string);
|
|
|
|
|
|
|
|
/* read brush spacing */
|
2001-10-29 20:51:21 +08:00
|
|
|
fgets (string, 255, fp);
|
|
|
|
GIMP_BRUSH (brush)->spacing = g_ascii_strtod (string, NULL);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* read brush radius */
|
2001-10-29 20:51:21 +08:00
|
|
|
fgets (string, 255, fp);
|
|
|
|
gimp_brush_generated_set_radius (brush, g_ascii_strtod (string, NULL));
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* read brush hardness */
|
2001-10-29 20:51:21 +08:00
|
|
|
fgets (string, 255, fp);
|
|
|
|
gimp_brush_generated_set_hardness (brush, g_ascii_strtod (string, NULL));
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* read brush aspect_ratio */
|
2001-10-29 20:51:21 +08:00
|
|
|
fgets (string, 255, fp);
|
|
|
|
gimp_brush_generated_set_aspect_ratio (brush, g_ascii_strtod (string, NULL));
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* read brush angle */
|
2001-10-29 20:51:21 +08:00
|
|
|
fgets (string, 255, fp);
|
|
|
|
gimp_brush_generated_set_angle (brush, g_ascii_strtod (string, NULL));
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
|
|
|
|
gimp_brush_generated_thaw (brush);
|
|
|
|
|
2002-12-01 00:31:39 +08:00
|
|
|
if (stingy_memory_use)
|
2001-02-11 09:39:24 +08:00
|
|
|
temp_buf_swap (GIMP_BRUSH (brush)->mask);
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
GIMP_DATA (brush)->dirty = FALSE;
|
|
|
|
|
2001-02-14 22:57:14 +08:00
|
|
|
return GIMP_DATA (brush);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_brush_generated_freeze (GimpBrushGenerated *brush)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
|
|
|
|
|
|
|
brush->freeze++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_brush_generated_thaw (GimpBrushGenerated *brush)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
|
2003-11-14 23:33:40 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
if (brush->freeze > 0)
|
|
|
|
brush->freeze--;
|
|
|
|
|
2001-12-02 22:59:30 +08:00
|
|
|
if (!brush->freeze)
|
2001-02-11 09:39:24 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
|
|
|
gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
|
|
|
|
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);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
if (radius < 0.0)
|
|
|
|
radius = 0.0;
|
2000-02-24 19:39:26 +08:00
|
|
|
else if (radius > 32767.0)
|
1998-07-09 13:31:06 +08:00
|
|
|
radius = 32767.0;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (radius == brush->radius)
|
|
|
|
return radius;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
brush->radius = radius;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
2001-12-02 22:59:30 +08:00
|
|
|
if (!brush->freeze)
|
2001-02-11 09:39:24 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->radius;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
|
|
|
gimp_brush_generated_set_hardness (GimpBrushGenerated *brush,
|
|
|
|
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);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
if (hardness < 0.0)
|
|
|
|
hardness = 0.0;
|
2000-09-29 20:00:00 +08:00
|
|
|
else if (hardness > 1.0)
|
1998-07-09 13:31:06 +08:00
|
|
|
hardness = 1.0;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (brush->hardness == hardness)
|
|
|
|
return hardness;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
brush->hardness = hardness;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (!brush->freeze)
|
2001-02-11 09:39:24 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
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
|
|
|
|
gimp_brush_generated_set_angle (GimpBrushGenerated *brush,
|
|
|
|
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);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
if (angle < 0.0)
|
1999-10-27 02:27:27 +08:00
|
|
|
angle = -1.0 * fmod (angle, 180.0);
|
2000-09-29 20:00:00 +08:00
|
|
|
else if (angle > 180.0)
|
1999-10-27 02:27:27 +08:00
|
|
|
angle = fmod (angle, 180.0);
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (brush->angle == angle)
|
|
|
|
return angle;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
brush->angle = angle;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (!brush->freeze)
|
2001-02-11 09:39:24 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->angle;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
|
|
|
gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush,
|
|
|
|
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);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
if (ratio < 1.0)
|
|
|
|
ratio = 1.0;
|
2000-09-29 20:00:00 +08:00
|
|
|
else if (ratio > 1000)
|
1998-07-09 13:31:06 +08:00
|
|
|
ratio = 1000;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (brush->aspect_ratio == ratio)
|
|
|
|
return ratio;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
brush->aspect_ratio = ratio;
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-15 20:15:24 +08:00
|
|
|
if (!brush->freeze)
|
2001-02-11 09:39:24 +08:00
|
|
|
gimp_data_dirty (GIMP_DATA (brush));
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->aspect_ratio;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
2000-09-29 20:00:00 +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);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->angle;
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gfloat
|
2000-09-29 20:00:00 +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);
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return brush->aspect_ratio;
|
|
|
|
}
|