Index: apps/recorder/albumart.c =================================================================== --- apps/recorder/albumart.c (revision 16114) +++ apps/recorder/albumart.c (working copy) @@ -224,6 +224,42 @@ 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 +static fb_data output_bmp_buffer[LCD_WIDTH*LCD_HEIGHT]; + /* 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 +275,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 +284,34 @@ void draw_album_art(struct gui_wps *gwps short width = bmp->width; short height = bmp->height; + output_bmp.format = bmp->format; + output_bmp.data = (char *)output_bmp_buffer; + + 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; + if (factx < facty) + fact = factx; + else + fact = 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) + { + 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 */