diff options
author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2008-06-29 14:12:34 +0000 |
---|---|---|
committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2008-06-29 14:12:34 +0000 |
commit | a15fe143900dc0b77a6f73d21872daa2f24890a9 (patch) | |
tree | ae96b14bd48f36ee26606e13da81261677e7bfdb | |
parent | f2ccfe9d3dbff5055d3a5028ed6994ce1d1ddb86 (diff) | |
download | libgpod-tmz-a15fe143900dc0b77a6f73d21872daa2f24890a9.tar.gz libgpod-tmz-a15fe143900dc0b77a6f73d21872daa2f24890a9.tar.xz libgpod-tmz-a15fe143900dc0b77a6f73d21872daa2f24890a9.zip |
* src/ithumb-writer.c (itdb_write_ithumb_files): fix bug when
writing photos (loop variable "it" re-used inside loop).
Rename loop variable to "itw" also in case of writing artwork.
* src/itdb_thumb.c (itdb_thumb_to_pixbuf_at_size):
If requesting a thumb from the iPod smaller than available, none
would be returned. Fixed. Thumbs from the iPod would not be
scaled even if requested. Fixed.
If requesting a thumb from a file or existing pixbuf, scaling
was done even if none was requested (width/height =
0/-1). Fixed.
Introduced selection of smallest available thumbnail
(width/height = 0) besides largest available thumbnail
(width/height = -1).
TODO: consider aspect ratio of requested picture (currently it
is very likely that some of the square thumbs are returned...)
src/itdb_artwork.c (itdb_artwork_get_thumbnail):
Introduced selection of smallest available thumbnail
(width/height = 0) besides largest available thumbnail
(width/height = -1). (Only necessary documentation.)
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@2025 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | src/itdb_artwork.c | 8 | ||||
-rw-r--r-- | src/itdb_thumb.c | 190 |
3 files changed, 154 insertions, 66 deletions
@@ -4,6 +4,28 @@ writing photos (loop variable "it" re-used inside loop). Rename loop variable to "itw" also in case of writing artwork. + * src/itdb_thumb.c (itdb_thumb_to_pixbuf_at_size): + + If requesting a thumb from the iPod smaller than available, none + would be returned. Fixed. Thumbs from the iPod would not be + scaled even if requested. Fixed. + + If requesting a thumb from a file or existing pixbuf, scaling + was done even if none was requested (width/height = + 0/-1). Fixed. + + Introduced selection of smallest available thumbnail + (width/height = 0) besides largest available thumbnail + (width/height = -1). + + TODO: consider aspect ratio of requested picture (currently it + is very likely that some of the square thumbs are returned...) + + src/itdb_artwork.c (itdb_artwork_get_thumbnail): + Introduced selection of smallest available thumbnail + (width/height = 0) besides largest available thumbnail + (width/height = -1). (Only necessary documentation.) + 2008-06-28 Christophe Fergeau <teuf@gnome.org> patch by: Mike Heffner <mikeh@fesnel.com> diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c index 390841f..4cc81c0 100644 --- a/src/itdb_artwork.c +++ b/src/itdb_artwork.c @@ -888,10 +888,12 @@ gpointer itdb_thumb_ipod_item_to_pixbuf (Itdb_Device *device, /** * itdb_artwork_get_thumbnail! * @artwork: an #Itdb_Artwork - * @width: width of the pixbuf to retrieve, -1 for the biggest possible size - * (with no scaling) + * + * @width: width of the pixbuf to retrieve, -1 for the biggest + * possible size and 0 for the smallest possible size (with no scaling) + * * @height: height of the pixbuf to retrieve, -1 for the biggest possible size - * (with no scaling) + * and 0 for the smallest possible size (with no scaling) * * Returns a #GdkPixbuf representing the thumbnail stored in @artwork * scaling it if appropriate. If either height or width is -1, then the diff --git a/src/itdb_thumb.c b/src/itdb_thumb.c index 37008b2..42a87f2 100644 --- a/src/itdb_thumb.c +++ b/src/itdb_thumb.c @@ -363,6 +363,12 @@ const GList *itdb_thumb_ipod_get_thumbs (Itdb_Thumb_Ipod *thumbs) * gpointer is returned which you have to cast to a #GdkPixbuf using * GDK_PIXBUF() yourself. * + * @width: width of the pixbuf to retrieve, -1 for the biggest + * possible size and 0 for the smallest possible size (with no scaling) + * + * @height: height of the pixbuf to retrieve, -1 for the biggest possible size + * and 0 for the smallest possible size (with no scaling) + * * Return value: a #GdkPixbuf that must be unreffed with gdk_pixbuf_unref() * after use, or NULL if the creation of the gdk-pixbuf failed or if * libgpod was compiled without gdk-pixbuf support. @@ -372,71 +378,129 @@ gpointer itdb_thumb_to_pixbuf_at_size (Itdb_Device *device, Itdb_Thumb *thumb, { GdkPixbuf *pixbuf=NULL; - if (thumb->data_type == ITDB_THUMB_TYPE_FILE) - { - Itdb_Thumb_File *thumb_file = (Itdb_Thumb_File *)thumb; - pixbuf = gdk_pixbuf_new_from_file_at_size (thumb_file->filename, - width, height, - NULL); - } - else if (thumb->data_type == ITDB_THUMB_TYPE_MEMORY) - { - Itdb_Thumb_Memory *thumb_mem = (Itdb_Thumb_Memory *)thumb; - GdkPixbufLoader *loader = gdk_pixbuf_loader_new (); - g_return_val_if_fail (loader, FALSE); - if ((width != -1) && (height != -1)) { - gdk_pixbuf_loader_set_size (loader, width, height); - } - gdk_pixbuf_loader_write (loader, - thumb_mem->image_data, - thumb_mem->image_data_len, - NULL); - gdk_pixbuf_loader_close (loader, NULL); - pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); - if (pixbuf) - g_object_ref (pixbuf); - g_object_unref (loader); - } - else if (thumb->data_type == ITDB_THUMB_TYPE_PIXBUF) - { - Itdb_Thumb_Pixbuf *thumb_pixbuf = (Itdb_Thumb_Pixbuf*)thumb; - pixbuf = gdk_pixbuf_scale_simple (thumb_pixbuf->pixbuf, - width, height, - GDK_INTERP_BILINEAR); - } - else if (thumb->data_type == ITDB_THUMB_TYPE_IPOD) + switch (thumb->data_type) { - Itdb_Thumb_Ipod *thumb_ipod = (Itdb_Thumb_Ipod *)thumb; - const GList *thumb; - Itdb_Thumb_Ipod_Item *chosen; + case ITDB_THUMB_TYPE_FILE: + { + Itdb_Thumb_File *thumb_file = (Itdb_Thumb_File *)thumb; + if ((width != -1) && (height !=-1) && (width != 0) && (height != 0)) + { /* scale */ + pixbuf = gdk_pixbuf_new_from_file_at_size (thumb_file->filename, + width, height, + NULL); + } + else + { /* don't scale */ + pixbuf = gdk_pixbuf_new_from_file (thumb_file->filename, NULL); + } + break; + } + case ITDB_THUMB_TYPE_MEMORY: + { + Itdb_Thumb_Memory *thumb_mem = (Itdb_Thumb_Memory *)thumb; + GdkPixbufLoader *loader = gdk_pixbuf_loader_new (); + g_return_val_if_fail (loader, FALSE); + if ((width != -1) && (height !=-1) && (width != 0) && (height != 0)) + { + gdk_pixbuf_loader_set_size (loader, width, height); + } + gdk_pixbuf_loader_write (loader, + thumb_mem->image_data, + thumb_mem->image_data_len, + NULL); + gdk_pixbuf_loader_close (loader, NULL); + pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + if (pixbuf) + g_object_ref (pixbuf); + g_object_unref (loader); + break; + } + case ITDB_THUMB_TYPE_PIXBUF: + { + Itdb_Thumb_Pixbuf *thumb_pixbuf = (Itdb_Thumb_Pixbuf*)thumb; + if ((width != -1) && (height !=-1) && (width != 0) && (height != 0)) + { + pixbuf = gdk_pixbuf_scale_simple (thumb_pixbuf->pixbuf, + width, height, + GDK_INTERP_BILINEAR); + } + else + { + pixbuf = g_object_ref (thumb_pixbuf->pixbuf); + } + break; + } + case ITDB_THUMB_TYPE_IPOD: + { + Itdb_Thumb_Ipod *thumb_ipod = (Itdb_Thumb_Ipod *)thumb; + const GList *thumb; + Itdb_Thumb_Ipod_Item *chosen; + gint w=width; + gint h=height; + + if ((width == -1) || (height == -1)) + { /* choose the largest availale thumbnail */ + w = G_MAXINT; + h = G_MAXINT; + } + + if (device == NULL) { + /* device is needed to get the ipod mountpoint */ + return NULL; + } + chosen = NULL; + for (thumb = itdb_thumb_ipod_get_thumbs (thumb_ipod); + thumb != NULL; + thumb = thumb->next) { + Itdb_Thumb_Ipod_Item *item = (Itdb_Thumb_Ipod_Item*)thumb->data; + if (chosen == NULL) + { /* make sure we select *something* */ + chosen = item; + } + if ((chosen->width > w) && (chosen->height > h)) + { /* try to find a thumb in size between the chosen and + the current one */ + if ((item->width >= w) && (item->height >= h)) + { + if ((item->width < chosen->width) || (item->height < chosen->height)) + { + chosen = item; + } + } + } + if ((chosen->width < w) || (chosen->height < h)) + { /* try to find something bigger */ + if ((item->width > chosen->width) || (item->height > chosen->height)) + { + chosen = item; + } + } + } + if (chosen != NULL) + { + GdkPixbuf *pix = itdb_thumb_ipod_item_to_pixbuf (device, chosen); + if ((width != -1) && (height !=-1) && (width != 0) && (height != 0)) + { /* scale */ + gdouble scalex = (gdouble)width/chosen->width; + gdouble scaley = (gdouble)height/chosen->height; + gdouble scale = MIN (scalex, scaley); + pixbuf = gdk_pixbuf_scale_simple (pix, + chosen->width*scale, + chosen->height*scale, + GDK_INTERP_BILINEAR); + g_object_unref (pix); + } + else + { /* don't scale */ + pixbuf = pix; + } + } + break; + } + case ITDB_THUMB_TYPE_INVALID: + g_return_val_if_reached (NULL); + } /* switch (...) */ - if (device == NULL) { - /* device is needed to get the ipod mountpoint */ - return NULL; - } - chosen = NULL; - for (thumb = itdb_thumb_ipod_get_thumbs (thumb_ipod); - thumb != NULL; - thumb = thumb->next) { - Itdb_Thumb_Ipod_Item *item = (Itdb_Thumb_Ipod_Item*)thumb->data; - if ((width >= item->width) && (height >= item->height)) { - if (chosen == NULL) { - chosen = item; - } - if ((item->width > chosen->width) - && (item->height > chosen->height)) { - chosen = item; - } - } - } - if (chosen != NULL) { - GdkPixbuf *pixbuf; - pixbuf = itdb_thumb_ipod_item_to_pixbuf (device, chosen); - return pixbuf; - } else { - return NULL; - } - } return pixbuf; } |