1
0
Fork 0
forked from len0rd/rockbox

Search for, and load, JPEG album art files.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20837 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andrew Mahone 2009-05-01 23:31:43 +00:00
parent 60d4209383
commit 54e6eb3bda
2 changed files with 78 additions and 4 deletions

View file

@ -53,6 +53,7 @@
#include "metadata.h" #include "metadata.h"
#ifdef HAVE_ALBUMART #ifdef HAVE_ALBUMART
#include "albumart.h" #include "albumart.h"
#include "jpeg_load.h"
#endif #endif
#define GUARD_BUFSIZE (32*1024) #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 /* 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. buffer, with a struct bitmap and the actual data immediately following.
Return value is the total size (struct + data). */ 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 rc;
int pathlen = strlen(path);
struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx];
/* FIXME: alignment may be needed for the data buffer. */ /* FIXME: alignment may be needed for the data buffer. */
bmp->data = &buffer[buf_widx + sizeof(struct bitmap)]; bmp->data = &buffer[buf_widx + sizeof(struct bitmap)];
@ -846,8 +848,12 @@ static int load_bitmap(int fd)
get_albumart_size(bmp); get_albumart_size(bmp);
rc = read_bmp_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| if (strcmp(path + pathlen - 4, ".bmp"))
FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); 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); return rc + (rc > 0 ? sizeof(struct bitmap) : 0);
} }
#endif #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 */ /* Bitmap file: we load the data instead of the file */
int rc; int rc;
mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */
rc = load_bitmap(fd); rc = load_image(fd, file);
mutex_unlock(&llist_mutex); mutex_unlock(&llist_mutex);
if (rc <= 0) if (rc <= 0)
{ {

View file

@ -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: /* Look for the first matching album art bitmap in the following list:
* ./<trackname><size>.bmp * ./<trackname><size>.bmp
* ./<albumname><size>.bmp * ./<albumname><size>.bmp
@ -113,6 +134,9 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
const char *artist; const char *artist;
int dirlen; int dirlen;
int albumlen; int albumlen;
#if LCD_DEPTH > 1
int pathlen;
#endif
if (!id3 || !buf) if (!id3 || !buf)
return false; return false;
@ -135,25 +159,55 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
{ {
/* if it doesn't exist, /* if it doesn't exist,
* we look for a file specific to the track's album name */ * 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), snprintf(path, sizeof(path),
"%s%s%s.bmp", dir, id3->album, size_string); "%s%s%s.bmp", dir, id3->album, size_string);
fix_path_part(path, dirlen, albumlen); fix_path_part(path, dirlen, albumlen);
found = file_exists(path); found = file_exists(path);
#endif
} }
if (!found) if (!found)
{ {
/* if it still doesn't exist, we look for a generic file */ /* 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), snprintf(path, sizeof(path),
"%scover%s.bmp", dir, size_string); "%scover%s.bmp", dir, size_string);
found = file_exists(path); 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; artist = id3->albumartist != NULL ? id3->albumartist : id3->artist;
if (!found && artist && id3->album) if (!found && artist && id3->album)
{ {
/* look in the albumart subdir of .rockbox */ /* 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), snprintf(path, sizeof(path),
ROCKBOX_DIR "/albumart/%s-%s%s.bmp", ROCKBOX_DIR "/albumart/%s-%s%s.bmp",
artist, artist,
@ -161,6 +215,7 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
size_string); size_string);
fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH);
found = file_exists(path); found = file_exists(path);
#endif
} }
if (!found) if (!found)
@ -180,19 +235,32 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
{ {
/* we look in the parent directory /* we look in the parent directory
* for a file specific to the track's album name */ * 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), snprintf(path, sizeof(path),
"%s%s%s.bmp", dir, id3->album, size_string); "%s%s%s.bmp", dir, id3->album, size_string);
fix_path_part(path, dirlen, albumlen); fix_path_part(path, dirlen, albumlen);
found = file_exists(path); found = file_exists(path);
#endif
} }
if (!found) if (!found)
{ {
/* if it still doesn't exist, we look in the parent directory /* if it still doesn't exist, we look in the parent directory
* for a generic file */ * 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), snprintf(path, sizeof(path),
"%scover%s.bmp", dir, size_string); "%scover%s.bmp", dir, size_string);
found = file_exists(path); found = file_exists(path);
#endif
} }
} }