summaryrefslogtreecommitdiff
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-3cc3e600fe3acd2361f63fd32007c4b3bfcd3a73.tar.gz
rockbox-3cc3e600fe3acd2361f63fd32007c4b3bfcd3a73.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 @@
34#define APETAG_ITEM_HEADER_FORMAT "ll" 34#define APETAG_ITEM_HEADER_FORMAT "ll"
35#define APETAG_ITEM_TYPE_MASK 3 35#define APETAG_ITEM_TYPE_MASK 3
36 36
37#ifdef HAVE_ALBUMART
38/* The AA header consists of the pseudo filename "Album Cover (Front).ext"
39 * whereas ".ext" is the file extension. For now ".jpg" and ".png" are
40 * supported by this APE metadata parser. Therefore the length is 22. */
41#define APETAG_AA_HEADER_LENGTH 22
42#endif
43
44struct apetag_header 37struct apetag_header
45{ 38{
46 char id[8]; 39 char id[8];
@@ -144,36 +137,34 @@ bool read_ape_tags(int fd, struct mp3entry* id3)
144#ifdef HAVE_ALBUMART 137#ifdef HAVE_ALBUMART
145 if (strcasecmp(name, "cover art (front)") == 0) 138 if (strcasecmp(name, "cover art (front)") == 0)
146 { 139 {
147 /* Allow to read at least APETAG_AA_HEADER_LENGTH bytes. */ 140 /* Skip any file name. */
148 r = read_string(fd, name, sizeof(name), 0, APETAG_AA_HEADER_LENGTH); 141 r = read_string(fd, value, sizeof(value), 0, -1);
142 r += read_string(fd, value, sizeof(value), -1, 4);
143
149 if (r == -1) 144 if (r == -1)
150 { 145 {
151 return false; 146 return false;
152 } 147 }
153 148
154 /* Gather the album art format from the pseudo file name's ending. */ 149 /* Gather the album art format from the magic number of the embedded binary. */
155 /* strcpy(name, name + strlen(name) - 4); */
156 id3->albumart.type = AA_TYPE_UNKNOWN; 150 id3->albumart.type = AA_TYPE_UNKNOWN;
157 char *ext = strrchr(name, '.'); 151 if (memcmp(value, "\xFF\xD8\xFF", 3) == 0)
158 if (ext)
159 { 152 {
160 if (strcasecmp(ext, ".jpg") == 0) 153 id3->albumart.type = AA_TYPE_JPG;
161 {
162 id3->albumart.type = AA_TYPE_JPG;
163 }
164 else if (strcasecmp(ext, ".jpeg") == 0)
165 {
166 id3->albumart.type = AA_TYPE_JPG;
167 }
168 else if (strcasecmp(ext, ".png") == 0)
169 {
170 id3->albumart.type = AA_TYPE_PNG;
171 }
172 } 154 }
155 else if (memcmp(value, "\x42\x4D", 2) == 0)
156 {
157 id3->albumart.type = AA_TYPE_BMP;
158 }
159 else if (memcmp(value, "\x89\x50\x4E\x47", 4) == 0)
160 {
161 id3->albumart.type = AA_TYPE_PNG;
162 }
163
173 /* Set the album art size and position. */ 164 /* Set the album art size and position. */
174 if (id3->albumart.type != AA_TYPE_UNKNOWN) 165 if (id3->albumart.type != AA_TYPE_UNKNOWN)
175 { 166 {
176 id3->albumart.pos = lseek(fd, 0, SEEK_CUR); 167 id3->albumart.pos = lseek(fd, - 4, SEEK_CUR);
177 id3->albumart.size = item.length - r; 168 id3->albumart.size = item.length - r;
178 id3->has_embedded_albumart = true; 169 id3->has_embedded_albumart = true;
179 } 170 }