Revision: 2025
http://gtkpod.svn.sourceforge.net/gtkpod/?rev=2025&view=rev
Author: jcsjcs
Date: 2008-06-29 07:12:34 -0700 (Sun, 29 Jun 2008)
Log Message:
-----------
* 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.)
Modified Paths:
--------------
libgpod/trunk/ChangeLog
libgpod/trunk/src/itdb_artwork.c
libgpod/trunk/src/itdb_thumb.c
Modified: libgpod/trunk/ChangeLog
===================================================================
--- libgpod/trunk/ChangeLog 2008-06-29 13:01:17 UTC (rev 2024)
+++ libgpod/trunk/ChangeLog 2008-06-29 14:12:34 UTC (rev 2025)
@@ -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 <[EMAIL PROTECTED]>
patch by: Mike Heffner <[EMAIL PROTECTED]>
Modified: libgpod/trunk/src/itdb_artwork.c
===================================================================
--- libgpod/trunk/src/itdb_artwork.c 2008-06-29 13:01:17 UTC (rev 2024)
+++ libgpod/trunk/src/itdb_artwork.c 2008-06-29 14:12:34 UTC (rev 2025)
@@ -888,10 +888,12 @@
/**
* 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
Modified: libgpod/trunk/src/itdb_thumb.c
===================================================================
--- libgpod/trunk/src/itdb_thumb.c 2008-06-29 13:01:17 UTC (rev 2024)
+++ libgpod/trunk/src/itdb_thumb.c 2008-06-29 14:12:34 UTC (rev 2025)
@@ -363,6 +363,12 @@
* 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 @@
{
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 (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;
- }
- }
+ 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 (...) */
+
return pixbuf;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2