summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 123c7bc85f..9c0ad138f7 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -52,6 +52,7 @@
52#include "albumart.h" 52#include "albumart.h"
53#include "jpeg_load.h" 53#include "jpeg_load.h"
54#include "bmp.h" 54#include "bmp.h"
55#include "playback.h"
55#endif 56#endif
56 57
57#define GUARD_BUFSIZE (32*1024) 58#define GUARD_BUFSIZE (32*1024)
@@ -908,10 +909,12 @@ static bool fill_buffer(void)
908/* Given a file descriptor to a bitmap file, write the bitmap data to the 909/* Given a file descriptor to a bitmap file, write the bitmap data to the
909 buffer, with a struct bitmap and the actual data immediately following. 910 buffer, with a struct bitmap and the actual data immediately following.
910 Return value is the total size (struct + data). */ 911 Return value is the total size (struct + data). */
911static int load_image(int fd, const char *path, struct dim *dim) 912static int load_image(int fd, const char *path, struct bufopen_bitmap_data *data)
912{ 913{
913 int rc; 914 int rc;
914 struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; 915 struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx];
916 struct dim *dim = data->dim;
917 struct mp3_albumart *aa = data->embedded_albumart;
915 918
916 /* get the desired image size */ 919 /* get the desired image size */
917 bmp->width = dim->width, bmp->height = dim->height; 920 bmp->width = dim->width, bmp->height = dim->height;
@@ -928,8 +931,13 @@ static int load_image(int fd, const char *path, struct dim *dim)
928 - sizeof(struct bitmap); 931 - sizeof(struct bitmap);
929 932
930#ifdef HAVE_JPEG 933#ifdef HAVE_JPEG
931 int pathlen = strlen(path); 934 if (aa != NULL)
932 if (strcmp(path + pathlen - 4, ".bmp")) 935 {
936 lseek(fd, aa->pos, SEEK_SET);
937 rc = clip_jpeg_fd(fd, aa->size, bmp, free, FORMAT_NATIVE|FORMAT_DITHER|
938 FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL);
939 }
940 else if (strcmp(path + strlen(path) - 4, ".bmp"))
933 rc = read_jpeg_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| 941 rc = read_jpeg_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER|
934 FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); 942 FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL);
935 else 943 else
@@ -1010,7 +1018,18 @@ int bufopen(const char *file, size_t offset, enum data_type type,
1010 if (fd < 0) 1018 if (fd < 0)
1011 return ERR_FILE_ERROR; 1019 return ERR_FILE_ERROR;
1012 1020
1013 size_t size = filesize(fd); 1021 size_t size = 0;
1022#ifdef HAVE_ALBUMART
1023 if (type == TYPE_BITMAP)
1024 { /* if albumart is embedded, the complete file is not buffered,
1025 * but only the jpeg part; filesize() would be wrong */
1026 struct bufopen_bitmap_data *aa = (struct bufopen_bitmap_data*)user_data;
1027 if (aa->embedded_albumart)
1028 size = aa->embedded_albumart->size;
1029 }
1030#endif
1031 if (size == 0)
1032 size = filesize(fd);
1014 bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC; 1033 bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC;
1015 1034
1016 size_t adjusted_offset = offset; 1035 size_t adjusted_offset = offset;
@@ -1058,7 +1077,7 @@ int bufopen(const char *file, size_t offset, enum data_type type,
1058 /* Bitmap file: we load the data instead of the file */ 1077 /* Bitmap file: we load the data instead of the file */
1059 int rc; 1078 int rc;
1060 mutex_lock(&llist_mod_mutex); /* Lock because load_bitmap yields */ 1079 mutex_lock(&llist_mod_mutex); /* Lock because load_bitmap yields */
1061 rc = load_image(fd, file, (struct dim*)user_data); 1080 rc = load_image(fd, file, (struct bufopen_bitmap_data*)user_data);
1062 mutex_unlock(&llist_mod_mutex); 1081 mutex_unlock(&llist_mod_mutex);
1063 if (rc <= 0) 1082 if (rc <= 0)
1064 { 1083 {