Commit c42e8147 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/core/Makefile.am app/core/gimpbrushgenerated-load.[ch]

2006-10-03  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/gimpbrushgenerated-load.[ch]
	* app/core/gimpbrushgenerated-save.[ch]
	* app/core/gimpbrushpipe-load.[ch]: new files.

	* app/core/gimpbrushgenerated.[ch]
	* app/core/gimpbrushpipe.[ch]: removed loading and saving code here.

	* app/core/gimp.c: changed accordingly.
parent d9cf806b
2006-10-03 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/gimpbrushgenerated-load.[ch]
* app/core/gimpbrushgenerated-save.[ch]
* app/core/gimpbrushpipe-load.[ch]: new files.
* app/core/gimpbrushgenerated.[ch]
* app/core/gimpbrushpipe.[ch]: removed loading and saving code here.
* app/core/gimp.c: changed accordingly.
2006-10-03 Michael Natterer <mitch@gimp.org>
 
* app/core/Makefile.am
......
......@@ -56,8 +56,14 @@ libappcore_a_sources = \
gimpbrushclipboard.h \
gimpbrushgenerated.c \
gimpbrushgenerated.h \
gimpbrushgenerated-load.c \
gimpbrushgenerated-load.h \
gimpbrushgenerated-save.c \
gimpbrushgenerated-save.h \
gimpbrushpipe.c \
gimpbrushpipe.h \
gimpbrushpipe-load.c \
gimpbrushpipe-load.h \
gimpbuffer.c \
gimpbuffer.h \
gimpchannel.c \
......
......@@ -52,9 +52,9 @@
#include "gimp-utils.h"
#include "gimpbrush.h"
#include "gimpbrush-load.h"
#include "gimpbrushgenerated.h"
#include "gimpbrushgenerated-load.h"
#include "gimpbrushclipboard.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipe-load.h"
#include "gimpbuffer.h"
#include "gimpcontext.h"
#include "gimpdatafactory.h"
......
This diff is collapsed.
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
#ifndef __GIMP_BRUSH_GENERATED_LOAD_H__
#define __GIMP_BRUSH_GENERATED_LOAD_H__
#define GIMP_BRUSH_GENERATED_FILE_EXTENSION ".vbr"
GList * gimp_brush_generated_load (const gchar *filename,
GError **error);
#endif /* __GIMP_BRUSH_GENERATED_LOAD_H__ */
This diff is collapsed.
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
#ifndef __GIMP_BRUSH_GENERATED_SAVE_H__
#define __GIMP_BRUSH_GENERATED_SAVE_H__
/* don't call this function directly, use gimp_data_save() instead */
gboolean gimp_brush_generated_save (GimpData *data,
GError **error);
#endif /* __GIMP_BRUSH_GENERATED_SAVE_H__ */
......@@ -20,16 +20,7 @@
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <glib-object.h>
#include <glib/gstdio.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
......@@ -39,8 +30,8 @@
#include "base/temp-buf.h"
#include "gimpbrushgenerated.h"
#include "gimp-intl.h"
#include "gimpbrushgenerated-load.h"
#include "gimpbrushgenerated-save.h"
#define OVERSAMPLING 5
......@@ -68,8 +59,6 @@ static void gimp_brush_generated_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
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);
......@@ -206,94 +195,6 @@ gimp_brush_generated_get_property (GObject *object,
}
}
static gboolean
gimp_brush_generated_save (GimpData *data,
GError **error)
{
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
const gchar *name = gimp_object_get_name (GIMP_OBJECT (data));
FILE *file;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gboolean have_shape = FALSE;
g_return_val_if_fail (name != NULL && *name != '\0', FALSE);
file = g_fopen (data->filename, "wb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (data->filename),
g_strerror (errno));
return FALSE;
}
/* write magic header */
fprintf (file, "GIMP-VBR\n");
/* write version */
if (brush->shape != GIMP_BRUSH_GENERATED_CIRCLE || brush->spikes > 2)
{
fprintf (file, "1.5\n");
have_shape = TRUE;
}
else
{
fprintf (file, "1.0\n");
}
/* write name */
fprintf (file, "%.255s\n", name);
if (have_shape)
{
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);
}
/* write brush spacing */
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
GIMP_BRUSH (brush)->spacing));
/* write brush radius */
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->radius));
if (have_shape)
{
/* write brush spikes */
fprintf (file, "%d\n", brush->spikes);
}
/* write brush hardness */
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->hardness));
/* write brush aspect_ratio */
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->aspect_ratio));
/* write brush angle */
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->angle));
fclose (file);
return TRUE;
}
static gchar *
gimp_brush_generated_get_extension (GimpData *data)
{
......@@ -533,179 +434,6 @@ gimp_brush_generated_new (const gchar *name,
return GIMP_DATA (brush);
}
GList *
gimp_brush_generated_load (const gchar *filename,
GError **error)
{
GimpBrush *brush;
FILE *file;
gchar string[256];
gchar *name = NULL;
GimpBrushGeneratedShape shape = GIMP_BRUSH_GENERATED_CIRCLE;
gboolean have_shape = FALSE;
gint spikes = 2;
gdouble spacing;
gdouble radius;
gdouble hardness;
gdouble aspect_ratio;
gdouble angle;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = g_fopen (filename, "rb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
return NULL;
}
/* make sure the file we are reading is the right type */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
if (strncmp (string, "GIMP-VBR", 8) != 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Not a GIMP brush file."),
gimp_filename_to_utf8 (filename));
goto failed;
}
/* make sure we are reading a compatible version */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
if (strncmp (string, "1.0", 3))
{
if (strncmp (string, "1.5", 3))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown GIMP brush version."),
gimp_filename_to_utf8 (filename));
goto failed;
}
else
{
have_shape = TRUE;
}
}
/* read name */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
g_strstrip (string);
/* the empty string is not an allowed name */
if (strlen (string) < 1)
g_strlcpy (string, _("Untitled"), sizeof (string));
name = gimp_any_to_utf8 (string, -1,
_("Invalid UTF-8 string in brush file '%s'."),
gimp_filename_to_utf8 (filename));
if (have_shape)
{
GEnumClass *enum_class;
GEnumValue *shape_val;
enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE);
/* read shape */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
g_strstrip (string);
shape_val = g_enum_get_value_by_nick (enum_class, string);
if (!shape_val)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in brush file '%s': "
"Unknown GIMP brush shape."),
gimp_filename_to_utf8 (filename));
goto failed;
}
shape = shape_val->value;
}
/* read brush spacing */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
spacing = g_ascii_strtod (string, NULL);
/* read brush radius */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
radius = g_ascii_strtod (string, NULL);
if (have_shape)
{
/* read brush radius */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
spikes = CLAMP (atoi (string), 2, 20);
}
/* read brush hardness */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
hardness = g_ascii_strtod (string, NULL);
/* read brush aspect_ratio */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
aspect_ratio = g_ascii_strtod (string, NULL);
/* read brush angle */
errno = 0;
if (! fgets (string, sizeof (string), file))
goto failed;
angle = g_ascii_strtod (string, NULL);
fclose (file);
brush = GIMP_BRUSH (gimp_brush_generated_new (name, shape, radius, spikes,
hardness, aspect_ratio, angle));
g_free (name);
brush->spacing = spacing;
return g_list_prepend (NULL, brush);
failed:
fclose (file);
if (name)
g_free (name);
if (error && *error == NULL)
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Error while reading brush file '%s': %s"),
gimp_filename_to_utf8 (filename),
errno ? g_strerror (errno) : _("File is truncated"));
return NULL;
}
GimpBrushGeneratedShape
gimp_brush_generated_set_shape (GimpBrushGenerated *brush,
GimpBrushGeneratedShape shape)
......
......@@ -25,9 +25,6 @@
#include "gimpbrush.h"
#define GIMP_BRUSH_GENERATED_FILE_EXTENSION ".vbr"
#define GIMP_TYPE_BRUSH_GENERATED (gimp_brush_generated_get_type ())
#define GIMP_BRUSH_GENERATED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGenerated))
#define GIMP_BRUSH_GENERATED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGeneratedClass))
......@@ -58,15 +55,13 @@ struct _GimpBrushGeneratedClass
GType gimp_brush_generated_get_type (void) G_GNUC_CONST;
GimpData * gimp_brush_generated_new (const gchar *name,
GimpData * gimp_brush_generated_new (const gchar *name,
GimpBrushGeneratedShape shape,
gfloat radius,
gint spikes,
gfloat hardness,
gfloat aspect_ratio,
gfloat angle);
GList * gimp_brush_generated_load (const gchar *file_name,
GError **error);
gfloat radius,
gint spikes,
gfloat hardness,
gfloat aspect_ratio,
gfloat angle);
GimpBrushGeneratedShape
gimp_brush_generated_set_shape (GimpBrushGenerated *brush,
......
......@@ -43,7 +43,6 @@
#include "libgimpbase/gimpbase.h"
#include "libgimpbase/gimpparasiteio.h"
#include "libgimpmath/gimpmath.h"
#include "core-types.h"
......@@ -51,243 +50,11 @@
#include "gimpbrush-load.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipe-load.h"
#include "gimp-intl.h"
static void gimp_brush_pipe_finalize (GObject *object);
static gint64 gimp_brush_pipe_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height);
static GimpBrush * gimp_brush_pipe_select_brush (GimpBrush *brush,
GimpCoords *last_coords,
GimpCoords *cur_coords);
static gboolean gimp_brush_pipe_want_null_motion (GimpBrush *brush,
GimpCoords *last_coords,
GimpCoords *cur_coords);
G_DEFINE_TYPE (GimpBrushPipe, gimp_brush_pipe, GIMP_TYPE_BRUSH);
#define parent_class gimp_brush_pipe_parent_class
static void
gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
GimpBrushClass *brush_class = GIMP_BRUSH_CLASS (klass);
object_class->finalize = gimp_brush_pipe_finalize;
gimp_object_class->get_memsize = gimp_brush_pipe_get_memsize;
viewable_class->get_popup_size = gimp_brush_pipe_get_popup_size;
brush_class->select_brush = gimp_brush_pipe_select_brush;
brush_class->want_null_motion = gimp_brush_pipe_want_null_motion;
}
static void
gimp_brush_pipe_init (GimpBrushPipe *pipe)
{
pipe->current = NULL;
pipe->dimension = 0;
pipe->rank = NULL;
pipe->stride = NULL;
pipe->nbrushes = 0;
pipe->brushes = NULL;
pipe->select = NULL;
pipe->index = NULL;
}
static void
gimp_brush_pipe_finalize (GObject *object)
{
GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (object);
if (pipe->rank)
{
g_free (pipe->rank);
pipe->rank = NULL;
}
if (pipe->stride)
{
g_free (pipe->stride);
pipe->stride = NULL;
}
if (pipe->brushes)
{
gint i;
for (i = 0; i < pipe->nbrushes; i++)
if (pipe->brushes[i])
g_object_unref (pipe->brushes[i]);
g_free (pipe->brushes);
pipe->brushes = NULL;
}
if (pipe->select)
{
g_free (pipe->select);
pipe->select = NULL;
}
if (pipe->index)
{
g_free (pipe->index);
pipe->index = NULL;
}
GIMP_BRUSH (pipe)->mask = NULL;
GIMP_BRUSH (pipe)->pixmap = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gint64
gimp_brush_pipe_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (object);
gint64 memsize = 0;
gint i;
memsize += pipe->dimension * (sizeof (gint) /* rank */ +
sizeof (gint) /* stride */ +
sizeof (PipeSelectModes));
for (i = 0; i < pipe->nbrushes; i++)
memsize += gimp_object_get_memsize (GIMP_OBJECT (pipe->brushes[i]),
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static gboolean
gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
gint width,
gint height,
gboolean dot_for_dot,
gint *popup_width,
gint *popup_height)
{
return gimp_viewable_get_size (viewable, popup_width, popup_height);
}
static GimpBrush *
gimp_brush_pipe_select_brush (GimpBrush *brush,
GimpCoords *last_coords,
GimpCoords *cur_coords)
{
GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (brush);
gint i, brushix, ix;
gdouble angle, velocity, spacing;
if (pipe->nbrushes == 1)
return GIMP_BRUSH (pipe->current);
/* calculates brush native spacing in pixels, based on it's width)*/
spacing = ((gdouble) pipe->current->spacing / 100) *
MAX (brush->mask->width, brush->mask->height);
brushix = 0;