[maemo-commits] [maemo-commits] r17447 - in projects/haf/trunk/hildon-thumbnail: . thumbs
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Feb 17 13:47:08 EET 2009
- Previous message: [maemo-commits] r17446 - projects/haf/tags/hildon-thumbnail/3.0.18
- Next message: [maemo-commits] r17448 - projects/haf/trunk/hildon-thumbnail/thumbs
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2009-02-17 13:47:07 +0200 (Tue, 17 Feb 2009) New Revision: 17447 Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h Log: 2009-02-17 Philip Van Hoof <pvanhoof at codeminded.be> * thumbs/hildon-thumbnail-factory.c * thumbs/hildon-thumbnail-factory.h: Added convenience function for rotating (this is untested atm, don't release this until I removed this warning please). Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog =================================================================== --- projects/haf/trunk/hildon-thumbnail/ChangeLog 2009-02-17 11:32:03 UTC (rev 17446) +++ projects/haf/trunk/hildon-thumbnail/ChangeLog 2009-02-17 11:47:07 UTC (rev 17447) @@ -1,3 +1,10 @@ +2009-02-17 Philip Van Hoof <pvanhoof at codeminded.be> + + * thumbs/hildon-thumbnail-factory.c + * thumbs/hildon-thumbnail-factory.h: Added convenience function for + rotating (this is untested atm, don't release this until I removed + this warning please). + 2009-02-16 Marius Vollmer <marius.vollmer at nokia.com> Released 3.0.18 Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c 2009-02-17 11:32:03 UTC (rev 17446) +++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.c 2009-02-17 11:47:07 UTC (rev 17447) @@ -97,6 +97,191 @@ guint64 size; } ThumbsCacheFile; +#define TRACKER_METADATA_SERVICE "org.freedesktop.Tracker" +#define TRACKER_METADATA_PATH "/org/freedesktop/Tracker/Metadata" +#define TRACKER_METADATA_INTERFACE "org.freedesktop.Tracker.Metadata" + +static DBusGProxy* +get_tracker_proxy (void) +{ + static DBusGProxy *proxy = NULL; + + if (!proxy) { + GError *error = NULL; + DBusGConnection *connection; + + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + + if (!error) { + proxy = dbus_g_proxy_new_for_name (connection, + TRACKER_METADATA_SERVICE, + TRACKER_METADATA_PATH, + TRACKER_METADATA_INTERFACE); + } else { + g_error_free (error); + } + } + + return proxy; +} + +/* Copied from GThumb (and/or many other projects that have copied this too) + * Returns a copy of pixbuf mirrored and or flipped. + * TO do a 180 degree rotations set both mirror and flipped TRUE + * if mirror and flip are FALSE, result is a simple copy. + */ +static GdkPixbuf * +_gdk_pixbuf_copy_mirror (GdkPixbuf *src, + gboolean mirror, + gboolean flip) +{ + GdkPixbuf *dest; + int has_alpha; + int w, h, srs; + int drs; + guchar *s_pix; + guchar *d_pix; + guchar *sp; + guchar *dp; + int i, j; + int a; + + if (!src) return NULL; + + w = gdk_pixbuf_get_width (src); + h = gdk_pixbuf_get_height (src); + has_alpha = gdk_pixbuf_get_has_alpha (src); + srs = gdk_pixbuf_get_rowstride (src); + s_pix = gdk_pixbuf_get_pixels (src); + + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8, w, h); + drs = gdk_pixbuf_get_rowstride (dest); + d_pix = gdk_pixbuf_get_pixels (dest); + + a = has_alpha ? 4 : 3; + + for (i = 0; i < h; i++) { + sp = s_pix + (i * srs); + if (flip) + dp = d_pix + ((h - i - 1) * drs); + else + dp = d_pix + (i * drs); + + if (mirror) { + dp += (w - 1) * a; + for (j = 0; j < w; j++) { + *(dp++) = *(sp++); /* r */ + *(dp++) = *(sp++); /* g */ + *(dp++) = *(sp++); /* b */ + if (has_alpha) *(dp) = *(sp++); /* a */ + dp -= (a + 3); + } + } else { + for (j = 0; j < w; j++) { + *(dp++) = *(sp++); /* r */ + *(dp++) = *(sp++); /* g */ + *(dp++) = *(sp++); /* b */ + if (has_alpha) *(dp++) = *(sp++); /* a */ + } + } + } + + return dest; +} + + +GdkPixbuf* +hildon_thumbnail_orientate (const gchar *uri, GdkPixbuf *image) +{ + GStrv keys, values = NULL; + gboolean rotated = FALSE; + GdkPixbuf *ret = image; + GError *error = NULL; + + keys = (GStrv) g_malloc0 (sizeof (gchar *) * 2); + + keys[0] = g_strdup ("Image:Orientation"); + keys[1] = NULL; + + dbus_g_proxy_call (get_tracker_proxy (), + "Queue", &error, + G_TYPE_STRING, "Files", + G_TYPE_STRING, uri, + G_TYPE_STRV, keys, + G_TYPE_INVALID, + G_TYPE_STRV, &values, + G_TYPE_INVALID); + + if (error) { + g_warning ("%s\n", error->message); + g_error_free (error); + g_strfreev (keys); + if (values) + g_strfreev (values); + return image; + } + + if (values && values[0]) { + + /* Mirror horizontal */ + if (g_strcmp0 (values[0], "2")) { + ret = _gdk_pixbuf_copy_mirror (image, TRUE, FALSE); + rotated = TRUE; + } + + /* Rotate 180 */ + if (g_strcmp0 (values[0], "3")) { + ret = gdk_pixbuf_rotate_simple (image, GDK_PIXBUF_ROTATE_UPSIDEDOWN); + rotated = TRUE; + } + + /* Mirror vertical */ + if (g_strcmp0 (values[0], "4")) { + ret = _gdk_pixbuf_copy_mirror (image, FALSE, TRUE); + rotated = TRUE; + } + + /* Mirror horizontal and rotate 270 CW */ + if (g_strcmp0 (values[0], "5")) { + GdkPixbuf *temp = _gdk_pixbuf_copy_mirror (image, TRUE, FALSE); + ret = gdk_pixbuf_rotate_simple (temp, GDK_PIXBUF_ROTATE_CLOCKWISE); + g_object_unref (temp); + rotated = TRUE; + } + + /* Rotate 90 CW */ + if (g_strcmp0 (values[0], "6")) { + ret = gdk_pixbuf_rotate_simple (image, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); + rotated = TRUE; + } + + /* Mirror horizontal and rotate 90 CW */ + + if (g_strcmp0 (values[0], "7")) { + GdkPixbuf *temp = _gdk_pixbuf_copy_mirror (image, TRUE, FALSE); + ret = gdk_pixbuf_rotate_simple (temp, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); + g_object_unref (temp); + rotated = TRUE; + } + + /* Rotate 270 CW */ + if (g_strcmp0 (values[0], "8")) { + ret = gdk_pixbuf_rotate_simple (image, GDK_PIXBUF_ROTATE_CLOCKWISE); + rotated = TRUE; + } + + g_strfreev (values); + } + + if (rotated) + g_object_unref (image); + + + g_strfreev (keys); + + return ret; +} + static void thumb_item_free(ThumbsItem* item) { g_free(item->uri); Modified: projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h =================================================================== --- projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h 2009-02-17 11:32:03 UTC (rev 17446) +++ projects/haf/trunk/hildon-thumbnail/thumbs/hildon-thumbnail-factory.h 2009-02-17 11:47:07 UTC (rev 17447) @@ -72,6 +72,22 @@ GType hildon_thumbnail_request_get_type (void); /** + * hildon_thumbnail_orientate: + * @uri: URI of the original image + * @image: GdkPixbuf of the thumbnail + * + * Rotates @image and then returns the rotated version. When rotated @image will + * be unreferenced once. Which means that you should do something like this: + * image = hildon_thumbnail_orientate (uri, image) and it wont create a memory + * leak. If no rotation was necessary then @image will just be returned back to + * you. + * + * Returns: @image or the rotated version of @image depending on the necessity + * of rotating. + **/ +GdkPixbuf* hildon_thumbnail_orientate (const gchar *uri, GdkPixbuf *image) G_GNUC_WARN_UNUSED_RESULT; + +/** * HildonThumbnailRequestPixbufCallback: * @self: the factory * @thumbnail: (allow-none): A pixbuf containing the thumbnail or %NULL. If application wishes to keep the structure, it must call g_object_ref() on it. The library does not cache returned pixbufs.
- Previous message: [maemo-commits] r17446 - projects/haf/tags/hildon-thumbnail/3.0.18
- Next message: [maemo-commits] r17448 - projects/haf/trunk/hildon-thumbnail/thumbs
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]