2006-12-09 13:33:38 -08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-07-08 22:31:06 -07:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
|
|
|
|
* gimp_brush_generated module Copyright 1998 Jay Cox <jaycox@earthlink.net>
|
|
|
|
|
*
|
2009-01-17 14:28:01 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-07-08 22:31:06 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 14:28:01 -08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-07-08 22:31:06 -07: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
|
2018-07-11 14:47:19 -07:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1998-07-08 22:31:06 -07:00
|
|
|
*/
|
2000-09-29 05:00:00 -07:00
|
|
|
|
1999-02-20 15:20:54 -08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2013-10-14 16:58:39 -07:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
|
#include <gegl.h>
|
2000-12-16 13:37:03 -08:00
|
|
|
|
2004-01-18 17:54:11 -08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-23 15:56:18 -08:00
|
|
|
|
2001-05-09 15:34:59 -07:00
|
|
|
#include "core-types.h"
|
2000-12-16 13:37:03 -08:00
|
|
|
|
1998-07-08 22:31:06 -07:00
|
|
|
#include "gimpbrushgenerated.h"
|
2006-10-03 05:29:07 -07:00
|
|
|
#include "gimpbrushgenerated-save.h"
|
1998-07-08 22:31:06 -07:00
|
|
|
|
2003-03-25 08:38:19 -08:00
|
|
|
#include "gimp-intl.h"
|
2002-12-02 05:39:09 -08:00
|
|
|
|
2000-12-29 07:22:01 -08:00
|
|
|
|
2006-10-03 05:29:07 -07:00
|
|
|
gboolean
|
2014-07-03 14:44:38 -07:00
|
|
|
gimp_brush_generated_save (GimpData *data,
|
|
|
|
|
GOutputStream *output,
|
|
|
|
|
GError **error)
|
2001-02-10 17:39:24 -08:00
|
|
|
{
|
2004-01-29 08:19:57 -08:00
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
|
2009-08-31 13:47:18 -07:00
|
|
|
const gchar *name = gimp_object_get_name (data);
|
2014-07-02 13:16:09 -07:00
|
|
|
GString *string;
|
2001-10-29 04:51:21 -08:00
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
2004-08-01 10:20:00 -07:00
|
|
|
gboolean have_shape = FALSE;
|
2001-02-04 09:34:30 -08:00
|
|
|
|
2006-05-29 08:43:05 -07:00
|
|
|
g_return_val_if_fail (name != NULL && *name != '\0', FALSE);
|
|
|
|
|
|
1999-10-26 11:27:27 -07:00
|
|
|
/* write magic header */
|
2014-07-02 13:16:09 -07:00
|
|
|
string = g_string_new ("GIMP-VBR\n");
|
1999-10-26 11:27:27 -07:00
|
|
|
|
|
|
|
|
/* write version */
|
2004-08-01 10:20:00 -07:00
|
|
|
if (brush->shape != GIMP_BRUSH_GENERATED_CIRCLE || brush->spikes > 2)
|
|
|
|
|
{
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append (string, "1.5\n");
|
2004-08-01 10:20:00 -07:00
|
|
|
have_shape = TRUE;
|
|
|
|
|
}
|
2004-07-31 20:06:58 -07:00
|
|
|
else
|
2004-08-01 10:20:00 -07:00
|
|
|
{
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append (string, "1.0\n");
|
2004-08-01 10:20:00 -07:00
|
|
|
}
|
1999-10-26 11:27:27 -07:00
|
|
|
|
|
|
|
|
/* write name */
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%.255s\n", name);
|
1999-10-26 11:27:27 -07:00
|
|
|
|
2004-08-01 10:20:00 -07:00
|
|
|
if (have_shape)
|
2004-07-31 20:06:58 -07: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);
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%s\n", shape_val->value_nick);
|
2004-07-31 20:06:58 -07:00
|
|
|
}
|
|
|
|
|
|
1999-10-26 11:27:27 -07:00
|
|
|
/* write brush spacing */
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
|
gimp_brush_get_spacing (GIMP_BRUSH (brush))));
|
1999-10-26 11:27:27 -07:00
|
|
|
|
|
|
|
|
/* write brush radius */
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
|
brush->radius));
|
1999-10-26 11:27:27 -07:00
|
|
|
|
2004-08-01 10:20:00 -07:00
|
|
|
if (have_shape)
|
|
|
|
|
{
|
|
|
|
|
/* write brush spikes */
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%d\n", brush->spikes);
|
2004-08-01 10:20:00 -07:00
|
|
|
}
|
|
|
|
|
|
1999-10-26 11:27:27 -07:00
|
|
|
/* write brush hardness */
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
|
brush->hardness));
|
1999-10-26 11:27:27 -07:00
|
|
|
|
|
|
|
|
/* write brush aspect_ratio */
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
|
brush->aspect_ratio));
|
1999-10-26 11:27:27 -07:00
|
|
|
|
|
|
|
|
/* write brush angle */
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
|
brush->angle));
|
|
|
|
|
|
|
|
|
|
if (! g_output_stream_write_all (output, string->str, string->len,
|
2014-09-07 11:30:14 -07:00
|
|
|
NULL, NULL, error))
|
2014-07-02 13:16:09 -07:00
|
|
|
{
|
|
|
|
|
g_string_free (string, TRUE);
|
2014-07-04 09:46:02 -07:00
|
|
|
|
2014-07-02 13:16:09 -07:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
1999-10-26 11:27:27 -07:00
|
|
|
|
2014-07-02 13:16:09 -07:00
|
|
|
g_string_free (string, TRUE);
|
1999-10-26 11:27:27 -07:00
|
|
|
|
2001-02-10 17:39:24 -08:00
|
|
|
return TRUE;
|
1998-07-15 05:15:24 -07:00
|
|
|
}
|