Update of /cvsroot/gtkpod/libgpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv21201/src
Modified Files:
itdb.h itdb_artwork.c itdb_photoalbum.c itdb_track.c
ithumb-writer.c
Log Message:
* When adding photos to the iPod the user may or may not want to
rotate the picture shown on the iPod screen, for example
deending on EXIF rotation value. This can now be achieved by
passing a new parameter 'rotation' to itdb_photodb_add_photo()
or itdb_photodb_add_photo_from_data(). (Valid values: 0, 90, 180,
270, rotation is counter-clockwise). These two functions now
also accept a GError pointer. As a consequence Itdb_Thumb had to
be extended with a field for the rotation value and
itdb_artwork_add_thumbnail have been extended to accept
@rotation and @error as well.
The actual rotation is carried out in
ithumb-writer.c/ithumb_writer_write_thumbnail() using
gdk_pixbuf_rotate_simple() and require gdk-pixbuf V2.6 or
higher.
In contrast, itdb_track_set_thumbnails() and
itdb_track_set_thumbnails_from_data have been left unchanged,
even though they could be extended to accept @rotation and
@error easily. Please let me know if this is wanted.
* configure.ac
src/itdb.h
src/itdb_artwork.c
src/itdb_photoalbum.c
src/itdb_track.c
src/ithumb-writer.c: implemented changes outlined above.
* tests/test-photos.c: added @rotation and @error to the
itdb_photodb_add_photo() call.
Index: itdb.h
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- itdb.h 11 Nov 2006 13:44:29 -0000 1.49
+++ itdb.h 23 Nov 2006 15:02:57 -0000 1.50
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-11-11 16:29:02 jcs>
+/* Time-stamp: <2006-11-23 23:27:35 jcs>
|
| Copyright (C) 2002-2006 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -431,17 +431,18 @@
*/
struct _Itdb_Thumb {
ItdbThumbType type;
- gchar *filename;
- guchar *image_data; /* holds the thumbnail data of
- non-transfered thumbnails when
- filename == NULL */
- gsize image_data_len; /* length of data */
+ gchar *filename;
+ guchar *image_data; /* holds the thumbnail data of
+ non-transfered thumbnails when
+ filename == NULL */
+ gsize image_data_len; /* length of data */
+ gint rotation; /* angle (0, 90, 180, 270) to rotate the image */
guint32 offset;
guint32 size;
- gint16 width;
- gint16 height;
- gint16 horizontal_padding;
- gint16 vertical_padding;
+ gint16 width;
+ gint16 height;
+ gint16 horizontal_padding;
+ gint16 vertical_padding;
};
struct _Itdb_Artwork {
@@ -1004,10 +1005,11 @@
* how to use. */
Itdb_PhotoDB *itdb_photodb_parse (const gchar *mp, GError **error);
Itdb_Artwork *itdb_photodb_add_photo (Itdb_PhotoDB *db, const gchar *filename,
- GError **error);
+ gint rotation, GError **error);
Itdb_Artwork *itdb_photodb_add_photo_from_data (Itdb_PhotoDB *db,
const guchar *image_data,
gsize image_data_len,
+ gint rotation,
GError **error);
void itdb_photodb_photoalbum_add_photo (Itdb_PhotoDB *db,
Itdb_PhotoAlbum *album,
@@ -1039,11 +1041,13 @@
ItdbThumbType type);
gboolean itdb_artwork_add_thumbnail (Itdb_Artwork *artwork,
ItdbThumbType type,
- const gchar *filename);
+ const gchar *filename,
+ gint rotation, GError **error);
gboolean itdb_artwork_add_thumbnail_from_data (Itdb_Artwork *artwork,
ItdbThumbType type,
const guchar *image_data,
- gsize image_data_len);
+ gsize image_data_len,
+ 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.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- itdb_artwork.c 12 Nov 2006 15:12:34 -0000 1.16
+++ itdb_artwork.c 23 Nov 2006 15:02:57 -0000 1.17
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-11-12 23:17:20 jcs>
+/* Time-stamp: <2006-11-23 23:27:35 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -163,18 +163,27 @@
* @artwork: an #Itdb_Thumbnail
* @type: thumbnail size
* @filename: image file 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 read from @filename yet, the file will be when @artwork is saved to
* disk. @filename must still exist when that happens.
*
+ * 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
+ * otherwise. @error is set appropriately.
**/
gboolean
itdb_artwork_add_thumbnail (Itdb_Artwork *artwork,
ItdbThumbType type,
- const gchar *filename)
+ const gchar *filename,
+ gint rotation,
+ GError **error)
{
#ifdef HAVE_GDKPIXBUF
/* This operation doesn't make sense when we can't save thumbnail files */
@@ -185,6 +194,9 @@
g_return_val_if_fail (filename, FALSE);
if (g_stat (filename, &statbuf) != 0) {
+ g_set_error (error, 0, -1,
+ _("Could not access file '%s'."),
+ filename);
return FALSE;
}
@@ -194,10 +206,13 @@
thumb = itdb_thumb_new ();
thumb->filename = g_strdup (filename);
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
}
@@ -210,19 +225,28 @@
* @image_data: data used to create the thumbnail (the raw contents of
* an image file)
* @image_data_len: length of above data block
+ * @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 processed yet. This will be done when @artwork
* is saved to disk.
*
+ * 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
+ * otherwise. @error is set appropriately.
**/
gboolean
itdb_artwork_add_thumbnail_from_data (Itdb_Artwork *artwork,
ItdbThumbType type,
const guchar *image_data,
- gsize image_data_len)
+ gsize image_data_len,
+ gint rotation,
+ GError **error)
{
#ifdef HAVE_GDKPIXBUF
/* This operation doesn't make sense when we can't save thumbnail files */
@@ -243,10 +267,13 @@
memcpy (thumb->image_data, image_data, image_data_len);
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
}
Index: itdb_photoalbum.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_photoalbum.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- itdb_photoalbum.c 31 Oct 2006 12:52:09 -0000 1.11
+++ itdb_photoalbum.c 23 Nov 2006 15:02:57 -0000 1.12
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-10-31 21:49:36 jcs>
+/* Time-stamp: <2006-11-23 23:29:44 jcs>
|
| Copyright (C) 2002-2006 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -333,6 +333,7 @@
const gchar *filename,
const guchar *image_data,
gsize image_data_len,
+ gint rotation,
GError **error)
{
#ifdef HAVE_GDKPIXBUF
@@ -408,14 +409,18 @@
{
result = itdb_artwork_add_thumbnail (artwork,
format->type,
- filename);
+ filename,
+ rotation,
+ error);
}
if (image_data)
{
result = itdb_artwork_add_thumbnail_from_data (artwork,
format->type,
image_data,
- image_data_len);
+ image_data_len,
+ rotation,
+ error);
}
}
@@ -453,45 +458,63 @@
* itdb_photodb_add_photo:
* @db: the #Itdb_PhotoDB to add the photo to.
* @filename: file with the photo to add.
+ * @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 (Itdb_PhotoDB *db,
const gchar *filename,
+ gint rotation,
GError **error)
{
g_return_val_if_fail (db, FALSE);
g_return_val_if_fail (filename, FALSE);
- return itdb_photodb_add_photo_internal (db, filename, NULL, 0, error);
+ return itdb_photodb_add_photo_internal (db, filename, NULL, 0, rotation,
error);
}
/**
* itdb_photodb_add_photo_from_data:
* @db: the #Itdb_PhotoDB to add the photo to.
- * @filename: file with the photo to add.
+ * @image_data: chunk of memory containing the image data (for example
+ * a jpg file)
+ * @image_data_len: length of above chunk of memory
+ * @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_data (Itdb_PhotoDB *db,
const guchar *image_data,
gsize image_data_len,
+ gint rotation,
GError **error)
{
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,
- error);
+ rotation, error);
}
Index: itdb_track.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_track.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- itdb_track.c 7 Nov 2006 12:08:19 -0000 1.23
+++ itdb_track.c 23 Nov 2006 15:02:57 -0000 1.24
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-11-07 20:54:45 jcs>
+/* Time-stamp: <2006-11-23 23:32:16 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -370,7 +370,9 @@
static gboolean itdb_track_set_thumbnails_internal (Itdb_Track *track,
const gchar *filename,
const guchar *image_data,
- gsize image_data_len)
+ gsize image_data_len,
+ gint rotation,
+ GError **error)
{
gboolean result = FALSE;
@@ -382,23 +384,25 @@
{
result = itdb_artwork_add_thumbnail (track->artwork,
ITDB_THUMB_COVER_SMALL,
- filename);
+ filename, rotation, error);
if (result == TRUE)
result = itdb_artwork_add_thumbnail (track->artwork,
ITDB_THUMB_COVER_LARGE,
- filename);
+ filename, rotation, error);
}
if (image_data)
{
result = itdb_artwork_add_thumbnail_from_data (track->artwork,
ITDB_THUMB_COVER_SMALL,
image_data,
- image_data_len);
+ image_data_len,
+ rotation, error);
if (result == TRUE)
result = itdb_artwork_add_thumbnail_from_data (track->artwork,
ITDB_THUMB_COVER_LARGE,
image_data,
- image_data_len);
+ image_data_len,
+ rotation, error);
}
if (result == TRUE)
@@ -443,7 +447,8 @@
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,
+ 0, NULL);
}
@@ -471,7 +476,8 @@
g_return_val_if_fail (image_data, FALSE);
return itdb_track_set_thumbnails_internal (track, NULL,
- image_data, image_data_len);
+ image_data, image_data_len,
+ 0, NULL);
}
Index: ithumb-writer.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/ithumb-writer.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- ithumb-writer.c 12 Nov 2006 15:12:40 -0000 1.23
+++ ithumb-writer.c 23 Nov 2006 15:02:57 -0000 1.24
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-11-13 00:03:30 jcs>
+/* Time-stamp: <2006-11-23 23:45:01 jcs>
*
* Copyright (C) 2005 Christophe Fergeau
*
@@ -304,13 +304,32 @@
gint width, height; /* must be gint -- see comment below */
g_return_val_if_fail (writer, FALSE);
+ g_return_val_if_fail (writer->img_info, FALSE);
g_return_val_if_fail (thumb, FALSE);
+ /* Make sure @rotation is valid (0, 90, 180, 270) */
+ thumb->rotation = thumb->rotation % 360;
+ thumb->rotation /= 90;
+ thumb->rotation *= 90;
+
+ /* If we rotate by 90 or 270 degrees interchange the width and
+ * height */
+
+ if ((thumb->rotation == 0) || (thumb->rotation == 180))
+ {
+ width = writer->img_info->width;
+ height = writer->img_info->height;
+ }
+ else
+ {
+ width = writer->img_info->height;
+ height = writer->img_info->width;
+ }
+
if (thumb->filename)
{ /* read image from filename */
pixbuf = gdk_pixbuf_new_from_file_at_size (thumb->filename,
- writer->img_info->width,
- writer->img_info->height,
+ width, height,
NULL);
g_free (thumb->filename);
@@ -321,8 +340,7 @@
GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
g_return_val_if_fail (loader, FALSE);
gdk_pixbuf_loader_set_size (loader,
- writer->img_info->width,
- writer->img_info->height);
+ width, height);
gdk_pixbuf_loader_write (loader,
thumb->image_data,
thumb->image_data_len,
@@ -342,6 +360,17 @@
return FALSE;
}
+ /* Rotate if necessary */
+ if (thumb->rotation != 0)
+ {
+ GdkPixbuf *new_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
thumb->rotation);
+ g_object_unref (pixbuf);
+ pixbuf = new_pixbuf;
+ }
+
+ /* Clean up */
+ thumb->rotation = 0;
+
/* !! cannot write directly to &thumb->width/height because
g_object_get() returns a gint, but thumb->width/height are
gint16 !! */
-------------------------------------------------------------------------
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