summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames D. Smith <smithjd15@gmail.com>2020-04-26 11:53:19 -0600
committerJames D. Smith <smithjd15@gmail.com>2020-04-26 13:05:39 -0600
commit3cc3e600fe3acd2361f63fd32007c4b3bfcd3a73 (patch)
tree8c439d17ea34303f8ddd46cbd596b3fc75e6c430
parent5751729284e486c6bfbe5426b4f4a978aed4154b (diff)
downloadrockbox-3cc3e60.tar.gz
rockbox-3cc3e60.zip
Get APEv2 tag album art format from magic number. Also support bmp artwork.
Change-Id: I81d8f79f47f09528e2f7fa462e579350451c81f1
-rw-r--r--lib/rbcodec/metadata/ape.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/lib/rbcodec/metadata/ape.c b/lib/rbcodec/metadata/ape.c
index d6457eab63..718f547bda 100644
--- a/lib/rbcodec/metadata/ape.c
+++ b/lib/rbcodec/metadata/ape.c
@@ -34,13 +34,6 @@
#define APETAG_ITEM_HEADER_FORMAT "ll"
#define APETAG_ITEM_TYPE_MASK 3
-#ifdef HAVE_ALBUMART
-/* The AA header consists of the pseudo filename "Album Cover (Front).ext"
- * whereas ".ext" is the file extension. For now ".jpg" and ".png" are
- * supported by this APE metadata parser. Therefore the length is 22. */
-#define APETAG_AA_HEADER_LENGTH 22
-#endif
-
struct apetag_header
{
char id[8];
@@ -144,36 +137,34 @@ bool read_ape_tags(int fd, struct mp3entry* id3)
#ifdef HAVE_ALBUMART
if (strcasecmp(name, "cover art (front)") == 0)
{
- /* Allow to read at least APETAG_AA_HEADER_LENGTH bytes. */
- r = read_string(fd, name, sizeof(name), 0, APETAG_AA_HEADER_LENGTH);
+ /* Skip any file name. */
+ r = read_string(fd, value, sizeof(value), 0, -1);
+ r += read_string(fd, value, sizeof(value), -1, 4);
+
if (r == -1)
{
return false;
}
- /* Gather the album art format from the pseudo file name's ending. */
- /* strcpy(name, name + strlen(name) - 4); */
+ /* Gather the album art format from the magic number of the embedded binary. */
id3->albumart.type = AA_TYPE_UNKNOWN;
- char *ext = strrchr(name, '.');
- if (ext)
+ if (memcmp(value, "\xFF\xD8\xFF", 3) == 0)
{
- if (strcasecmp(ext, ".jpg") == 0)
- {
- id3->albumart.type = AA_TYPE_JPG;
- }
- else if (strcasecmp(ext, ".jpeg") == 0)
- {
- id3->albumart.type = AA_TYPE_JPG;
- }
- else if (strcasecmp(ext, ".png") == 0)
- {
- id3->albumart.type = AA_TYPE_PNG;
- }
+ id3->albumart.type = AA_TYPE_JPG;
}
+ else if (memcmp(value, "\x42\x4D", 2) == 0)
+ {
+ id3->albumart.type = AA_TYPE_BMP;
+ }
+ else if (memcmp(value, "\x89\x50\x4E\x47", 4) == 0)
+ {
+ id3->albumart.type = AA_TYPE_PNG;
+ }
+
/* Set the album art size and position. */
if (id3->albumart.type != AA_TYPE_UNKNOWN)
{
- id3->albumart.pos = lseek(fd, 0, SEEK_CUR);
+ id3->albumart.pos = lseek(fd, - 4, SEEK_CUR);
id3->albumart.size = item.length - r;
id3->has_embedded_albumart = true;
}