From f633d5ed482848826b6b081078be0414a5aaa78f Mon Sep 17 00:00:00 2001 From: Albert Song Date: Fri, 13 Dec 2013 01:48:48 -0800 Subject: Add support for flac embeded album art. Change-Id: I077768f7d80b57976f9a7278b640ef67cf4f2af2 Reviewed-on: http://gerrit.rockbox.org/694 Reviewed-by: Thomas Martitz --- lib/rbcodec/metadata/flac.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lib/rbcodec/metadata/flac.c') diff --git a/lib/rbcodec/metadata/flac.c b/lib/rbcodec/metadata/flac.c index a8be4c6de4..df25bb9b4d 100644 --- a/lib/rbcodec/metadata/flac.c +++ b/lib/rbcodec/metadata/flac.c @@ -113,6 +113,56 @@ bool get_flac_metadata(int fd, struct mp3entry* id3) return rc; } } +#ifdef HAVE_ALBUMART + else if (type == 6) /* 6 is the PICTURE block */ + { + if(!id3->has_embedded_albumart) /* only use the first PICTURE */ + { + unsigned int buf_size = MIN(sizeof(id3->path), i); + int picframe_pos = 4; /* skip picture type */ + int mime_length, description_length; + + id3->albumart.pos = lseek(fd, 0, SEEK_CUR); + + int bytes_read = read(fd, buf, buf_size); + i -= bytes_read; + + mime_length = get_long_be(&buf[picframe_pos]); + + char *mime = buf + picframe_pos + 4; + picframe_pos += 4 + mime_length; + + id3->albumart.type = AA_TYPE_UNKNOWN; + if (memcmp(mime, "image/", 6) == 0) + { + mime += 6; + if (strcmp(mime, "jpeg") == 0 || strcmp(mime, "jpg") == 0){ + id3->albumart.type = AA_TYPE_JPG; + }else if (strcmp(mime, "png") == 0) + id3->albumart.type = AA_TYPE_PNG; + } + + description_length = get_long_be(&buf[picframe_pos]); + + /* 16 = skip picture width,height,color-depth,color-used */ + picframe_pos += 4 + description_length + 16; + + /* if we support the format and image length is in the buffer */ + if(id3->albumart.type != AA_TYPE_UNKNOWN + && (picframe_pos + 4) - buf_size > 0) + { + id3->has_embedded_albumart = true; + id3->albumart.size = get_long_be(&buf[picframe_pos]); + id3->albumart.pos += picframe_pos + 4; + } + } + + if (lseek(fd, i, SEEK_CUR) < 0) + { + return rc; + } + } +#endif else if (!last_metadata) { /* Skip to next metadata block */ -- cgit v1.2.3