Index: apps/recorder/albumart.c =================================================================== --- apps/recorder/albumart.c (revision 16170) +++ apps/recorder/albumart.c (working copy) @@ -224,6 +224,10 @@ bool find_albumart(const struct mp3entry return search_albumart_files(id3, size_string, buf, buflen); } +#include + +#define SCALE 1000 + /* 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 +243,8 @@ void draw_album_art(struct gui_wps *gwps return; #endif - struct bitmap *bmp; + struct bitmap *bmp, output_bmp; + int output_size = 0; if (bufgetdata(handle_id, 0, (void *)&bmp) <= 0) return; @@ -247,29 +252,77 @@ void draw_album_art(struct gui_wps *gwps short y = data->albumart_y; short width = bmp->width; short height = bmp->height; + short aa_max_width = data->albumart_max_width; + short aa_max_height = data->albumart_max_height; + unsigned short aa_xalign = data->albumart_xalign; + unsigned short aa_yalign = data->albumart_yalign; + + 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))) + { + unsigned long factx = aa_max_width * SCALE / width; + unsigned long facty = aa_max_height * SCALE / height; + unsigned long fact = MIN(factx, facty); + + /* resize image */ + short tmp_width = (width * fact + SCALE/2) / SCALE; + short tmp_height = (height * fact + SCALE/2) / SCALE; + + if (tmp_width != width || tmp_height != height) + { + output_bmp.width = tmp_width; + output_bmp.height = tmp_height; + output_bmp.format = bmp->format; + output_bmp.maskdata = NULL; + + if (!clear) + { + output_size = tmp_width * tmp_height * sizeof(fb_data); + if (output_size > data->img_buf_free) + { + /* Can't allocate the resized album art */ + output_size = 0; + goto out; + } + + output_bmp.data = data->img_buf_ptr; + data->img_buf_ptr += output_size; + data->img_buf_free -= output_size; + + smooth_resize_bitmap(bmp, &output_bmp); + } + + /* Resized bitmap is now in the output buffer, + copy it back to the bmp buffer */ + bmp = &output_bmp; + } + } +out: - if (data->albumart_max_width > 0) + if (aa_max_width > 0) { /* Crop if the bitmap is too wide */ - width = MIN(bmp->width, data->albumart_max_width); + width = MIN(bmp->width, aa_max_width); /* Align */ - if (data->albumart_xalign & WPS_ALBUMART_ALIGN_RIGHT) - x += data->albumart_max_width - width; - else if (data->albumart_xalign & WPS_ALBUMART_ALIGN_CENTER) - x += (data->albumart_max_width - width) / 2; + if (aa_xalign & WPS_ALBUMART_ALIGN_RIGHT) + x += aa_max_width - width; + else if (aa_xalign & WPS_ALBUMART_ALIGN_CENTER) + x += (aa_max_width - width) / 2; } - if (data->albumart_max_height > 0) + if (aa_max_height > 0) { /* Crop if the bitmap is too high */ - height = MIN(bmp->height, data->albumart_max_height); + height = MIN(bmp->height, aa_max_height); /* Align */ - if (data->albumart_yalign & WPS_ALBUMART_ALIGN_BOTTOM) - y += data->albumart_max_height - height; - else if (data->albumart_yalign & WPS_ALBUMART_ALIGN_CENTER) - y += (data->albumart_max_height - height) / 2; + if (aa_yalign & WPS_ALBUMART_ALIGN_BOTTOM) + y += aa_max_height - height; + else if (aa_yalign & WPS_ALBUMART_ALIGN_CENTER) + y += (aa_max_height - height) / 2; } if (!clear) @@ -279,6 +332,9 @@ void draw_album_art(struct gui_wps *gwps gwps->display->bitmap_part((fb_data*)bmp->data, 0, 0, bmp->width, x, y, width, height); gwps->display->set_drawmode(DRMODE_SOLID); + if (output_size) + data->img_buf_ptr -= output_size; + data->img_buf_free += output_size; } else { Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 16170) +++ apps/SOURCES (working copy) @@ -78,6 +78,7 @@ recorder/keyboard.c recorder/peakmeter.c #ifdef HAVE_ALBUMART recorder/albumart.c +plugins/lib/bmp_smooth_scale.c #endif #ifdef HAVE_LCD_COLOR gui/color_picker.c