diff options
| author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-11-23 15:02:58 +0000 |
|---|---|---|
| committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-11-23 15:02:58 +0000 |
| commit | 58934f71261254a236a1f736e360001d3912624e (patch) | |
| tree | a44dc93a06653376012cf0dd5c30028473f84598 /src/ithumb-writer.c | |
| parent | 7044c632719e31d7e7a644d1ab7c26989bcb7357 (diff) | |
| download | libgpod-58934f71261254a236a1f736e360001d3912624e.tar.gz libgpod-58934f71261254a236a1f736e360001d3912624e.tar.xz libgpod-58934f71261254a236a1f736e360001d3912624e.zip | |
* 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.
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1338 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/ithumb-writer.c')
| -rw-r--r-- | src/ithumb-writer.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c index 060ff2a..f20546f 100644 --- a/src/ithumb-writer.c +++ b/src/ithumb-writer.c @@ -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 @@ ithumb_writer_write_thumbnail (iThumbWriter *writer, 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 @@ ithumb_writer_write_thumbnail (iThumbWriter *writer, 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 @@ ithumb_writer_write_thumbnail (iThumbWriter *writer, 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 !! */ |
