diff options
-rw-r--r-- | apps/buffering.c | 14 | ||||
-rw-r--r-- | apps/recorder/albumart.c | 68 |
2 files changed, 78 insertions, 4 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index a4d425fb1d..66bd22f12d 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -53,6 +53,7 @@ | |||
53 | #include "metadata.h" | 53 | #include "metadata.h" |
54 | #ifdef HAVE_ALBUMART | 54 | #ifdef HAVE_ALBUMART |
55 | #include "albumart.h" | 55 | #include "albumart.h" |
56 | #include "jpeg_load.h" | ||
56 | #endif | 57 | #endif |
57 | 58 | ||
58 | #define GUARD_BUFSIZE (32*1024) | 59 | #define GUARD_BUFSIZE (32*1024) |
@@ -830,9 +831,10 @@ static bool fill_buffer(void) | |||
830 | /* Given a file descriptor to a bitmap file, write the bitmap data to the | 831 | /* Given a file descriptor to a bitmap file, write the bitmap data to the |
831 | buffer, with a struct bitmap and the actual data immediately following. | 832 | buffer, with a struct bitmap and the actual data immediately following. |
832 | Return value is the total size (struct + data). */ | 833 | Return value is the total size (struct + data). */ |
833 | static int load_bitmap(int fd) | 834 | static int load_image(int fd, const char *path) |
834 | { | 835 | { |
835 | int rc; | 836 | int rc; |
837 | int pathlen = strlen(path); | ||
836 | struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; | 838 | struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; |
837 | /* FIXME: alignment may be needed for the data buffer. */ | 839 | /* FIXME: alignment may be needed for the data buffer. */ |
838 | bmp->data = &buffer[buf_widx + sizeof(struct bitmap)]; | 840 | bmp->data = &buffer[buf_widx + sizeof(struct bitmap)]; |
@@ -846,8 +848,12 @@ static int load_bitmap(int fd) | |||
846 | 848 | ||
847 | get_albumart_size(bmp); | 849 | get_albumart_size(bmp); |
848 | 850 | ||
849 | rc = read_bmp_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| | 851 | if (strcmp(path + pathlen - 4, ".bmp")) |
850 | FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); | 852 | rc = read_jpeg_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| |
853 | FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); | ||
854 | else | ||
855 | rc = read_bmp_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| | ||
856 | FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); | ||
851 | return rc + (rc > 0 ? sizeof(struct bitmap) : 0); | 857 | return rc + (rc > 0 ? sizeof(struct bitmap) : 0); |
852 | } | 858 | } |
853 | #endif | 859 | #endif |
@@ -942,7 +948,7 @@ int bufopen(const char *file, size_t offset, enum data_type type) | |||
942 | /* Bitmap file: we load the data instead of the file */ | 948 | /* Bitmap file: we load the data instead of the file */ |
943 | int rc; | 949 | int rc; |
944 | mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ | 950 | mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ |
945 | rc = load_bitmap(fd); | 951 | rc = load_image(fd, file); |
946 | mutex_unlock(&llist_mutex); | 952 | mutex_unlock(&llist_mutex); |
947 | if (rc <= 0) | 953 | if (rc <= 0) |
948 | { | 954 | { |
diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c index 327f4dfe5c..cf4a3e8e11 100644 --- a/apps/recorder/albumart.c +++ b/apps/recorder/albumart.c | |||
@@ -91,6 +91,27 @@ static void fix_path_part(char* path, int offset, int count) | |||
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | #if LCD_DEPTH > 1 | ||
95 | const char * extensions[] = { "jpeg", "jpg", "bmp" }; | ||
96 | int extension_lens[] = { 4, 3, 3 }; | ||
97 | /* Try checking for several file extensions, return true if a file is found and | ||
98 | * leaving the path modified to include the matching extension. | ||
99 | */ | ||
100 | static bool try_exts(char *path, int len) | ||
101 | { | ||
102 | int i; | ||
103 | for (i = 0; i < 3; i++) | ||
104 | { | ||
105 | if (extension_lens[i] + len > MAX_PATH) | ||
106 | continue; | ||
107 | strcpy(path + len, extensions[i]); | ||
108 | if (file_exists(path)) | ||
109 | return true; | ||
110 | } | ||
111 | return false; | ||
112 | } | ||
113 | #endif | ||
114 | |||
94 | /* Look for the first matching album art bitmap in the following list: | 115 | /* Look for the first matching album art bitmap in the following list: |
95 | * ./<trackname><size>.bmp | 116 | * ./<trackname><size>.bmp |
96 | * ./<albumname><size>.bmp | 117 | * ./<albumname><size>.bmp |
@@ -113,6 +134,9 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, | |||
113 | const char *artist; | 134 | const char *artist; |
114 | int dirlen; | 135 | int dirlen; |
115 | int albumlen; | 136 | int albumlen; |
137 | #if LCD_DEPTH > 1 | ||
138 | int pathlen; | ||
139 | #endif | ||
116 | 140 | ||
117 | if (!id3 || !buf) | 141 | if (!id3 || !buf) |
118 | return false; | 142 | return false; |
@@ -135,25 +159,55 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, | |||
135 | { | 159 | { |
136 | /* if it doesn't exist, | 160 | /* if it doesn't exist, |
137 | * we look for a file specific to the track's album name */ | 161 | * we look for a file specific to the track's album name */ |
162 | #if LCD_DEPTH > 1 | ||
163 | pathlen = snprintf(path, sizeof(path), | ||
164 | "%s%s%s.", dir, id3->album, size_string); | ||
165 | fix_path_part(path, dirlen, albumlen); | ||
166 | found = try_exts(path, pathlen); | ||
167 | #else | ||
138 | snprintf(path, sizeof(path), | 168 | snprintf(path, sizeof(path), |
139 | "%s%s%s.bmp", dir, id3->album, size_string); | 169 | "%s%s%s.bmp", dir, id3->album, size_string); |
140 | fix_path_part(path, dirlen, albumlen); | 170 | fix_path_part(path, dirlen, albumlen); |
141 | found = file_exists(path); | 171 | found = file_exists(path); |
172 | #endif | ||
142 | } | 173 | } |
143 | 174 | ||
144 | if (!found) | 175 | if (!found) |
145 | { | 176 | { |
146 | /* if it still doesn't exist, we look for a generic file */ | 177 | /* if it still doesn't exist, we look for a generic file */ |
178 | #if LCD_DEPTH > 1 | ||
179 | pathlen = snprintf(path, sizeof(path), | ||
180 | "%scover%s.", dir, size_string); | ||
181 | found = try_exts(path, pathlen); | ||
182 | #else | ||
147 | snprintf(path, sizeof(path), | 183 | snprintf(path, sizeof(path), |
148 | "%scover%s.bmp", dir, size_string); | 184 | "%scover%s.bmp", dir, size_string); |
149 | found = file_exists(path); | 185 | found = file_exists(path); |
186 | #endif | ||
150 | } | 187 | } |
151 | 188 | ||
189 | #if LCD_DEPTH > 1 | ||
190 | if (!found) | ||
191 | { | ||
192 | snprintf (path, sizeof(path), "%sfolder.jpg", dir); | ||
193 | found = file_exists(path); | ||
194 | } | ||
195 | #endif | ||
196 | |||
152 | artist = id3->albumartist != NULL ? id3->albumartist : id3->artist; | 197 | artist = id3->albumartist != NULL ? id3->albumartist : id3->artist; |
153 | 198 | ||
154 | if (!found && artist && id3->album) | 199 | if (!found && artist && id3->album) |
155 | { | 200 | { |
156 | /* look in the albumart subdir of .rockbox */ | 201 | /* look in the albumart subdir of .rockbox */ |
202 | #if LCD_DEPTH > 1 | ||
203 | pathlen = snprintf(path, sizeof(path), | ||
204 | ROCKBOX_DIR "/albumart/%s-%s%s.", | ||
205 | artist, | ||
206 | id3->album, | ||
207 | size_string); | ||
208 | fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); | ||
209 | found = try_exts(path, pathlen); | ||
210 | #else | ||
157 | snprintf(path, sizeof(path), | 211 | snprintf(path, sizeof(path), |
158 | ROCKBOX_DIR "/albumart/%s-%s%s.bmp", | 212 | ROCKBOX_DIR "/albumart/%s-%s%s.bmp", |
159 | artist, | 213 | artist, |
@@ -161,6 +215,7 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, | |||
161 | size_string); | 215 | size_string); |
162 | fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); | 216 | fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); |
163 | found = file_exists(path); | 217 | found = file_exists(path); |
218 | #endif | ||
164 | } | 219 | } |
165 | 220 | ||
166 | if (!found) | 221 | if (!found) |
@@ -180,19 +235,32 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, | |||
180 | { | 235 | { |
181 | /* we look in the parent directory | 236 | /* we look in the parent directory |
182 | * for a file specific to the track's album name */ | 237 | * for a file specific to the track's album name */ |
238 | #if LCD_DEPTH > 1 | ||
239 | pathlen = snprintf(path, sizeof(path), | ||
240 | "%s%s%s.", dir, id3->album, size_string); | ||
241 | fix_path_part(path, dirlen, albumlen); | ||
242 | found = try_exts(path, pathlen); | ||
243 | #else | ||
183 | snprintf(path, sizeof(path), | 244 | snprintf(path, sizeof(path), |
184 | "%s%s%s.bmp", dir, id3->album, size_string); | 245 | "%s%s%s.bmp", dir, id3->album, size_string); |
185 | fix_path_part(path, dirlen, albumlen); | 246 | fix_path_part(path, dirlen, albumlen); |
186 | found = file_exists(path); | 247 | found = file_exists(path); |
248 | #endif | ||
187 | } | 249 | } |
188 | 250 | ||
189 | if (!found) | 251 | if (!found) |
190 | { | 252 | { |
191 | /* if it still doesn't exist, we look in the parent directory | 253 | /* if it still doesn't exist, we look in the parent directory |
192 | * for a generic file */ | 254 | * for a generic file */ |
255 | #if LCD_DEPTH > 1 | ||
256 | pathlen = snprintf(path, sizeof(path), | ||
257 | "%scover%s.", dir, size_string); | ||
258 | found = try_exts(path, pathlen); | ||
259 | #else | ||
193 | snprintf(path, sizeof(path), | 260 | snprintf(path, sizeof(path), |
194 | "%scover%s.bmp", dir, size_string); | 261 | "%scover%s.bmp", dir, size_string); |
195 | found = file_exists(path); | 262 | found = file_exists(path); |
263 | #endif | ||
196 | } | 264 | } |
197 | } | 265 | } |
198 | 266 | ||