[Rhythmbox-devel] [patch] Fix album cover aspect ratios in merge branch



The code that displays album covers in the merge branch assumes that all
such images will be square.  If you try to use an image that isn't
square, it gets stretched out along the narrow dimension, distorting the
image.  For example, you wind up with something like this:

    http://web.ics.purdue.edu/~kuliniew/images/rb-cover-bad.png

Observe that the image being used is of the front *and* back of the
album, so its height should be double its width.  (Yes, I know you'd
normally want to use just the front of the album cover, but that's the
image I happened to have lying around on my hard disk.  Besides, I'm
sure there's got to be *some* album out there that doesn't come in the
standard CD jewel case.)

Instead, you'd expect the image to be scaled without distorting its
aspect ratio, like this:

    http://web.ics.purdue.edu/~kuliniew/images/rb-cover-good.png

I've gone ahead and fixed this problem.  You can either grab it from my
arch branch (patch-1 and patch-2 are what you want, though at the moment
there aren't any other patches there):

    Name: kuliniew purdue edu--2004
    Location: http://web.ics.purdue.edu/~kuliniew/arch
    Branch: rhythmbox--cover--0.9

Or you could just use the attached patch.
--- orig/lib/rb-cover.c
+++ mod/lib/rb-cover.c
@@ -738,6 +738,7 @@
 	gchar *cover_path, *small_cover_path;
 	GdkPixbufLoader *loader;
 	GdkPixbuf *pixbuf, *small_pixbuf;
+	int width, height;
 
 	if (!artist || !album || !data)
 		return GNOME_VFS_ERROR_BAD_PARAMETERS;
@@ -767,10 +768,19 @@
 		gdk_pixbuf_loader_close (loader, NULL);
 
 		pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-		small_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
-							TREE_COVER_SIZE,
-							TREE_COVER_SIZE,
-							GDK_INTERP_BILINEAR);
+		width = gdk_pixbuf_get_width (pixbuf);
+		height = gdk_pixbuf_get_height (pixbuf);
+		if (width > height) {
+			small_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+								TREE_COVER_SIZE,
+								height * TREE_COVER_SIZE / width,
+								GDK_INTERP_BILINEAR);
+		} else {
+			small_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+								width * TREE_COVER_SIZE / height,
+								TREE_COVER_SIZE,
+								GDK_INTERP_BILINEAR);
+		}
 
 		if (gdk_pixbuf_save (pixbuf, cover_path, "jpeg", NULL, NULL) &&
 		    gdk_pixbuf_save (small_pixbuf, small_cover_path, "jpeg", NULL, NULL)) {
@@ -803,6 +813,7 @@
 	GdkPixbufLoader *loader;
 	GdkPixbuf *pixbuf, *small_pixbuf;
 	gboolean ret_val;
+	int width, height;
 
 	loader = gdk_pixbuf_loader_new ();
 
@@ -813,10 +824,19 @@
 		gdk_pixbuf_loader_close (loader, NULL);
 
 		pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-		small_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
-							TREE_COVER_SIZE,
-							TREE_COVER_SIZE,
-							GDK_INTERP_BILINEAR);
+		width = gdk_pixbuf_get_width (pixbuf);
+		height = gdk_pixbuf_get_height (pixbuf);
+		if (width > height) {
+			small_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+								TREE_COVER_SIZE,
+								height * TREE_COVER_SIZE / width,
+								GDK_INTERP_BILINEAR);
+		} else {
+			small_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+								width * TREE_COVER_SIZE / height,
+								TREE_COVER_SIZE,
+								GDK_INTERP_BILINEAR);
+		}
 
 		ret_val = gdk_pixbuf_save_to_buffer (small_pixbuf,
 						     &write_handle->small_cover_data,


--- orig/widgets/rb-album-cover.c
+++ mod/widgets/rb-album-cover.c
@@ -700,7 +700,11 @@
 	if (cover_size > MAX_COVER_SIZE)
 		cover_size = MAX_COVER_SIZE;
 
-	gdk_pixbuf_loader_set_size (loader, cover_size, cover_size);
+	if (w > h) {
+		gdk_pixbuf_loader_set_size (loader, cover_size, h * cover_size / w);
+	} else {
+		gdk_pixbuf_loader_set_size (loader, w * cover_size / h, cover_size);
+	}
 }
 
 static void 

Attachment: signature.asc
Description: Digital signature



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