diff --git a/ChangeLog b/ChangeLog index 6c22bad11f..e1fe86897a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2004-01-29 Michael Natterer + + 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 * app/tools/gimpcurvestool.c diff --git a/app/core/gimpbrush-load.c b/app/core/gimpbrush-load.c index a7952a1636..b4307e0c57 100644 --- a/app/core/gimpbrush-load.c +++ b/app/core/gimpbrush-load.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; diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c index a7952a1636..b4307e0c57 100644 --- a/app/core/gimpbrush.c +++ b/app/core/gimpbrush.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; diff --git a/app/core/gimpbrushgenerated-load.c b/app/core/gimpbrushgenerated-load.c index d1d42f2411..fd480da4d3 100644 --- a/app/core/gimpbrushgenerated-load.c +++ b/app/core/gimpbrushgenerated-load.c @@ -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; + GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data); - 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; + radius = CLAMP (radius, 0.0, 32767.0); - if (radius == brush->radius) - return radius; + if (brush->radius != radius) + { + brush->radius = radius; - brush->radius = radius; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->radius; } @@ -493,18 +490,15 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush, { g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0); - if (hardness < 0.0) - hardness = 0.0; - else if (hardness > 1.0) - hardness = 1.0; + hardness = CLAMP (hardness, 0.0, 1.0); - if (brush->hardness == hardness) - return hardness; + if (brush->hardness != hardness) + { + brush->hardness = hardness; - brush->hardness = hardness; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->hardness; } @@ -520,13 +514,13 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush, else if (angle > 180.0) angle = fmod (angle, 180.0); - if (brush->angle == angle) - return angle; + if (brush->angle != angle) + { + brush->angle = angle; - brush->angle = angle; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->angle; } @@ -537,18 +531,15 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush, { g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0); - if (ratio < 1.0) - ratio = 1.0; - else if (ratio > 1000) - ratio = 1000; + ratio = CLAMP (ratio, 1.0, 1000.0); - if (brush->aspect_ratio == ratio) - return ratio; + if (brush->aspect_ratio != ratio) + { + brush->aspect_ratio = ratio; - brush->aspect_ratio = ratio; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->aspect_ratio; } diff --git a/app/core/gimpbrushgenerated-save.c b/app/core/gimpbrushgenerated-save.c index d1d42f2411..fd480da4d3 100644 --- a/app/core/gimpbrushgenerated-save.c +++ b/app/core/gimpbrushgenerated-save.c @@ -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; + GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data); - 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; + radius = CLAMP (radius, 0.0, 32767.0); - if (radius == brush->radius) - return radius; + if (brush->radius != radius) + { + brush->radius = radius; - brush->radius = radius; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->radius; } @@ -493,18 +490,15 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush, { g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0); - if (hardness < 0.0) - hardness = 0.0; - else if (hardness > 1.0) - hardness = 1.0; + hardness = CLAMP (hardness, 0.0, 1.0); - if (brush->hardness == hardness) - return hardness; + if (brush->hardness != hardness) + { + brush->hardness = hardness; - brush->hardness = hardness; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->hardness; } @@ -520,13 +514,13 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush, else if (angle > 180.0) angle = fmod (angle, 180.0); - if (brush->angle == angle) - return angle; + if (brush->angle != angle) + { + brush->angle = angle; - brush->angle = angle; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->angle; } @@ -537,18 +531,15 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush, { g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0); - if (ratio < 1.0) - ratio = 1.0; - else if (ratio > 1000) - ratio = 1000; + ratio = CLAMP (ratio, 1.0, 1000.0); - if (brush->aspect_ratio == ratio) - return ratio; + if (brush->aspect_ratio != ratio) + { + brush->aspect_ratio = ratio; - brush->aspect_ratio = ratio; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->aspect_ratio; } diff --git a/app/core/gimpbrushgenerated.c b/app/core/gimpbrushgenerated.c index d1d42f2411..fd480da4d3 100644 --- a/app/core/gimpbrushgenerated.c +++ b/app/core/gimpbrushgenerated.c @@ -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; + GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data); - 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; + radius = CLAMP (radius, 0.0, 32767.0); - if (radius == brush->radius) - return radius; + if (brush->radius != radius) + { + brush->radius = radius; - brush->radius = radius; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->radius; } @@ -493,18 +490,15 @@ gimp_brush_generated_set_hardness (GimpBrushGenerated *brush, { g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0); - if (hardness < 0.0) - hardness = 0.0; - else if (hardness > 1.0) - hardness = 1.0; + hardness = CLAMP (hardness, 0.0, 1.0); - if (brush->hardness == hardness) - return hardness; + if (brush->hardness != hardness) + { + brush->hardness = hardness; - brush->hardness = hardness; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->hardness; } @@ -520,13 +514,13 @@ gimp_brush_generated_set_angle (GimpBrushGenerated *brush, else if (angle > 180.0) angle = fmod (angle, 180.0); - if (brush->angle == angle) - return angle; + if (brush->angle != angle) + { + brush->angle = angle; - brush->angle = angle; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->angle; } @@ -537,18 +531,15 @@ gimp_brush_generated_set_aspect_ratio (GimpBrushGenerated *brush, { g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0); - if (ratio < 1.0) - ratio = 1.0; - else if (ratio > 1000) - ratio = 1000; + ratio = CLAMP (ratio, 1.0, 1000.0); - if (brush->aspect_ratio == ratio) - return ratio; + if (brush->aspect_ratio != ratio) + { + brush->aspect_ratio = ratio; - brush->aspect_ratio = ratio; - - if (!brush->freeze) - gimp_data_dirty (GIMP_DATA (brush)); + if (! brush->freeze) + gimp_data_dirty (GIMP_DATA (brush)); + } return brush->aspect_ratio; } diff --git a/app/core/gimpbrushgenerated.h b/app/core/gimpbrushgenerated.h index 381514fd1e..5f320086a0 100644 --- a/app/core/gimpbrushgenerated.h +++ b/app/core/gimpbrushgenerated.h @@ -59,7 +59,8 @@ struct _GimpBrushGeneratedClass GType gimp_brush_generated_get_type (void) G_GNUC_CONST; -GimpData * gimp_brush_generated_new (gfloat radius, +GimpData * gimp_brush_generated_new (const gchar *name, + gfloat radius, gfloat hardness, gfloat angle, gfloat aspect_ratio, diff --git a/app/core/gimpbrushpipe-load.c b/app/core/gimpbrushpipe-load.c index d3191f1ad4..5ca458dfef 100644 --- a/app/core/gimpbrushpipe-load.c +++ b/app/core/gimpbrushpipe-load.c @@ -92,19 +92,19 @@ gimp_brush_pipe_get_type (void) static const GTypeInfo brush_info = { sizeof (GimpBrushPipeClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gimp_brush_pipe_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpBrushPipe), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_brush_pipe_init, + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_brush_pipe_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpBrushPipe), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_brush_pipe_init, }; brush_type = g_type_register_static (GIMP_TYPE_BRUSH, - "GimpBrushPipe", - &brush_info, 0); + "GimpBrushPipe", + &brush_info, 0); } return brush_type; @@ -151,11 +151,7 @@ gimp_brush_pipe_init (GimpBrushPipe *pipe) static void gimp_brush_pipe_finalize (GObject *object) { - GimpBrushPipe *pipe; - - g_return_if_fail (GIMP_IS_BRUSH_PIPE (object)); - - pipe = GIMP_BRUSH_PIPE (object); + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (object); if (pipe->rank) { @@ -201,12 +197,10 @@ static gint64 gimp_brush_pipe_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpBrushPipe *pipe; + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (object); gint64 memsize = 0; gint i; - pipe = GIMP_BRUSH_PIPE (object); - memsize += pipe->dimension * (sizeof (gint) /* rank */ + sizeof (gint) /* stride */ + sizeof (PipeSelectModes)); @@ -227,9 +221,7 @@ gimp_brush_pipe_get_popup_size (GimpViewable *viewable, gint *popup_width, gint *popup_height) { - GimpBrush *brush; - - brush = GIMP_BRUSH (viewable); + GimpBrush *brush = GIMP_BRUSH (viewable); *popup_width = brush->mask->width; *popup_height = brush->mask->height; @@ -242,13 +234,11 @@ gimp_brush_pipe_select_brush (GimpBrush *brush, GimpCoords *last_coords, GimpCoords *cur_coords) { - GimpBrushPipe *pipe; + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (brush); gint i, brushix, ix; gdouble angle; GRand *gr; - pipe = GIMP_BRUSH_PIPE (brush); - if (pipe->nbrushes == 1) return GIMP_BRUSH (pipe->current); @@ -263,6 +253,7 @@ gimp_brush_pipe_select_brush (GimpBrush *brush, case PIPE_SELECT_INCREMENTAL: ix = (pipe->index[i] + 1) % pipe->rank[i]; break; + case PIPE_SELECT_ANGULAR: angle = atan2 (cur_coords->y - last_coords->y, cur_coords->x - last_coords->x); @@ -275,31 +266,36 @@ gimp_brush_pipe_select_brush (GimpBrush *brush, angle -= 2.0 * G_PI; ix = RINT (angle / (2.0 * G_PI) * pipe->rank[i]); break; + case PIPE_SELECT_RANDOM: /* This probably isn't the right way */ ix = g_rand_int_range (gr, 0, pipe->rank[i]); break; + case PIPE_SELECT_PRESSURE: ix = RINT (cur_coords->pressure * (pipe->rank[i] - 1)); break; + case PIPE_SELECT_TILT_X: - ix = RINT (cur_coords->xtilt / 2.0 * pipe->rank[i]) + pipe->rank[i]/2; + ix = RINT (cur_coords->xtilt / 2.0 * pipe->rank[i]) + pipe->rank[i] / 2; break; + case PIPE_SELECT_TILT_Y: - ix = RINT (cur_coords->ytilt / 2.0 * pipe->rank[i]) + pipe->rank[i]/2; + ix = RINT (cur_coords->ytilt / 2.0 * pipe->rank[i]) + pipe->rank[i] / 2; break; + case PIPE_SELECT_CONSTANT: default: ix = pipe->index[i]; break; } - pipe->index[i] = CLAMP (ix, 0, pipe->rank[i]-1); + pipe->index[i] = CLAMP (ix, 0, pipe->rank[i] - 1); brushix += pipe->stride[i] * pipe->index[i]; } /* Make sure is inside bounds */ - brushix = CLAMP (brushix, 0, pipe->nbrushes-1); + brushix = CLAMP (brushix, 0, pipe->nbrushes - 1); pipe->current = pipe->brushes[brushix]; @@ -313,11 +309,9 @@ gimp_brush_pipe_want_null_motion (GimpBrush *brush, GimpCoords *last_coords, GimpCoords *cur_coords) { - GimpBrushPipe *pipe; + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (brush); gint i; - pipe = GIMP_BRUSH_PIPE (brush); - if (pipe->nbrushes == 1) return TRUE; @@ -344,9 +338,11 @@ gimp_brush_pipe_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); + if (fd == -1) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, @@ -364,22 +360,21 @@ gimp_brush_pipe_load (const gchar *filename, if (buffer->len > 0 && buffer->len < 1024) { - pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE, NULL); + gchar *utf8 = + gimp_any_to_utf8 (buffer->str, buffer->len, + _("Invalid UTF-8 string in brush file '%s'."), + gimp_filename_to_utf8 (filename)); - if (g_utf8_validate (buffer->str, buffer->len, NULL)) - { - gimp_object_set_name (GIMP_OBJECT (pipe), buffer->str); - } - else - { - g_message (_("Invalid UTF-8 string in brush file '%s'."), - gimp_filename_to_utf8 (filename)); - gimp_object_set_name (GIMP_OBJECT (pipe), _("Unnamed")); - } + pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE, + "name", utf8, + NULL); + + g_free (utf8); } + g_string_free (buffer, TRUE); - if (!pipe) + if (! pipe) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in brush file '%s': " diff --git a/app/core/gimpbrushpipe.c b/app/core/gimpbrushpipe.c index d3191f1ad4..5ca458dfef 100644 --- a/app/core/gimpbrushpipe.c +++ b/app/core/gimpbrushpipe.c @@ -92,19 +92,19 @@ gimp_brush_pipe_get_type (void) static const GTypeInfo brush_info = { sizeof (GimpBrushPipeClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gimp_brush_pipe_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpBrushPipe), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_brush_pipe_init, + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_brush_pipe_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpBrushPipe), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_brush_pipe_init, }; brush_type = g_type_register_static (GIMP_TYPE_BRUSH, - "GimpBrushPipe", - &brush_info, 0); + "GimpBrushPipe", + &brush_info, 0); } return brush_type; @@ -151,11 +151,7 @@ gimp_brush_pipe_init (GimpBrushPipe *pipe) static void gimp_brush_pipe_finalize (GObject *object) { - GimpBrushPipe *pipe; - - g_return_if_fail (GIMP_IS_BRUSH_PIPE (object)); - - pipe = GIMP_BRUSH_PIPE (object); + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (object); if (pipe->rank) { @@ -201,12 +197,10 @@ static gint64 gimp_brush_pipe_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpBrushPipe *pipe; + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (object); gint64 memsize = 0; gint i; - pipe = GIMP_BRUSH_PIPE (object); - memsize += pipe->dimension * (sizeof (gint) /* rank */ + sizeof (gint) /* stride */ + sizeof (PipeSelectModes)); @@ -227,9 +221,7 @@ gimp_brush_pipe_get_popup_size (GimpViewable *viewable, gint *popup_width, gint *popup_height) { - GimpBrush *brush; - - brush = GIMP_BRUSH (viewable); + GimpBrush *brush = GIMP_BRUSH (viewable); *popup_width = brush->mask->width; *popup_height = brush->mask->height; @@ -242,13 +234,11 @@ gimp_brush_pipe_select_brush (GimpBrush *brush, GimpCoords *last_coords, GimpCoords *cur_coords) { - GimpBrushPipe *pipe; + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (brush); gint i, brushix, ix; gdouble angle; GRand *gr; - pipe = GIMP_BRUSH_PIPE (brush); - if (pipe->nbrushes == 1) return GIMP_BRUSH (pipe->current); @@ -263,6 +253,7 @@ gimp_brush_pipe_select_brush (GimpBrush *brush, case PIPE_SELECT_INCREMENTAL: ix = (pipe->index[i] + 1) % pipe->rank[i]; break; + case PIPE_SELECT_ANGULAR: angle = atan2 (cur_coords->y - last_coords->y, cur_coords->x - last_coords->x); @@ -275,31 +266,36 @@ gimp_brush_pipe_select_brush (GimpBrush *brush, angle -= 2.0 * G_PI; ix = RINT (angle / (2.0 * G_PI) * pipe->rank[i]); break; + case PIPE_SELECT_RANDOM: /* This probably isn't the right way */ ix = g_rand_int_range (gr, 0, pipe->rank[i]); break; + case PIPE_SELECT_PRESSURE: ix = RINT (cur_coords->pressure * (pipe->rank[i] - 1)); break; + case PIPE_SELECT_TILT_X: - ix = RINT (cur_coords->xtilt / 2.0 * pipe->rank[i]) + pipe->rank[i]/2; + ix = RINT (cur_coords->xtilt / 2.0 * pipe->rank[i]) + pipe->rank[i] / 2; break; + case PIPE_SELECT_TILT_Y: - ix = RINT (cur_coords->ytilt / 2.0 * pipe->rank[i]) + pipe->rank[i]/2; + ix = RINT (cur_coords->ytilt / 2.0 * pipe->rank[i]) + pipe->rank[i] / 2; break; + case PIPE_SELECT_CONSTANT: default: ix = pipe->index[i]; break; } - pipe->index[i] = CLAMP (ix, 0, pipe->rank[i]-1); + pipe->index[i] = CLAMP (ix, 0, pipe->rank[i] - 1); brushix += pipe->stride[i] * pipe->index[i]; } /* Make sure is inside bounds */ - brushix = CLAMP (brushix, 0, pipe->nbrushes-1); + brushix = CLAMP (brushix, 0, pipe->nbrushes - 1); pipe->current = pipe->brushes[brushix]; @@ -313,11 +309,9 @@ gimp_brush_pipe_want_null_motion (GimpBrush *brush, GimpCoords *last_coords, GimpCoords *cur_coords) { - GimpBrushPipe *pipe; + GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (brush); gint i; - pipe = GIMP_BRUSH_PIPE (brush); - if (pipe->nbrushes == 1) return TRUE; @@ -344,9 +338,11 @@ gimp_brush_pipe_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); + if (fd == -1) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, @@ -364,22 +360,21 @@ gimp_brush_pipe_load (const gchar *filename, if (buffer->len > 0 && buffer->len < 1024) { - pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE, NULL); + gchar *utf8 = + gimp_any_to_utf8 (buffer->str, buffer->len, + _("Invalid UTF-8 string in brush file '%s'."), + gimp_filename_to_utf8 (filename)); - if (g_utf8_validate (buffer->str, buffer->len, NULL)) - { - gimp_object_set_name (GIMP_OBJECT (pipe), buffer->str); - } - else - { - g_message (_("Invalid UTF-8 string in brush file '%s'."), - gimp_filename_to_utf8 (filename)); - gimp_object_set_name (GIMP_OBJECT (pipe), _("Unnamed")); - } + pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE, + "name", utf8, + NULL); + + g_free (utf8); } + g_string_free (buffer, TRUE); - if (!pipe) + if (! pipe) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in brush file '%s': " diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c index 08a5c75dbd..e60a44231a 100644 --- a/app/core/gimpdata.c +++ b/app/core/gimpdata.c @@ -84,19 +84,19 @@ gimp_data_get_type (void) static const GTypeInfo data_info = { sizeof (GimpDataClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gimp_data_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpData), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_data_init, + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_data_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpData), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_data_init, }; data_type = g_type_register_static (GIMP_TYPE_VIEWABLE, - "GimpData", - &data_info, 0); + "GimpData", + &data_info, 0); } return data_type; @@ -137,8 +137,8 @@ static void gimp_data_init (GimpData *data) { data->filename = NULL; - data->writeable = TRUE; - data->dirty = FALSE; + data->writeable = FALSE; + data->dirty = TRUE; data->internal = FALSE; } @@ -306,6 +306,7 @@ gimp_data_create_filename (GimpData *data, g_return_if_fail (GIMP_IS_DATA (data)); g_return_if_fail (basename != NULL); g_return_if_fail (dest_dir != NULL); + g_return_if_fail (g_path_is_absolute (dest_dir)); safe_name = g_strdup (basename); if (safe_name[0] == '.') @@ -363,9 +364,10 @@ gimp_data_duplicate (GimpData *data, GQuark gimp_data_error_quark (void) { - static GQuark q = 0; - if (q == 0) - q = g_quark_from_static_string ("gimp-data-error-quark"); + static GQuark quark = 0; - return q; + if (! quark) + quark = g_quark_from_static_string ("gimp-data-error-quark"); + + return quark; } diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c index dc0af56a66..1b0fc61d77 100644 --- a/app/core/gimpgradient.c +++ b/app/core/gimpgradient.c @@ -97,19 +97,19 @@ gimp_gradient_get_type (void) static const GTypeInfo gradient_info = { sizeof (GimpGradientClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gimp_gradient_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpGradient), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_gradient_init, + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_gradient_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpGradient), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_gradient_init, }; gradient_type = g_type_register_static (GIMP_TYPE_DATA, - "GimpGradient", - &gradient_info, 0); + "GimpGradient", + &gradient_info, 0); } return gradient_type; @@ -312,16 +312,19 @@ gimp_gradient_new (const gchar *name, GimpData * gimp_gradient_get_standard (void) { - static GimpGradient *standard_gradient = NULL; + static GimpData *standard_gradient = NULL; if (! standard_gradient) { - standard_gradient = GIMP_GRADIENT (gimp_gradient_new ("Standard", FALSE)); + standard_gradient = gimp_gradient_new ("Standard", FALSE); + + standard_gradient->dirty = FALSE; + standard_gradient->internal = TRUE; g_object_ref (standard_gradient); } - return GIMP_DATA (standard_gradient); + return standard_gradient; } GimpData * @@ -339,6 +342,7 @@ gimp_gradient_load (const gchar *filename, gchar line[1024]; 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 = fopen (filename, "rb"); @@ -469,9 +473,7 @@ gimp_gradient_load (const gchar *filename, static void gimp_gradient_dirty (GimpData *data) { - GimpGradient *gradient; - - gradient = GIMP_GRADIENT (data); + GimpGradient *gradient = GIMP_GRADIENT (data); gradient->last_visited = NULL; @@ -483,14 +485,13 @@ static gboolean gimp_gradient_save (GimpData *data, GError **error) { - GimpGradient *gradient; + GimpGradient *gradient = GIMP_GRADIENT (data); GimpGradientSegment *seg; gint num_segments; FILE *file; - gradient = GIMP_GRADIENT (data); - file = fopen (data->filename, "wb"); + if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c index 4d1e2528f7..a4e7233322 100644 --- a/app/core/gimppalette-load.c +++ b/app/core/gimppalette-load.c @@ -67,7 +67,6 @@ static TempBuf * gimp_palette_get_new_preview (GimpViewable *viewable, gint height); static gchar * gimp_palette_get_description (GimpViewable *viewable, gchar **tooltip); -static void gimp_palette_dirty (GimpData *data); static gboolean gimp_palette_save (GimpData *data, GError **error); static gchar * gimp_palette_get_extension (GimpData *data); @@ -92,19 +91,19 @@ gimp_palette_get_type (void) static const GTypeInfo palette_info = { sizeof (GimpPaletteClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gimp_palette_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpPalette), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_palette_init, + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_palette_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpPalette), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_palette_init, }; palette_type = g_type_register_static (GIMP_TYPE_DATA, - "GimpPalette", - &palette_info, 0); + "GimpPalette", + &palette_info, 0); } return palette_type; @@ -135,7 +134,6 @@ gimp_palette_class_init (GimpPaletteClass *klass) viewable_class->get_new_preview = gimp_palette_get_new_preview; viewable_class->get_description = gimp_palette_get_description; - data_class->dirty = gimp_palette_dirty; data_class->save = gimp_palette_save; data_class->get_extension = gimp_palette_get_extension; data_class->duplicate = gimp_palette_duplicate; @@ -168,15 +166,13 @@ static gint64 gimp_palette_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (object); GList *list; gint64 memsize = 0; - palette = GIMP_PALETTE (object); - for (list = palette->colors; list; list = g_list_next (list)) { - GimpPaletteEntry *entry = (GimpPaletteEntry *) list->data; + GimpPaletteEntry *entry = list->data; memsize += sizeof (GList) + sizeof (GimpPaletteEntry); @@ -208,12 +204,10 @@ gimp_palette_get_popup_size (GimpViewable *viewable, gint *popup_width, gint *popup_height) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (viewable); gint p_width; gint p_height; - palette = GIMP_PALETTE (viewable); - if (! palette->n_colors) return FALSE; @@ -240,7 +234,7 @@ gimp_palette_get_new_preview (GimpViewable *viewable, gint width, gint height) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (viewable); GimpPaletteEntry *entry; TempBuf *temp_buf; guchar *buf; @@ -252,8 +246,6 @@ gimp_palette_get_new_preview (GimpViewable *viewable, gint cell_size; gint x, y, i; - palette = GIMP_PALETTE (viewable); - temp_buf = temp_buf_new (width, height, 3, 0, 0, @@ -324,33 +316,30 @@ GimpData * gimp_palette_new (const gchar *name, gboolean stingy_memory_use) { - GimpPalette *palette = NULL; - g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (*name != '\0', NULL); - palette = g_object_new (GIMP_TYPE_PALETTE, - "name", name, - NULL); - - gimp_data_dirty (GIMP_DATA (palette)); - - return GIMP_DATA (palette); + return g_object_new (GIMP_TYPE_PALETTE, + "name", name, + NULL); } GimpData * gimp_palette_get_standard (void) { - static GimpPalette *standard_palette = NULL; + static GimpData *standard_palette = NULL; if (! standard_palette) { - standard_palette = g_object_new (GIMP_TYPE_PALETTE, NULL); + standard_palette = gimp_palette_new ("Standard", FALSE); - gimp_object_set_name (GIMP_OBJECT (standard_palette), "Standard"); + standard_palette->dirty = FALSE; + standard_palette->internal = TRUE; + + g_object_ref (standard_palette); } - return GIMP_DATA (standard_palette); + return standard_palette; } GimpData * @@ -361,19 +350,20 @@ gimp_palette_load (const gchar *filename, GimpPalette *palette; gchar str[1024]; gchar *tok; - FILE *fp; + FILE *file; gint r, g, b; GimpRGB color; gint linenum; g_return_val_if_fail (filename != NULL, NULL); - g_return_val_if_fail (*filename != '\0', NULL); + g_return_val_if_fail (g_path_is_absolute (filename), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); r = g = b = 0; - /* Open the requested file */ - if (! (fp = fopen (filename, "r"))) + file = fopen (filename, "r"); + + if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for reading: %s"), @@ -383,7 +373,7 @@ gimp_palette_load (const gchar *filename, linenum = 0; - fread (str, 13, 1, fp); + fread (str, 13, 1, file); str[13] = '\0'; linenum++; if (strcmp (str, "GIMP Palette\n")) @@ -401,20 +391,20 @@ gimp_palette_load (const gchar *filename, "Missing magic header."), gimp_filename_to_utf8 (filename)); - fclose (fp); + fclose (file); return NULL; } palette = g_object_new (GIMP_TYPE_PALETTE, NULL); - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -433,13 +423,13 @@ gimp_palette_load (const gchar *filename, gimp_object_set_name (GIMP_OBJECT (palette), utf8); g_free (utf8); - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -463,13 +453,13 @@ gimp_palette_load (const gchar *filename, palette->n_columns = columns; - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -491,7 +481,7 @@ gimp_palette_load (const gchar *filename, g_free (utf8); } - while (! feof (fp)) + while (! feof (file)) { if (str[0] != '#') { @@ -539,16 +529,16 @@ gimp_palette_load (const gchar *filename, gimp_palette_add_entry (palette, tok, &color); } - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { - if (feof (fp)) + if (feof (file)) break; g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -556,31 +546,22 @@ gimp_palette_load (const gchar *filename, linenum++; } - fclose (fp); + fclose (file); return GIMP_DATA (palette); } -static void -gimp_palette_dirty (GimpData *data) -{ - if (GIMP_DATA_CLASS (parent_class)->dirty) - GIMP_DATA_CLASS (parent_class)->dirty (data); -} - static gboolean gimp_palette_save (GimpData *data, GError **error) { - GimpPalette *palette; - GimpPaletteEntry *entry; - GList *list; - FILE *fp; - guchar r, g, b; + GimpPalette *palette = GIMP_PALETTE (data); + GList *list; + FILE *file; - palette = GIMP_PALETTE (data); + file = fopen (data->filename, "w"); - if (! (fp = fopen (data->filename, "w"))) + if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for writing: %s"), @@ -589,22 +570,21 @@ gimp_palette_save (GimpData *data, return FALSE; } - fprintf (fp, "GIMP Palette\n"); - fprintf (fp, "Name: %s\n", GIMP_OBJECT (palette)->name); - fprintf (fp, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256)); + fprintf (file, "GIMP Palette\n"); + fprintf (file, "Name: %s\n", GIMP_OBJECT (palette)->name); + fprintf (file, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256)); for (list = palette->colors; list; list = g_list_next (list)) { - entry = (GimpPaletteEntry *) list->data; + GimpPaletteEntry *entry = list->data; + guchar r, g, b; gimp_rgb_get_uchar (&entry->color, &r, &g, &b); - fprintf (fp, "%3d %3d %3d\t%s\n", - r, g, b, - entry->name); + fprintf (file, "%3d %3d %3d\t%s\n", r, g, b, entry->name); } - fclose (fp); + fclose (file); return TRUE; } @@ -619,12 +599,10 @@ static GimpData * gimp_palette_duplicate (GimpData *data, gboolean stingy_memory_use) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (data); GimpPalette *new; GList *list; - palette = GIMP_PALETTE (data); - new = g_object_new (GIMP_TYPE_PALETTE, NULL); new->n_columns = palette->n_columns; @@ -659,7 +637,8 @@ gimp_palette_add_entry (GimpPalette *palette, palette->colors = g_list_append (palette->colors, entry); palette->n_colors += 1; - gimp_data_dirty (GIMP_DATA (palette)); + /* will make the palette dirty too */ + gimp_object_name_changed (GIMP_OBJECT (palette)); return entry; } @@ -703,7 +682,8 @@ gimp_palette_delete_entry (GimpPalette *palette, &color); } - gimp_data_dirty (GIMP_DATA (palette)); + /* will make the palette dirty too */ + gimp_object_name_changed (GIMP_OBJECT (palette)); } } diff --git a/app/core/gimppalette-save.c b/app/core/gimppalette-save.c index 4d1e2528f7..a4e7233322 100644 --- a/app/core/gimppalette-save.c +++ b/app/core/gimppalette-save.c @@ -67,7 +67,6 @@ static TempBuf * gimp_palette_get_new_preview (GimpViewable *viewable, gint height); static gchar * gimp_palette_get_description (GimpViewable *viewable, gchar **tooltip); -static void gimp_palette_dirty (GimpData *data); static gboolean gimp_palette_save (GimpData *data, GError **error); static gchar * gimp_palette_get_extension (GimpData *data); @@ -92,19 +91,19 @@ gimp_palette_get_type (void) static const GTypeInfo palette_info = { sizeof (GimpPaletteClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gimp_palette_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpPalette), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_palette_init, + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_palette_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpPalette), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_palette_init, }; palette_type = g_type_register_static (GIMP_TYPE_DATA, - "GimpPalette", - &palette_info, 0); + "GimpPalette", + &palette_info, 0); } return palette_type; @@ -135,7 +134,6 @@ gimp_palette_class_init (GimpPaletteClass *klass) viewable_class->get_new_preview = gimp_palette_get_new_preview; viewable_class->get_description = gimp_palette_get_description; - data_class->dirty = gimp_palette_dirty; data_class->save = gimp_palette_save; data_class->get_extension = gimp_palette_get_extension; data_class->duplicate = gimp_palette_duplicate; @@ -168,15 +166,13 @@ static gint64 gimp_palette_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (object); GList *list; gint64 memsize = 0; - palette = GIMP_PALETTE (object); - for (list = palette->colors; list; list = g_list_next (list)) { - GimpPaletteEntry *entry = (GimpPaletteEntry *) list->data; + GimpPaletteEntry *entry = list->data; memsize += sizeof (GList) + sizeof (GimpPaletteEntry); @@ -208,12 +204,10 @@ gimp_palette_get_popup_size (GimpViewable *viewable, gint *popup_width, gint *popup_height) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (viewable); gint p_width; gint p_height; - palette = GIMP_PALETTE (viewable); - if (! palette->n_colors) return FALSE; @@ -240,7 +234,7 @@ gimp_palette_get_new_preview (GimpViewable *viewable, gint width, gint height) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (viewable); GimpPaletteEntry *entry; TempBuf *temp_buf; guchar *buf; @@ -252,8 +246,6 @@ gimp_palette_get_new_preview (GimpViewable *viewable, gint cell_size; gint x, y, i; - palette = GIMP_PALETTE (viewable); - temp_buf = temp_buf_new (width, height, 3, 0, 0, @@ -324,33 +316,30 @@ GimpData * gimp_palette_new (const gchar *name, gboolean stingy_memory_use) { - GimpPalette *palette = NULL; - g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (*name != '\0', NULL); - palette = g_object_new (GIMP_TYPE_PALETTE, - "name", name, - NULL); - - gimp_data_dirty (GIMP_DATA (palette)); - - return GIMP_DATA (palette); + return g_object_new (GIMP_TYPE_PALETTE, + "name", name, + NULL); } GimpData * gimp_palette_get_standard (void) { - static GimpPalette *standard_palette = NULL; + static GimpData *standard_palette = NULL; if (! standard_palette) { - standard_palette = g_object_new (GIMP_TYPE_PALETTE, NULL); + standard_palette = gimp_palette_new ("Standard", FALSE); - gimp_object_set_name (GIMP_OBJECT (standard_palette), "Standard"); + standard_palette->dirty = FALSE; + standard_palette->internal = TRUE; + + g_object_ref (standard_palette); } - return GIMP_DATA (standard_palette); + return standard_palette; } GimpData * @@ -361,19 +350,20 @@ gimp_palette_load (const gchar *filename, GimpPalette *palette; gchar str[1024]; gchar *tok; - FILE *fp; + FILE *file; gint r, g, b; GimpRGB color; gint linenum; g_return_val_if_fail (filename != NULL, NULL); - g_return_val_if_fail (*filename != '\0', NULL); + g_return_val_if_fail (g_path_is_absolute (filename), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); r = g = b = 0; - /* Open the requested file */ - if (! (fp = fopen (filename, "r"))) + file = fopen (filename, "r"); + + if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for reading: %s"), @@ -383,7 +373,7 @@ gimp_palette_load (const gchar *filename, linenum = 0; - fread (str, 13, 1, fp); + fread (str, 13, 1, file); str[13] = '\0'; linenum++; if (strcmp (str, "GIMP Palette\n")) @@ -401,20 +391,20 @@ gimp_palette_load (const gchar *filename, "Missing magic header."), gimp_filename_to_utf8 (filename)); - fclose (fp); + fclose (file); return NULL; } palette = g_object_new (GIMP_TYPE_PALETTE, NULL); - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -433,13 +423,13 @@ gimp_palette_load (const gchar *filename, gimp_object_set_name (GIMP_OBJECT (palette), utf8); g_free (utf8); - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -463,13 +453,13 @@ gimp_palette_load (const gchar *filename, palette->n_columns = columns; - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -491,7 +481,7 @@ gimp_palette_load (const gchar *filename, g_free (utf8); } - while (! feof (fp)) + while (! feof (file)) { if (str[0] != '#') { @@ -539,16 +529,16 @@ gimp_palette_load (const gchar *filename, gimp_palette_add_entry (palette, tok, &color); } - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { - if (feof (fp)) + if (feof (file)) break; g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -556,31 +546,22 @@ gimp_palette_load (const gchar *filename, linenum++; } - fclose (fp); + fclose (file); return GIMP_DATA (palette); } -static void -gimp_palette_dirty (GimpData *data) -{ - if (GIMP_DATA_CLASS (parent_class)->dirty) - GIMP_DATA_CLASS (parent_class)->dirty (data); -} - static gboolean gimp_palette_save (GimpData *data, GError **error) { - GimpPalette *palette; - GimpPaletteEntry *entry; - GList *list; - FILE *fp; - guchar r, g, b; + GimpPalette *palette = GIMP_PALETTE (data); + GList *list; + FILE *file; - palette = GIMP_PALETTE (data); + file = fopen (data->filename, "w"); - if (! (fp = fopen (data->filename, "w"))) + if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for writing: %s"), @@ -589,22 +570,21 @@ gimp_palette_save (GimpData *data, return FALSE; } - fprintf (fp, "GIMP Palette\n"); - fprintf (fp, "Name: %s\n", GIMP_OBJECT (palette)->name); - fprintf (fp, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256)); + fprintf (file, "GIMP Palette\n"); + fprintf (file, "Name: %s\n", GIMP_OBJECT (palette)->name); + fprintf (file, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256)); for (list = palette->colors; list; list = g_list_next (list)) { - entry = (GimpPaletteEntry *) list->data; + GimpPaletteEntry *entry = list->data; + guchar r, g, b; gimp_rgb_get_uchar (&entry->color, &r, &g, &b); - fprintf (fp, "%3d %3d %3d\t%s\n", - r, g, b, - entry->name); + fprintf (file, "%3d %3d %3d\t%s\n", r, g, b, entry->name); } - fclose (fp); + fclose (file); return TRUE; } @@ -619,12 +599,10 @@ static GimpData * gimp_palette_duplicate (GimpData *data, gboolean stingy_memory_use) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (data); GimpPalette *new; GList *list; - palette = GIMP_PALETTE (data); - new = g_object_new (GIMP_TYPE_PALETTE, NULL); new->n_columns = palette->n_columns; @@ -659,7 +637,8 @@ gimp_palette_add_entry (GimpPalette *palette, palette->colors = g_list_append (palette->colors, entry); palette->n_colors += 1; - gimp_data_dirty (GIMP_DATA (palette)); + /* will make the palette dirty too */ + gimp_object_name_changed (GIMP_OBJECT (palette)); return entry; } @@ -703,7 +682,8 @@ gimp_palette_delete_entry (GimpPalette *palette, &color); } - gimp_data_dirty (GIMP_DATA (palette)); + /* will make the palette dirty too */ + gimp_object_name_changed (GIMP_OBJECT (palette)); } } diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c index 4d1e2528f7..a4e7233322 100644 --- a/app/core/gimppalette.c +++ b/app/core/gimppalette.c @@ -67,7 +67,6 @@ static TempBuf * gimp_palette_get_new_preview (GimpViewable *viewable, gint height); static gchar * gimp_palette_get_description (GimpViewable *viewable, gchar **tooltip); -static void gimp_palette_dirty (GimpData *data); static gboolean gimp_palette_save (GimpData *data, GError **error); static gchar * gimp_palette_get_extension (GimpData *data); @@ -92,19 +91,19 @@ gimp_palette_get_type (void) static const GTypeInfo palette_info = { sizeof (GimpPaletteClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gimp_palette_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpPalette), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_palette_init, + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_palette_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpPalette), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_palette_init, }; palette_type = g_type_register_static (GIMP_TYPE_DATA, - "GimpPalette", - &palette_info, 0); + "GimpPalette", + &palette_info, 0); } return palette_type; @@ -135,7 +134,6 @@ gimp_palette_class_init (GimpPaletteClass *klass) viewable_class->get_new_preview = gimp_palette_get_new_preview; viewable_class->get_description = gimp_palette_get_description; - data_class->dirty = gimp_palette_dirty; data_class->save = gimp_palette_save; data_class->get_extension = gimp_palette_get_extension; data_class->duplicate = gimp_palette_duplicate; @@ -168,15 +166,13 @@ static gint64 gimp_palette_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (object); GList *list; gint64 memsize = 0; - palette = GIMP_PALETTE (object); - for (list = palette->colors; list; list = g_list_next (list)) { - GimpPaletteEntry *entry = (GimpPaletteEntry *) list->data; + GimpPaletteEntry *entry = list->data; memsize += sizeof (GList) + sizeof (GimpPaletteEntry); @@ -208,12 +204,10 @@ gimp_palette_get_popup_size (GimpViewable *viewable, gint *popup_width, gint *popup_height) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (viewable); gint p_width; gint p_height; - palette = GIMP_PALETTE (viewable); - if (! palette->n_colors) return FALSE; @@ -240,7 +234,7 @@ gimp_palette_get_new_preview (GimpViewable *viewable, gint width, gint height) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (viewable); GimpPaletteEntry *entry; TempBuf *temp_buf; guchar *buf; @@ -252,8 +246,6 @@ gimp_palette_get_new_preview (GimpViewable *viewable, gint cell_size; gint x, y, i; - palette = GIMP_PALETTE (viewable); - temp_buf = temp_buf_new (width, height, 3, 0, 0, @@ -324,33 +316,30 @@ GimpData * gimp_palette_new (const gchar *name, gboolean stingy_memory_use) { - GimpPalette *palette = NULL; - g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (*name != '\0', NULL); - palette = g_object_new (GIMP_TYPE_PALETTE, - "name", name, - NULL); - - gimp_data_dirty (GIMP_DATA (palette)); - - return GIMP_DATA (palette); + return g_object_new (GIMP_TYPE_PALETTE, + "name", name, + NULL); } GimpData * gimp_palette_get_standard (void) { - static GimpPalette *standard_palette = NULL; + static GimpData *standard_palette = NULL; if (! standard_palette) { - standard_palette = g_object_new (GIMP_TYPE_PALETTE, NULL); + standard_palette = gimp_palette_new ("Standard", FALSE); - gimp_object_set_name (GIMP_OBJECT (standard_palette), "Standard"); + standard_palette->dirty = FALSE; + standard_palette->internal = TRUE; + + g_object_ref (standard_palette); } - return GIMP_DATA (standard_palette); + return standard_palette; } GimpData * @@ -361,19 +350,20 @@ gimp_palette_load (const gchar *filename, GimpPalette *palette; gchar str[1024]; gchar *tok; - FILE *fp; + FILE *file; gint r, g, b; GimpRGB color; gint linenum; g_return_val_if_fail (filename != NULL, NULL); - g_return_val_if_fail (*filename != '\0', NULL); + g_return_val_if_fail (g_path_is_absolute (filename), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); r = g = b = 0; - /* Open the requested file */ - if (! (fp = fopen (filename, "r"))) + file = fopen (filename, "r"); + + if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for reading: %s"), @@ -383,7 +373,7 @@ gimp_palette_load (const gchar *filename, linenum = 0; - fread (str, 13, 1, fp); + fread (str, 13, 1, file); str[13] = '\0'; linenum++; if (strcmp (str, "GIMP Palette\n")) @@ -401,20 +391,20 @@ gimp_palette_load (const gchar *filename, "Missing magic header."), gimp_filename_to_utf8 (filename)); - fclose (fp); + fclose (file); return NULL; } palette = g_object_new (GIMP_TYPE_PALETTE, NULL); - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -433,13 +423,13 @@ gimp_palette_load (const gchar *filename, gimp_object_set_name (GIMP_OBJECT (palette), utf8); g_free (utf8); - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -463,13 +453,13 @@ gimp_palette_load (const gchar *filename, palette->n_columns = columns; - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -491,7 +481,7 @@ gimp_palette_load (const gchar *filename, g_free (utf8); } - while (! feof (fp)) + while (! feof (file)) { if (str[0] != '#') { @@ -539,16 +529,16 @@ gimp_palette_load (const gchar *filename, gimp_palette_add_entry (palette, tok, &color); } - if (! fgets (str, 1024, fp)) + if (! fgets (str, 1024, file)) { - if (feof (fp)) + if (feof (file)) break; g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); - fclose (fp); + fclose (file); g_object_unref (palette); return NULL; } @@ -556,31 +546,22 @@ gimp_palette_load (const gchar *filename, linenum++; } - fclose (fp); + fclose (file); return GIMP_DATA (palette); } -static void -gimp_palette_dirty (GimpData *data) -{ - if (GIMP_DATA_CLASS (parent_class)->dirty) - GIMP_DATA_CLASS (parent_class)->dirty (data); -} - static gboolean gimp_palette_save (GimpData *data, GError **error) { - GimpPalette *palette; - GimpPaletteEntry *entry; - GList *list; - FILE *fp; - guchar r, g, b; + GimpPalette *palette = GIMP_PALETTE (data); + GList *list; + FILE *file; - palette = GIMP_PALETTE (data); + file = fopen (data->filename, "w"); - if (! (fp = fopen (data->filename, "w"))) + if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for writing: %s"), @@ -589,22 +570,21 @@ gimp_palette_save (GimpData *data, return FALSE; } - fprintf (fp, "GIMP Palette\n"); - fprintf (fp, "Name: %s\n", GIMP_OBJECT (palette)->name); - fprintf (fp, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256)); + fprintf (file, "GIMP Palette\n"); + fprintf (file, "Name: %s\n", GIMP_OBJECT (palette)->name); + fprintf (file, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256)); for (list = palette->colors; list; list = g_list_next (list)) { - entry = (GimpPaletteEntry *) list->data; + GimpPaletteEntry *entry = list->data; + guchar r, g, b; gimp_rgb_get_uchar (&entry->color, &r, &g, &b); - fprintf (fp, "%3d %3d %3d\t%s\n", - r, g, b, - entry->name); + fprintf (file, "%3d %3d %3d\t%s\n", r, g, b, entry->name); } - fclose (fp); + fclose (file); return TRUE; } @@ -619,12 +599,10 @@ static GimpData * gimp_palette_duplicate (GimpData *data, gboolean stingy_memory_use) { - GimpPalette *palette; + GimpPalette *palette = GIMP_PALETTE (data); GimpPalette *new; GList *list; - palette = GIMP_PALETTE (data); - new = g_object_new (GIMP_TYPE_PALETTE, NULL); new->n_columns = palette->n_columns; @@ -659,7 +637,8 @@ gimp_palette_add_entry (GimpPalette *palette, palette->colors = g_list_append (palette->colors, entry); palette->n_colors += 1; - gimp_data_dirty (GIMP_DATA (palette)); + /* will make the palette dirty too */ + gimp_object_name_changed (GIMP_OBJECT (palette)); return entry; } @@ -703,7 +682,8 @@ gimp_palette_delete_entry (GimpPalette *palette, &color); } - gimp_data_dirty (GIMP_DATA (palette)); + /* will make the palette dirty too */ + gimp_object_name_changed (GIMP_OBJECT (palette)); } } diff --git a/app/core/gimppattern-load.c b/app/core/gimppattern-load.c index e2e0f5fe37..99e0679f41 100644 --- a/app/core/gimppattern-load.c +++ b/app/core/gimppattern-load.c @@ -163,11 +163,9 @@ static gint64 gimp_pattern_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpPattern *pattern; + GimpPattern *pattern = GIMP_PATTERN (object); gint64 memsize = 0; - pattern = GIMP_PATTERN (object); - if (pattern->mask) memsize += temp_buf_get_memsize (pattern->mask); @@ -201,13 +199,11 @@ gimp_pattern_get_new_preview (GimpViewable *viewable, gint width, gint height) { - GimpPattern *pattern; + GimpPattern *pattern = GIMP_PATTERN (viewable); TempBuf *temp_buf; gint copy_width; gint copy_height; - pattern = GIMP_PATTERN (viewable); - copy_width = MIN (width, pattern->mask->width); copy_height = MIN (height, pattern->mask->height); @@ -269,9 +265,9 @@ gimp_pattern_new (const gchar *name, g_return_val_if_fail (name != NULL, NULL); - pattern = g_object_new (GIMP_TYPE_PATTERN, NULL); - - gimp_object_set_name (GIMP_OBJECT (pattern), name); + pattern = g_object_new (GIMP_TYPE_PATTERN, + "name", name, + NULL); pattern->mask = temp_buf_new (32, 32, 3, 0, 0, NULL); @@ -294,33 +290,20 @@ gimp_pattern_new (const gchar *name, GimpData * gimp_pattern_get_standard (void) { - static GimpPattern *standard_pattern = NULL; + static GimpData *standard_pattern = NULL; if (! standard_pattern) { - guchar *data; - gint row, col; + standard_pattern = gimp_pattern_new ("Standard", FALSE); - standard_pattern = g_object_new (GIMP_TYPE_PATTERN, NULL); - - gimp_object_set_name (GIMP_OBJECT (standard_pattern), "Standard"); - - standard_pattern->mask = temp_buf_new (32, 32, 3, 0, 0, NULL); - - data = temp_buf_data (standard_pattern->mask); - - for (row = 0; row < standard_pattern->mask->height; row++) - for (col = 0; col < standard_pattern->mask->width; col++) - { - memset (data, (col % 2) && (row % 2) ? 255 : 0, 3); - data += 3; - } + standard_pattern->dirty = FALSE; + standard_pattern->internal = TRUE; /* set ref_count to 2 --> never swap the standard pattern */ g_object_ref (standard_pattern); } - return GIMP_DATA (standard_pattern); + return standard_pattern; } GimpData * @@ -335,6 +318,7 @@ gimp_pattern_load (const gchar *filename, gchar *name = NULL; 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); @@ -401,6 +385,7 @@ gimp_pattern_load (const gchar *filename, "Could not read %d bytes: %s"), gimp_filename_to_utf8 (filename), bn_size, g_strerror (errno)); + g_free (name); goto error; } @@ -411,10 +396,14 @@ gimp_pattern_load (const gchar *filename, name = utf8; } - if (!name) + if (! name) name = g_strdup (_("Unnamed")); - pattern = g_object_new (GIMP_TYPE_PATTERN, NULL); + pattern = g_object_new (GIMP_TYPE_PATTERN, + "name", name, + NULL); + + g_free (name); pattern->mask = temp_buf_new (header.width, header.height, header.bytes, 0, 0, NULL); @@ -433,9 +422,6 @@ gimp_pattern_load (const gchar *filename, close (fd); - gimp_object_set_name (GIMP_OBJECT (pattern), name); - g_free (name); - /* Swap the pattern to disk (if we're being stingy with memory) */ if (stingy_memory_use) temp_buf_swap (pattern->mask); @@ -445,8 +431,6 @@ gimp_pattern_load (const gchar *filename, error: if (pattern) g_object_unref (pattern); - else if (name) - g_free (name); close (fd); diff --git a/app/core/gimppattern.c b/app/core/gimppattern.c index e2e0f5fe37..99e0679f41 100644 --- a/app/core/gimppattern.c +++ b/app/core/gimppattern.c @@ -163,11 +163,9 @@ static gint64 gimp_pattern_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpPattern *pattern; + GimpPattern *pattern = GIMP_PATTERN (object); gint64 memsize = 0; - pattern = GIMP_PATTERN (object); - if (pattern->mask) memsize += temp_buf_get_memsize (pattern->mask); @@ -201,13 +199,11 @@ gimp_pattern_get_new_preview (GimpViewable *viewable, gint width, gint height) { - GimpPattern *pattern; + GimpPattern *pattern = GIMP_PATTERN (viewable); TempBuf *temp_buf; gint copy_width; gint copy_height; - pattern = GIMP_PATTERN (viewable); - copy_width = MIN (width, pattern->mask->width); copy_height = MIN (height, pattern->mask->height); @@ -269,9 +265,9 @@ gimp_pattern_new (const gchar *name, g_return_val_if_fail (name != NULL, NULL); - pattern = g_object_new (GIMP_TYPE_PATTERN, NULL); - - gimp_object_set_name (GIMP_OBJECT (pattern), name); + pattern = g_object_new (GIMP_TYPE_PATTERN, + "name", name, + NULL); pattern->mask = temp_buf_new (32, 32, 3, 0, 0, NULL); @@ -294,33 +290,20 @@ gimp_pattern_new (const gchar *name, GimpData * gimp_pattern_get_standard (void) { - static GimpPattern *standard_pattern = NULL; + static GimpData *standard_pattern = NULL; if (! standard_pattern) { - guchar *data; - gint row, col; + standard_pattern = gimp_pattern_new ("Standard", FALSE); - standard_pattern = g_object_new (GIMP_TYPE_PATTERN, NULL); - - gimp_object_set_name (GIMP_OBJECT (standard_pattern), "Standard"); - - standard_pattern->mask = temp_buf_new (32, 32, 3, 0, 0, NULL); - - data = temp_buf_data (standard_pattern->mask); - - for (row = 0; row < standard_pattern->mask->height; row++) - for (col = 0; col < standard_pattern->mask->width; col++) - { - memset (data, (col % 2) && (row % 2) ? 255 : 0, 3); - data += 3; - } + standard_pattern->dirty = FALSE; + standard_pattern->internal = TRUE; /* set ref_count to 2 --> never swap the standard pattern */ g_object_ref (standard_pattern); } - return GIMP_DATA (standard_pattern); + return standard_pattern; } GimpData * @@ -335,6 +318,7 @@ gimp_pattern_load (const gchar *filename, gchar *name = NULL; 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); @@ -401,6 +385,7 @@ gimp_pattern_load (const gchar *filename, "Could not read %d bytes: %s"), gimp_filename_to_utf8 (filename), bn_size, g_strerror (errno)); + g_free (name); goto error; } @@ -411,10 +396,14 @@ gimp_pattern_load (const gchar *filename, name = utf8; } - if (!name) + if (! name) name = g_strdup (_("Unnamed")); - pattern = g_object_new (GIMP_TYPE_PATTERN, NULL); + pattern = g_object_new (GIMP_TYPE_PATTERN, + "name", name, + NULL); + + g_free (name); pattern->mask = temp_buf_new (header.width, header.height, header.bytes, 0, 0, NULL); @@ -433,9 +422,6 @@ gimp_pattern_load (const gchar *filename, close (fd); - gimp_object_set_name (GIMP_OBJECT (pattern), name); - g_free (name); - /* Swap the pattern to disk (if we're being stingy with memory) */ if (stingy_memory_use) temp_buf_swap (pattern->mask); @@ -445,8 +431,6 @@ gimp_pattern_load (const gchar *filename, error: if (pattern) g_object_unref (pattern); - else if (name) - g_free (name); close (fd);