diff --git a/apps/buffering.c b/apps/buffering.c index a4d425f..66e3d8d 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(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 - 3, "bmp")) + rc = read_bmp_file(path, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| + FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); + else + rc = read_jpeg_file(path, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| + FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); return rc + (rc > 0 ? sizeof(struct bitmap) : 0); } #endif @@ -911,11 +917,22 @@ int bufopen(const char *file, size_t offset, enum data_type type) /* Other cases: there is a little more work. */ - int fd = open(file, O_RDONLY); - if (fd < 0) - return ERR_FILE_ERROR; + size_t size; + int fd; +#ifdef HAVE_ALBUMART + /* load_image() handles the file open */ + if (type != TYPE_BITMAP) +#endif + { + fd = open(file, O_RDONLY); + if (fd < 0) + return ERR_FILE_ERROR; + size = filesize(fd); + } +#ifdef HAVE_ALBUMART + else size = 0; +#endif - size_t size = filesize(fd); bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC; size_t adjusted_offset = offset; @@ -942,12 +959,11 @@ 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(file); mutex_unlock(&llist_mutex); if (rc <= 0) { rm_handle(h); - close(fd); return ERR_FILE_ERROR; } h->filerem = 0; diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c index 327f4df..db17481 100644 --- a/apps/recorder/albumart.c +++ b/apps/recorder/albumart.c @@ -91,6 +91,30 @@ 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) +{ + DEBUGF("try_exts\n"); + int i; + for (i = 0; i < 3; i++) + { + if (extension_lens[i] + len > MAX_PATH) + continue; + strcpy(path + len, extensions[i]); + DEBUGF("try path %s\n",path); + if (file_exists(path)) + return true; + } + DEBUGF("none found\n"); + return false; +} +#endif + /* Look for the first matching album art bitmap in the following list: * ./.bmp * ./.bmp @@ -113,6 +137,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,18 +162,31 @@ 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 } artist = id3->albumartist != NULL ? id3->albumartist : id3->artist; @@ -154,6 +194,15 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, 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 +210,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 +230,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 } }