[gnome-photos] Absorb eog-pixbuf-util.[ch] from Eye of GNOME into photos-utils.[ch]
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Absorb eog-pixbuf-util.[ch] from Eye of GNOME into photos-utils.[ch]
- Date: Sat, 8 Sep 2012 17:32:50 +0000 (UTC)
commit 1c0cfdd4843e1bc2996d18302330f238e3929808
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Sep 8 19:21:10 2012 +0200
Absorb eog-pixbuf-util.[ch] from Eye of GNOME into photos-utils.[ch]
eog-pixbuf-util.[ch] neither had copyright nor license notices.
src/photos-utils.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/photos-utils.h | 8 +++
2 files changed, 149 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 9c5701f..863a4c0 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -319,6 +319,147 @@ photos_utils_get_icon_size (void)
}
+gchar *
+photos_utils_get_pixbuf_common_suffix (GdkPixbufFormat *format)
+{
+ gchar **extensions;
+ gchar *result = NULL;
+ gint i;
+
+ if (format == NULL)
+ return NULL;
+
+ extensions = gdk_pixbuf_format_get_extensions (format);
+ if (extensions[0] == NULL)
+ return NULL;
+
+ /* try to find 3-char suffix first, use the last occurence */
+ for (i = 0; extensions [i] != NULL; i++)
+ {
+ if (strlen (extensions[i]) <= 3)
+ {
+ g_free (result);
+ result = g_ascii_strdown (extensions[i], -1);
+ }
+ }
+
+ /* otherwise take the first one */
+ if (result == NULL)
+ result = g_ascii_strdown (extensions[0], -1);
+
+ g_strfreev (extensions);
+
+ return result;
+}
+
+
+static gchar *
+photos_utils_get_pixbuf_suffix_from_basename (const gchar *basename)
+{
+ gchar *suffix;
+ gchar *suffix_start;
+ guint len;
+
+ /* FIXME: does this work for all locales? */
+ suffix_start = g_utf8_strrchr (basename, -1, '.');
+
+ if (suffix_start == NULL)
+ return NULL;
+
+ len = strlen (suffix_start) - 1;
+ suffix = g_strndup (suffix_start+1, len);
+
+ return suffix;
+}
+
+
+GdkPixbufFormat *
+photos_utils_get_pixbuf_format (GFile *file)
+{
+ GdkPixbufFormat *format;
+ gchar *basename;
+ gchar *path;
+ gchar *suffix;
+
+ g_return_val_if_fail (file != NULL, NULL);
+
+ path = g_file_get_path (file);
+ basename = g_path_get_basename (path);
+ suffix = photos_utils_get_pixbuf_suffix_from_basename (basename);
+
+ format = photos_utils_get_pixbuf_format_by_suffix (suffix);
+
+ g_free (path);
+ g_free (basename);
+ g_free (suffix);
+
+ return format;
+}
+
+
+GdkPixbufFormat*
+photos_utils_get_pixbuf_format_by_suffix (const gchar *suffix)
+{
+ GSList *list;
+ GSList *it;
+ GdkPixbufFormat *result = NULL;
+
+ g_return_val_if_fail (suffix != NULL, NULL);
+
+ list = gdk_pixbuf_get_formats ();
+
+ for (it = list; (it != NULL) && (result == NULL); it = it->next)
+ {
+ GdkPixbufFormat *format;
+ gchar **extensions;
+ gint i;
+
+ format = (GdkPixbufFormat*) it->data;
+
+ extensions = gdk_pixbuf_format_get_extensions (format);
+ for (i = 0; extensions[i] != NULL; i++)
+ {
+ /* g_print ("check extension: %s against %s\n", extensions[i], suffix); */
+ if (g_ascii_strcasecmp (suffix, extensions[i]) == 0)
+ {
+ result = format;
+ break;
+ }
+ }
+
+ g_strfreev (extensions);
+ }
+
+ g_slist_free (list);
+
+ return result;
+}
+
+
+GSList *
+photos_utils_get_pixbuf_savable_formats (void)
+{
+ GSList *list;
+ GSList *write_list = NULL;
+ GSList *it;
+
+ list = gdk_pixbuf_get_formats ();
+
+ for (it = list; it != NULL; it = it->next)
+ {
+ GdkPixbufFormat *format;
+
+ format = (GdkPixbufFormat*) it->data;
+ if (gdk_pixbuf_format_is_writable (format))
+ write_list = g_slist_prepend (write_list, format);
+ }
+
+ g_slist_free (list);
+ write_list = g_slist_reverse (write_list);
+
+ return write_list;
+}
+
GtkBorder *
photos_utils_get_thumbnail_frame_border (void)
{
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 2a10d93..8e86deb 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -48,6 +48,14 @@ gchar *photos_utils_filename_strip_extension (const gchar *filename
gint photos_utils_get_icon_size (void);
+char* photos_utils_get_pixbuf_common_suffix (GdkPixbufFormat *format);
+
+GdkPixbufFormat* photos_utils_get_pixbuf_format (GFile *file);
+
+GdkPixbufFormat* photos_utils_get_pixbuf_format_by_suffix (const char *suffix);
+
+GSList* photos_utils_get_pixbuf_savable_formats (void);
+
GtkBorder *photos_utils_get_thumbnail_frame_border (void);
GList *photos_utils_get_urns_from_paths (GList *paths, GtkTreeModel *model);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]