Index: apps/recorder/albumart.c =================================================================== --- apps/recorder/albumart.c (revision 16132) +++ apps/recorder/albumart.c (working copy) @@ -224,6 +224,41 @@ 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 + /* 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 +274,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; @@ -248,6 +284,48 @@ 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 = data->img_buf_ptr; + + output_size = output_bmp.width * output_bmp.height * sizeof(fb_data); + if (output_size > data->img_buf_free) + { + /* Can't allocate the resized album art */ + output_size = 0; + goto out; + } + data->img_buf_ptr += output_size; + data->img_buf_free -= output_size; + + simple_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) { /* Crop if the bitmap is too wide */ @@ -279,6 +357,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 {