summaryrefslogtreecommitdiffstats
path: root/apps/metadata/id3tags.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-02-09 20:13:13 +0000
committerThomas Martitz <kugel@rockbox.org>2011-02-09 20:13:13 +0000
commitf577a6a22c646669e56c5436859d2f5ec8b421e8 (patch)
tree04673c08ff7fc1e12ad4eb4147b705e0bd0fd926 /apps/metadata/id3tags.c
parent0d902c8c54bbc36f24b40c49eb9872aa75b779e4 (diff)
downloadrockbox-f577a6a22c646669e56c5436859d2f5ec8b421e8.tar.gz
rockbox-f577a6a22c646669e56c5436859d2f5ec8b421e8.tar.bz2
rockbox-f577a6a22c646669e56c5436859d2f5ec8b421e8.zip
Embedded album art support in MP3/ID3v2 tags.
- Support is limited to non-desync jpeg in id3v2 tags. Other formats (hopefully) follow in the future. - Embedded album art takes precedence over files in album art files. - No additional buffers are used, the jpeg is read directly from the audio file. Flyspray: FS#11216 Author: Yoshihisa Uchida and I git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29259 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/metadata/id3tags.c')
-rw-r--r--apps/metadata/id3tags.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/apps/metadata/id3tags.c b/apps/metadata/id3tags.c
index 75056a273c..a20a59f06e 100644
--- a/apps/metadata/id3tags.c
+++ b/apps/metadata/id3tags.c
@@ -290,6 +290,63 @@ static int parsegenre( struct mp3entry* entry, char* tag, int bufferpos )
}
}
+#ifdef HAVE_ALBUMART
+/* parse embed albumart */
+static int parsealbumart( struct mp3entry* entry, char* tag, int bufferpos )
+{
+ entry->embed_albumart = false;
+
+ /* we currently don't support unsynchronizing albumart */
+ if (entry->albumart.type == AA_TYPE_UNSYNC)
+ return bufferpos;
+
+ entry->albumart.type = AA_TYPE_UNKNOWN;
+
+ char *start = tag;
+ /* skip text encoding */
+ tag += 1;
+
+ if (memcmp(tag, "image/", 6) == 0)
+ {
+ /* ID3 v2.3+ */
+ tag += 6;
+ if (strcmp(tag, "jpeg") == 0)
+ {
+ entry->albumart.type = AA_TYPE_JPG;
+ tag += 5;
+ }
+ else if (strcmp(tag, "png") == 0)
+ {
+ entry->albumart.type = AA_TYPE_PNG;
+ tag += 4;
+ }
+ }
+ else
+ {
+ /* ID3 v2.2 */
+ if (memcmp(tag, "JPG", 3) == 0)
+ entry->albumart.type = AA_TYPE_JPG;
+ else if (memcmp(tag, "PNG", 3) == 0)
+ entry->albumart.type = AA_TYPE_PNG;
+ tag += 3;
+ }
+
+ if (entry->albumart.type != AA_TYPE_UNKNOWN)
+ {
+ /* skip picture type */
+ tag += 1;
+ /* skip description */
+ tag = strchr(tag, '\0') + 1;
+ /* fixup offset&size for image data */
+ entry->albumart.pos += tag - start;
+ entry->albumart.size -= tag - start;
+ entry->embed_albumart = true;
+ }
+ /* return bufferpos as we didn't store anything in id3v2buf */
+ return bufferpos;
+}
+#endif
+
/* parse user defined text, looking for album artist and replaygain
* information.
*/
@@ -439,6 +496,10 @@ static const struct tag_resolver taglist[] = {
{ "COM", 3, offsetof(struct mp3entry, comment), NULL, false },
{ "TCON", 4, offsetof(struct mp3entry, genre_string), &parsegenre, false },
{ "TCO", 3, offsetof(struct mp3entry, genre_string), &parsegenre, false },
+#ifdef HAVE_ALBUMART
+ { "APIC", 4, 0, &parsealbumart, true },
+ { "PIC", 3, 0, &parsealbumart, true },
+#endif
{ "TXXX", 4, 0, &parseuser, false },
#if CONFIG_CODEC == SWCODEC
{ "RVA2", 4, 0, &parserva2, true },
@@ -961,6 +1022,21 @@ void setid3v2title(int fd, struct mp3entry *entry)
if (ptag && !*ptag)
*ptag = tag;
+ /* albumart */
+ if ((!entry->embed_albumart) &&
+ ((tr->tag_length == 4 && !memcmp( header, "APIC", 4)) ||
+ (tr->tag_length == 3 && !memcmp( header, "PIC" , 3))))
+ {
+ if (unsynch || (global_unsynch && version <= ID3_VER_2_3))
+ entry->albumart.type = AA_TYPE_UNSYNC;
+ else
+ {
+ entry->albumart.pos = lseek(fd, 0, SEEK_CUR) - framelen;
+ entry->albumart.size = totframelen;
+ entry->albumart.type = AA_TYPE_UNKNOWN;
+ }
+ }
+
if( tr->ppFunc )
bufferpos = tr->ppFunc(entry, tag, bufferpos);