diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | src/itdb.h | 14 | ||||
-rw-r--r-- | src/itdb_artwork.c | 74 | ||||
-rw-r--r-- | src/itdb_photoalbum.c | 52 | ||||
-rw-r--r-- | src/itdb_track.c | 39 | ||||
-rw-r--r-- | src/ithumb-writer.c | 8 |
6 files changed, 194 insertions, 6 deletions
@@ -12,6 +12,19 @@ models choking on filenames with uppercase extensions like test.MP3. Not sure if it helps, though. + * src/itdb.h + src/itdb_artwork.c + src/itdb_photoalbum.c + src/itdb_track.c + src/ithumb-writer.c: + Added new API functions: itdb_photodb_add_photo_from_pixbuf + function(), itdb_track_set_thumbnails_from_pixbuf() and + itdb_artwork_add_thumbnail_from_pixbuf(). Thanks to Christophe + Fergeau. + + * docs/reference/libgpod-sections.txt: added descriptions by + Christophe Fergeau. + 2007-03-02 Todd Zullinger <tmzullinger at users.sourceforge.net> * bindings/Makefile.am: only descend into the python subdir if @@ -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_Track *track, 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 @@ -1044,6 +1048,11 @@ Itdb_Artwork *itdb_photodb_add_photo_from_data (Itdb_PhotoDB *db, gint position, gint rotation, GError **error); +Itdb_Artwork *itdb_photodb_add_photo_from_pixbuf (Itdb_PhotoDB *db, + gpointer pixbuf, + gint position, + gint rotation, + GError **error); void itdb_photodb_photoalbum_add_photo (Itdb_PhotoDB *db, Itdb_PhotoAlbum *album, Itdb_Artwork *photo, @@ -1082,6 +1091,11 @@ gboolean itdb_artwork_add_thumbnail_from_data (Itdb_Artwork *artwork, 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 80b9a7f..648e67e 100644 --- a/src/itdb_artwork.c +++ b/src/itdb_artwork.c @@ -1,4 +1,4 @@ -/* Time-stamp: <2007-03-21 14:12:58 jcs> +/* Time-stamp: <2007-03-21 17:30:57 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -218,6 +218,66 @@ itdb_artwork_add_thumbnail (Itdb_Artwork *artwork, #endif } +/** + * itdb_artwork_add_thumbnail_from_pixbuf + * @artwork: an #Itdb_Thumbnail + * @type: thumbnail size + * @pixbuf: #GdkPixbuf to use to create the thumbnail + * @rotation: angle by which the image should be rotated + * counterclockwise. Valid values are 0, 90, 180 and 270. + * @error: return location for a #GError or NULL + * + * Appends a thumbnail of type @type to existing thumbnails in @artwork. No + * data is generated from @pixbuf yet, it will be done when @artwork is saved + * to disk. @pixbuf is ref'ed by this function, but is not copied, so it should + * not be modified before the database is saved. + * + * For the rotation angle you can also use the gdk constants + * GDK_PIXBUF_ROTATE_NONE, ..._COUNTERCLOCKWISE, ..._UPSIDEDOWN AND + * ..._CLOCKWISE. + * + * Return value: TRUE if the thumbnail could be successfully added, FALSE + * otherwise. @error is set appropriately. + **/ +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 @@ -667,6 +727,12 @@ itdb_thumb_get_gdk_pixbuf (Itdb_Device *device, Itdb_Thumb *thumb) g_object_ref (pixbuf); g_object_unref (loader); } + else if (thumb->pixbuf) + { /* use pixbuf data */ + pixbuf = gdk_pixbuf_scale_simple (thumb->pixbuf, + width, height, + GDK_INTERP_BILINEAR); + } if (!pixbuf) { @@ -783,6 +849,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); } @@ -814,6 +883,9 @@ Itdb_Thumb *itdb_thumb_duplicate (Itdb_Thumb *thumb) 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_photoalbum.c b/src/itdb_photoalbum.c index f9aa048..6e291c6 100644 --- a/src/itdb_photoalbum.c +++ b/src/itdb_photoalbum.c @@ -35,7 +35,9 @@ #include <stdio.h> #include <string.h> #include <glib/gi18n-lib.h> - +#ifdef HAVE_GDKPIXBUF +#include <gdk-pixbuf/gdk-pixbuf.h> +#endif /* Short summary: @@ -331,6 +333,7 @@ static Itdb_Artwork *itdb_photodb_add_photo_internal (Itdb_PhotoDB *db, const gchar *filename, const guchar *image_data, gsize image_data_len, + gpointer pixbuf, gint position, gint rotation, GError **error) @@ -345,6 +348,7 @@ static Itdb_Artwork *itdb_photodb_add_photo_internal (Itdb_PhotoDB *db, g_return_val_if_fail (db->device, NULL); g_return_val_if_fail (filename || image_data, NULL); g_return_val_if_fail (!(image_data && (image_data_len == 0)), NULL); + g_return_val_if_fail (!(pixbuf && (!GDK_IS_PIXBUF (pixbuf))), NULL); if (!ipod_supports_photos (db->device)) { @@ -421,6 +425,14 @@ static Itdb_Artwork *itdb_photodb_add_photo_internal (Itdb_PhotoDB *db, rotation, error); } + if (pixbuf) + { + result = itdb_artwork_add_thumbnail_from_pixbuf (artwork, + format->type, + pixbuf, + rotation, + error); + } } if (result != TRUE) @@ -483,7 +495,7 @@ Itdb_Artwork *itdb_photodb_add_photo (Itdb_PhotoDB *db, g_return_val_if_fail (db, FALSE); g_return_val_if_fail (filename, FALSE); - return itdb_photodb_add_photo_internal (db, filename, NULL, 0, + return itdb_photodb_add_photo_internal (db, filename, NULL, 0, NULL, position, rotation, error); } @@ -520,7 +532,41 @@ Itdb_Artwork *itdb_photodb_add_photo_from_data (Itdb_PhotoDB *db, g_return_val_if_fail (db, FALSE); g_return_val_if_fail (image_data, FALSE); - return itdb_photodb_add_photo_internal (db, NULL, image_data, image_data_len, + return itdb_photodb_add_photo_internal (db, NULL, + image_data, image_data_len, + NULL, position, rotation, error); +} + +/** + * itdb_photodb_add_photo_from_pixbuf: + * @db: the #Itdb_PhotoDB to add the photo to. + * @pixbuf: a #GdkPixbuf to use as the image data + * @position: position where to insert the new photo (-1 to append at + * the end) + * @rotation: angle by which the image should be rotated + * counterclockwise. Valid values are 0, 90, 180 and 270. + * @error: return location for a #GError or NULL + * + * Add a photo to the PhotoDB. The photo is automatically added to the + * first Photoalbum, which by default contains a list of all photos in + * the database. If no Photoalbums exist one is created automatically. + * + * For the rotation angle you can also use the gdk constants + * GDK_PIXBUF_ROTATE_NONE, ..._COUNTERCLOCKWISE, ..._UPSIDEDOWN AND + * ..._CLOCKWISE. + * + * Return value: a pointer to the added photo. + **/ +Itdb_Artwork *itdb_photodb_add_photo_from_pixbuf (Itdb_PhotoDB *db, + gpointer pixbuf, + gint position, + gint rotation, + GError **error) +{ + g_return_val_if_fail (db, FALSE); + g_return_val_if_fail (pixbuf, FALSE); + + return itdb_photodb_add_photo_internal (db, NULL, NULL, 0, pixbuf, position, rotation, error); } diff --git a/src/itdb_track.c b/src/itdb_track.c index 81445aa..ca52528 100644 --- a/src/itdb_track.c +++ b/src/itdb_track.c @@ -381,6 +381,7 @@ static gboolean itdb_track_set_thumbnails_internal (Itdb_Track *track, 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_thumbnails_internal (Itdb_Track *track, 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_Track *track, 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,28 @@ gboolean itdb_track_set_thumbnails_from_data (Itdb_Track *track, return itdb_track_set_thumbnails_internal (track, NULL, image_data, image_data_len, - 0, NULL); + NULL, 0, NULL); +} + +/** + * itdb_track_set_thumbnails_from_pixbuf: + * @track: an #Itdb_Track + * @pixbuf: a #GdkPixbuf used to generate the thumbnail + * + * Uses @pixbuf to generate iPod thumbnails. To save memory, the thumbnails + * will only be generated when necessary, ie when itdb_save() or a + * similar function is called. + * + * Return value: TRUE if the thumbnail could be added, FALSE otherwise. + **/ +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 9ee8122..562684b 100644 --- a/src/ithumb-writer.c +++ b/src/ithumb-writer.c @@ -357,6 +357,14 @@ ithumb_writer_write_thumbnail (iThumbWriter *writer, 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) { |