Commit e759ce35 authored by Michael Natterer's avatar Michael Natterer 😴

app, plug-ins: clean up gimpbrush-header.h and gimppattern-header.h

Namespace the header structs, s/GBRUSH/GIMP_BRUSH/,
s/GPATTERN/GIMP_PATTERN/.
parent bd09e6d4
......@@ -18,16 +18,17 @@
#ifndef __GIMP_BRUSH_HEADER_H__
#define __GIMP_BRUSH_HEADER_H__
#define GBRUSH_FILE_VERSION 2
#define GBRUSH_MAGIC (('G' << 24) + ('I' << 16) + ('M' << 8) + ('P' << 0))
#define GIMP_BRUSH_FILE_VERSION 2
#define GIMP_BRUSH_MAGIC (('G' << 24) + ('I' << 16) + \
('M' << 8) + ('P' << 0))
/* All field entries are MSB */
typedef struct _BrushHeader BrushHeader;
typedef struct _GimpBrushHeader GimpBrushHeader;
struct _BrushHeader
struct _GimpBrushHeader
{
guint32 header_size; /* header_size = sizeof (BrushHeader) + brush name */
guint32 header_size; /* = sizeof (GimpBrushHeader) + brush name */
guint32 version; /* brush file version # */
guint32 width; /* width of brush */
guint32 height; /* height of brush */
......
......@@ -136,7 +136,7 @@ gimp_brush_load_brush (GimpContext *context,
{
GimpBrush *brush;
gsize bn_size;
BrushHeader header;
GimpBrushHeader header;
gchar *name = NULL;
guchar *pixmap;
guchar *mask;
......@@ -225,7 +225,7 @@ gimp_brush_load_brush (GimpContext *context,
/* fallthrough */
case 2:
if (header.magic_number == GBRUSH_MAGIC)
if (header.magic_number == GIMP_BRUSH_MAGIC)
break;
default:
......@@ -235,7 +235,7 @@ gimp_brush_load_brush (GimpContext *context,
return NULL;
}
if (header.header_size < sizeof (BrushHeader))
if (header.header_size < sizeof (GimpBrushHeader))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Unsupported brush format"));
......
......@@ -21,7 +21,7 @@
#include "gimpdata.h"
#define GIMP_BRUSH_MAX_SIZE 10000.0 /*Max size in either dimension in px*/
#define GIMP_BRUSH_MAX_SIZE 10000 /* Max size in either dimension in px */
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
#define GIMP_BRUSH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))
......
......@@ -18,16 +18,17 @@
#ifndef __GIMP_PATTERN_HEADER_H__
#define __GIMP_PATTERN_HEADER_H__
#define GPATTERN_FILE_VERSION 1
#define GPATTERN_MAGIC (('G' << 24) + ('P' << 16) + ('A' << 8) + ('T' << 0))
#define GIMP_PATTERN_FILE_VERSION 1
#define GIMP_PATTERN_MAGIC (('G' << 24) + ('P' << 16) + \
('A' << 8) + ('T' << 0))
/* All field entries are MSB */
typedef struct _PatternHeader PatternHeader;
typedef struct _GimpPatternHeader GimpPatternHeader;
struct _PatternHeader
struct _GimpPatternHeader
{
guint32 header_size; /* header_size = sizeof(PatternHeader) + pattern name */
guint32 header_size; /* = sizeof (GimpPatternHeader) + pattern name */
guint32 version; /* pattern file version # */
guint32 width; /* width of pattern */
guint32 height; /* height of pattern */
......
......@@ -42,7 +42,7 @@ gimp_pattern_load (GimpContext *context,
{
GimpPattern *pattern = NULL;
const Babl *format = NULL;
PatternHeader header;
GimpPatternHeader header;
gsize size;
gsize bytes_read;
gint bn_size;
......@@ -70,7 +70,7 @@ gimp_pattern_load (GimpContext *context,
header.magic_number = g_ntohl (header.magic_number);
/* Check for correct file format */
if (header.magic_number != GPATTERN_MAGIC || header.version != 1 ||
if (header.magic_number != GIMP_PATTERN_MAGIC || header.version != 1 ||
header.header_size <= sizeof (header))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
......
......@@ -348,7 +348,7 @@ load_image (GFile *file,
{
GInputStream *input;
gchar *name;
BrushHeader bh;
GimpBrushHeader bh;
guchar *brush_buf = NULL;
gint32 image_ID;
gint32 layer_ID;
......@@ -368,7 +368,7 @@ load_image (GFile *file,
if (! input)
return -1;
size = G_STRUCT_OFFSET (BrushHeader, magic_number);
size = G_STRUCT_OFFSET (GimpBrushHeader, magic_number);
if (! g_input_stream_read_all (input, &bh, size,
&bytes_read, NULL, error) ||
......@@ -406,7 +406,7 @@ load_image (GFile *file,
/* Version 1 didn't have a magic number and had no spacing */
bh.spacing = 25;
bh.header_size += 8;
if (bh.header_size < sizeof (BrushHeader))
if (bh.header_size < sizeof (GimpBrushHeader))
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unsupported brush format"));
......@@ -421,7 +421,7 @@ load_image (GFile *file,
if (! g_input_stream_read_all (input,
(guchar *) &bh +
G_STRUCT_OFFSET (BrushHeader,
G_STRUCT_OFFSET (GimpBrushHeader,
magic_number), size,
&bytes_read, NULL, error) ||
bytes_read != size)
......@@ -447,8 +447,8 @@ load_image (GFile *file,
}
}
if (bh.magic_number == GBRUSH_MAGIC &&
bh.header_size > sizeof (BrushHeader))
if (bh.magic_number == GIMP_BRUSH_MAGIC &&
bh.header_size > sizeof (GimpBrushHeader))
break;
default:
......@@ -457,7 +457,7 @@ load_image (GFile *file,
return -1;
}
if ((size = (bh.header_size - sizeof (BrushHeader))) > 0)
if ((size = (bh.header_size - sizeof (GimpBrushHeader))) > 0)
{
gchar *temp = g_new (gchar, size);
......@@ -502,15 +502,15 @@ load_image (GFile *file,
{
case 1:
{
PatternHeader ph;
GimpPatternHeader ph;
/* For backwards-compatibility, check if a pattern follows.
* The obsolete .gpb format did it this way.
*/
if (g_input_stream_read_all (input, &ph, sizeof (PatternHeader),
if (g_input_stream_read_all (input, &ph, sizeof (GimpPatternHeader),
&bytes_read, NULL, NULL) &&
bytes_read == sizeof (PatternHeader))
bytes_read == sizeof (GimpPatternHeader))
{
/* rearrange the bytes in each unsigned int */
ph.header_size = g_ntohl (ph.header_size);
......@@ -520,16 +520,16 @@ load_image (GFile *file,
ph.bytes = g_ntohl (ph.bytes);
ph.magic_number = g_ntohl (ph.magic_number);
if (ph.magic_number == GPATTERN_MAGIC &&
if (ph.magic_number == GIMP_PATTERN_MAGIC &&
ph.version == 1 &&
ph.header_size > sizeof (PatternHeader) &&
ph.header_size > sizeof (GimpPatternHeader) &&
ph.bytes == 3 &&
ph.width == bh.width &&
ph.height == bh.height &&
g_input_stream_skip (input,
ph.header_size - sizeof (PatternHeader),
ph.header_size - sizeof (GimpPatternHeader),
NULL, NULL) ==
ph.header_size - sizeof (PatternHeader))
ph.header_size - sizeof (GimpPatternHeader))
{
guchar *plain_brush = brush_buf;
gint i;
......@@ -661,7 +661,7 @@ save_image (GFile *file,
GError **error)
{
GOutputStream *output;
BrushHeader bh;
GimpBrushHeader bh;
guchar *brush_buf;
GeglBuffer *buffer;
const Babl *format;
......@@ -709,16 +709,16 @@ save_image (GFile *file,
width = gimp_drawable_width (drawable_ID);
height = gimp_drawable_height (drawable_ID);
bh.header_size = g_htonl (sizeof (BrushHeader) +
bh.header_size = g_htonl (sizeof (GimpBrushHeader) +
strlen (info.description) + 1);
bh.version = g_htonl (2);
bh.width = g_htonl (width);
bh.height = g_htonl (height);
bh.bytes = g_htonl (file_bpp);
bh.magic_number = g_htonl (GBRUSH_MAGIC);
bh.magic_number = g_htonl (GIMP_BRUSH_MAGIC);
bh.spacing = g_htonl (info.spacing);
if (! g_output_stream_write_all (output, &bh, sizeof (BrushHeader),
if (! g_output_stream_write_all (output, &bh, sizeof (GimpBrushHeader),
NULL, NULL, error))
{
g_object_unref (output);
......
......@@ -453,7 +453,7 @@ gih_load_one_brush (GInputStream *input,
GError **error)
{
gchar *name = NULL;
BrushHeader bh;
GimpBrushHeader bh;
guchar *brush_buf = NULL;
gint32 layer_ID;
gsize size;
......@@ -487,7 +487,8 @@ gih_load_one_brush (GInputStream *input,
return FALSE;
}
if ((bh.magic_number != GBRUSH_MAGIC || bh.version != 2) ||
if ((bh.magic_number != GIMP_BRUSH_MAGIC ||
bh.version != 2) ||
bh.header_size <= sizeof (bh))
{
return FALSE;
......@@ -526,15 +527,15 @@ gih_load_one_brush (GInputStream *input,
if (bh.bytes == 1)
{
PatternHeader ph;
GimpPatternHeader ph;
/* For backwards-compatibility, check if a pattern follows.
* The obsolete .gpb format did it this way.
*/
if (g_input_stream_read_all (input, &ph, sizeof (PatternHeader),
if (g_input_stream_read_all (input, &ph, sizeof (GimpPatternHeader),
&bytes_read, NULL, error) &&
bytes_read == sizeof (PatternHeader))
bytes_read == sizeof (GimpPatternHeader))
{
/* rearrange the bytes in each unsigned int */
ph.header_size = g_ntohl (ph.header_size);
......@@ -544,16 +545,16 @@ gih_load_one_brush (GInputStream *input,
ph.bytes = g_ntohl (ph.bytes);
ph.magic_number = g_ntohl (ph.magic_number);
if (ph.magic_number == GPATTERN_MAGIC &&
if (ph.magic_number == GIMP_PATTERN_MAGIC &&
ph.version == 1 &&
ph.header_size > sizeof (PatternHeader) &&
ph.header_size > sizeof (GimpPatternHeader) &&
ph.bytes == 3 &&
ph.width == bh.width &&
ph.height == bh.height &&
g_input_stream_skip (input,
ph.header_size - sizeof (PatternHeader),
ph.header_size - sizeof (GimpPatternHeader),
NULL, NULL) ==
ph.header_size - sizeof (PatternHeader))
ph.header_size - sizeof (GimpPatternHeader))
{
guchar *plain_brush = brush_buf;
gint i;
......@@ -580,7 +581,7 @@ gih_load_one_brush (GInputStream *input,
g_free (plain_brush);
}
else if (! g_seekable_seek (G_SEEKABLE (input),
- sizeof (PatternHeader), G_SEEK_CUR,
- sizeof (GimpPatternHeader), G_SEEK_CUR,
NULL, NULL))
{
g_message (_("GIMP brush file appears to be corrupted."));
......@@ -1188,7 +1189,7 @@ gih_save_one_brush (GOutputStream *output,
{
GeglBuffer *buffer;
const Babl *format;
BrushHeader bh;
GimpBrushHeader bh;
guchar *data;
GimpImageType drawable_type;
gint bpp;
......@@ -1225,7 +1226,7 @@ gih_save_one_brush (GOutputStream *output,
bh.width = g_htonl (rect->width);
bh.height = g_htonl (rect->height);
bh.bytes = g_htonl (bpp);
bh.magic_number = g_htonl (GBRUSH_MAGIC);
bh.magic_number = g_htonl (GIMP_BRUSH_MAGIC);
bh.spacing = g_htonl (info.spacing);
if (! g_output_stream_write_all (output, &bh, sizeof (bh),
......
......@@ -319,7 +319,7 @@ load_image (GFile *file,
GError **error)
{
GInputStream *input;
PatternHeader ph;
GimpPatternHeader ph;
gchar *name;
gchar *temp;
guchar *buf;
......@@ -340,9 +340,9 @@ load_image (GFile *file,
if (! input)
return -1;
if (! g_input_stream_read_all (input, &ph, sizeof (PatternHeader),
if (! g_input_stream_read_all (input, &ph, sizeof (GimpPatternHeader),
&bytes_read, NULL, error) ||
bytes_read != sizeof (PatternHeader))
bytes_read != sizeof (GimpPatternHeader))
{
g_object_unref (input);
return -1;
......@@ -356,27 +356,27 @@ load_image (GFile *file,
ph.bytes = g_ntohl (ph.bytes);
ph.magic_number = g_ntohl (ph.magic_number);
if (ph.magic_number != GPATTERN_MAGIC ||
if (ph.magic_number != GIMP_PATTERN_MAGIC ||
ph.version != 1 ||
ph.header_size <= sizeof (PatternHeader))
ph.header_size <= sizeof (GimpPatternHeader))
{
g_object_unref (input);
return -1;
}
temp = g_new (gchar, ph.header_size - sizeof (PatternHeader));
temp = g_new (gchar, ph.header_size - sizeof (GimpPatternHeader));
if (! g_input_stream_read_all (input,
temp, ph.header_size - sizeof (PatternHeader),
temp, ph.header_size - sizeof (GimpPatternHeader),
&bytes_read, NULL, error) ||
bytes_read != ph.header_size - sizeof (PatternHeader))
bytes_read != ph.header_size - sizeof (GimpPatternHeader))
{
g_free (temp);
g_object_unref (input);
return -1;
}
name = gimp_any_to_utf8 (temp, ph.header_size - sizeof (PatternHeader) - 1,
name = gimp_any_to_utf8 (temp, ph.header_size - sizeof (GimpPatternHeader) - 1,
_("Invalid UTF-8 string in pattern file '%s'."),
g_file_get_parse_name (file));
g_free (temp);
......@@ -496,7 +496,7 @@ save_image (GFile *file,
GError **error)
{
GOutputStream *output;
PatternHeader ph;
GimpPatternHeader ph;
GeglBuffer *buffer;
const Babl *file_format;
guchar *buf;
......@@ -546,14 +546,14 @@ save_image (GFile *file,
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
ph.header_size = g_htonl (sizeof (PatternHeader) + strlen (description) + 1);
ph.header_size = g_htonl (sizeof (GimpPatternHeader) + strlen (description) + 1);
ph.version = g_htonl (1);
ph.width = g_htonl (width);
ph.height = g_htonl (height);
ph.bytes = g_htonl (babl_format_get_bytes_per_pixel (file_format));
ph.magic_number = g_htonl (GPATTERN_MAGIC);
ph.magic_number = g_htonl (GIMP_PATTERN_MAGIC);
if (! g_output_stream_write_all (output, &ph, sizeof (PatternHeader),
if (! g_output_stream_write_all (output, &ph, sizeof (GimpPatternHeader),
NULL, NULL, error))
{
g_object_unref (output);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment