commit 539a2f8810ce9af5707e41d1838cf844e4bd67a0
Author: Christophe Fergeau <christophe@anevia.com>
Date:   Thu Mar 1 14:37:13 2007 +0100

    add itdb_track_set_thumbnails_from_pixbuf and related functions

diff --git a/src/itdb.h b/src/itdb.h
index b9b570c..64c940d 100644
--- a/src/itdb.h
+++ b/src/itdb.h
@@ -445,6 +445,7 @@ struct _Itdb_Thumb {
 				 non-transfered thumbnails when
 				 filename == NULL */
     gsize   image_data_len;   /* length of data */
+    gpointer *pixbuf;
     gint    rotation;         /* angle (0, 90, 180, 270) to rotate the image */
     guint32 offset;
     guint32 size;
@@ -1030,6 +1031,9 @@ gboolean itdb_track_set_thumbnails (Itdb
 gboolean itdb_track_set_thumbnails_from_data (Itdb_Track *track,
 					      const guchar *image_data,
 					      gsize image_data_len);
+gboolean itdb_track_set_thumbnails_from_pixbuf (Itdb_Track *track,
+                                                gpointer pixbuf);
+
 void itdb_track_remove_thumbnails (Itdb_Track *track);
 
 /* photoalbum functions -- see itdb_photoalbum.c for instructions on
@@ -1082,6 +1086,11 @@ gboolean itdb_artwork_add_thumbnail_from
 					       const guchar *image_data,
 					       gsize image_data_len,
 					       gint rotation, GError **error);
+gboolean itdb_artwork_add_thumbnail_from_pixbuf (Itdb_Artwork *artwork,
+                                                 ItdbThumbType type,
+                                                 gpointer pixbuf,
+                                                 gint rotation,
+                                                 GError **error);
 void itdb_artwork_remove_thumbnail (Itdb_Artwork *artwork,
 				    Itdb_Thumb *thumb);
 void itdb_artwork_remove_thumbnails (Itdb_Artwork *artwork);
diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c
index b959f4f..28af514 100644
--- a/src/itdb_artwork.c
+++ b/src/itdb_artwork.c
@@ -218,6 +218,46 @@ #endif
 }
 
 
+gboolean
+itdb_artwork_add_thumbnail_from_pixbuf (Itdb_Artwork *artwork,
+                                        ItdbThumbType type,
+                                        gpointer pixbuf,
+                                        gint rotation,
+                                        GError **error)
+{
+#ifdef HAVE_GDKPIXBUF
+/* This operation doesn't make sense when we can't save thumbnail files */
+    Itdb_Thumb *thumb;
+    GTimeVal time;
+    gint rowstride;
+    gint height;
+
+    g_return_val_if_fail (artwork, FALSE);
+    g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
+
+    g_get_current_time (&time);
+    g_object_get (G_OBJECT (pixbuf),
+                  "height", &height,
+                  "rowstride", &rowstride,
+                  NULL);
+    artwork->artwork_size  = rowstride * height;
+    artwork->creation_date = time.tv_sec;
+
+    thumb = itdb_thumb_new ();
+    g_object_ref (G_OBJECT (pixbuf));
+    thumb->pixbuf = pixbuf;
+    thumb->type = type;
+    thumb->rotation = rotation;
+    artwork->thumbnails = g_list_append (artwork->thumbnails, thumb);
+
+    return TRUE;
+#else
+    g_set_error (error, 0, -1,
+		 _("Artwork support not compiled into libgpod."));
+    return FALSE;
+#endif
+}
+
 /**
  * itdb_artwork_add_thumbnail_from_data
  * @artwork: an #Itdb_Thumbnail
@@ -782,6 +822,9 @@ void itdb_thumb_free (Itdb_Thumb *thumb)
     g_return_if_fail (thumb);
 
     g_free (thumb->image_data);
+    if (thumb->pixbuf) {
+        g_object_unref (G_OBJECT (thumb->pixbuf));
+    }
     g_free (thumb->filename);
     g_free (thumb);
 }
@@ -813,6 +856,9 @@ Itdb_Thumb *itdb_thumb_duplicate (Itdb_T
 	memcpy (new_thumb->image_data, thumb->image_data,
 		new_thumb->image_data_len);
     }
+    if (thumb->pixbuf) {
+        g_object_ref (G_OBJECT (thumb->pixbuf));
+    }
     return new_thumb;
 }
 
diff --git a/src/itdb_track.c b/src/itdb_track.c
index 848846a..07af1e3 100644
--- a/src/itdb_track.c
+++ b/src/itdb_track.c
@@ -381,6 +381,7 @@ static gboolean itdb_track_set_thumbnail
 						    const gchar *filename,
 						    const guchar *image_data,
 						    gsize image_data_len,
+                                                    gpointer *pixbuf,
 						    gint rotation,
 						    GError **error)
 {					     
@@ -414,6 +415,19 @@ static gboolean itdb_track_set_thumbnail
 							   image_data_len,
 							   rotation, error);
     }
+    if (pixbuf)
+    {
+        result = itdb_artwork_add_thumbnail_from_pixbuf (track->artwork,
+                                                         ITDB_THUMB_COVER_SMALL,
+                                                         pixbuf, rotation,
+                                                         error);
+        if (result == TRUE) {
+            result = itdb_artwork_add_thumbnail_from_pixbuf (track->artwork,
+                                                             ITDB_THUMB_COVER_LARGE,
+                                                             pixbuf, rotation,
+                                                             error);
+        }
+    }
 
     if (result == TRUE)
     {
@@ -457,7 +471,7 @@ gboolean itdb_track_set_thumbnails (Itdb
     g_return_val_if_fail (track, FALSE);
     g_return_val_if_fail (filename, FALSE);
 
-    return itdb_track_set_thumbnails_internal (track, filename, NULL, 0,
+    return itdb_track_set_thumbnails_internal (track, filename, NULL, 0, NULL,
 					       0, NULL);
 }
 
@@ -487,7 +501,17 @@ gboolean itdb_track_set_thumbnails_from_
 
     return itdb_track_set_thumbnails_internal (track, NULL,
 					       image_data, image_data_len,
-					       0, NULL);
+                                               NULL, 0, NULL);
+}
+
+gboolean itdb_track_set_thumbnails_from_pixbuf (Itdb_Track *track,
+                                                gpointer pixbuf)
+{
+    g_return_val_if_fail (track, FALSE);
+    g_return_val_if_fail (pixbuf, FALSE);
+
+    return itdb_track_set_thumbnails_internal (track, NULL, NULL, 0,
+                                               pixbuf, 0, NULL);
 }
 
 
diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c
index 4a731a4..4b670ae 100644
--- a/src/ithumb-writer.c
+++ b/src/ithumb-writer.c
@@ -357,6 +357,14 @@ ithumb_writer_write_thumbnail (iThumbWri
 	thumb->image_data = NULL;
 	thumb->image_data_len = 0;
     }
+    else if (thumb->pixbuf)
+    {
+        pixbuf = gdk_pixbuf_scale_simple (GDK_PIXBUF(thumb->pixbuf),
+                                          width, height,
+                                          GDK_INTERP_BILINEAR);
+        g_object_unref (thumb->pixbuf);
+        thumb->pixbuf = NULL;
+    }
 
     if (pixbuf == NULL)
     {
