rhythmbox r5780 - in trunk: . lib shell



Author: hadess
Date: Fri Jun 27 15:19:24 2008
New Revision: 5780
URL: http://svn.gnome.org/viewvc/rhythmbox?rev=5780&view=rev

Log:
2008-06-27  Bastien Nocera  <hadess hadess net>

	* lib/rb-util.c (rb_scale_pixbuf_to_size):
	* lib/rb-util.h:
	* shell/rb-shell.c (rb_shell_db_metadata_art_cb): Add
	rb_scale_pixbuf_to_size to scale to a specific GtkIconSize,
	respecting the scale ratio (Closes: #528231)



Modified:
   trunk/ChangeLog
   trunk/lib/rb-util.c
   trunk/lib/rb-util.h
   trunk/shell/rb-shell.c

Modified: trunk/lib/rb-util.c
==============================================================================
--- trunk/lib/rb-util.c	(original)
+++ trunk/lib/rb-util.c	Fri Jun 27 15:19:24 2008
@@ -1048,3 +1048,37 @@
 	gtk_tree_view_column_set_fixed_width (column, max_width + padding);
 }
 
+/**
+ * rb_scale_pixbuf_to_size:
+ * @pixbuf: the #GdkPixbuf containing the original image
+ * @size: a stock icon size
+ *
+ * Creates a new #GdkPixbuf from the original one, for a target of
+ * size, respecting the aspect ratio of the image.
+ */
+GdkPixbuf *
+rb_scale_pixbuf_to_size (GdkPixbuf *pixbuf, GtkIconSize size)
+{
+	int icon_size;
+	int width, height;
+	int d_width, d_height;
+
+	g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
+
+	if (gtk_icon_size_lookup (size, &icon_size, NULL) == FALSE)
+		return NULL;
+
+	width = gdk_pixbuf_get_width (pixbuf);
+	height = gdk_pixbuf_get_height (pixbuf);
+
+	if (width > height) {
+		d_width = icon_size;
+		d_height = d_width * height / width;
+	} else {
+		d_height = icon_size;
+		d_width = d_height * width / height;
+	}
+
+	return gdk_pixbuf_scale_simple (pixbuf, d_width, d_height, GDK_INTERP_BILINEAR);
+}
+

Modified: trunk/lib/rb-util.h
==============================================================================
--- trunk/lib/rb-util.h	(original)
+++ trunk/lib/rb-util.h	Fri Jun 27 15:19:24 2008
@@ -97,6 +97,9 @@
 					  const char **strings,
 					  int padding);
 
+GdkPixbuf *rb_scale_pixbuf_to_size (GdkPixbuf *pixbuf,
+				    GtkIconSize size);
+
 G_END_DECLS
 
 #endif /* __RB_UTIL_H */

Modified: trunk/shell/rb-shell.c
==============================================================================
--- trunk/shell/rb-shell.c	(original)
+++ trunk/shell/rb-shell.c	Fri Jun 27 15:19:24 2008
@@ -1758,7 +1758,6 @@
 	GdkPixbuf *pixbuf = NULL;
 	GdkPixbuf *my_pixbuf;
 	RhythmDBEntry *playing_entry;
-	gint icon_size;
 	guint time;
 
 	playing_entry = rb_shell_player_get_playing_entry (shell->priv->player_shell);
@@ -1778,11 +1777,7 @@
 	if (G_VALUE_HOLDS (metadata, GDK_TYPE_PIXBUF)) {
 		pixbuf = GDK_PIXBUF (g_value_get_object (metadata));
 		if (pixbuf != NULL) {
-			gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &icon_size, NULL);
-			my_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
-					icon_size, icon_size,
-					GDK_INTERP_BILINEAR);
-
+			my_pixbuf = rb_scale_pixbuf_to_size (pixbuf, GTK_ICON_SIZE_DIALOG);
 			shell->priv->cached_art_icon = g_object_ref_sink (gtk_image_new_from_pixbuf (my_pixbuf));
 			g_object_unref (my_pixbuf);
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]