Update of /cvsroot/gtkpod/libgpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv19423/src
Modified Files:
itdb.h itdb_artwork.c itdb_photoalbum.c itdb_track.c
ithumb-writer.c
Log Message:
* 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.
Index: itdb.h
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- itdb.h 25 Feb 2007 04:27:09 -0000 1.60
+++ itdb.h 21 Mar 2007 08:37:20 -0000 1.61
@@ -445,6 +445,7 @@
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_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 @@
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 @@
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);
Index: itdb_artwork.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_artwork.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- itdb_artwork.c 21 Mar 2007 05:19:14 -0000 1.19
+++ itdb_artwork.c 21 Mar 2007 08:37:20 -0000 1.20
@@ -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 @@
#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 @@
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 @@
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 @@
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;
}
Index: itdb_photoalbum.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_photoalbum.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- itdb_photoalbum.c 14 Jan 2007 13:34:07 -0000 1.16
+++ itdb_photoalbum.c 21 Mar 2007 08:37:20 -0000 1.17
@@ -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 @@
const gchar *filename,
const guchar *image_data,
gsize image_data_len,
+ gpointer pixbuf,
gint position,
gint rotation,
GError **error)
@@ -345,6 +348,7 @@
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 @@
rotation,
error);
}
+ if (pixbuf)
+ {
+ result = itdb_artwork_add_thumbnail_from_pixbuf (artwork,
+ format->type,
+ pixbuf,
+ rotation,
+ error);
+ }
}
if (result != TRUE)
@@ -483,7 +495,7 @@
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 @@
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);
}
Index: itdb_track.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_track.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- itdb_track.c 13 Jan 2007 20:24:50 -0000 1.25
+++ itdb_track.c 21 Mar 2007 08:37:20 -0000 1.26
@@ -381,6 +381,7 @@
const gchar *filename,
const guchar *image_data,
gsize image_data_len,
+ gpointer *pixbuf,
gint rotation,
GError **error)
{
@@ -414,6 +415,19 @@
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 @@
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 @@
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);
}
Index: ithumb-writer.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/ithumb-writer.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- ithumb-writer.c 9 Feb 2007 16:01:59 -0000 1.27
+++ ithumb-writer.c 21 Mar 2007 08:37:20 -0000 1.28
@@ -357,6 +357,14 @@
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)
{
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2