summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-05-01 23:31:43 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-05-01 23:31:43 +0000
commit54e6eb3bdaea5a904d77a50866cb400857427c08 (patch)
treeb4fcb445f7e005cf50db9bdb36bcb5cb6fbddb76
parent60d420938372477226184fb9012de7f6b4ea2d83 (diff)
downloadrockbox-54e6eb3bdaea5a904d77a50866cb400857427c08.zip
rockbox-54e6eb3bdaea5a904d77a50866cb400857427c08.tar.gz
rockbox-54e6eb3bdaea5a904d77a50866cb400857427c08.tar.bz2
rockbox-54e6eb3bdaea5a904d77a50866cb400857427c08.tar.xz
Search for, and load, JPEG album art files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20837 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/buffering.c14
-rw-r--r--apps/recorder/albumart.c68
2 files changed, 78 insertions, 4 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index a4d425f..66bd22f 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 327f4df..cf4a3e8 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:
* ./<trackname><size>.bmp
* ./<albumname><size>.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
}
}