Index: apps/recorder/bmp.c =================================================================== --- apps/recorder/bmp.c (Revision 16312) +++ apps/recorder/bmp.c (Arbeitskopie) @@ -162,6 +162,33 @@ return ret; } +int get_bmp_size(int fd, struct bitmap *bmp) +{ + struct bmp_header bmph; + + int ret = read(fd, &bmph, sizeof(struct bmp_header)); + + if (ret < 0) + return ret * 10 - 2; + + if (ret != sizeof(struct bmp_header)) { + DEBUGF("get_bmp_size: can't read BMP header."); + return -3; + } + + bmp->width = readlong(&bmph.width); + bmp->height = readlong(&bmph.height); + + /* Top-down BMP file */ + if (bmp->height < 0) + bmp->height = -bmp->height; + + if (-1 == lseek(fd, -ret, SEEK_CUR)) + return 0; + + return bmp->width * bmp->height * sizeof(fb_data); +} + /****************************************************************************** * read_bmp_fd() * Index: apps/recorder/bmp.h =================================================================== --- apps/recorder/bmp.h (Revision 16312) +++ apps/recorder/bmp.h (Arbeitskopie) @@ -39,4 +39,8 @@ struct bitmap *bm, int maxsize, int format); + +int get_bmp_size(int fd, + struct bitmap *bmp); + #endif Index: apps/recorder/albumart.c =================================================================== --- apps/recorder/albumart.c (Revision 16312) +++ apps/recorder/albumart.c (Arbeitskopie) @@ -29,6 +29,7 @@ #include "misc.h" #include "settings.h" +#define SCALE 1000 /* Strip filename from a full path * @@ -292,3 +293,50 @@ gwps->display->set_drawmode(DRMODE_SOLID); } } + +int get_albumart_size(struct bitmap *dst_bmp, struct bitmap *src_bmp) +{ + struct wps_data *data = gui_wps[0].data; + short aa_max_width = data->albumart_max_width; + short aa_max_height = data->albumart_max_height; + const unsigned short aa_xscaling = data->albumart_xscaling; + const unsigned short aa_yscaling = data->albumart_yscaling; + const short width = src_bmp->width; + const short height = src_bmp->height; + + dst_bmp->width = width; + dst_bmp->height = height; + + if (aa_max_width == 0) + aa_max_width = width; + if (aa_max_height == 0) + aa_max_height = height; + + if (((aa_xscaling & WPS_ALBUMART_DECREASE) && (aa_max_width < width)) || + ((aa_xscaling & WPS_ALBUMART_INCREASE) && (aa_max_width > width)) || + ((aa_yscaling & WPS_ALBUMART_DECREASE) && (aa_max_height < height)) || + ((aa_yscaling & WPS_ALBUMART_INCREASE) && (aa_max_height > height))) + { + /* need to resize */ + const unsigned long factx = aa_max_width * SCALE / width; + const unsigned long facty = aa_max_height * SCALE / height; + + if (factx == facty) + { + dst_bmp->width = aa_max_width; + dst_bmp->height = aa_max_height; + } + else if (factx < facty) + { + dst_bmp->width = aa_max_width; + dst_bmp->height = (height * factx + SCALE/2) / SCALE; + } + else + { + dst_bmp->width = (width * facty + SCALE/2) / SCALE; + dst_bmp->height = aa_max_height; + } + } + + return dst_bmp->width * dst_bmp->height * sizeof(fb_data); +} Index: apps/recorder/albumart.h =================================================================== --- apps/recorder/albumart.h (Revision 16312) +++ apps/recorder/albumart.h (Arbeitskopie) @@ -38,6 +38,8 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, char *buf, int buflen); +int get_albumart_size(struct bitmap *dst_bmp, struct bitmap *src_bmp); + #endif /* HAVE_ALBUMART */ #endif /* _ALBUMART_H_ */ Index: apps/gui/gwps.h =================================================================== --- apps/gui/gwps.h (Revision 16312) +++ apps/gui/gwps.h (Arbeitskopie) @@ -341,10 +341,11 @@ unsigned char wps_uses_albumart; /* WPS_ALBUMART_NONE, _CHECK, _LOAD */ short albumart_x; short albumart_y; - unsigned short albumart_xalign; /* WPS_ALBUMART_ALIGN_LEFT, _CENTER, _RIGHT, - + .._INCREASE, + .._DECREASE */ - unsigned short albumart_yalign; /* WPS_ALBUMART_ALIGN_TOP, _CENTER, _BOTTOM, - + .._INCREASE, + .._DECREASE */ + unsigned short albumart_xalign; /* WPS_ALBUMART_ALIGN_LEFT, _CENTER, _RIGHT */ + unsigned short albumart_yalign; /* WPS_ALBUMART_ALIGN_TOP, _CENTER, _BOTTOM */ + /* A bit redeundant imo, but needed if we want to have scaling without keeping the original aspect ratio */ + unsigned short albumart_xscaling; /* WPS_ALBUMART_INCREASE, _DECREASE */ + unsigned short albumart_yscaling; /* WPS_ALBUMART_INCREASE, _DECREASE */ short albumart_max_width; short albumart_max_height; Index: apps/gui/wps_parser.c =================================================================== --- apps/gui/wps_parser.c (Revision 16312) +++ apps/gui/wps_parser.c (Arbeitskopie) @@ -662,6 +662,8 @@ wps_data->albumart_max_height = -1; wps_data->albumart_xalign = WPS_ALBUMART_ALIGN_CENTER; /* default */ wps_data->albumart_yalign = WPS_ALBUMART_ALIGN_CENTER; /* default */ + wps_data->albumart_xscaling = (WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE); /* default */ + wps_data->albumart_yscaling = (WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE); /* default */ /* format: %Cl|x|y|[[l|c|r][d|i|s]mwidth]|[[t|c|b][d|i|s]mheight]| */ @@ -717,15 +719,15 @@ break; case 'd': case 'D': - wps_data->albumart_xalign |= WPS_ALBUMART_DECREASE; + wps_data->albumart_xscaling |= WPS_ALBUMART_DECREASE; break; case 'i': case 'I': - wps_data->albumart_xalign |= WPS_ALBUMART_INCREASE; + wps_data->albumart_xscaling |= WPS_ALBUMART_INCREASE; break; case 's': case 'S': - wps_data->albumart_xalign |= + wps_data->albumart_xscaling |= (WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE); break; default: @@ -777,15 +779,15 @@ break; case 'd': case 'D': - wps_data->albumart_yalign |= WPS_ALBUMART_DECREASE; + wps_data->albumart_yscaling |= WPS_ALBUMART_DECREASE; break; case 'i': case 'I': - wps_data->albumart_yalign |= WPS_ALBUMART_INCREASE; + wps_data->albumart_yscaling |= WPS_ALBUMART_INCREASE; break; case 's': case 'S': - wps_data->albumart_yalign |= + wps_data->albumart_yscaling |= (WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE); break; default: Index: apps/SOURCES =================================================================== --- apps/SOURCES (Revision 16312) +++ apps/SOURCES (Arbeitskopie) @@ -78,6 +78,7 @@ recorder/peakmeter.c #ifdef HAVE_ALBUMART recorder/albumart.c +plugins/lib/bmp_smooth_scale.c #endif #ifdef HAVE_LCD_COLOR gui/color_picker.c Index: apps/buffering.c =================================================================== --- apps/buffering.c (Revision 16312) +++ apps/buffering.c (Arbeitskopie) @@ -49,6 +49,8 @@ #include "pcmbuf.h" #include "buffer.h" #include "bmp.h" +#include "albumart.h" +#include "plugins/lib/bmp.h" #ifdef SIMULATOR #define ata_disk_is_active() 1 @@ -833,16 +835,58 @@ static int load_bitmap(const int fd) { int rc; - struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; + struct bitmap *bmp, orig_bmp; + int free, orig_sz; + + orig_sz = get_bmp_size(fd, &orig_bmp); + + if (orig_sz <= 0) + return orig_sz; + + bmp = (struct bitmap *)&buffer[buf_widx]; + free = (int)MIN(buffer_len - BUF_USED, buffer_len - buf_widx) + - sizeof(struct bitmap); + + rc = get_albumart_size(bmp, &orig_bmp); + + if (rc > free) + return 0; + /* FIXME: alignment may be needed for the data buffer. */ bmp->data = &buffer[buf_widx + sizeof(struct bitmap)]; + if (bmp->width == orig_bmp.width && bmp->height == orig_bmp.height) + { #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) - bmp->maskdata = NULL; + bmp->maskdata = NULL; #endif + rc = read_bmp_fd(fd, bmp, free, FORMAT_ANY|FORMAT_DITHER); + } + else + { + int ex_free = free - rc; - int free = (int)MIN(buffer_len - BUF_USED, buffer_len - buf_widx); - rc = read_bmp_fd(fd, bmp, free, FORMAT_ANY|FORMAT_DITHER); + if (orig_sz > ex_free) + return 0; + +#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) + orig_bmp.maskdata = NULL; +#endif + /* FIXME: alignment may be needed for the data buffer. */ + orig_bmp.data = &buffer[buf_widx + sizeof(struct bitmap) + rc]; + + orig_sz = read_bmp_fd(fd, &orig_bmp, ex_free, FORMAT_ANY|FORMAT_DITHER); + + if (orig_sz <= 0) + return orig_sz; + +#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) + bmp->maskdata = orig_bmp.maskdata; + bmp->format = orig_bmp.format; +#endif + smooth_resize_bitmap(&orig_bmp, bmp); + } + return rc + (rc > 0 ? sizeof(struct bitmap) : 0); } #endif