app/gimpbrush.c app/gimpbrushpipe.c app/pattern_header.h fixed #8150.

2000-10-01  Michael Natterer  <mitch@gimp.org>

	* app/gimpbrush.c
	* app/gimpbrushpipe.c
	* app/pattern_header.h
	* app/patterns.c: (Hopefully) fixed #8150.

	- If something goes wrong during loading, free the resp. object
	  immediately and close it's FD.
	- When destroying, check each pointer before freeing it.
	- Never use if (!gimp_brush_load_brush() || !pattern_load())
	  but check the return values of both calls separately.
	  (the original code tried to free an already destroyed temp_buf).
	- stuff like below (s/sz_PatternHeader/sizeof(PatternHeader)/g etc.)
This commit is contained in:
Michael Natterer 2000-10-01 18:53:39 +00:00 committed by Michael Natterer
parent b04bbd9a74
commit 4eeb875946
11 changed files with 206 additions and 114 deletions

View File

@ -1,3 +1,18 @@
2000-10-01 Michael Natterer <mitch@gimp.org>
* app/gimpbrush.c
* app/gimpbrushpipe.c
* app/pattern_header.h
* app/patterns.c: (Hopefully) fixed #8150.
- If something goes wrong during loading, free the resp. object
immediately and close it's FD.
- When destroying, check each pointer before freeing it.
- Never use if (!gimp_brush_load_brush() || !pattern_load())
but check the return values of both calls separately.
(the original code tried to free an already destroyed temp_buf).
- stuff like below (s/sz_PatternHeader/sizeof(PatternHeader)/g etc.)
2000-09-30 Nick Lamb <njl195@zepler.org.uk>
* plug-ins/common/*.c: Add <string.h> where it is called for

View File

@ -124,7 +124,7 @@ gimp_brush_get_type (void)
GimpBrush *
gimp_brush_new (gchar *filename)
{
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
if (gimp_brush_load (brush, filename))
return brush;
@ -215,7 +215,6 @@ gimp_brush_load (GimpBrush *brush,
if (! gimp_brush_load_brush (brush, fp, filename))
{
fclose (fp);
return FALSE;
}
@ -243,6 +242,7 @@ gimp_brush_load_brush (GimpBrush *brush,
/* Read in the header size */
if ((fread (buf, 1, sizeof (BrushHeader), fp)) < sizeof (BrushHeader))
{
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -258,6 +258,7 @@ gimp_brush_load_brush (GimpBrush *brush,
{
if (header.version != 1)
{
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -279,6 +280,7 @@ gimp_brush_load_brush (GimpBrush *brush,
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -311,6 +313,7 @@ gimp_brush_load_brush (GimpBrush *brush,
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}

View File

@ -124,7 +124,7 @@ gimp_brush_get_type (void)
GimpBrush *
gimp_brush_new (gchar *filename)
{
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
if (gimp_brush_load (brush, filename))
return brush;
@ -215,7 +215,6 @@ gimp_brush_load (GimpBrush *brush,
if (! gimp_brush_load_brush (brush, fp, filename))
{
fclose (fp);
return FALSE;
}
@ -243,6 +242,7 @@ gimp_brush_load_brush (GimpBrush *brush,
/* Read in the header size */
if ((fread (buf, 1, sizeof (BrushHeader), fp)) < sizeof (BrushHeader))
{
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -258,6 +258,7 @@ gimp_brush_load_brush (GimpBrush *brush,
{
if (header.version != 1)
{
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -279,6 +280,7 @@ gimp_brush_load_brush (GimpBrush *brush,
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -311,6 +313,7 @@ gimp_brush_load_brush (GimpBrush *brush,
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}

View File

@ -52,14 +52,16 @@ gimp_brush_pixmap_destroy (GtkObject *object)
{
GimpBrushPixmap *pixmap;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_BRUSH_PIXMAP (object));
pixmap = GIMP_BRUSH_PIXMAP (object);
temp_buf_free (pixmap->pixmap_mask);
if (pixmap->pixmap_mask)
temp_buf_free (pixmap->pixmap_mask);
if (GTK_OBJECT_CLASS (gimp_brush_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_class)->destroy) (object);
GTK_OBJECT_CLASS (gimp_brush_class)->destroy (object);
}
static void
@ -210,14 +212,15 @@ gimp_brush_pipe_destroy (GtkObject *object)
g_free (pipe->stride);
for (i = 1; i < pipe->nbrushes; i++)
gtk_object_unref (GTK_OBJECT (pipe->brushes[i]));
if (pipe->brushes[i])
gtk_object_unref (GTK_OBJECT (pipe->brushes[i]));
g_free (pipe->brushes);
g_free (pipe->select);
g_free (pipe->index);
if (GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy) (object);
GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy (object);
}
static void
@ -234,9 +237,12 @@ gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
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;
}
@ -319,13 +325,16 @@ gimp_brush_pipe_load (gchar *filename)
{
gimp_pixpipe_params_init (&params);
gimp_pixpipe_params_parse (paramstring, &params);
pipe->dimension = params.dim;
pipe->rank = g_new (gint, pipe->dimension);
pipe->select = g_new (PipeSelectModes, pipe->dimension);
pipe->index = g_new (gint, pipe->dimension);
pipe->rank = g_new0 (gint, pipe->dimension);
pipe->select = g_new0 (PipeSelectModes, pipe->dimension);
pipe->index = g_new0 (gint, pipe->dimension);
/* placement is not used at all ?? */
if (params.free_placement_string)
g_free (params.placement);
for (i = 0; i < pipe->dimension; i++)
{
pipe->rank[i] = params.rank[i];
@ -364,7 +373,7 @@ gimp_brush_pipe_load (gchar *filename)
totalcells = 1; /* Not all necessarily present, maybe */
for (i = 0; i < pipe->dimension; i++)
totalcells *= pipe->rank[i];
pipe->stride = g_new (gint, pipe->dimension);
pipe->stride = g_new0 (gint, pipe->dimension);
for (i = 0; i < pipe->dimension; i++)
{
if (i == 0)
@ -390,6 +399,10 @@ gimp_brush_pipe_load (gchar *filename)
{
pipe->brushes[pipe->nbrushes] =
GIMP_BRUSH_PIXMAP (gtk_type_new (GIMP_TYPE_BRUSH_PIXMAP));
gtk_object_ref (GTK_OBJECT (pipe->brushes[pipe->nbrushes]));
gtk_object_sink (GTK_OBJECT (pipe->brushes[pipe->nbrushes]));
g_free (GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name);
GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name = NULL;
}
@ -398,16 +411,20 @@ gimp_brush_pipe_load (gchar *filename)
/* load the brush */
if (!gimp_brush_load_brush (GIMP_BRUSH (pipe->brushes[pipe->nbrushes]),
fp, filename)
|| !pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load one of the\n"
"brushes in the brush pipe."));
fclose (fp);
fp, filename))
{
g_message (_("Failed to load one of the brushes in the brush pipe."));
pattern_free (pattern);
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
}
if (!pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load one of the brushes in the brush pipe."));
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
if (pipe->nbrushes == 0)
{
@ -415,8 +432,10 @@ gimp_brush_pipe_load (gchar *filename)
g_free (GIMP_BRUSH (pipe)->name);
GIMP_BRUSH (pipe)->name = name;
}
pipe->brushes[pipe->nbrushes]->pixmap_mask = pattern->mask;
g_free (pattern->name);
pipe->nbrushes++;
}
@ -432,8 +451,8 @@ GimpBrushPipe *
gimp_brush_pixmap_load (gchar *filename)
{
GimpBrushPipe *pipe;
GPattern *pattern;
FILE *fp;
GPattern *pattern;
FILE *fp;
if ((fp = fopen (filename, "rb")) == NULL)
return NULL;
@ -460,16 +479,21 @@ gimp_brush_pixmap_load (gchar *filename)
/* load the brush */
if (!gimp_brush_load_brush (GIMP_BRUSH (pipe->brushes[0]),
fp, filename)
|| !pattern_load (pattern, fp, filename))
fp, filename))
{
g_message (_("Failed to load pixmap brush."));
fclose (fp);
pattern_free (pattern);
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
if (!pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load pixmap brush."));
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
pipe->brushes[0]->pixmap_mask = pattern->mask;
pipe->nbrushes = 1;

View File

@ -52,14 +52,16 @@ gimp_brush_pixmap_destroy (GtkObject *object)
{
GimpBrushPixmap *pixmap;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_BRUSH_PIXMAP (object));
pixmap = GIMP_BRUSH_PIXMAP (object);
temp_buf_free (pixmap->pixmap_mask);
if (pixmap->pixmap_mask)
temp_buf_free (pixmap->pixmap_mask);
if (GTK_OBJECT_CLASS (gimp_brush_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_class)->destroy) (object);
GTK_OBJECT_CLASS (gimp_brush_class)->destroy (object);
}
static void
@ -210,14 +212,15 @@ gimp_brush_pipe_destroy (GtkObject *object)
g_free (pipe->stride);
for (i = 1; i < pipe->nbrushes; i++)
gtk_object_unref (GTK_OBJECT (pipe->brushes[i]));
if (pipe->brushes[i])
gtk_object_unref (GTK_OBJECT (pipe->brushes[i]));
g_free (pipe->brushes);
g_free (pipe->select);
g_free (pipe->index);
if (GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy) (object);
GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy (object);
}
static void
@ -234,9 +237,12 @@ gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
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;
}
@ -319,13 +325,16 @@ gimp_brush_pipe_load (gchar *filename)
{
gimp_pixpipe_params_init (&params);
gimp_pixpipe_params_parse (paramstring, &params);
pipe->dimension = params.dim;
pipe->rank = g_new (gint, pipe->dimension);
pipe->select = g_new (PipeSelectModes, pipe->dimension);
pipe->index = g_new (gint, pipe->dimension);
pipe->rank = g_new0 (gint, pipe->dimension);
pipe->select = g_new0 (PipeSelectModes, pipe->dimension);
pipe->index = g_new0 (gint, pipe->dimension);
/* placement is not used at all ?? */
if (params.free_placement_string)
g_free (params.placement);
for (i = 0; i < pipe->dimension; i++)
{
pipe->rank[i] = params.rank[i];
@ -364,7 +373,7 @@ gimp_brush_pipe_load (gchar *filename)
totalcells = 1; /* Not all necessarily present, maybe */
for (i = 0; i < pipe->dimension; i++)
totalcells *= pipe->rank[i];
pipe->stride = g_new (gint, pipe->dimension);
pipe->stride = g_new0 (gint, pipe->dimension);
for (i = 0; i < pipe->dimension; i++)
{
if (i == 0)
@ -390,6 +399,10 @@ gimp_brush_pipe_load (gchar *filename)
{
pipe->brushes[pipe->nbrushes] =
GIMP_BRUSH_PIXMAP (gtk_type_new (GIMP_TYPE_BRUSH_PIXMAP));
gtk_object_ref (GTK_OBJECT (pipe->brushes[pipe->nbrushes]));
gtk_object_sink (GTK_OBJECT (pipe->brushes[pipe->nbrushes]));
g_free (GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name);
GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name = NULL;
}
@ -398,16 +411,20 @@ gimp_brush_pipe_load (gchar *filename)
/* load the brush */
if (!gimp_brush_load_brush (GIMP_BRUSH (pipe->brushes[pipe->nbrushes]),
fp, filename)
|| !pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load one of the\n"
"brushes in the brush pipe."));
fclose (fp);
fp, filename))
{
g_message (_("Failed to load one of the brushes in the brush pipe."));
pattern_free (pattern);
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
}
if (!pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load one of the brushes in the brush pipe."));
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
if (pipe->nbrushes == 0)
{
@ -415,8 +432,10 @@ gimp_brush_pipe_load (gchar *filename)
g_free (GIMP_BRUSH (pipe)->name);
GIMP_BRUSH (pipe)->name = name;
}
pipe->brushes[pipe->nbrushes]->pixmap_mask = pattern->mask;
g_free (pattern->name);
pipe->nbrushes++;
}
@ -432,8 +451,8 @@ GimpBrushPipe *
gimp_brush_pixmap_load (gchar *filename)
{
GimpBrushPipe *pipe;
GPattern *pattern;
FILE *fp;
GPattern *pattern;
FILE *fp;
if ((fp = fopen (filename, "rb")) == NULL)
return NULL;
@ -460,16 +479,21 @@ gimp_brush_pixmap_load (gchar *filename)
/* load the brush */
if (!gimp_brush_load_brush (GIMP_BRUSH (pipe->brushes[0]),
fp, filename)
|| !pattern_load (pattern, fp, filename))
fp, filename))
{
g_message (_("Failed to load pixmap brush."));
fclose (fp);
pattern_free (pattern);
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
if (!pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load pixmap brush."));
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
pipe->brushes[0]->pixmap_mask = pattern->mask;
pipe->nbrushes = 1;

View File

@ -15,25 +15,25 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PATTERN_HEADER_H__
#define __PATTERN_HEADER_H__
typedef struct _PatternHeader PatternHeader;
#define GPATTERN_FILE_VERSION 1
#define GPATTERN_MAGIC (('G' << 24) + ('P' << 16) + ('A' << 8) + ('T' << 0))
#define sz_PatternHeader (sizeof (PatternHeader))
/* All field entries are MSB */
typedef struct _PatternHeader PatternHeader;
struct _PatternHeader
{
unsigned int header_size; /* header_size = sz_PatternHeader + pattern name */
unsigned int version; /* pattern file version # */
unsigned int width; /* width of pattern */
unsigned int height; /* height of pattern */
unsigned int bytes; /* depth of pattern in bytes */
unsigned int magic_number; /* GIMP pattern magic number */
guint header_size; /* header_size = sizeof(PatternHeader) + pattern name */
guint version; /* pattern file version # */
guint width; /* width of pattern */
guint height; /* height of pattern */
guint bytes; /* depth of pattern in bytes */
guint magic_number; /* GIMP pattern magic number */
};
/* In a pattern file, next comes the pattern name, null-terminated. After that

View File

@ -124,7 +124,7 @@ gimp_brush_get_type (void)
GimpBrush *
gimp_brush_new (gchar *filename)
{
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
if (gimp_brush_load (brush, filename))
return brush;
@ -215,7 +215,6 @@ gimp_brush_load (GimpBrush *brush,
if (! gimp_brush_load_brush (brush, fp, filename))
{
fclose (fp);
return FALSE;
}
@ -243,6 +242,7 @@ gimp_brush_load_brush (GimpBrush *brush,
/* Read in the header size */
if ((fread (buf, 1, sizeof (BrushHeader), fp)) < sizeof (BrushHeader))
{
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -258,6 +258,7 @@ gimp_brush_load_brush (GimpBrush *brush,
{
if (header.version != 1)
{
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -279,6 +280,7 @@ gimp_brush_load_brush (GimpBrush *brush,
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
@ -311,6 +313,7 @@ gimp_brush_load_brush (GimpBrush *brush,
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}

View File

@ -52,14 +52,16 @@ gimp_brush_pixmap_destroy (GtkObject *object)
{
GimpBrushPixmap *pixmap;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_BRUSH_PIXMAP (object));
pixmap = GIMP_BRUSH_PIXMAP (object);
temp_buf_free (pixmap->pixmap_mask);
if (pixmap->pixmap_mask)
temp_buf_free (pixmap->pixmap_mask);
if (GTK_OBJECT_CLASS (gimp_brush_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_class)->destroy) (object);
GTK_OBJECT_CLASS (gimp_brush_class)->destroy (object);
}
static void
@ -210,14 +212,15 @@ gimp_brush_pipe_destroy (GtkObject *object)
g_free (pipe->stride);
for (i = 1; i < pipe->nbrushes; i++)
gtk_object_unref (GTK_OBJECT (pipe->brushes[i]));
if (pipe->brushes[i])
gtk_object_unref (GTK_OBJECT (pipe->brushes[i]));
g_free (pipe->brushes);
g_free (pipe->select);
g_free (pipe->index);
if (GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy) (object);
GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy (object);
}
static void
@ -234,9 +237,12 @@ gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
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;
}
@ -319,13 +325,16 @@ gimp_brush_pipe_load (gchar *filename)
{
gimp_pixpipe_params_init (&params);
gimp_pixpipe_params_parse (paramstring, &params);
pipe->dimension = params.dim;
pipe->rank = g_new (gint, pipe->dimension);
pipe->select = g_new (PipeSelectModes, pipe->dimension);
pipe->index = g_new (gint, pipe->dimension);
pipe->rank = g_new0 (gint, pipe->dimension);
pipe->select = g_new0 (PipeSelectModes, pipe->dimension);
pipe->index = g_new0 (gint, pipe->dimension);
/* placement is not used at all ?? */
if (params.free_placement_string)
g_free (params.placement);
for (i = 0; i < pipe->dimension; i++)
{
pipe->rank[i] = params.rank[i];
@ -364,7 +373,7 @@ gimp_brush_pipe_load (gchar *filename)
totalcells = 1; /* Not all necessarily present, maybe */
for (i = 0; i < pipe->dimension; i++)
totalcells *= pipe->rank[i];
pipe->stride = g_new (gint, pipe->dimension);
pipe->stride = g_new0 (gint, pipe->dimension);
for (i = 0; i < pipe->dimension; i++)
{
if (i == 0)
@ -390,6 +399,10 @@ gimp_brush_pipe_load (gchar *filename)
{
pipe->brushes[pipe->nbrushes] =
GIMP_BRUSH_PIXMAP (gtk_type_new (GIMP_TYPE_BRUSH_PIXMAP));
gtk_object_ref (GTK_OBJECT (pipe->brushes[pipe->nbrushes]));
gtk_object_sink (GTK_OBJECT (pipe->brushes[pipe->nbrushes]));
g_free (GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name);
GIMP_BRUSH (pipe->brushes[pipe->nbrushes])->name = NULL;
}
@ -398,16 +411,20 @@ gimp_brush_pipe_load (gchar *filename)
/* load the brush */
if (!gimp_brush_load_brush (GIMP_BRUSH (pipe->brushes[pipe->nbrushes]),
fp, filename)
|| !pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load one of the\n"
"brushes in the brush pipe."));
fclose (fp);
fp, filename))
{
g_message (_("Failed to load one of the brushes in the brush pipe."));
pattern_free (pattern);
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
}
if (!pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load one of the brushes in the brush pipe."));
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
if (pipe->nbrushes == 0)
{
@ -415,8 +432,10 @@ gimp_brush_pipe_load (gchar *filename)
g_free (GIMP_BRUSH (pipe)->name);
GIMP_BRUSH (pipe)->name = name;
}
pipe->brushes[pipe->nbrushes]->pixmap_mask = pattern->mask;
g_free (pattern->name);
pipe->nbrushes++;
}
@ -432,8 +451,8 @@ GimpBrushPipe *
gimp_brush_pixmap_load (gchar *filename)
{
GimpBrushPipe *pipe;
GPattern *pattern;
FILE *fp;
GPattern *pattern;
FILE *fp;
if ((fp = fopen (filename, "rb")) == NULL)
return NULL;
@ -460,16 +479,21 @@ gimp_brush_pixmap_load (gchar *filename)
/* load the brush */
if (!gimp_brush_load_brush (GIMP_BRUSH (pipe->brushes[0]),
fp, filename)
|| !pattern_load (pattern, fp, filename))
fp, filename))
{
g_message (_("Failed to load pixmap brush."));
fclose (fp);
pattern_free (pattern);
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
if (!pattern_load (pattern, fp, filename))
{
g_message (_("Failed to load pixmap brush."));
gtk_object_sink (GTK_OBJECT (pipe));
return NULL;
}
pipe->brushes[0]->pixmap_mask = pattern->mask;
pipe->nbrushes = 1;

View File

@ -15,25 +15,25 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PATTERN_HEADER_H__
#define __PATTERN_HEADER_H__
typedef struct _PatternHeader PatternHeader;
#define GPATTERN_FILE_VERSION 1
#define GPATTERN_MAGIC (('G' << 24) + ('P' << 16) + ('A' << 8) + ('T' << 0))
#define sz_PatternHeader (sizeof (PatternHeader))
/* All field entries are MSB */
typedef struct _PatternHeader PatternHeader;
struct _PatternHeader
{
unsigned int header_size; /* header_size = sz_PatternHeader + pattern name */
unsigned int version; /* pattern file version # */
unsigned int width; /* width of pattern */
unsigned int height; /* height of pattern */
unsigned int bytes; /* depth of pattern in bytes */
unsigned int magic_number; /* GIMP pattern magic number */
guint header_size; /* header_size = sizeof(PatternHeader) + pattern name */
guint version; /* pattern file version # */
guint width; /* width of pattern */
guint height; /* height of pattern */
guint bytes; /* depth of pattern in bytes */
guint magic_number; /* GIMP pattern magic number */
};
/* In a pattern file, next comes the pattern name, null-terminated. After that

View File

@ -15,25 +15,25 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PATTERN_HEADER_H__
#define __PATTERN_HEADER_H__
typedef struct _PatternHeader PatternHeader;
#define GPATTERN_FILE_VERSION 1
#define GPATTERN_MAGIC (('G' << 24) + ('P' << 16) + ('A' << 8) + ('T' << 0))
#define sz_PatternHeader (sizeof (PatternHeader))
/* All field entries are MSB */
typedef struct _PatternHeader PatternHeader;
struct _PatternHeader
{
unsigned int header_size; /* header_size = sz_PatternHeader + pattern name */
unsigned int version; /* pattern file version # */
unsigned int width; /* width of pattern */
unsigned int height; /* height of pattern */
unsigned int bytes; /* depth of pattern in bytes */
unsigned int magic_number; /* GIMP pattern magic number */
guint header_size; /* header_size = sizeof(PatternHeader) + pattern name */
guint version; /* pattern file version # */
guint width; /* width of pattern */
guint height; /* height of pattern */
guint bytes; /* depth of pattern in bytes */
guint magic_number; /* GIMP pattern magic number */
};
/* In a pattern file, next comes the pattern name, null-terminated. After that

View File

@ -46,7 +46,6 @@ gint num_patterns = 0;
static GPattern *standard_pattern = NULL;
/* local function prototypes */
static GSList * insert_pattern_in_list (GSList *, GPattern *);
static void load_pattern (gchar *);
static void pattern_free_func (gpointer, gpointer);
static gint pattern_compare_func (gconstpointer,
@ -151,14 +150,14 @@ pattern_load (GPattern *pattern,
FILE *fp,
gchar *filename)
{
gint bn_size;
guchar buf [sz_PatternHeader];
PatternHeader header;
gint bn_size;
guchar buf [sizeof (PatternHeader)];
guint *hp;
gint i;
gint i;
/* Read in the header size */
if ((fread (buf, 1, sz_PatternHeader, fp)) < sz_PatternHeader)
if ((fread (buf, 1, sizeof (PatternHeader), fp)) < sizeof (PatternHeader))
{
fclose (fp);
pattern_free (pattern);
@ -167,7 +166,7 @@ pattern_load (GPattern *pattern,
/* rearrange the bytes in each unsigned int */
hp = (guint *) &header;
for (i = 0; i < (sz_PatternHeader / 4); i++)
for (i = 0; i < (sizeof (PatternHeader) / 4); i++)
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
@ -185,8 +184,8 @@ pattern_load (GPattern *pattern,
/* Check for correct version */
if (header.version != GPATTERN_FILE_VERSION)
{
g_message (_("Unknown GIMP version #%d in \"%s\"\n"), header.version,
filename);
g_message (_("Unknown GIMP pattern version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
pattern_free (pattern);
return FALSE;
@ -197,12 +196,12 @@ pattern_load (GPattern *pattern,
temp_buf_new (header.width, header.height, header.bytes, 0, 0, NULL);
/* Read in the pattern name */
if ((bn_size = (header.header_size - sz_PatternHeader)))
if ((bn_size = (header.header_size - sizeof (PatternHeader))))
{
pattern->name = g_new (gchar, bn_size);
if ((fread (pattern->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP pattern file...aborting."));
g_message (_("Error in GIMP pattern file \"%s\""), filename);
fclose (fp);
pattern_free (pattern);
return FALSE;
@ -216,7 +215,10 @@ pattern_load (GPattern *pattern,
if ((fread (temp_buf_data (pattern->mask), 1,
header.width * header.height * header.bytes, fp)) <
header.width * header.height * header.bytes)
g_message (_("GIMP pattern file appears to be truncated."));
{
g_message (_("GIMP pattern file \"%s\" appears to be truncated."),
filename);
}
/* success */
return TRUE;
@ -252,20 +254,13 @@ pattern_compare_func (gconstpointer first,
((const GPattern *) second)->name);
}
static GSList *
insert_pattern_in_list (GSList *list,
GPattern *pattern)
{
return g_slist_insert_sorted (list, pattern, pattern_compare_func);
}
static void
load_pattern (gchar *filename)
{
GPattern *pattern;
FILE *fp;
pattern = g_new (GPattern, 1);
pattern = g_new0 (GPattern, 1);
pattern->filename = g_strdup (filename);
pattern->name = NULL;
@ -280,7 +275,7 @@ load_pattern (gchar *filename)
if (! pattern_load (pattern, fp, filename))
{
g_message (_("Pattern load failed"));
g_message (_("Error loading pattern \"%s\""), filename);
return;
}
@ -289,5 +284,6 @@ load_pattern (gchar *filename)
/*temp_buf_swap (pattern->mask);*/
pattern_list = insert_pattern_in_list (pattern_list, pattern);
pattern_list = g_slist_insert_sorted (pattern_list, pattern,
pattern_compare_func);
}