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"
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
#include <errno.h>
|
2004-08-02 01:20:00 +08:00
|
|
|
#include <stdlib.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#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>
|
2005-02-07 09:24:22 +08:00
|
|
|
#include <glib/gstdio.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
|
|
|
|
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-save.h"
|
1998-07-09 13:31:06 +08:00
|
|
|
|
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
|
|
|
|
2006-10-03 20:29:07 +08:00
|
|
|
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
|
|
|
{
|
2004-01-30 00:19:57 +08:00
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
|
2009-09-01 04:47:18 +08:00
|
|
|
const gchar *name = gimp_object_get_name (data);
|
2004-01-30 00:19:57 +08:00
|
|
|
FILE *file;
|
2001-10-29 20:51:21 +08:00
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
2004-08-02 01:20:00 +08:00
|
|
|
gboolean have_shape = FALSE;
|
2001-02-05 01:34:30 +08:00
|
|
|
|
2006-05-29 23:43:05 +08:00
|
|
|
g_return_val_if_fail (name != NULL && *name != '\0', FALSE);
|
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
file = g_fopen (gimp_data_get_filename (data), "wb");
|
2001-02-05 01:34:30 +08:00
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
if (! file)
|
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"),
|
2009-10-31 22:24:57 +08:00
|
|
|
gimp_filename_to_utf8 (gimp_data_get_filename (data)),
|
2004-08-01 11:06:58 +08:00
|
|
|
g_strerror (errno));
|
2001-02-11 09:39:24 +08:00
|
|
|
return FALSE;
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write magic header */
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "GIMP-VBR\n");
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write version */
|
2004-08-02 01:20:00 +08:00
|
|
|
if (brush->shape != GIMP_BRUSH_GENERATED_CIRCLE || brush->spikes > 2)
|
|
|
|
{
|
|
|
|
fprintf (file, "1.5\n");
|
|
|
|
have_shape = TRUE;
|
|
|
|
}
|
2004-08-01 11:06:58 +08:00
|
|
|
else
|
2004-08-02 01:20:00 +08:00
|
|
|
{
|
|
|
|
fprintf (file, "1.0\n");
|
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write name */
|
2006-05-29 23:43:05 +08:00
|
|
|
fprintf (file, "%.255s\n", name);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
if (have_shape)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *shape_val;
|
|
|
|
|
|
|
|
enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE);
|
|
|
|
|
|
|
|
/* write shape */
|
|
|
|
shape_val = g_enum_get_value (enum_class, brush->shape);
|
|
|
|
fprintf (file, "%s\n", shape_val->value_nick);
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* write brush spacing */
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "%s\n",
|
2003-11-14 23:33:40 +08:00
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
2006-12-06 08:01:27 +08:00
|
|
|
gimp_brush_get_spacing (GIMP_BRUSH (brush))));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush radius */
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "%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->radius));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
if (have_shape)
|
|
|
|
{
|
|
|
|
/* write brush spikes */
|
|
|
|
fprintf (file, "%d\n", brush->spikes);
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* write brush hardness */
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "%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 */
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "%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 */
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "%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
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
fclose (file);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
return TRUE;
|
1998-07-15 20:15:24 +08:00
|
|
|
}
|