summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2005-11-24 13:31:24 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2005-11-24 13:31:24 +0000
commit3a2fe6f896ff3dfe9f66e074cd1c75d27f49b01a (patch)
treea81674e47ced1e16abdd14dce1bb1a792f6ce9bc
parent413674fba5e513b11b0522fb5cc9356169f7c85d (diff)
downloadlibgpod-3a2fe6f896ff3dfe9f66e074cd1c75d27f49b01a.tar.gz
libgpod-3a2fe6f896ff3dfe9f66e074cd1c75d27f49b01a.tar.xz
libgpod-3a2fe6f896ff3dfe9f66e074cd1c75d27f49b01a.zip
* overall changes to support itdb_image_get_gdk_pixbuf(). Run
"tests/test-thumbnails <ipod_mount> to copy all thumbnails into the current directory. git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1172 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r--ChangeLog6
-rw-r--r--src/db-artwork-parser.c36
-rw-r--r--src/db-artwork-writer.c30
-rw-r--r--src/db-image-parser.c87
-rw-r--r--src/db-image-parser.h2
-rw-r--r--src/itdb.h27
-rw-r--r--src/itdb_itunesdb.c2
-rw-r--r--tests/test-covers.c65
8 files changed, 145 insertions, 110 deletions
diff --git a/ChangeLog b/ChangeLog
index 83cfd62..3203ac3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2005-11-23 Christophe Fergeau <teuf@gnome.org>
+ * overall changes to support itdb_image_get_gdk_pixbuf(). Run
+ "tests/test-thumbnails <ipod_mount> to copy all thumbnails into
+ the current directory.
+
+2005-11-23 Christophe Fergeau <teuf@gnome.org>
+
* src/db-artwork-debug.c: (get_utf16_string):
* src/db-artwork-parser.c: (get_utf16_string), (parse_mhod_3),
(parse_mhni), (ipod_supports_cover_art), (ipod_parse_artwork_db):
diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c
index 4a1997c..8be8be7 100644
--- a/src/db-artwork-parser.c
+++ b/src/db-artwork-parser.c
@@ -22,6 +22,12 @@
*
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
#include "itdb.h"
#include "db-artwork-debug.h"
#include "db-artwork-parser.h"
@@ -98,8 +104,32 @@ get_utf16_string (void* buffer, gint length)
}
+static char *
+mhod3_get_ithmb_filename (MhodHeaderArtworkType3 *mhod3,
+ Itdb_iTunesDB *db)
+{
+ char *paths[] = {"iPod_Control", "Artwork", NULL, NULL};
+ char *filename;
+ char *result;
+
+ g_assert (mhod3 != NULL);
+ g_assert (db != NULL);
+
+ filename = get_utf16_string (mhod3->string, mhod3->string_len);
+ if ((filename == NULL) || (strlen (filename) < 2)) {
+ return NULL;
+ }
+
+ paths[2] = filename+1;
+ result = itdb_resolve_path (db->mountpoint, (const char **)paths);
+ g_free (filename);
+ return result;
+}
+
+
static int
-parse_mhod_3 (DBParseContext *ctx, Itdb_Image *image, GError *error)
+parse_mhod_3 (DBParseContext *ctx, Itdb_iTunesDB *db,
+ Itdb_Image *image, GError *error)
{
MhodHeader *mhod;
MhodHeaderArtworkType3 *mhod3;
@@ -117,7 +147,7 @@ parse_mhod_3 (DBParseContext *ctx, Itdb_Image *image, GError *error)
if ((GINT_FROM_LE (mhod3->type) & 0x00FFFFFF) != MHOD_ARTWORK_TYPE_FILE_NAME) {
return -1;
}
- image->filename = get_utf16_string (mhod3->string, mhod3->string_len);
+ image->filename = mhod3_get_ithmb_filename (mhod3, db);
dump_mhod_type_3 (mhod3);
return 0;
}
@@ -145,7 +175,7 @@ parse_mhni (DBParseContext *ctx, iPodSong *song, GError *error)
if (mhod_ctx == NULL) {
return -1;
}
- parse_mhod_3 (mhod_ctx, thumb, error);
+ parse_mhod_3 (mhod_ctx, song->itdb, thumb, error);
g_free (mhod_ctx);
return 0;
diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c
index 33e673c..9a6924c 100644
--- a/src/db-artwork-writer.c
+++ b/src/db-artwork-writer.c
@@ -241,31 +241,6 @@ enum iPodThumbnailType {
#define RETURN_SIZE_FOR(id, size) if (strncmp (id, header_id, 4) == 0) return (size)
-static const IpodArtworkFormat *
-get_artwork_info (IpodDevice *ipod, int image_type)
-{
- const IpodArtworkFormat *formats;
-
- if (ipod == NULL) {
- return NULL;
- }
-
- g_object_get (G_OBJECT (ipod), "artwork-formats", &formats, NULL);
- if (formats == NULL) {
- return NULL;
- }
-
- while ((formats->type != -1) && (formats->type != image_type)) {
- formats++;
- }
-
- if (formats->type == -1) {
- return NULL;
- }
-
- return formats;
-}
-
/* Returns the "real" size for a header, ie the size iTunes uses for it
* (padding included)
@@ -477,7 +452,8 @@ write_mhii (Itdb_Track *song, iPodBuffer *buffer)
return -1;
}
thumb = (Itdb_Image *)it->data;
- img_info = get_artwork_info (song->itdb->device, thumb->type);
+ img_info = ipod_get_artwork_info_from_type (
+ song->itdb->device, thumb->type);
if (img_info == NULL) {
return -1;
}
@@ -571,7 +547,7 @@ write_mhif (Itdb_iTunesDB *db, iPodBuffer *buffer, enum iPodThumbnailType type)
}
mhif->total_len = mhif->header_len;
- img_info = get_artwork_info (db->device, type);
+ img_info = ipod_get_artwork_info_from_type (db->device, type);
if (img_info == NULL) {
return -1;
}
diff --git a/src/db-image-parser.c b/src/db-image-parser.c
index d2f152c..372013c 100644
--- a/src/db-image-parser.c
+++ b/src/db-image-parser.c
@@ -31,6 +31,10 @@
#include "db-artwork-parser.h"
#include "db-image-parser.h"
+#if HAVE_GDKPIXBUF
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#endif
+#include <glib/gi18n-lib.h>
static unsigned char *
unpack_RGB_565 (gushort *pixels, unsigned int bytes_len)
@@ -123,14 +127,59 @@ itdb_image_get_rgb_data (Itdb_Image *image)
return pixels;
- /* return gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE,
- 8, image->width, image->height,
- image->width * 3,
- (GdkPixbufDestroyNotify)g_free,
- NULL);
- */
}
+/* Convert the pixeldata in @image to a GdkPixbuf.
+ Since we want to have gdk-pixbuf dependency optional, a generic
+ gpointer is returned which you have to cast to (GdkPixbuf *)
+ yourself. If gdk-pixbuf is not installed the NULL pointer is
+ returned.
+ The returned GdkPixbuf must be freed with gdk_pixbuf_unref() after
+ use. */
+gpointer
+itdb_image_get_gdk_pixbuf (Itdb_iTunesDB *itdb, Itdb_Image *image)
+{
+#if HAVE_GDKPIXBUF
+ GdkPixbuf *result;
+ guchar *pixels;
+ const IpodArtworkFormat *img_info;
+
+ g_return_val_if_fail (itdb, NULL);
+ g_return_val_if_fail (image, NULL);
+
+ pixels = itdb_image_get_rgb_data (image);
+ if (pixels == NULL)
+ {
+ return NULL;
+ }
+
+ img_info = ipod_get_artwork_info_from_type (itdb->device,
+ image->type);
+
+ if (img_info == NULL)
+ {
+ g_print (_("Unable to obtain image info on image (type: %d, filename: '%s'\n)"), image->type, image->filename);
+ g_free (pixels);
+ return NULL;
+ }
+
+ result = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE,
+ 8, image->width, image->height,
+ img_info->width*3,
+ (GdkPixbufDestroyNotify)g_free,
+ NULL);
+
+ /* !! do not g_free(pixels) here: it will be freed when doing a
+ * gdk_pixbuf_unref() on the GdkPixbuf !! */
+
+ return result;
+#else
+ return NULL;
+#endif
+}
+
+
+
static int
image_type_from_corr_id (IpodDevice *ipod, int corr_id)
{
@@ -155,6 +204,32 @@ image_type_from_corr_id (IpodDevice *ipod, int corr_id)
return -1;
}
+
+G_GNUC_INTERNAL const IpodArtworkFormat *
+ipod_get_artwork_info_from_type (IpodDevice *ipod, int image_type)
+{
+ const IpodArtworkFormat *formats;
+
+ if (ipod == NULL) {
+ return NULL;
+ }
+
+ g_object_get (G_OBJECT (ipod), "artwork-formats", &formats, NULL);
+ if (formats == NULL) {
+ return NULL;
+ }
+
+ while ((formats->type != -1) && (formats->type != image_type)) {
+ formats++;
+ }
+
+ if (formats->type == -1) {
+ return NULL;
+ }
+
+ return formats;
+}
+
G_GNUC_INTERNAL Itdb_Image *
ipod_image_new_from_mhni (MhniHeader *mhni, Itdb_iTunesDB *db)
{
diff --git a/src/db-image-parser.h b/src/db-image-parser.h
index 8cf082f..8f3ef1c 100644
--- a/src/db-image-parser.h
+++ b/src/db-image-parser.h
@@ -46,5 +46,7 @@ G_GNUC_INTERNAL Itdb_Image *ipod_image_new_from_mhni (MhniHeader *mhni,
G_GNUC_INTERNAL int itdb_write_ithumb_files (Itdb_iTunesDB *db,
const char *mount_point);
+G_GNUC_INTERNAL const IpodArtworkFormat *ipod_get_artwork_info_from_type (
+ IpodDevice *ipod, int image_type);
#endif
diff --git a/src/itdb.h b/src/itdb.h
index 5cd2ff6..f1a7e61 100644
--- a/src/itdb.h
+++ b/src/itdb.h
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-11-19 16:26:13 jcs>
+/* Time-stamp: <2005-11-24 21:34:51 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -312,16 +312,17 @@ typedef struct SPLRules
/* This structure can represent two slightly different images:
- * - an image before it's transferred to the iPod (it will then be scaled
- * as necessary to generate the 2 thumbnails needed by the iPod),
- * for such images, filename points to a 'real' image file, offset is
- * not significant, size, width and height may or may not be set
- * and id corresponds to the image id to write in mhii records of the
- * photo database
- *
- * - a thumbnail (big or small) stored on a database in the iPod.
- * For such images, id isn't significant, filename point to a .ithmb file
- * on the iPod
+
+ - an image before it's transferred to the iPod (it will then be
+ scaled as necessary to generate the 2 thumbnails needed by the
+ iPod), for such images, filename points to a 'real' image file,
+ offset is not significant, size, width and height may or may not
+ be set and id corresponds to the image id to write in mhii
+ records of the photo database
+
+ - a thumbnail (big or small) stored on a database in the iPod. For
+ such images, id isn't significant, filename point to a .ithmb
+ file on the iPod
*/
struct _Itdb_Image {
int type;
@@ -733,7 +734,9 @@ unsigned char *itdb_image_get_rgb_data (Itdb_Image *image);
int itdb_track_set_thumbnail (Itdb_Track *song, const char *filename);
void itdb_track_remove_thumbnail (Itdb_Track *song);
void itdb_track_free_generated_thumbnails (Itdb_Track *track);
-
+/* the following funciton returns a pointer to a GdkPixbuf if
+ gdk-pixbuf is installed -- a NULL pointer otherwise. */
+gpointer itdb_image_get_gdk_pixbuf (Itdb_iTunesDB *itdb, Itdb_Image *image);
/* time functions */
guint64 itdb_time_get_mac_time (void);
time_t itdb_time_mac_to_host (guint64 mactime);
diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c
index 3e02427..195321e 100644
--- a/src/itdb_itunesdb.c
+++ b/src/itdb_itunesdb.c
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-11-19 17:05:44 jcs>
+/* Time-stamp: <2005-11-20 16:06:58 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
diff --git a/tests/test-covers.c b/tests/test-covers.c
index fb21d00..5816ce2 100644
--- a/tests/test-covers.c
+++ b/tests/test-covers.c
@@ -31,70 +31,13 @@
#include <locale.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
-static GdkPixbuf *
-ipod_image_to_gdk_pixbuf (Itdb_Image *image)
-{
- GdkPixbuf *result;
- guchar *pixels;
- int row_stride;
-
- g_print ("width: %d height: %d size: %d\n",
- image->width, image->height, image->size);
-
-/*
-description photo: size width nano: size width
-==================== ===== ===== ===== =====
-artwork big 39200 140 20000 100
-artwork small 6272 56 3528 42
-photo full-screen ? ? 46464 176
-photo thumbnail ? ? 3108 42
-*/
-
- switch (image->size)
- {
- case 39200: /* ITDB_IMAGE_FULL_SCREEN */
- row_stride = 140;
- break;
-
- case 46464: /* iPod nano photo database full screen */
- row_stride = 176;
- break;
-
- case 6272: /* ITDB_IMAGE_NOW_PLAYING */
- row_stride = 56;
- break;
-
- case 3108: /* iPod nano photo database thumbnails */
-/* if (width > 42) width = 42;
- if (height > 37) height = 37; ??? */
- row_stride = 42;
- break;
-
- default:
- return NULL;
- }
-
-
- pixels = itdb_image_get_rgb_data (image);
- if (pixels == NULL) {
- return NULL;
- }
-
- result = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE,
- 8, image->width, image->height,
- row_stride * 3,
- (GdkPixbufDestroyNotify)g_free,
- NULL);
- return result;
-}
-
static void
-save_itdb_image (Itdb_Image *image, const char *filename)
+save_itdb_image (Itdb_iTunesDB *itdb, Itdb_Image *image, const char *filename)
{
GdkPixbuf *thumb;
- thumb = ipod_image_to_gdk_pixbuf (image);
+ thumb = itdb_image_get_gdk_pixbuf (itdb, image);
if (thumb != NULL) {
gdk_pixbuf_save (thumb, filename, "png", NULL, NULL);
gdk_pixbuf_unref (thumb);
@@ -114,12 +57,12 @@ save_song_thumbnails (Itdb_Track *song)
g_return_if_fail (image);
filename = NULL;
- filename = g_strdup_printf ("/tmp/%s-%s-%s-%d-%016"G_GINT64_MODIFIER"x.png",
+ filename = g_strdup_printf ("%s-%s-%s-%d-%016"G_GINT64_MODIFIER"x.png",
song->artist, song->album,
song->title, image->type,
song->dbid);
if (filename != NULL) {
- save_itdb_image (image, filename);
+ save_itdb_image (song->itdb, image, filename);
g_free (filename);
}
}