diff options
| author | Christophe Fergeau <teuf@gnome.org> | 2005-11-23 18:21:52 +0000 |
|---|---|---|
| committer | Christophe Fergeau <teuf@gnome.org> | 2005-11-23 18:21:52 +0000 |
| commit | df739448ee81be2c415b2202c9b2d83c1cedf2de (patch) | |
| tree | c32d396b78585c2673f4c2c3a54093923c93c6fe /src/db-artwork-parser.c | |
| parent | 559cf826c24c86febec9c600107ffba9e161a4fb (diff) | |
| download | libgpod-df739448ee81be2c415b2202c9b2d83c1cedf2de.tar.gz libgpod-df739448ee81be2c415b2202c9b2d83c1cedf2de.tar.xz libgpod-df739448ee81be2c415b2202c9b2d83c1cedf2de.zip | |
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):
* src/db-artwork-parser.h:
* src/db-artwork-writer.c: (get_artwork_info), (write_mhod_type_3),
(write_mhni), (write_mhod), (write_mhii), (write_mhif):
* src/db-image-parser.c: (unpack_RGB_565),
(image_type_from_corr_id), (ipod_image_new_from_mhni):
* src/db-image-parser.h:
* src/itdb.h:
* src/ithumb-writer.c: (pack_RGB_565),
(ithumb_writer_write_thumbnail), (ipod_image_get_ithmb_filename),
(ithumb_writer_new), (ithumb_writer_free), (write_thumbnail),
(itdb_write_ithumb_files):
* tests/test-covers.c: (save_song_thumbnails): rework artwork code in
an attempt to properly support artwork on all the iPod models
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1171 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/db-artwork-parser.c')
| -rw-r--r-- | src/db-artwork-parser.c | 87 |
1 files changed, 60 insertions, 27 deletions
diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c index 4ec007e..4a1997c 100644 --- a/src/db-artwork-parser.c +++ b/src/db-artwork-parser.c @@ -78,9 +78,28 @@ parse_mhia (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error) return 0; } -#ifdef DEBUG_ARTWORKDB +static char * +get_utf16_string (void* buffer, gint length) +{ + char *result; + gunichar2 *tmp; + int i; + /* Byte-swap the utf16 characters if necessary (I'm relying + * on gcc to optimize most of this code away on LE platforms) + */ + tmp = g_memdup (buffer, length); + for (i = 0; i < length/2; i++) { + tmp[i] = GINT16_FROM_LE (tmp[i]); + } + result = g_utf16_to_utf8 (tmp, length/2, NULL, NULL, NULL); + g_free (tmp); + + return result; + +} + static int -parse_mhod_3 (DBParseContext *ctx, GError *error) +parse_mhod_3 (DBParseContext *ctx, Itdb_Image *image, GError *error) { MhodHeader *mhod; MhodHeaderArtworkType3 *mhod3; @@ -98,50 +117,37 @@ parse_mhod_3 (DBParseContext *ctx, 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); dump_mhod_type_3 (mhod3); return 0; } -#endif static int parse_mhni (DBParseContext *ctx, iPodSong *song, GError *error) { MhniHeader *mhni; -#ifndef DEBUG_ARTWORKDB + DBParseContext *mhod_ctx; Itdb_Image *thumb; -#endif mhni = db_parse_context_get_m_header (ctx, MhniHeader, "mhni"); if (mhni == NULL) { return -1; } db_parse_context_set_total_len (ctx, GINT_FROM_LE (mhni->total_len)); - dump_mhni (mhni); -#ifdef DEBUG_ARTWORKDB - { - DBParseContext *mhod_ctx; - - /* No information useful to us in mhod type 3, do not parse - * it in non-debug mode - * FIXME: really? it contains the thumbnail file name! - * we infer it from the correlation id, but is this - * always The Right Thing to do? - */ - mhod_ctx = db_parse_context_get_sub_context (ctx, ctx->header_len); - if (mhod_ctx == NULL) { - return -1; - } - parse_mhod_3 (mhod_ctx, NULL); - g_free (mhod_ctx); - } -#else - thumb = ipod_image_new_from_mhni (mhni, song->itdb->mountpoint); + + thumb = ipod_image_new_from_mhni (mhni, song->itdb); if (thumb != NULL) { song->thumbnails = g_list_append (song->thumbnails, thumb); } -#endif + + mhod_ctx = db_parse_context_get_sub_context (ctx, ctx->header_len); + if (mhod_ctx == NULL) { + return -1; + } + parse_mhod_3 (mhod_ctx, thumb, error); + g_free (mhod_ctx); + return 0; } @@ -422,6 +428,30 @@ ipod_db_get_photo_db_path (const char *mount_point) } +static gboolean +ipod_supports_cover_art (IpodDevice *ipod) +{ + const IpodArtworkFormat *formats; + + if (ipod == NULL) { + return FALSE; + } + + g_object_get (G_OBJECT (ipod), "artwork-formats", &formats, NULL); + if (formats == NULL) { + return FALSE; + } + + while (formats->type != -1) { + if ((formats->type == IPOD_COVER_SMALL) + || (formats->type == IPOD_COVER_LARGE)) { + return TRUE; + } + formats++; + } + + return FALSE; +} int ipod_parse_artwork_db (Itdb_iTunesDB *db) @@ -431,6 +461,9 @@ ipod_parse_artwork_db (Itdb_iTunesDB *db) g_return_val_if_fail (db, -1); + if (!ipod_supports_cover_art (db->device)) { + return -1; + } ctx = NULL; filename = ipod_db_get_artwork_db_path (db->mountpoint); if (filename == NULL) { |
