Index: apps/recorder/albumart.c =================================================================== --- apps/recorder/albumart.c (revision 16230) +++ apps/recorder/albumart.c (working copy) @@ -28,7 +28,9 @@ #include "debug.h" #include "misc.h" #include "settings.h" +#include "plugins/lib/bmp.h" +#define SCALE 1000 /* Strip filename from a full path * @@ -292,3 +294,72 @@ void draw_album_art(struct gui_wps *gwps gwps->display->set_drawmode(DRMODE_SOLID); } } + +int albumart_resize_bmp(struct bitmap *bmp, int bmp_byte, int free) +{ + struct wps_data *data = gui_wps[0].data; + struct bitmap output_bmp; + short aa_max_width = data->albumart_max_width; + short aa_max_height = data->albumart_max_height; + const unsigned short aa_xalign = data->albumart_xalign; + const unsigned short aa_yalign = data->albumart_yalign; + const short width = bmp->width; + const short height = bmp->height; + + int output_size = 0; + + if (aa_max_width == 0 && aa_max_height == 0) + return bmp_byte; + + if (!(((aa_xalign & WPS_ALBUMART_DECREASE) && (aa_max_width < width)) || + ((aa_xalign & WPS_ALBUMART_INCREASE) && (aa_max_width > width)) || + ((aa_yalign & WPS_ALBUMART_DECREASE) && (aa_max_height < height)) || + ((aa_yalign & WPS_ALBUMART_INCREASE) && (aa_max_height > height)))) + return bmp_byte; + + if (aa_max_width == 0) + aa_max_width = aa_max_height; + else if (aa_max_height == 0) + aa_max_height = aa_max_width; + + const unsigned long factx = aa_max_width * SCALE / width; + const unsigned long facty = aa_max_height * SCALE / height; + const unsigned long fact = MIN(factx, facty); + + /* resize image */ + const short tmp_width = (width * fact + SCALE/2) / SCALE; + const short tmp_height = (height * fact + SCALE/2) / SCALE; + + if (tmp_width == width && tmp_height == height) + return bmp_byte; + + output_size = tmp_width * tmp_height * sizeof(fb_data); + + /* Can't allocate the resized album art */ + if (output_size > data->img_buf_free || output_size > free) + return bmp_byte; + + output_bmp.width = tmp_width; + output_bmp.height = tmp_height; + output_bmp.format = bmp->format; + output_bmp.maskdata = bmp->maskdata; + output_bmp.data = data->img_buf_ptr; + + data->img_buf_ptr += output_size; + data->img_buf_free -= output_size; + +#ifdef HAVE_LCD_COLOR + smooth_resize_bitmap(bmp, &output_bmp); +#else /* HAVE_LCD_COLOR */ + simple_resize_bitmap(bmp, &output_bmp); +#endif /* HAVE_LCD_COLOR */ + + bmp->width = tmp_width; + bmp->height = tmp_height; + memcpy(bmp->data, output_bmp.data, output_size); + + data->img_buf_ptr -= output_size; + data->img_buf_free += output_size; + + return output_size; +} Index: apps/recorder/albumart.h =================================================================== --- apps/recorder/albumart.h (revision 16230) +++ apps/recorder/albumart.h (working copy) @@ -38,6 +38,8 @@ void draw_album_art(struct gui_wps *gwps bool search_albumart_files(const struct mp3entry *id3, const char *size_string, char *buf, int buflen); +int albumart_resize_bmp(struct bitmap *bmp, int bmp_byte, int free); + #endif /* HAVE_ALBUMART */ #endif /* _ALBUMART_H_ */ Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 16230) +++ apps/SOURCES (working copy) @@ -78,6 +78,11 @@ recorder/keyboard.c recorder/peakmeter.c #ifdef HAVE_ALBUMART recorder/albumart.c +#ifdef HAVE_LCD_COLOR +plugins/lib/bmp_smooth_scale.c +#else +plugins/lib/bmp.c +#endif #endif #ifdef HAVE_LCD_COLOR gui/color_picker.c Index: apps/buffering.c =================================================================== --- apps/buffering.c (revision 16230) +++ apps/buffering.c (working copy) @@ -49,6 +49,7 @@ #include "pcmbuf.h" #include "buffer.h" #include "bmp.h" +#include "albumart.h" #ifdef SIMULATOR #define ata_disk_is_active() 1 @@ -841,6 +842,10 @@ static int load_bitmap(const int fd) int free = (int)MIN(buffer_len - BUF_USED, buffer_len - buf_widx); rc = read_bmp_fd(fd, bmp, free, FORMAT_ANY|FORMAT_DITHER); + + if (rc > 0) + rc = albumart_resize_bmp(bmp, rc, free - sizeof(struct bitmap)); + return rc + (rc > 0 ? sizeof(struct bitmap) : 0); } #endif