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 @@ #include "metadata.h" #ifdef HAVE_ALBUMART #include "albumart.h" +#include "jpeg_load.h" #endif #define GUARD_BUFSIZE (32*1024) @@ -830,9 +831,10 @@ static bool fill_buffer(void) /* Given a file descriptor to a bitmap file, write the bitmap data to the buffer, with a struct bitmap and the actual data immediately following. Return value is the total size (struct + data). */ -static int load_bitmap(int fd) +static int load_image(int fd, const char *path) { int rc; + int pathlen = strlen(path); struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; /* FIXME: alignment may be needed for the data buffer. */ bmp->data = &buffer[buf_widx + sizeof(struct bitmap)]; @@ -846,8 +848,12 @@ static int load_bitmap(int fd) get_albumart_size(bmp); - rc = read_bmp_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| - FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); + if (strcmp(path + pathlen - 4, ".bmp")) + rc = read_jpeg_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| + FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); + else + rc = read_bmp_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| + FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); return rc + (rc > 0 ? sizeof(struct bitmap) : 0); } #endif @@ -942,7 +948,7 @@ int bufopen(const char *file, size_t offset, enum data_type type) /* Bitmap file: we load the data instead of the file */ int rc; mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ - rc = load_bitmap(fd); + rc = load_image(fd, file); mutex_unlock(&llist_mutex); if (rc <= 0) { 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) } } +#if LCD_DEPTH > 1 +const char * extensions[] = { "jpeg", "jpg", "bmp" }; +int extension_lens[] = { 4, 3, 3 }; +/* Try checking for several file extensions, return true if a file is found and + * leaving the path modified to include the matching extension. + */ +static bool try_exts(char *path, int len) +{ + int i; + for (i = 0; i < 3; i++) + { + if (extension_lens[i] + len > MAX_PATH) + continue; + strcpy(path + len, extensions[i]); + if (file_exists(path)) + return true; + } + return false; +} +#endif + /* Look for the first matching album art bitmap in the following list: * ./.bmp * ./.bmp @@ -113,6 +134,9 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, const char *artist; int dirlen; int albumlen; +#if LCD_DEPTH > 1 + int pathlen; +#endif if (!id3 || !buf) return false; @@ -135,25 +159,55 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, { /* if it doesn't exist, * we look for a file specific to the track's album name */ +#if LCD_DEPTH > 1 + pathlen = snprintf(path, sizeof(path), + "%s%s%s.", dir, id3->album, size_string); + fix_path_part(path, dirlen, albumlen); + found = try_exts(path, pathlen); +#else snprintf(path, sizeof(path), "%s%s%s.bmp", dir, id3->album, size_string); fix_path_part(path, dirlen, albumlen); found = file_exists(path); +#endif } if (!found) { /* if it still doesn't exist, we look for a generic file */ +#if LCD_DEPTH > 1 + pathlen = snprintf(path, sizeof(path), + "%scover%s.", dir, size_string); + found = try_exts(path, pathlen); +#else snprintf(path, sizeof(path), "%scover%s.bmp", dir, size_string); found = file_exists(path); +#endif } +#if LCD_DEPTH > 1 + if (!found) + { + snprintf (path, sizeof(path), "%sfolder.jpg", dir); + found = file_exists(path); + } +#endif + artist = id3->albumartist != NULL ? id3->albumartist : id3->artist; if (!found && artist && id3->album) { /* look in the albumart subdir of .rockbox */ +#if LCD_DEPTH > 1 + pathlen = snprintf(path, sizeof(path), + ROCKBOX_DIR "/albumart/%s-%s%s.", + artist, + id3->album, + size_string); + fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); + found = try_exts(path, pathlen); +#else snprintf(path, sizeof(path), ROCKBOX_DIR "/albumart/%s-%s%s.bmp", artist, @@ -161,6 +215,7 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, size_string); fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); found = file_exists(path); +#endif } if (!found) @@ -180,19 +235,32 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, { /* we look in the parent directory * for a file specific to the track's album name */ +#if LCD_DEPTH > 1 + pathlen = snprintf(path, sizeof(path), + "%s%s%s.", dir, id3->album, size_string); + fix_path_part(path, dirlen, albumlen); + found = try_exts(path, pathlen); +#else snprintf(path, sizeof(path), "%s%s%s.bmp", dir, id3->album, size_string); fix_path_part(path, dirlen, albumlen); found = file_exists(path); +#endif } if (!found) { /* if it still doesn't exist, we look in the parent directory * for a generic file */ +#if LCD_DEPTH > 1 + pathlen = snprintf(path, sizeof(path), + "%scover%s.", dir, size_string); + found = try_exts(path, pathlen); +#else snprintf(path, sizeof(path), "%scover%s.bmp", dir, size_string); found = file_exists(path); +#endif } }