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

GimpData code review:

2004-01-29  Michael Natterer  <mitch@gimp.org>

	GimpData code review:

	* app/core/gimpdata.c (gimp_data_init): default to
	writable = FALSE and dirty = TRUE.

	* app/core/gimpbrushgenerated.[ch]: added "const gchar *name" to
	gimp_brush_generated_new().

	* app/core/gimpbrush.c
	* app/core/gimpbrushgenerated.c
	* app/core/gimpbrushpipe.c
	* app/core/gimpgradient.c
	* app/core/gimppalette.c
	* app/core/gimppattern.c: set all standard datas to clean and
	internal, check for g_path_is_absolute() in all load functions,
	pass the data's name as construct property to g_object_new()
	instead of calling gimp_object_set_name() after creation, fixed
	some UTF-8 handling, spacing, indentation, coding style, general
	cleanup.
parent 4591bc1a
2004-01-29 Michael Natterer <mitch@gimp.org>
GimpData code review:
* app/core/gimpdata.c (gimp_data_init): default to
writable = FALSE and dirty = TRUE.
* app/core/gimpbrushgenerated.[ch]: added "const gchar *name" to
gimp_brush_generated_new().
* app/core/gimpbrush.c
* app/core/gimpbrushgenerated.c
* app/core/gimpbrushpipe.c
* app/core/gimpgradient.c
* app/core/gimppalette.c
* app/core/gimppattern.c: set all standard datas to clean and
internal, check for g_path_is_absolute() in all load functions,
pass the data's name as construct property to g_object_new()
instead of calling gimp_object_set_name() after creation, fixed
some UTF-8 handling, spacing, indentation, coding style, general
cleanup.
2004-01-29 Sven Neumann <sven@gimp.org>
 
* app/tools/gimpcurvestool.c
......@@ -184,9 +184,7 @@ gimp_brush_init (GimpBrush *brush)
static void
gimp_brush_finalize (GObject *object)
{
GimpBrush *brush;
brush = GIMP_BRUSH (object);
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->mask)
{
......@@ -207,11 +205,9 @@ static gint64
gimp_brush_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpBrush *brush;
GimpBrush *brush = GIMP_BRUSH (object);
gint64 memsize = 0;
brush = GIMP_BRUSH (object);
if (brush->mask)
memsize += temp_buf_get_memsize (brush->mask);
......@@ -230,9 +226,7 @@ gimp_brush_get_popup_size (GimpViewable *viewable,
gint *popup_width,
gint *popup_height)
{
GimpBrush *brush;
brush = GIMP_BRUSH (viewable);
GimpBrush *brush = GIMP_BRUSH (viewable);
if (brush->mask->width > width || brush->mask->height > height)
{
......@@ -250,7 +244,7 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
gint width,
gint height)
{
GimpBrush *brush;
GimpBrush *brush = GIMP_BRUSH (viewable);
gint brush_width;
gint brush_height;
TempBuf *mask_buf = NULL;
......@@ -262,8 +256,6 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
gint x, y;
gboolean scale = FALSE;
brush = GIMP_BRUSH (viewable);
mask_buf = gimp_brush_get_mask (brush);
pixmap_buf = gimp_brush_get_pixmap (brush);
......@@ -341,9 +333,7 @@ static gchar *
gimp_brush_get_description (GimpViewable *viewable,
gchar **tooltip)
{
GimpBrush *brush;
brush = GIMP_BRUSH (viewable);
GimpBrush *brush = GIMP_BRUSH (viewable);
if (tooltip)
*tooltip = NULL;
......@@ -364,36 +354,29 @@ GimpData *
gimp_brush_new (const gchar *name,
gboolean stingy_memory_use)
{
GimpBrush *brush;
g_return_val_if_fail (name != NULL, NULL);
brush = GIMP_BRUSH (gimp_brush_generated_new (5.0, 0.5, 0.0, 1.0,
stingy_memory_use));
gimp_object_set_name (GIMP_OBJECT (brush), name);
return GIMP_DATA (brush);
return gimp_brush_generated_new (name, 5.0, 0.5, 0.0, 1.0,
stingy_memory_use);
}
GimpData *
gimp_brush_get_standard (void)
{
static GimpBrush *standard_brush = NULL;
static GimpData *standard_brush = NULL;
if (! standard_brush)
{
standard_brush = GIMP_BRUSH (gimp_brush_generated_new (5.0, 0.5,
0.0, 1.0,
FALSE));
standard_brush = gimp_brush_new ("Standard", FALSE);
gimp_object_set_name (GIMP_OBJECT (standard_brush), "Standard");
standard_brush->dirty = FALSE;
standard_brush->internal = TRUE;
/* set ref_count to 2 --> never swap the standard brush */
g_object_ref (standard_brush);
}
return GIMP_DATA (standard_brush);
return standard_brush;
}
GimpData *
......@@ -405,6 +388,7 @@ gimp_brush_load (const gchar *filename,
gint fd;
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);
fd = open (filename, O_RDONLY | _O_BINARY);
......@@ -630,7 +614,12 @@ gimp_brush_load_brush (gint fd,
if (!name)
name = g_strdup (_("Unnamed"));
brush = g_object_new (GIMP_TYPE_BRUSH, NULL);
brush = g_object_new (GIMP_TYPE_BRUSH,
"name", name,
NULL);
g_free (name);
brush->mask = temp_buf_new (header.width, header.height, 1, 0, 0, NULL);
mask = temp_buf_data (brush->mask);
......@@ -721,7 +710,6 @@ gimp_brush_load_brush (gint fd,
"Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA."),
gimp_filename_to_utf8 (filename), header.bytes);
g_free (name);
return NULL;
}
......@@ -732,13 +720,9 @@ gimp_brush_load_brush (gint fd,
_("Fatal parse error in brush file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
g_free (name);
return NULL;
}
gimp_object_set_name (GIMP_OBJECT (brush), name);
g_free (name);
brush->spacing = header.spacing;
brush->x_axis.x = header.width / 2.0;
brush->x_axis.y = 0.0;
......
......@@ -184,9 +184,7 @@ gimp_brush_init (GimpBrush *brush)
static void
gimp_brush_finalize (GObject *object)
{
GimpBrush *brush;
brush = GIMP_BRUSH (object);
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->mask)
{
......@@ -207,11 +205,9 @@ static gint64
gimp_brush_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpBrush *brush;
GimpBrush *brush = GIMP_BRUSH (object);
gint64 memsize = 0;
brush = GIMP_BRUSH (object);
if (brush->mask)
memsize += temp_buf_get_memsize (brush->mask);
......@@ -230,9 +226,7 @@ gimp_brush_get_popup_size (GimpViewable *viewable,
gint *popup_width,
gint *popup_height)
{
GimpBrush *brush;
brush = GIMP_BRUSH (viewable);
GimpBrush *brush = GIMP_BRUSH (viewable);
if (brush->mask->width > width || brush->mask->height > height)
{
......@@ -250,7 +244,7 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
gint width,
gint height)
{
GimpBrush *brush;
GimpBrush *brush = GIMP_BRUSH (viewable);
gint brush_width;
gint brush_height;
TempBuf *mask_buf = NULL;
......@@ -262,8 +256,6 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
gint x, y;
gboolean scale = FALSE;
brush = GIMP_BRUSH (viewable);
mask_buf = gimp_brush_get_mask (brush);
pixmap_buf = gimp_brush_get_pixmap (brush);
......@@ -341,9 +333,7 @@ static gchar *
gimp_brush_get_description (GimpViewable *viewable,
gchar **tooltip)
{
GimpBrush *brush;
brush = GIMP_BRUSH (viewable);
GimpBrush *brush = GIMP_BRUSH (viewable);
if (tooltip)
*tooltip = NULL;
......@@ -364,36 +354,29 @@ GimpData *
gimp_brush_new (const gchar *name,
gboolean stingy_memory_use)
{
GimpBrush *brush;
g_return_val_if_fail (name != NULL, NULL);
brush = GIMP_BRUSH (gimp_brush_generated_new (5.0, 0.5, 0.0, 1.0,
stingy_memory_use));
gimp_object_set_name (GIMP_OBJECT (brush), name);
return GIMP_DATA (brush);
return gimp_brush_generated_new (name, 5.0, 0.5, 0.0, 1.0,
stingy_memory_use);
}
GimpData *
gimp_brush_get_standard (void)
{
static GimpBrush *standard_brush = NULL;
static GimpData *standard_brush = NULL;
if (! standard_brush)
{
standard_brush = GIMP_BRUSH (gimp_brush_generated_new (5.0, 0.5,
0.0, 1.0,
FALSE));
standard_brush = gimp_brush_new ("Standard", FALSE);
gimp_object_set_name (GIMP_OBJECT (standard_brush), "Standard");
standard_brush->dirty = FALSE;
standard_brush->internal = TRUE;
/* set ref_count to 2 --> never swap the standard brush */
g_object_ref (standard_brush);
}
return GIMP_DATA (standard_brush);
return standard_brush;
}
GimpData *
......@@ -405,6 +388,7 @@ gimp_brush_load (const gchar *filename,
gint fd;
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);
fd = open (filename, O_RDONLY | _O_BINARY);
......@@ -630,7 +614,12 @@ gimp_brush_load_brush (gint fd,
if (!name)
name = g_strdup (_("Unnamed"));
brush = g_object_new (GIMP_TYPE_BRUSH, NULL);
brush = g_object_new (GIMP_TYPE_BRUSH,
"name", name,
NULL);
g_free (name);
brush->mask = temp_buf_new (header.width, header.height, 1, 0, 0, NULL);
mask = temp_buf_data (brush->mask);
......@@ -721,7 +710,6 @@ gimp_brush_load_brush (gint fd,
"Unsupported brush depth %d\n"
"GIMP brushes must be GRAY or RGBA."),
gimp_filename_to_utf8 (filename), header.bytes);
g_free (name);
return NULL;
}
......@@ -732,13 +720,9 @@ gimp_brush_load_brush (gint fd,
_("Fatal parse error in brush file '%s': "
"File appears truncated."),
gimp_filename_to_utf8 (filename));
g_free (name);
return NULL;
}
gimp_object_set_name (GIMP_OBJECT (brush), name);
g_free (name);
brush->spacing = header.spacing;
brush->x_axis.x = header.width / 2.0;
brush->x_axis.y = 0.0;
......
......@@ -46,6 +46,7 @@
/* local function prototypes */
static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass);
static void gimp_brush_generated_init (GimpBrushGenerated *brush);
......@@ -70,19 +71,19 @@ gimp_brush_generated_get_type (void)
static const GTypeInfo brush_info =
{
sizeof (GimpBrushGeneratedClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_brush_generated_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpBrushGenerated),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_brush_generated_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_brush_generated_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpBrushGenerated),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_brush_generated_init,
};
brush_type = g_type_register_static (GIMP_TYPE_BRUSH,
"GimpBrushGenerated",
&brush_info, 0);
"GimpBrushGenerated",
&brush_info, 0);
}
return brush_type;
......@@ -117,14 +118,13 @@ static gboolean
gimp_brush_generated_save (GimpData *data,
GError **error)
{
GimpBrushGenerated *brush;
FILE *fp;
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
FILE *file;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
brush = GIMP_BRUSH_GENERATED (data);
file = fopen (data->filename, "wb");
/* we are (finaly) ready to try to save the generated brush file */
if ((fp = fopen (data->filename, "wb")) == NULL)
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
......@@ -134,40 +134,40 @@ gimp_brush_generated_save (GimpData *data,
}
/* write magic header */
fprintf (fp, "GIMP-VBR\n");
fprintf (file, "GIMP-VBR\n");
/* write version */
fprintf (fp, "1.0\n");
fprintf (file, "1.0\n");
/* write name */
fprintf (fp, "%.255s\n", GIMP_OBJECT (brush)->name);
fprintf (file, "%.255s\n", GIMP_OBJECT (brush)->name);
/* write brush spacing */
fprintf (fp, "%s\n",
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
GIMP_BRUSH (brush)->spacing));
/* write brush radius */
fprintf (fp, "%s\n",
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->radius));
/* write brush hardness */
fprintf (fp, "%s\n",
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->hardness));
/* write brush aspect_ratio */
fprintf (fp, "%s\n",
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->aspect_ratio));
/* write brush angle */
fprintf (fp, "%s\n",
fprintf (file, "%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
brush->angle));
fclose (fp);
fclose (file);
return TRUE;
}
......@@ -182,11 +182,10 @@ static GimpData *
gimp_brush_generated_duplicate (GimpData *data,
gboolean stingy_memory_use)
{
GimpBrushGenerated *brush;
brush = GIMP_BRUSH_GENERATED (data);
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
return gimp_brush_generated_new (brush->radius,
return gimp_brush_generated_new (GIMP_OBJECT (brush)->name,
brush->radius,
brush->hardness,
brush->angle,
brush->aspect_ratio,
......@@ -213,28 +212,24 @@ gauss (gdouble f)
static void
gimp_brush_generated_dirty (GimpData *data)
{
GimpBrushGenerated *brush;
GimpBrush *gbrush = NULL;
gint x, y;
guchar *centerp;
gdouble d;
gdouble exponent;
guchar a;
gint length;
gint width, height;
guchar *lookup;
gdouble sum;
gdouble c, s;
gdouble short_radius;
gdouble buffer[OVERSAMPLING];
brush = GIMP_BRUSH_GENERATED (data);
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
GimpBrush *gbrush = GIMP_BRUSH (brush);
gint x, y;
guchar *centerp;
gdouble d;
gdouble exponent;
guchar a;
gint length;
gint width, height;
guchar *lookup;
gdouble sum;
gdouble c, s;
gdouble short_radius;
gdouble buffer[OVERSAMPLING];
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
gbrush = GIMP_BRUSH (brush);
if (gbrush->mask)
temp_buf_free (gbrush->mask);
......@@ -331,18 +326,20 @@ gimp_brush_generated_dirty (GimpData *data)
}
GimpData *
gimp_brush_generated_new (gfloat radius,
gfloat hardness,
gfloat angle,
gfloat aspect_ratio,
gboolean stingy_memory_use)
gimp_brush_generated_new (const gchar *name,
gfloat radius,
gfloat hardness,
gfloat angle,
gfloat aspect_ratio,
gboolean stingy_memory_use)
{
GimpBrushGenerated *brush;
/* set up normal brush data */
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL);
g_return_val_if_fail (name != NULL, NULL);
gimp_object_set_name (GIMP_OBJECT (brush), "Untitled");
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED,
"name", name,
NULL);
GIMP_BRUSH (brush)->spacing = 20;
......@@ -367,13 +364,16 @@ gimp_brush_generated_load (const gchar *filename,
GError **error)
{
GimpBrushGenerated *brush;
FILE *fp;
FILE *file;
gchar string[256];
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);
if ((fp = fopen (filename, "rb")) == NULL)
file = fopen (filename, "rb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
......@@ -382,7 +382,7 @@ gimp_brush_generated_load (const gchar *filename,
}
/* make sure the file we are reading is the right type */
fgets (string, 255, fp);
fgets (string, 255, file);
if (strncmp (string, "GIMP-VBR", 8) != 0)
{
......@@ -394,7 +394,7 @@ gimp_brush_generated_load (const gchar *filename,
}
/* make sure we are reading a compatible version */
fgets (string, 255, fp);
fgets (string, 255, file);
if (strncmp (string, "1.0", 3))
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
......@@ -404,38 +404,38 @@ gimp_brush_generated_load (const gchar *filename,
return NULL;
}
/* read name */
fgets (string, 255, file);
g_strstrip (string);
/* create new brush */
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED, NULL);
brush = g_object_new (GIMP_TYPE_BRUSH_GENERATED,
"name", string,
NULL);
gimp_brush_generated_freeze (brush);
/* read name */
fgets (string, 255, fp);
if (string[strlen (string) - 1] == '\n')
string[strlen (string) - 1] = 0;
gimp_object_set_name (GIMP_OBJECT (brush), string);
/* read brush spacing */
fgets (string, 255, fp);
fgets (string, 255, file);
GIMP_BRUSH (brush)->spacing = g_ascii_strtod (string, NULL);
/* read brush radius */
fgets (string, 255, fp);
fgets (string, 255, file);
gimp_brush_generated_set_radius (brush, g_ascii_strtod (string, NULL));
/* read brush hardness */
fgets (string, 255, fp);
fgets (string, 255, file);
gimp_brush_generated_set_hardness (brush, g_ascii_strtod (string, NULL));
/* read brush aspect_ratio */
fgets (string, 255, fp);
fgets (string, 255, file);
gimp_brush_generated_set_aspect_ratio (brush, g_ascii_strtod (string, NULL));
/* read brush angle */
fgets (string, 255, fp);
fgets (string, 255, file);
gimp_brush_generated_set_angle (brush, g_ascii_strtod (string, NULL));
fclose (fp);
fclose (file);
gimp_brush_generated_thaw (brush);
......@@ -461,7 +461,7 @@ gimp_brush_generated_thaw (GimpBrushGenerated *brush)
if (brush->freeze > 0)
brush->freeze--;
if (!brush->freeze)
if (! brush->freeze)
gimp_data_dirty (GIMP_DATA (brush));
}
......@@ -471,18 +471,15 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
{
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
if (radius < 0.0)
radius = 0.0;
else if (radius > 32767.0)
radius = 32767.0;