Index: apps/recorder/albumart.c =================================================================== --- apps/recorder/albumart.c (revision 16132) +++ apps/recorder/albumart.c (working copy) @@ -28,6 +28,7 @@ #include "debug.h" #include "misc.h" #include "settings.h" +#include "buffer.h" /* Strip filename from a full path @@ -224,6 +225,48 @@ bool find_albumart(const struct mp3entry return search_albumart_files(id3, size_string, buf, buflen); } +/** + * Very simple image scale from src to dst (nearest neighbour). + * Source and destination dimensions are read from the struct bitmap. + * */ +static void simple_resize_bitmap(struct bitmap *src, struct bitmap *dst) +{ + const int srcw = src->width; + const int srch = src->height; + const int dstw = dst->width; + const int dsth = dst->height; + const fb_data *srcd = (fb_data*)(src->data); + const fb_data *dstd = (fb_data*)(dst->data); + + const long xrstep = ((srcw-1) << 8) / (dstw-1); + const long yrstep = ((srch-1) << 8) / (dsth-1); + fb_data *src_row, *dst_row; + long xr, yr = 0; + int src_x, src_y, dst_x, dst_y; + for (dst_y=0; dst_y < dsth; dst_y++) + { + src_y = (yr >> 8); + src_row = (fb_data*)&srcd[src_y * srcw]; + dst_row = (fb_data*)&dstd[dst_y * dstw]; + for (xr=0,dst_x=0; dst_x < dstw; dst_x++) + { + src_x = (xr >> 8); + dst_row[dst_x] = src_row[src_x]; + xr += xrstep; + } + yr += yrstep; + } +} + +#define SCALE 1000 +#define OUTPUT_SIZE (LCD_WIDTH*LCD_HEIGHT) +static fb_data *output_bmp_buffer; + +void albumart_resize_init(void) +{ + output_bmp_buffer = buffer_alloc(OUTPUT_SIZE * sizeof(fb_data)); +} + /* Draw the album art bitmap from the given handle ID onto the given WPS. Call with clear = true to clear the bitmap instead of drawing it. */ void draw_album_art(struct gui_wps *gwps, int handle_id, bool clear) @@ -239,7 +282,7 @@ void draw_album_art(struct gui_wps *gwps return; #endif - struct bitmap *bmp; + struct bitmap *bmp, output_bmp; if (bufgetdata(handle_id, 0, (void *)&bmp) <= 0) return; @@ -248,6 +291,36 @@ void draw_album_art(struct gui_wps *gwps short width = bmp->width; short height = bmp->height; + if (((data->albumart_xalign & WPS_ALBUMART_DECREASE) && (data->albumart_max_width < bmp->width)) || + ((data->albumart_xalign & WPS_ALBUMART_INCREASE) && (data->albumart_max_width > bmp->width)) || + ((data->albumart_yalign & WPS_ALBUMART_DECREASE) && (data->albumart_max_height < bmp->height)) || + ((data->albumart_yalign & WPS_ALBUMART_INCREASE) && (data->albumart_max_height > bmp->height))) + { + unsigned long factx = data->albumart_max_width * SCALE / bmp->width; + unsigned long facty = data->albumart_max_height * SCALE / bmp->height; + unsigned long fact = MIN(factx, facty); + + /* resize image */ + output_bmp.width = (bmp->width * fact + SCALE/2) / SCALE; + output_bmp.height = (bmp->height * fact + SCALE/2) / SCALE; + + if (output_bmp.width != bmp->width || output_bmp.height != bmp->height) + { + output_bmp.format = bmp->format; + output_bmp.maskdata = NULL; + + if (!clear) + { + output_bmp.data = (char *)output_bmp_buffer; + simple_resize_bitmap(bmp, &output_bmp); + } + + /* Resized bitmap is now in the output buffer, + copy it back to the bmp buffer */ + bmp = &output_bmp; + } + } + if (data->albumart_max_width > 0) { /* Crop if the bitmap is too wide */ Index: apps/recorder/albumart.h =================================================================== --- apps/recorder/albumart.h (revision 16132) +++ apps/recorder/albumart.h (working copy) @@ -37,6 +37,7 @@ void draw_album_art(struct gui_wps *gwps bool search_albumart_files(const struct mp3entry *id3, const char *size_string, char *buf, int buflen); +void albumart_resize_init(void); #endif /* HAVE_ALBUMART */ Index: apps/gui/gwps.c =================================================================== --- apps/gui/gwps.c (revision 16132) +++ apps/gui/gwps.c (working copy) @@ -56,6 +56,9 @@ #include "cuesheet.h" #include "ata_idle_notify.h" #include "root_menu.h" +#ifdef HAVE_ALBUMART +#include "albumart.h" +#endif #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1)) #include "backdrop.h" @@ -795,6 +798,9 @@ void gui_sync_wps_init(void) #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 unload_remote_wps_backdrop(); #endif +#ifdef HAVE_ALBUMART + albumart_resize_init(); +#endif } #ifdef HAVE_ALBUMART