From 532d42d01267c07c485e0f4eca853b9a838dd1a1 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Thu, 3 Jun 2004 11:34:51 +0000 Subject: [PATCH] removed commented-out message. 2004-06-03 Sven Neumann * app/core/gimpdatafactory.c (gimp_data_factory_load_data): removed commented-out message. * app/core/gimppattern.[ch]: fixed handling of errors and PNG comments in new pattern loader. Renamed functions for consistency with other data loaders. * app/core/gimp.c: changed accordingly. --- ChangeLog | 11 ++++ app/core/gimp.c | 12 ++-- app/core/gimpdatafactory.c | 5 -- app/core/gimppattern-load.c | 107 +++++++++++++----------------------- app/core/gimppattern.c | 107 +++++++++++++----------------------- app/core/gimppattern.h | 4 +- 6 files changed, 95 insertions(+), 151 deletions(-) diff --git a/ChangeLog b/ChangeLog index 026bbc7af9..4c6aa7deec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-06-03 Sven Neumann + + * app/core/gimpdatafactory.c (gimp_data_factory_load_data): + removed commented-out message. + + * app/core/gimppattern.[ch]: fixed handling of errors and PNG + comments in new pattern loader. Renamed functions for consistency + with other data loaders. + + * app/core/gimp.c: changed accordingly. + 2004-06-03 Dave Neary * app/core/gimp.c: diff --git a/app/core/gimp.c b/app/core/gimp.c index e65b5a8e68..2d6d60cfe5 100644 --- a/app/core/gimp.c +++ b/app/core/gimp.c @@ -567,20 +567,20 @@ gimp_real_initialize (Gimp *gimp, static const GimpDataFactoryLoaderEntry pattern_loader_entries[] = { - { gimp_pattern_native_load, GIMP_PATTERN_FILE_EXTENSION }, - { gimp_pattern_load, NULL /* Fallback - try to load all files */ } + { gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION }, + { gimp_pattern_load_pixbuf, NULL } }; static const GimpDataFactoryLoaderEntry gradient_loader_entries[] = { - { gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION }, - { gimp_gradient_load, NULL /* fallback loader */ } + { gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION }, + { gimp_gradient_load, NULL /* legacy loader */ } }; static const GimpDataFactoryLoaderEntry palette_loader_entries[] = { - { gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION }, - { gimp_palette_load, NULL /* fallback loader */ } + { gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION }, + { gimp_palette_load, NULL /* legacy loader */ } }; if (gimp->be_verbose) diff --git a/app/core/gimpdatafactory.c b/app/core/gimpdatafactory.c index 452764f598..edf8446834 100644 --- a/app/core/gimpdatafactory.c +++ b/app/core/gimpdatafactory.c @@ -579,11 +579,6 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data, } else { - /* - g_message (_("Trying fallback loader on file '%s' " - "with unknown extension."), - gimp_filename_to_utf8 (file_data->filename)); - */ goto insert; } } diff --git a/app/core/gimppattern-load.c b/app/core/gimppattern-load.c index 37707d3d50..5f728ef8b8 100644 --- a/app/core/gimppattern-load.c +++ b/app/core/gimppattern-load.c @@ -307,9 +307,9 @@ gimp_pattern_get_standard (void) } GimpData * -gimp_pattern_native_load (const gchar *filename, - gboolean stingy_memory_use, - GError **error) +gimp_pattern_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpPattern *pattern = NULL; gint fd; @@ -438,95 +438,64 @@ gimp_pattern_native_load (const gchar *filename, } GimpData * -gimp_pattern_load (const gchar *filename, - gboolean stingy_memory_use, - GError **error) +gimp_pattern_load_pixbuf (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { - GimpPattern *pattern = NULL; - GdkPixbuf *pat_buf = NULL; - guchar *pat_data, *buf_data; - gchar *name = NULL; - gint width, - height, - bytes, - rowstride, - i; - gchar *utf8_filename; - gsize filename_length; + GimpPattern *pattern; + GdkPixbuf *pixbuf; + guchar *pat_data; + guchar *buf_data; + gchar *name; + gint width; + gint height; + gint bytes; + gint rowstride; + gint i; 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); - pat_buf = gdk_pixbuf_new_from_file (filename, error); + pixbuf = gdk_pixbuf_new_from_file (filename, error); - if (*error) + if (! pixbuf) + return NULL; + + name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Comment")); + + if (! name) { - if ((*error)->domain == G_FILE_ERROR) - g_message (_("Could not open file %s: %s"), - gimp_filename_to_utf8 (filename), - (*error)->message); - else if ((*error)->domain == GDK_PIXBUF_ERROR) - g_message (_("Filename %s is not a valid GdkPixbuf: %s"), - gimp_filename_to_utf8 (filename), - (*error)->message); - - return NULL; + gchar *basename = g_path_get_basename (filename); + + name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL); + + g_free (basename); } - - /* Read in the pattern name - - First try to get a "comment" option, this could be set for pnm, - jpeg and gif (it isn't yet) - Then try the tEXt option, which is set for pngs, - Then fall back to filename - */ - - utf8_filename = g_filename_to_utf8 (filename, -1, NULL, &filename_length, - error); - if (*error) - { - g_message (_("Problem converting filename to UTF8: %s"), - (*error)->message); - utf8_filename = "Unnamed"; - g_clear_error (error); - } - - name = g_strdup (gdk_pixbuf_get_option (pat_buf, "comment")); - - if (name == NULL) - name = g_strdup (gdk_pixbuf_get_option (pat_buf, "tEXt")); - - if (name == NULL) - name = g_strdup (utf8_filename); - pattern = g_object_new (GIMP_TYPE_PATTERN, "name", name, NULL); - g_free (name); - g_free (utf8_filename); - width = gdk_pixbuf_get_width (pat_buf); - height = gdk_pixbuf_get_height (pat_buf); - bytes = gdk_pixbuf_get_n_channels (pat_buf); - rowstride = gdk_pixbuf_get_rowstride (pat_buf); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + bytes = gdk_pixbuf_get_n_channels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); - pattern->mask = temp_buf_new (width, height, bytes, - 0, 0, NULL); - - pat_data = gdk_pixbuf_get_pixels (pat_buf); + pattern->mask = temp_buf_new (width, height, bytes, 0, 0, NULL); + + pat_data = gdk_pixbuf_get_pixels (pixbuf); buf_data = temp_buf_data (pattern->mask); for (i = 0; i < height; i++) { - memcpy(buf_data + i * width * bytes, pat_data, width * bytes); + memcpy (buf_data + i * width * bytes, pat_data, width * bytes); pat_data += rowstride; } - /* Free up loaded Pixbuf */ - g_object_unref (pat_buf); - + g_object_unref (pixbuf); + /* Swap the pattern to disk (if we're being stingy with memory) */ if (stingy_memory_use) temp_buf_swap (pattern->mask); diff --git a/app/core/gimppattern.c b/app/core/gimppattern.c index 37707d3d50..5f728ef8b8 100644 --- a/app/core/gimppattern.c +++ b/app/core/gimppattern.c @@ -307,9 +307,9 @@ gimp_pattern_get_standard (void) } GimpData * -gimp_pattern_native_load (const gchar *filename, - gboolean stingy_memory_use, - GError **error) +gimp_pattern_load (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { GimpPattern *pattern = NULL; gint fd; @@ -438,95 +438,64 @@ gimp_pattern_native_load (const gchar *filename, } GimpData * -gimp_pattern_load (const gchar *filename, - gboolean stingy_memory_use, - GError **error) +gimp_pattern_load_pixbuf (const gchar *filename, + gboolean stingy_memory_use, + GError **error) { - GimpPattern *pattern = NULL; - GdkPixbuf *pat_buf = NULL; - guchar *pat_data, *buf_data; - gchar *name = NULL; - gint width, - height, - bytes, - rowstride, - i; - gchar *utf8_filename; - gsize filename_length; + GimpPattern *pattern; + GdkPixbuf *pixbuf; + guchar *pat_data; + guchar *buf_data; + gchar *name; + gint width; + gint height; + gint bytes; + gint rowstride; + gint i; 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); - pat_buf = gdk_pixbuf_new_from_file (filename, error); + pixbuf = gdk_pixbuf_new_from_file (filename, error); - if (*error) + if (! pixbuf) + return NULL; + + name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Comment")); + + if (! name) { - if ((*error)->domain == G_FILE_ERROR) - g_message (_("Could not open file %s: %s"), - gimp_filename_to_utf8 (filename), - (*error)->message); - else if ((*error)->domain == GDK_PIXBUF_ERROR) - g_message (_("Filename %s is not a valid GdkPixbuf: %s"), - gimp_filename_to_utf8 (filename), - (*error)->message); - - return NULL; + gchar *basename = g_path_get_basename (filename); + + name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL); + + g_free (basename); } - - /* Read in the pattern name - - First try to get a "comment" option, this could be set for pnm, - jpeg and gif (it isn't yet) - Then try the tEXt option, which is set for pngs, - Then fall back to filename - */ - - utf8_filename = g_filename_to_utf8 (filename, -1, NULL, &filename_length, - error); - if (*error) - { - g_message (_("Problem converting filename to UTF8: %s"), - (*error)->message); - utf8_filename = "Unnamed"; - g_clear_error (error); - } - - name = g_strdup (gdk_pixbuf_get_option (pat_buf, "comment")); - - if (name == NULL) - name = g_strdup (gdk_pixbuf_get_option (pat_buf, "tEXt")); - - if (name == NULL) - name = g_strdup (utf8_filename); - pattern = g_object_new (GIMP_TYPE_PATTERN, "name", name, NULL); - g_free (name); - g_free (utf8_filename); - width = gdk_pixbuf_get_width (pat_buf); - height = gdk_pixbuf_get_height (pat_buf); - bytes = gdk_pixbuf_get_n_channels (pat_buf); - rowstride = gdk_pixbuf_get_rowstride (pat_buf); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + bytes = gdk_pixbuf_get_n_channels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); - pattern->mask = temp_buf_new (width, height, bytes, - 0, 0, NULL); - - pat_data = gdk_pixbuf_get_pixels (pat_buf); + pattern->mask = temp_buf_new (width, height, bytes, 0, 0, NULL); + + pat_data = gdk_pixbuf_get_pixels (pixbuf); buf_data = temp_buf_data (pattern->mask); for (i = 0; i < height; i++) { - memcpy(buf_data + i * width * bytes, pat_data, width * bytes); + memcpy (buf_data + i * width * bytes, pat_data, width * bytes); pat_data += rowstride; } - /* Free up loaded Pixbuf */ - g_object_unref (pat_buf); - + g_object_unref (pixbuf); + /* Swap the pattern to disk (if we're being stingy with memory) */ if (stingy_memory_use) temp_buf_swap (pattern->mask); diff --git a/app/core/gimppattern.h b/app/core/gimppattern.h index 1804137a80..c159217ca6 100644 --- a/app/core/gimppattern.h +++ b/app/core/gimppattern.h @@ -54,10 +54,10 @@ GType gimp_pattern_get_type (void) G_GNUC_CONST; GimpData * gimp_pattern_new (const gchar *name, gboolean stingy_memory_use); GimpData * gimp_pattern_get_standard (void); -GimpData * gimp_pattern_native_load (const gchar *filename, +GimpData * gimp_pattern_load (const gchar *filename, gboolean stingy_memory_use, GError **error); -GimpData * gimp_pattern_load (const gchar *filename, +GimpData * gimp_pattern_load_pixbuf (const gchar *filename, gboolean stingy_memory_use, GError **error);